Skip to content

Commit 87b5e65

Browse files
authored
security-agent: use remote hostname component (#43380)
### What does this PR do? Make use of the remote hostname component for fetching the hostname in the security agent (for both CWS and CSPM parts) instead of calling the underlying functions manually. ### Motivation ### Describe how you validated your changes ### Additional Notes Co-authored-by: paul.cacheux <[email protected]>
1 parent b2f9be6 commit 87b5e65

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

cmd/security-agent/subcommands/start/command.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import (
3131
"github.com/DataDog/datadog-agent/comp/core/config"
3232
"github.com/DataDog/datadog-agent/comp/core/configsync/configsyncimpl"
3333
fxinstrumentation "github.com/DataDog/datadog-agent/comp/core/fxinstrumentation/fx"
34-
"github.com/DataDog/datadog-agent/comp/core/hostname/hostnameimpl"
34+
"github.com/DataDog/datadog-agent/comp/core/hostname/hostnameinterface"
35+
"github.com/DataDog/datadog-agent/comp/core/hostname/remotehostnameimpl"
3536
ipc "github.com/DataDog/datadog-agent/comp/core/ipc/def"
3637
ipcfx "github.com/DataDog/datadog-agent/comp/core/ipc/fx"
3738
log "github.com/DataDog/datadog-agent/comp/core/log/def"
@@ -63,7 +64,6 @@ import (
6364
configutils "github.com/DataDog/datadog-agent/pkg/config/utils"
6465
ddruntime "github.com/DataDog/datadog-agent/pkg/runtime"
6566
"github.com/DataDog/datadog-agent/pkg/security/agent"
66-
"github.com/DataDog/datadog-agent/pkg/security/utils/hostnameutils"
6767
"github.com/DataDog/datadog-agent/pkg/status/health"
6868
"github.com/DataDog/datadog-agent/pkg/util/coredump"
6969
"github.com/DataDog/datadog-agent/pkg/util/fxutil"
@@ -101,7 +101,7 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
101101
LogParams: log.ForDaemon(command.LoggerName, "security_agent.log_file", pkgconfigsetup.DefaultSecurityAgentLogFile),
102102
}),
103103
core.Bundle(),
104-
hostnameimpl.Module(),
104+
remotehostnameimpl.Module(),
105105
statsd.Module(),
106106
secretsfx.Module(),
107107
// workloadmeta setup
@@ -116,8 +116,8 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
116116
fx.Provide(func(config config.Component, statsd statsd.Component) (ddgostatsd.ClientInterface, error) {
117117
return statsd.CreateForHostPort(configutils.GetBindHost(config), config.GetInt("dogstatsd_port"))
118118
}),
119-
fx.Provide(func(stopper startstop.Stopper, log log.Component, config config.Component, statsdClient ddgostatsd.ClientInterface, compression logscompression.Component, ipc ipc.Component) (status.InformationProvider, *agent.RuntimeSecurityAgent, error) {
120-
hostnameDetected, err := hostnameutils.GetHostnameWithContextAndFallback(context.TODO(), ipc)
119+
fx.Provide(func(stopper startstop.Stopper, log log.Component, config config.Component, statsdClient ddgostatsd.ClientInterface, compression logscompression.Component, hostname hostnameinterface.Component) (status.InformationProvider, *agent.RuntimeSecurityAgent, error) {
120+
hostnameDetected, err := hostname.Get(context.TODO())
121121
if err != nil {
122122
return status.NewInformationProvider(nil), nil, err
123123
}
@@ -134,8 +134,8 @@ func Commands(globalParams *command.GlobalParams) []*cobra.Command {
134134
// TODO - components: Do not remove runtimeAgent ref until "github.com/DataDog/datadog-agent/pkg/security/agent" is a component so they're not GCed
135135
return status.NewInformationProvider(runtimeAgent.StatusProvider()), runtimeAgent, nil
136136
}),
137-
fx.Provide(func(stopper startstop.Stopper, log log.Component, config config.Component, statsdClient ddgostatsd.ClientInterface, sysprobeconfig sysprobeconfig.Component, wmeta workloadmeta.Component, compression logscompression.Component, ipc ipc.Component) (status.InformationProvider, *compliance.Agent, error) {
138-
hostnameDetected, err := hostnameutils.GetHostnameWithContextAndFallback(context.TODO(), ipc)
137+
fx.Provide(func(stopper startstop.Stopper, log log.Component, config config.Component, statsdClient ddgostatsd.ClientInterface, sysprobeconfig sysprobeconfig.Component, wmeta workloadmeta.Component, compression logscompression.Component, ipc ipc.Component, hostname hostnameinterface.Component) (status.InformationProvider, *compliance.Agent, error) {
138+
hostnameDetected, err := hostname.Get(context.TODO())
139139
if err != nil {
140140
return status.NewInformationProvider(nil), nil, err
141141
}

0 commit comments

Comments
 (0)