From fcc35c3dee090882825f5c80120789b551dd7c0d Mon Sep 17 00:00:00 2001 From: Dustin Long Date: Tue, 21 Nov 2023 12:17:30 -0500 Subject: [PATCH] Remove fx.Supply(params) from system-probe, enable trace-agent, fix tests --- cmd/agent/subcommands/diagnose/command_test.go | 4 ++-- cmd/agent/subcommands/run/command_windows.go | 2 +- cmd/system-probe/subcommands/run/command.go | 4 ---- cmd/trace-agent/subcommands/run/command.go | 2 ++ cmd/trace-agent/test/testsuite/secrets_test.go | 2 +- comp/core/config/config.go | 3 ++- comp/core/secrets/secretsimpl/exec_windows.go | 7 +++++-- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/cmd/agent/subcommands/diagnose/command_test.go b/cmd/agent/subcommands/diagnose/command_test.go index d72468da1d80f..e65974556221f 100644 --- a/cmd/agent/subcommands/diagnose/command_test.go +++ b/cmd/agent/subcommands/diagnose/command_test.go @@ -75,8 +75,8 @@ func TestShowMetadataInventoryHostCommand(t *testing.T) { Commands(&command.GlobalParams{}), []string{"diagnose", "show-metadata", "inventory-host"}, printPayload, - func(cliParams *cliParams, coreParams core.BundleParams) { - require.Equal(t, false, coreParams.ConfigLoadSecrets()) + func(cliParams *cliParams, coreParams core.BundleParams, secretParams secrets.Params) { + require.Equal(t, false, secretParams.Enabled) require.Equal(t, "inventory-host", cliParams.payloadName) }) } diff --git a/cmd/agent/subcommands/run/command_windows.go b/cmd/agent/subcommands/run/command_windows.go index 0608618c65a09..7e88d057bda77 100644 --- a/cmd/agent/subcommands/run/command_windows.go +++ b/cmd/agent/subcommands/run/command_windows.go @@ -114,8 +114,8 @@ func StartAgentWithDefaults(ctxChan <-chan context.Context) (<-chan error, error hostMetadata, invAgent, invHost, + secretResolver, ) - secretResolver) if err != nil { return err } diff --git a/cmd/system-probe/subcommands/run/command.go b/cmd/system-probe/subcommands/run/command.go index 65411135354d2..f288aa756c310 100644 --- a/cmd/system-probe/subcommands/run/command.go +++ b/cmd/system-probe/subcommands/run/command.go @@ -29,8 +29,6 @@ import ( "github.com/DataDog/datadog-agent/cmd/system-probe/utils" "github.com/DataDog/datadog-agent/comp/core/config" "github.com/DataDog/datadog-agent/comp/core/log" - "github.com/DataDog/datadog-agent/comp/core/secrets" - "github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig" "github.com/DataDog/datadog-agent/comp/core/sysprobeconfig/sysprobeconfigimpl" "github.com/DataDog/datadog-agent/comp/core/telemetry" @@ -74,13 +72,11 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command { fx.Supply(cliParams), fx.Supply(config.NewAgentParams("", config.WithConfigMissingOK(true))), fx.Supply(sysprobeconfigimpl.NewParams(sysprobeconfigimpl.WithSysProbeConfFilePath(globalParams.ConfFilePath))), - fx.Supply(secrets.NewDisabledParams()), fx.Supply(log.ForDaemon("SYS-PROBE", "log_file", common.DefaultLogFile)), config.Module, telemetry.Module, sysprobeconfigimpl.Module, rcclient.Module, - secretsimpl.Module, // use system-probe config instead of agent config for logging fx.Provide(func(lc fx.Lifecycle, params log.Params, sysprobeconfig sysprobeconfig.Component) (log.Component, error) { return log.NewLogger(lc, params, sysprobeconfig) diff --git a/cmd/trace-agent/subcommands/run/command.go b/cmd/trace-agent/subcommands/run/command.go index 274e9151d3b19..eeb896e88e36b 100644 --- a/cmd/trace-agent/subcommands/run/command.go +++ b/cmd/trace-agent/subcommands/run/command.go @@ -17,6 +17,7 @@ import ( coreconfig "github.com/DataDog/datadog-agent/comp/core/config" corelog "github.com/DataDog/datadog-agent/comp/core/log" "github.com/DataDog/datadog-agent/comp/core/secrets" + "github.com/DataDog/datadog-agent/comp/core/secrets/secretsimpl" "github.com/DataDog/datadog-agent/comp/core/workloadmeta" "github.com/DataDog/datadog-agent/comp/core/workloadmeta/collectors" "github.com/DataDog/datadog-agent/comp/trace" @@ -64,6 +65,7 @@ func runFx(ctx context.Context, cliParams *RunParams, defaultConfPath string) er // to allow the agent to work as a service. fx.Provide(func() context.Context { return ctx }), // fx.Supply(ctx) fails with a missing type error. fx.Supply(coreconfig.NewAgentParams(cliParams.ConfPath)), + secretsimpl.Module, fx.Supply(secrets.NewEnabledParams()), coreconfig.Module, fx.Provide(func() corelog.Params { diff --git a/cmd/trace-agent/test/testsuite/secrets_test.go b/cmd/trace-agent/test/testsuite/secrets_test.go index 840a4b7b1bc76..b36af03955384 100644 --- a/cmd/trace-agent/test/testsuite/secrets_test.go +++ b/cmd/trace-agent/test/testsuite/secrets_test.go @@ -23,7 +23,7 @@ func TestSecrets(t *testing.T) { // install trace-agent with -tags=secrets binTraceAgent := filepath.Join(tmpDir, "trace-agent") - cmd := exec.Command("go", "build", "-o", binTraceAgent, "-tags=secrets", "github.com/DataDog/datadog-agent/cmd/trace-agent") + cmd := exec.Command("go", "build", "-o", binTraceAgent, "github.com/DataDog/datadog-agent/cmd/trace-agent") cmd.Stdout = io.Discard if err := cmd.Run(); err != nil { t.Skip(err.Error()) diff --git a/comp/core/config/config.go b/comp/core/config/config.go index cc2f98eb78c15..a74673cc88614 100644 --- a/comp/core/config/config.go +++ b/comp/core/config/config.go @@ -39,7 +39,8 @@ type dependencies struct { fx.In Params Params - Secret secrets.Component + // secrets Component is optional, if not provided, the config will not decrypt secrets + Secret secrets.Component `optional:"true"` } func (d dependencies) getParams() *Params { diff --git a/comp/core/secrets/secretsimpl/exec_windows.go b/comp/core/secrets/secretsimpl/exec_windows.go index 2d37d05f7c4ca..820300228f22d 100644 --- a/comp/core/secrets/secretsimpl/exec_windows.go +++ b/comp/core/secrets/secretsimpl/exec_windows.go @@ -93,8 +93,11 @@ func getServicePid(serviceName string) (uint32, error) { m := &mgr.Mgr{Handle: h} defer m.Disconnect() - hSvc, err := windows.OpenService(m.Handle, syscall.StringToUTF16Ptr(serviceName), - windows.SERVICE_QUERY_STATUS) + utf16ServiceName, err := syscall.UTF16PtrFromString(serviceName) + if err != nil { + return 0, fmt.Errorf("invalid service name %s: %v", serviceName, err) + } + hSvc, err := windows.OpenService(m.Handle, utf16ServiceName, windows.SERVICE_QUERY_STATUS) if err != nil { return 0, fmt.Errorf("could not access service %s: %v", serviceName, err) }