Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -485,16 +485,8 @@ main-build-dockerized: build-volumes

.PHONY: main-build-nodeps
main-build-nodeps:
$(GOBUILD) \
central \
compliance/cmd/compliance \
config-controller \
migrator \
operator/cmd \
sensor/admission-control \
sensor/kubernetes \
sensor/upgrader \
compliance/virtualmachines/roxagent
$(GOBUILD) central
$(GOBUILD) operator/cmd
mv bin/linux_$(GOARCH)/cmd bin/linux_$(GOARCH)/stackrox-operator
ifndef CI
CGO_ENABLED=0 $(GOBUILD) roxctl
Expand Down
69 changes: 68 additions & 1 deletion central/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"net/http"
"os"
"os/signal"
"path/filepath"
"syscall"
"time"

Expand Down Expand Up @@ -230,6 +231,15 @@
"github.com/stackrox/rox/pkg/sync"
"github.com/stackrox/rox/pkg/utils"
pkgVersion "github.com/stackrox/rox/pkg/version"

// BusyBox-style consolidation - import app packages
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Importing app packages into central causes their init() side effects (like memlimit.SetMemoryLimit) to run in the central process as well.

Some of these .../app packages (e.g. compliance, admission-control, k8s sensor, roxagent) call memlimit.SetMemoryLimit() or other side-effectful logic in init(). With these imports now always pulled into the central binary, that logic also runs when central starts, not just for the symlinked binaries. To avoid unintended impact on central’s own resource configuration, consider moving such calls out of init() and into the respective Run() paths so they only execute when that app is actually invoked.

complianceapp "github.com/stackrox/rox/compliance/cmd/compliance/app"

Check failure on line 236 in central/main.go

View workflow job for this annotation

GitHub Actions / style-check

invalid import "github.com/stackrox/rox/compliance/cmd/compliance/app": central cannot import from compliance/cmd/compliance/app; only allowed roots are [central generated image pkg tests/bad-ca]
roxagentapp "github.com/stackrox/rox/compliance/virtualmachines/roxagent/app"

Check failure on line 237 in central/main.go

View workflow job for this annotation

GitHub Actions / style-check

invalid import "github.com/stackrox/rox/compliance/virtualmachines/roxagent/app": central cannot import from compliance/virtualmachines/roxagent/app; only allowed roots are [central generated image pkg tests/bad-ca]
configcontrollerapp "github.com/stackrox/rox/config-controller/app"

Check failure on line 238 in central/main.go

View workflow job for this annotation

GitHub Actions / style-check

invalid import "github.com/stackrox/rox/config-controller/app": central cannot import from config-controller/app; only allowed roots are [central generated image pkg tests/bad-ca]
migratorapp "github.com/stackrox/rox/migrator/app"

Check failure on line 239 in central/main.go

View workflow job for this annotation

GitHub Actions / style-check

invalid import "github.com/stackrox/rox/migrator/app": central cannot import from migrator/app; only allowed roots are [central generated image pkg tests/bad-ca]
admissioncontrolapp "github.com/stackrox/rox/sensor/admission-control/app"

Check failure on line 240 in central/main.go

View workflow job for this annotation

GitHub Actions / style-check

invalid import "github.com/stackrox/rox/sensor/admission-control/app": central cannot import from sensor/admission-control/app; only allowed roots are [central generated image pkg tests/bad-ca]
kubernetessensorapp "github.com/stackrox/rox/sensor/kubernetes/app"

Check failure on line 241 in central/main.go

View workflow job for this annotation

GitHub Actions / style-check

invalid import "github.com/stackrox/rox/sensor/kubernetes/app": central cannot import from sensor/kubernetes/app; only allowed roots are [central generated image pkg tests/bad-ca]
sensorupgraderapp "github.com/stackrox/rox/sensor/upgrader/app"

Check failure on line 242 in central/main.go

View workflow job for this annotation

GitHub Actions / style-check

invalid import "github.com/stackrox/rox/sensor/upgrader/app": central cannot import from sensor/upgrader/app; only allowed roots are [central generated image pkg tests/bad-ca]
)
Comment on lines +234 to 243
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix import formatting: pipeline failure due to extra blank line.

The CI style check failed because of an extra blank line before the BusyBox imports block.

Suggested fix
 	pkgVersion "github.com/stackrox/rox/pkg/version"
-
 	// BusyBox-style consolidation - import app packages
 	complianceapp "github.com/stackrox/rox/compliance/cmd/compliance/app"
🧰 Tools
🪛 GitHub Actions: Style

