Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Elastic Agent] Add fleet.host.id for sending to endpoint. #21042

Merged
merged 2 commits into from
Sep 14, 2020
Merged
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
1 change: 1 addition & 0 deletions x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@
- 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]
- Add support for dynamic inputs with providers and `{{variable|"default"}}` substitution. {pull}20839[20839]
- Add support for EQL based condition on inputs {pull}20994[20994]
- Send `fleet.host.id` to Endpoint Security {pull}21042[21042]
10 changes: 8 additions & 2 deletions x-pack/elastic-agent/pkg/agent/application/fleet_decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ package application
import (
"fmt"

"github.com/elastic/go-sysinfo/types"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/transpiler"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/logger"
)

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

fleet := transpiler.NewDict([]transpiler.Node{agent, token, kbn})
host := transpiler.NewKey("host", transpiler.NewDict([]transpiler.Node{
transpiler.NewKey("id", transpiler.NewStrVal(hostInfo.UniqueID)),
}))

fleet := transpiler.NewDict([]transpiler.Node{agent, token, kbn, host})
err = transpiler.Insert(rootAst, fleet, "fleet")
if err != nil {
return err
Expand Down
11 changes: 10 additions & 1 deletion x-pack/elastic-agent/pkg/agent/application/managed_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"net/http"
"net/url"

"github.com/elastic/go-sysinfo"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/filters"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/info"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configuration"
Expand Down Expand Up @@ -113,6 +115,13 @@ func newManaged(
errors.M(errors.MetaKeyURI, cfg.Fleet.Kibana.Host))
}

sysInfo, err := sysinfo.Host()
if err != nil {
return nil, errors.New(err,
"fail to get system information",
errors.TypeUnexpected)
}

managedApplication := &Managed{
log: log,
agentInfo: agentInfo,
Expand Down Expand Up @@ -160,7 +169,7 @@ func newManaged(
router,
&configModifiers{
Decorators: []decoratorFunc{injectMonitoring},
Filters: []filterFunc{filters.StreamChecker, injectFleet(config)},
Filters: []filterFunc{filters.StreamChecker, injectFleet(config, sysInfo.Info())},
},
monitor,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ revision: 5
fleet:
agent:
id: fleet-agent-id
host:
id: host-agent-id
api:
access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw
kibana:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Endpoint Host
fleet:
agent:
id: fleet-agent-id
host:
id: host-agent-id
access_api_key: VuaCfGcBCdbkQm-e5aOx:ui2lp2axTNmsyakw9tvNnw
kibana:
protocol: https
Expand Down