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

Change local fleet-server connection to localhost:8221 #1867

Merged
merged 4 commits into from
Dec 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
31 changes: 31 additions & 0 deletions changelog/fragments/1669929902-fix-local-fleet-server-port.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: bug-fix

# Change summary; a 80ish characters long description of the change.
summary: elastic-agent will use local port when running fleet-server

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
description: The elastic-agent will now use the 8221 locally bound port when running fleet-server instead of the external port (8220).

# Affected component; a word indicating the component this changeset affects.
component:

# PR number; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: 1234

# Issue number; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
#issue: 1234
10 changes: 9 additions & 1 deletion internal/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ func (c *enrollCmd) Execute(ctx context.Context, streams *cli.IOStreams) error {
if localFleetServer {
// Ensure that the agent does not use a proxy configuration
// when connecting to the local fleet server.
// TODO At this point remote config has $HOSTNAME:8220 - is that expected or do we part port 8221?
michel-laterman marked this conversation as resolved.
Show resolved Hide resolved
c.remoteConfig.Transport.Proxy.Disable = true
}

Expand Down Expand Up @@ -301,7 +302,10 @@ func (c *enrollCmd) writeDelayEnroll(streams *cli.IOStreams) error {
func (c *enrollCmd) fleetServerBootstrap(ctx context.Context, persistentConfig map[string]interface{}) (string, error) {
c.log.Debug("verifying communication with running Elastic Agent daemon")
agentRunning := true
_, err := getDaemonState(ctx)
if c.options.FleetServer.InternalPort == 0 {
c.options.FleetServer.InternalPort = defaultFleetServerInternalPort
}
Comment on lines +306 to +308
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The InternalURL is set when the agent is creating the fleet tls settings (line 321), however it expects a non-zero internal port value in order to do so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fine. we have a check like this inside createFleetServerBootstrapConfig i'm ok with moving this up.

_, err := getDaemonStatus(ctx)
if err != nil {
if !c.options.FleetServer.SpawnAgent {
// wait longer to try and communicate with the Elastic Agent
Expand Down Expand Up @@ -336,6 +340,7 @@ func (c *enrollCmd) fleetServerBootstrap(ctx context.Context, persistentConfig m
if err != nil {
return "", err
}
c.options.FleetServer.InternalPort = fleetConfig.Server.InternalPort

configToStore := map[string]interface{}{
"agent": agentConfig,
Expand Down Expand Up @@ -545,6 +550,9 @@ func (c *enrollCmd) enroll(ctx context.Context, persistentConfig map[string]inte
// use internal URL for future requests
if c.options.InternalURL != "" {
fleetConfig.Client.Host = c.options.InternalURL
// fleet-server will bind the internal listenter to localhost:8221
// InternalURL is localhost:8221, however cert uses $HOSTNAME, so we need to disable verification.
fleetConfig.Client.Transport.TLS.VerificationMode = tlscommon.VerifyNone
joshdover marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down