WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions cmd/system-probe/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package command

import (
"os"
"path/filepath"
"slices"
"strings"

Expand All @@ -27,10 +28,27 @@ type GlobalParams struct {
// file, to allow overrides from the command line
ConfFilePath string

// datadogConfFilePath holds the path to the folder containing the datadog.yaml configuration file
datadogConfFilePath string

// FleetPoliciesDirPath holds the path to the folder containing the fleet policies
FleetPoliciesDirPath string
}

// DatadogConfFilePath uses a fallback from datadogConfFilePath to ConfFilePath if not specified
func (g GlobalParams) DatadogConfFilePath() string {
confPath := g.datadogConfFilePath
// if no explicit path provided for datadog.yaml, fallback to provided directory of system-probe.yaml
if confPath == "" && g.ConfFilePath != "" {
confPath = g.ConfFilePath
if strings.HasSuffix(confPath, ".yaml") {
// strip filename because it is specifying system-probe.yaml file, not datadog.yaml
confPath = filepath.Dir(confPath)
}
}
return confPath
}

// SubcommandFactory is a callable that will return a slice of subcommands.
type SubcommandFactory func(globalParams *GlobalParams) []*cobra.Command

Expand All @@ -50,6 +68,7 @@ Runtime Security Monitoring, Universal Service Monitoring, and others.`,
}

sysprobeCmd.PersistentFlags().StringVarP(&globalParams.ConfFilePath, "config", "c", "", "path to directory containing system-probe.yaml")
sysprobeCmd.PersistentFlags().StringVarP(&globalParams.datadogConfFilePath, "datadogcfgpath", "", "", "path to directory containing datadog.yaml")
sysprobeCmd.PersistentFlags().StringVarP(&globalParams.FleetPoliciesDirPath, "fleetcfgpath", "", "", "path to the directory containing fleet policies")
_ = sysprobeCmd.PersistentFlags().MarkHidden("fleetcfgpath")

Expand Down
29 changes: 29 additions & 0 deletions cmd/system-probe/command/command_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2025-present Datadog, Inc.

package command

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDatadogConfPath(t *testing.T) {
cases := []struct {
params GlobalParams
expected string
}{
{GlobalParams{}, ""},
{GlobalParams{ConfFilePath: "/some/other/dir"}, "/some/other/dir"},
{GlobalParams{ConfFilePath: "/some/other/dir/system-probe.yaml"}, "/some/other/dir"},
{GlobalParams{ConfFilePath: "/some/other/dir", datadogConfFilePath: "/another/dir"}, "/another/dir"},
{GlobalParams{ConfFilePath: "/some/other/dir", datadogConfFilePath: "/another/dir/datadog.yaml"}, "/another/dir/datadog.yaml"},
}

for _, c := range cases {
assert.Equal(t, c.expected, c.params.DatadogConfFilePath(), "%+v", c.params)
}
}
8 changes: 4 additions & 4 deletions cmd/system-probe/subcommands/compliance/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
}

// CheckCommand returns the 'compliance check' command
func CheckCommand(_ *command.GlobalParams) *cobra.Command {
func CheckCommand(globalParams *command.GlobalParams) *cobra.Command {
checkArgs := &cli.CheckParams{}

cmd := &cobra.Command{
Use: "check",
Short: "Run compliance check(s)",
RunE: func(_ *cobra.Command, args []string) error {
bundleParams := core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true),
}

Expand All @@ -73,7 +73,7 @@ func CheckCommand(_ *command.GlobalParams) *cobra.Command {
return cmd
}

func complianceLoadCommand(_ *command.GlobalParams) *cobra.Command {
func complianceLoadCommand(globalParams *command.GlobalParams) *cobra.Command {
loadArgs := &cli.LoadParams{}

loadCmd := &cobra.Command{
Expand All @@ -85,7 +85,7 @@ func complianceLoadCommand(_ *command.GlobalParams) *cobra.Command {
return fxutil.OneShot(cli.RunLoad,
fx.Supply(loadArgs),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true),
}),
core.Bundle(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/system-probe/subcommands/config/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
return fxutil.OneShot(callback,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath), sysprobeconfigimpl.WithFleetPoliciesDirPath(globalParams.FleetPoliciesDirPath)),
LogParams: log.ForOneShot(command.LoggerName, "off", true),
}),
Expand Down
2 changes: 1 addition & 1 deletion cmd/system-probe/subcommands/coverage/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
return fxutil.OneShot(requestCoverage,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath), sysprobeconfigimpl.WithFleetPoliciesDirPath(globalParams.FleetPoliciesDirPath)),
LogParams: log.ForOneShot(command.LoggerName, "off", false),
}),
Expand Down
2 changes: 1 addition & 1 deletion cmd/system-probe/subcommands/debug/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
return fxutil.OneShot(debugRuntime,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath), sysprobeconfigimpl.WithFleetPoliciesDirPath(globalParams.FleetPoliciesDirPath)),
LogParams: log.ForOneShot(command.LoggerName, "off", false),
}),
Expand Down
2 changes: 1 addition & 1 deletion cmd/system-probe/subcommands/modrestart/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
return fxutil.OneShot(moduleRestart,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
SysprobeConfigParams: sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath), sysprobeconfigimpl.WithFleetPoliciesDirPath(globalParams.FleetPoliciesDirPath)),
LogParams: log.ForOneShot(command.LoggerName, "off", false),
}),
Expand Down
2 changes: 1 addition & 1 deletion cmd/system-probe/subcommands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
Long: `Runs the system-probe in the foreground`,
RunE: func(_ *cobra.Command, _ []string) error {
return fxutil.OneShot(run,
fx.Supply(config.NewAgentParams("")),
fx.Supply(config.NewAgentParams(globalParams.DatadogConfFilePath())),
// Force FX to load Datadog configuration before System Probe config.
// This is necessary because the 'software_inventory.enabled' setting is defined in the Datadog configuration.
// Without this explicit dependency, FX might initialize System Probe's config first, causing pkgconfigsetup.Datadog().GetBool()
Expand Down
12 changes: 6 additions & 6 deletions cmd/system-probe/subcommands/runtime/activity_dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ func activityDumpCommands(globalParams *command.GlobalParams) []*cobra.Command {
return []*cobra.Command{activityDumpCmd}
}

func listCommands(_ *command.GlobalParams) []*cobra.Command {
func listCommands(globalParams *command.GlobalParams) []*cobra.Command {
activityDumpListCmd := &cobra.Command{
Use: "list",
Short: "get the list of running activity dumps",
RunE: func(_ *cobra.Command, _ []string) error {
return fxutil.OneShot(listActivityDumps,
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand All @@ -92,7 +92,7 @@ func stopCommands(globalParams *command.GlobalParams) []*cobra.Command {
return fxutil.OneShot(stopActivityDump,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down Expand Up @@ -145,7 +145,7 @@ func generateDumpCommands(globalParams *command.GlobalParams) []*cobra.Command {
return fxutil.OneShot(generateActivityDump,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down Expand Up @@ -223,7 +223,7 @@ func generateEncodingCommands(globalParams *command.GlobalParams) []*cobra.Comma
return fxutil.OneShot(generateEncodingFromActivityDump,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down Expand Up @@ -284,7 +284,7 @@ func diffCommands(globalParams *command.GlobalParams) []*cobra.Command {
return fxutil.OneShot(diffActivityDump,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down
22 changes: 11 additions & 11 deletions cmd/system-probe/subcommands/runtime/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func evalCommands(globalParams *command.GlobalParams) []*cobra.Command {
return fxutil.OneShot(evalRule,
fx.Supply(evalArgs),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "off", false)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down Expand Up @@ -118,7 +118,7 @@ func commonCheckPoliciesCommands(globalParams *command.GlobalParams) []*cobra.Co
return fxutil.OneShot(checkPolicies,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "off", false)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand All @@ -135,14 +135,14 @@ func commonCheckPoliciesCommands(globalParams *command.GlobalParams) []*cobra.Co
return []*cobra.Command{commonCheckPoliciesCmd}
}

func commonReloadPoliciesCommands(_ *command.GlobalParams) []*cobra.Command {
func commonReloadPoliciesCommands(globalParams *command.GlobalParams) []*cobra.Command {
commonReloadPoliciesCmd := &cobra.Command{
Use: "reload",
Short: "Reload policies",
RunE: func(_ *cobra.Command, _ []string) error {
return fxutil.OneShot(reloadRuntimePolicies,
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand All @@ -153,14 +153,14 @@ func commonReloadPoliciesCommands(_ *command.GlobalParams) []*cobra.Command {
}

// nolint: deadcode, unused
func selfTestCommands(_ *command.GlobalParams) []*cobra.Command {
func selfTestCommands(globalParams *command.GlobalParams) []*cobra.Command {
selfTestCmd := &cobra.Command{
Use: "self-test",
Short: "Run runtime self test",
RunE: func(_ *cobra.Command, _ []string) error {
return fxutil.OneShot(runRuntimeSelfTest,
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down Expand Up @@ -191,7 +191,7 @@ func downloadPolicyCommands(globalParams *command.GlobalParams) []*cobra.Command
return fxutil.OneShot(downloadPolicy,
fx.Supply(downloadPolicyArgs),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(globalParams.ConfFilePath),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "off", false)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down Expand Up @@ -227,7 +227,7 @@ func processCacheCommands(globalParams *command.GlobalParams) []*cobra.Command {
return fxutil.OneShot(dumpProcessCache,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down Expand Up @@ -266,7 +266,7 @@ func networkNamespaceCommands(globalParams *command.GlobalParams) []*cobra.Comma
return fxutil.OneShot(dumpNetworkNamespace,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand All @@ -285,15 +285,15 @@ func networkNamespaceCommands(globalParams *command.GlobalParams) []*cobra.Comma
}

//nolint:unused // TODO(SEC) Fix unused linter
func discardersCommands(_ *command.GlobalParams) []*cobra.Command {
func discardersCommands(globalParams *command.GlobalParams) []*cobra.Command {

dumpDiscardersCmd := &cobra.Command{
Use: "dump",
Short: "dump discarders",
RunE: func(_ *cobra.Command, _ []string) error {
return fxutil.OneShot(dumpDiscarders,
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down
6 changes: 3 additions & 3 deletions cmd/system-probe/subcommands/runtime/security_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func securityProfileShowCommands(globalParams *command.GlobalParams) []*cobra.Co
return fxutil.OneShot(showSecurityProfile,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down Expand Up @@ -107,7 +107,7 @@ func listSecurityProfileCommands(globalParams *command.GlobalParams) []*cobra.Co
return fxutil.OneShot(listSecurityProfiles,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down Expand Up @@ -221,7 +221,7 @@ func saveSecurityProfileCommands(globalParams *command.GlobalParams) []*cobra.Co
return fxutil.OneShot(saveSecurityProfile,
fx.Supply(cliParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
LogParams: log.ForOneShot(command.LoggerName, "info", true)}),
core.Bundle(),
secretsnoopfx.Module(),
Expand Down
2 changes: 1 addition & 1 deletion cmd/system-probe/subcommands/usm/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func makeOneShotCommand(
runFunc,
fx.Supply(globalParams),
fx.Supply(core.BundleParams{
ConfigParams: config.NewAgentParams(""),
ConfigParams: config.NewAgentParams(globalParams.DatadogConfFilePath()),
SysprobeConfigParams: sysconfigimpl.NewParams(
sysconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath),
sysconfigimpl.WithFleetPoliciesDirPath(globalParams.FleetPoliciesDirPath)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
upgrade:
- |
system-probe will now attempt to read `datadog.yaml` from the same directory as `system-probe.yaml`.
Previously, system-probe would always use the default configuration directory to read `datadog.yaml`.
If you need to specify a different directory for `datadog.yaml`, you may use the `--datadogcfgpath` CLI argument to system-probe.