[error] 234-234: style-slim failed: Too many blank lines in imports (imports formatting check)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@central/main.go` around lines 234 - 243, Remove the extra blank line
preceding the BusyBox-style consolidation import block so the import comment and
the grouped imports are contiguous; locate the import block that lists
complianceapp, roxagentapp, configcontrollerapp, migratorapp,
admissioncontrolapp, kubernetessensorapp, and sensorupgraderapp and delete the
stray empty line above the comment so the style check passes.


var (
Expand Down Expand Up @@ -278,7 +288,8 @@
log.Info("Central terminated")
}

func main() {
// Main is the exported entry point for the central binary.
func Main() {
defer utils.IgnoreError(log.InnerLogger.Sync)

premain.StartMain()
Expand Down Expand Up @@ -1061,3 +1072,59 @@
}
log.Info("Central terminated")
}

// Dispatcher wrapper functions for BusyBox-style invocation
func migratorMain() {
migratorapp.Run()
}

func complianceMain() {
complianceapp.Run()
}

func kubernetesSensorMain() {
kubernetessensorapp.Run()
}

func sensorUpgraderMain() {
sensorupgraderapp.Run()
}

func admissionControlMain() {
admissioncontrolapp.Run()
}

func configControllerMain() {
configcontrollerapp.Run()
}

func roxagentMain() {
roxagentapp.Run()
}

func main() {
// BusyBox-style dispatcher: check how we were called
binaryName := filepath.Base(os.Args[0])

switch binaryName {
case "central":
Main()
case "migrator":
migratorMain()
case "compliance":
complianceMain()
case "kubernetes-sensor":
Comment on lines +1107 to +1116
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): Defaulting to central on unknown binary names may hide misconfigurations.

Because any unexpected binaryName falls through to Main(), misnamed symlinks or typos will silently run central instead of failing fast. It would be safer to log a clear warning or exit non‑zero when the name is not recognized, so configuration issues are detected rather than masked.

Suggested implementation:

func main() {
	// BusyBox-style dispatcher: check how we were called
	binaryName := filepath.Base(os.Args[0])

	switch binaryName {
	case "central":
		Main()
	case "migrator":
		migratorMain()
	case "compliance":
		complianceMain()
	case "kubernetes-sensor":
		kubernetesSensorMain()
	case "sensor-upgrader":
		sensorUpgraderMain()
	case "admission-control":
		admissionControlMain()
	case "config-controller":
		configControllerMain()
	case "roxagent":
		roxagentMain()
	default:
		log.Errorf("unknown binary name %q; expected one of [central, migrator, compliance, kubernetes-sensor, sensor-upgrader, admission-control, config-controller, roxagent]", binaryName)
		os.Exit(1)
	}
}

You will also need to:

  1. Ensure the import block at the top of central/main.go includes:
    • "os"
    • "path/filepath"
  2. Confirm that log is a logger with Errorf available (e.g. from your existing logging package). If not, adjust the logging call to match your logging API.
  3. Make sure functions like Main, kubernetesSensorMain, sensorUpgraderMain, and admissionControlMain are defined in this file or imported from the appropriate packages.

kubernetesSensorMain()
case "sensor-upgrader":
sensorUpgraderMain()
case "admission-control":
admissionControlMain()
case "config-controller":
configControllerMain()
case "roxagent":
roxagentMain()
default:
// Default to central if called with unknown name
Main()
}
}
44 changes: 44 additions & 0 deletions compliance/cmd/compliance/app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package app

import (
"context"

"github.com/stackrox/rox/compliance"
"github.com/stackrox/rox/compliance/node"
"github.com/stackrox/rox/compliance/node/index"
"github.com/stackrox/rox/compliance/node/inventory"
"github.com/stackrox/rox/pkg/continuousprofiling"
"github.com/stackrox/rox/pkg/env"
"github.com/stackrox/rox/pkg/logging"
"github.com/stackrox/rox/pkg/memlimit"
"github.com/stackrox/rox/pkg/retry/handler"
)

func init() {
memlimit.SetMemoryLimit()
}

var (
log = logging.LoggerForModule()
)

// Run is the main entry point for the compliance application.
func Run() {
if err := continuousprofiling.SetupClient(continuousprofiling.DefaultConfig()); err != nil {
log.Errorf("unable to start continuous profiling: %v", err)
}

np := &node.EnvNodeNameProvider{}
cfg := index.DefaultNodeIndexerConfig()

scanner := inventory.NewNodeInventoryComponentScanner(np)
scanner.Connect(env.NodeScanningEndpoint.Setting())
cachedNodeIndexer := index.NewCachingNodeIndexer(cfg, env.NodeIndexCacheDuration.DurationSetting(), env.NodeIndexCachePath.Setting())

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
umhNodeInv := handler.NewUnconfirmedMessageHandler(ctx, "node-inventory", env.NodeScanningAckDeadlineBase.DurationSetting())
umhNodeIndex := handler.NewUnconfirmedMessageHandler(ctx, "node-index", env.NodeScanningAckDeadlineBase.DurationSetting())
c := compliance.NewComplianceApp(np, scanner, cachedNodeIndexer, umhNodeInv, umhNodeIndex)
c.Start()
}
40 changes: 2 additions & 38 deletions compliance/cmd/compliance/main.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,7 @@
package main

import (
"context"

"github.com/stackrox/rox/compliance"
"github.com/stackrox/rox/compliance/node"
"github.com/stackrox/rox/compliance/node/index"
"github.com/stackrox/rox/compliance/node/inventory"
"github.com/stackrox/rox/pkg/continuousprofiling"
"github.com/stackrox/rox/pkg/env"
"github.com/stackrox/rox/pkg/logging"
"github.com/stackrox/rox/pkg/memlimit"
"github.com/stackrox/rox/pkg/retry/handler"
)

func init() {
memlimit.SetMemoryLimit()
}

var (
log = logging.LoggerForModule()
)
import "github.com/stackrox/rox/compliance/cmd/compliance/app"

func main() {
if err := continuousprofiling.SetupClient(continuousprofiling.DefaultConfig()); err != nil {
log.Errorf("unable to start continuous profiling: %v", err)
}

np := &node.EnvNodeNameProvider{}
cfg := index.DefaultNodeIndexerConfig()

scanner := inventory.NewNodeInventoryComponentScanner(np)
scanner.Connect(env.NodeScanningEndpoint.Setting())
cachedNodeIndexer := index.NewCachingNodeIndexer(cfg, env.NodeIndexCacheDuration.DurationSetting(), env.NodeIndexCachePath.Setting())

ctx, cancel := context.WithCancel(context.Background())
defer cancel()
umhNodeInv := handler.NewUnconfirmedMessageHandler(ctx, "node-inventory", env.NodeScanningAckDeadlineBase.DurationSetting())
umhNodeIndex := handler.NewUnconfirmedMessageHandler(ctx, "node-index", env.NodeScanningAckDeadlineBase.DurationSetting())
c := compliance.NewComplianceApp(np, scanner, cachedNodeIndexer, umhNodeInv, umhNodeIndex)
c.Start()
app.Run()
}
37 changes: 37 additions & 0 deletions compliance/virtualmachines/roxagent/app/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package app

import (
"context"
"os"
"os/signal"
"syscall"

"github.com/stackrox/rox/compliance/virtualmachines/roxagent/cmd"
"github.com/stackrox/rox/pkg/logging"
)

var log = logging.LoggerForModule()

// Run is the main entry point for the roxagent application.
func Run() {
// Create a context that is cancellable on the usual command line signals. Double
// signal forcefully exits.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
sigC := make(chan os.Signal, 1)
signal.Notify(sigC, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigC
log.Errorf("%s caught, shutting down...", sig)
// Cancel the main context.
cancel()
go func() {
// A second signal will forcefully quit.
<-sigC
os.Exit(1)
}()
}()
if err := cmd.RootCmd(ctx).Execute(); err != nil {
log.Fatal(err)
}
}
33 changes: 2 additions & 31 deletions compliance/virtualmachines/roxagent/main.go
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
package main

import (
"context"
"os"
"os/signal"
"syscall"

"github.com/stackrox/rox/compliance/virtualmachines/roxagent/cmd"
"github.com/stackrox/rox/pkg/logging"
)

var log = logging.LoggerForModule()
import "github.com/stackrox/rox/compliance/virtualmachines/roxagent/app"

func main() {
// Create a context that is cancellable on the usual command line signals. Double
// signal forcefully exits.
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go func() {
sigC := make(chan os.Signal, 1)
signal.Notify(sigC, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigC
log.Errorf("%s caught, shutting down...", sig)
// Cancel the main context.
cancel()
go func() {
// A second signal will forcefully quit.
<-sigC
os.Exit(1)
}()
}()
if err := cmd.RootCmd(ctx).Execute(); err != nil {
log.Fatal(err)
}
app.Run()
}
Loading
Loading