-
Notifications
You must be signed in to change notification settings - Fork 168
Pass --header
enrollment option to fleet-server
#8071
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
base: main
Are you sure you want to change the base?
Changes from all commits
20d706d
a605062
735671e
8d5d663
7a181cd
36e7d3e
09f458f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 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: enhancement | ||
|
||
# Change summary; a 80ish characters long description of the change. | ||
summary: Add --header to enrollment communication with Fleet Server | ||
|
||
# Long description; in case the summary is not enough to describe the change | ||
# this field accommodate a description without length limits. | ||
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment. | ||
description: | | ||
The --header option for the enrollment command now adds the headers to the communication with Fleet Server. This | ||
allows a proxy that requires specific headers present for traffic to flow to be placed in front of a Fleet Server | ||
to be used and still allowing the Elastic Agent to enroll. | ||
|
||
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc. | ||
component: elastic-agent | ||
|
||
# PR URL; 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: https://github.com/elastic/elastic-agent/pull/8071 | ||
|
||
# Issue URL; 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: https://github.com/elastic/elastic-agent/issues/6823 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,10 +57,7 @@ func (m *mockStore) Save(in io.Reader) error { | |
|
||
func TestEnroll(t *testing.T) { | ||
testutils.InitStorage(t) | ||
skipCreateSecret := false | ||
if runtime.GOOS == "darwin" { | ||
skipCreateSecret = true | ||
} | ||
skipCreateSecret := runtime.GOOS == "darwin" | ||
|
||
log, _ := logger.New("tst", false) | ||
|
||
|
@@ -424,6 +421,79 @@ func TestEnroll(t *testing.T) { | |
assert.Equal(t, host, config.Client.Host) | ||
}, | ||
)) | ||
|
||
t.Run("headers are sent to server", withServer( | ||
func(t *testing.T) *http.ServeMux { | ||
mux := http.NewServeMux() | ||
mux.HandleFunc("/api/fleet/agents/enroll", func(w http.ResponseWriter, r *http.Request) { | ||
if r.Header.Get("X-Test-Header") != "Test-Value" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This proves we use a header for I see in enroll.go we explicitly add the header to |
||
w.WriteHeader(http.StatusInternalServerError) | ||
_, _ = w.Write([]byte(` | ||
{ | ||
"statusCode": 500, | ||
"error": "Missing required X-Test-Header header" | ||
}`)) | ||
return | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
_, _ = w.Write([]byte(` | ||
{ | ||
"action": "created", | ||
"item": { | ||
"id": "a9328860-ec54-11e9-93c4-d72ab8a69391", | ||
"active": true, | ||
"policy_id": "69f3f5a0-ec52-11e9-93c4-d72ab8a69391", | ||
"type": "PERMANENT", | ||
"enrolled_at": "2019-10-11T18:26:37.158Z", | ||
"user_provided_metadata": { | ||
"custom": "customize" | ||
}, | ||
"local_metadata": { | ||
"platform": "linux", | ||
"version": "8.0.0" | ||
}, | ||
"actions": [], | ||
"access_api_key": "my-access-api-key" | ||
} | ||
}`)) | ||
}) | ||
return mux | ||
}, func(t *testing.T, host string) { | ||
url := "http://" + host | ||
store := &mockStore{} | ||
cmd, err := newEnrollCmd( | ||
log, | ||
&enrollCmdOption{ | ||
URL: url, | ||
CAs: []string{}, | ||
EnrollAPIKey: "my-enrollment-api-key", | ||
Insecure: true, | ||
UserProvidedMetadata: map[string]interface{}{"custom": "customize"}, | ||
SkipCreateSecret: skipCreateSecret, | ||
SkipDaemonRestart: true, | ||
Headers: map[string]string{ | ||
"X-Test-Header": "Test-Value", | ||
}, | ||
}, | ||
"", | ||
store, | ||
nil, | ||
) | ||
require.NoError(t, err) | ||
|
||
streams, _, _, _ := cli.NewTestingIOStreams() | ||
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute) | ||
defer cancel() | ||
err = cmd.Execute(ctx, streams) | ||
require.NoError(t, err, "enroll command should return no error") | ||
|
||
assert.True(t, store.Called, "the store should have been called") | ||
config, err := readConfig(store.Content) | ||
require.NoError(t, err) | ||
assert.Equal(t, "my-access-api-key", config.AccessAPIKey) | ||
assert.Equal(t, host, config.Client.Host) | ||
}, | ||
)) | ||
} | ||
|
||
func TestValidateArgs(t *testing.T) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,11 +13,12 @@ import ( | |
|
||
// Config is the configuration for the client. | ||
type Config struct { | ||
Protocol Protocol `config:"protocol" yaml:"protocol,omitempty"` | ||
SpaceID string `config:"space.id" yaml:"space.id,omitempty"` | ||
Path string `config:"path" yaml:"path,omitempty"` | ||
Host string `config:"host" yaml:"host,omitempty"` | ||
Hosts []string `config:"hosts" yaml:"hosts,omitempty"` | ||
Protocol Protocol `config:"protocol" yaml:"protocol,omitempty"` | ||
SpaceID string `config:"space.id" yaml:"space.id,omitempty"` | ||
Path string `config:"path" yaml:"path,omitempty"` | ||
Host string `config:"host" yaml:"host,omitempty"` | ||
Hosts []string `config:"hosts" yaml:"hosts,omitempty"` | ||
Headers map[string]string `config:"headers" yaml:"headers,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the headers are secrets, is this going to leak them in diagnostics? Are they either already redacted or not included in diagnostics at all? |
||
|
||
Transport httpcommon.HTTPTransportSettings `config:",inline" yaml:",inline"` | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current version doesn't quite read correctly as a sentence to me.