Skip to content

Commit b67442e

Browse files
authored
[Elastic Agent] Add fleet.host.id for sending to endpoint. (#21042)
* Add fleet.host.id for sending to endpoint. * Add changelog entry.
1 parent c2efa09 commit b67442e

5 files changed

Lines changed: 23 additions & 3 deletions

File tree

x-pack/elastic-agent/CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@
1919
- Users of the Docker image can now pass `FLEET_ENROLL_INSECURE=1` to include the `--insecure` flag with the `elastic-agent enroll` command {issue}20312[20312] {pull}20713[20713]
2020
- Add support for dynamic inputs with providers and `{{variable|"default"}}` substitution. {pull}20839[20839]
2121
- Add support for EQL based condition on inputs {pull}20994[20994]
22+
- Send `fleet.host.id` to Endpoint Security {pull}21042[21042]

x-pack/elastic-agent/pkg/agent/application/fleet_decorator.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ package application
77
import (
88
"fmt"
99

10+
"github.com/elastic/go-sysinfo/types"
11+
1012
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/transpiler"
1113
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config"
1214
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger"
1315
)
1416

15-
func injectFleet(cfg *config.Config) func(*logger.Logger, *transpiler.AST) error {
17+
func injectFleet(cfg *config.Config, hostInfo types.HostInfo) func(*logger.Logger, *transpiler.AST) error {
1618
return func(logger *logger.Logger, rootAst *transpiler.AST) error {
1719
config, err := cfg.ToMapStr()
1820
if err != nil {
@@ -37,7 +39,11 @@ func injectFleet(cfg *config.Config) func(*logger.Logger, *transpiler.AST) error
3739
return fmt.Errorf("failed to get agent key from fleet config")
3840
}
3941

40-
fleet := transpiler.NewDict([]transpiler.Node{agent, token, kbn})
42+
host := transpiler.NewKey("host", transpiler.NewDict([]transpiler.Node{
43+
transpiler.NewKey("id", transpiler.NewStrVal(hostInfo.UniqueID)),
44+
}))
45+
46+
fleet := transpiler.NewDict([]transpiler.Node{agent, token, kbn, host})
4147
err = transpiler.Insert(rootAst, fleet, "fleet")
4248
if err != nil {
4349
return err

x-pack/elastic-agent/pkg/agent/application/managed_mode.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import (
1111
"net/http"
1212
"net/url"
1313

14+
"github.com/elastic/go-sysinfo"
15+
1416
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/filters"
1517
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info"
1618
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configuration"
@@ -113,6 +115,13 @@ func newManaged(
113115
errors.M(errors.MetaKeyURI, cfg.Fleet.Kibana.Host))
114116
}
115117

118+
sysInfo, err := sysinfo.Host()
119+
if err != nil {
120+
return nil, errors.New(err,
121+
"fail to get system information",
122+
errors.TypeUnexpected)
123+
}
124+
116125
managedApplication := &Managed{
117126
log: log,
118127
agentInfo: agentInfo,
@@ -160,7 +169,7 @@ func newManaged(
160169
router,
161170
&configModifiers{
162171
Decorators: []decoratorFunc{injectMonitoring},
163-
Filters: []filterFunc{filters.StreamChecker, injectFleet(config)},
172+
Filters: []filterFunc{filters.StreamChecker, injectFleet(config, sysInfo.Info())},
164173
},
165174
monitor,
166175
)

x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic-endpoint-security.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ revision: 5
22
fleet:
33
agent:
44
id: fleet-agent-id
5+
host:
6+
id: host-agent-id
57
api:
68
access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw
79
kibana:

x-pack/elastic-agent/pkg/agent/program/testdata/endpoint_basic.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ name: Endpoint Host
33
fleet:
44
agent:
55
id: fleet-agent-id
6+
host:
7+
id: host-agent-id
68
access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw
79
kibana:
810
protocol: https

0 commit comments

Comments
 (0)