Skip to content
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 @@ -73,6 +73,7 @@
- Change timestamp in elatic-agent-json.log to use UTC {issue}25391[25391]
- Fix add support for Logstash output. {pull}24305[24305]
- Do not log Elasticsearch configuration for monitoring output when running with debug. {pull}26583[26583]
- Fix issue where proxy enrollment options broke enrollment command. {pull}26749[26749]

==== New features

Expand Down
21 changes: 11 additions & 10 deletions x-pack/elastic-agent/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,15 @@ func (c *enrollCmd) Execute(ctx context.Context) error {
// will communicate to the internal fleet server on localhost only.
// Connection setup should disable proxies in that case.
localFleetServer := c.options.FleetServer.ConnStr != ""
if localFleetServer {
token, err := c.fleetServerBootstrap(ctx)
if err != nil {
return err
Comment thread
blakerouse marked this conversation as resolved.
}
if c.options.EnrollAPIKey == "" && token != "" {
c.options.EnrollAPIKey = token
}
}

c.remoteConfig, err = c.options.remoteConfig()
if err != nil {
Expand All @@ -208,19 +217,10 @@ func (c *enrollCmd) Execute(ctx context.Context) error {
errors.TypeConfig,
errors.M(errors.MetaKeyURI, c.options.URL))
}

if localFleetServer {
// Ensure that the agent does not use a proxy configuration
// when connecting to the local fleet server.
c.remoteConfig.Transport.Proxy.Disable = true

token, err := c.fleetServerBootstrap(ctx)
if err != nil {
return err
}
if c.options.EnrollAPIKey == "" && token != "" {
c.options.EnrollAPIKey = token
}
}

c.client, err = fleetclient.NewWithConfig(c.log, c.remoteConfig)
Expand Down Expand Up @@ -402,6 +402,7 @@ func (c *enrollCmd) daemonReload(ctx context.Context) error {
func (c *enrollCmd) enrollWithBackoff(ctx context.Context, persistentConfig map[string]interface{}) error {
delay(ctx, enrollDelay)

c.log.Infof("Starting enrollment to URL: %s", c.client.URI())
err := c.enroll(ctx, persistentConfig)
signal := make(chan struct{})
backExp := backoff.NewExpBackoff(signal, 60*time.Second, 10*time.Minute)
Expand All @@ -419,7 +420,7 @@ func (c *enrollCmd) enrollWithBackoff(ctx context.Context, persistentConfig map[
break
}
backExp.Wait()
c.log.Info("Retrying to enroll...")
c.log.Infof("Retrying enrollment to URL: %s", c.client.URI())
err = c.enroll(ctx, persistentConfig)
}

Expand Down