-
Notifications
You must be signed in to change notification settings - Fork 168
Adding test for enrolling local FIPS agent into ECH FIPS Fleet Server #8197
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
Open
ycombinator
wants to merge
2
commits into
elastic:main
Choose a base branch
from
ycombinator:fips-agent-enroll-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License 2.0; | ||
// you may not use this file except in compliance with the Elastic License 2.0. | ||
|
||
//go:build integration | ||
|
||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/elastic/elastic-agent-libs/kibana" | ||
"github.com/elastic/elastic-agent-libs/testing/estools" | ||
atesting "github.com/elastic/elastic-agent/pkg/testing" | ||
"github.com/elastic/elastic-agent/pkg/testing/define" | ||
"github.com/elastic/elastic-agent/pkg/testing/tools" | ||
|
||
"github.com/gofrs/uuid/v5" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestEnrollFIPS enrolls the locally-built FIPS-capable Elastic Agent into a | ||
// FIPS-capable Fleet Server running in ECH, adds an integration | ||
// to this Agent, and checks that data from the integration shows up in Elasticsearch. | ||
// This test proves that it's possible for a local (on-prem) FIPS-capable Elastic Agent | ||
// to enroll into a FIPS-capable Fleet Server (aka Integrations Server) running in ECH, | ||
// while also exercising the connection between Fleet and the Elastic Package Registry (EPR) | ||
// and also ensuring that the data path from Agent to Elasticsearch works as well. | ||
func TestEnrollFIPS(t *testing.T) { | ||
info := define.Require(t, define.Requirements{ | ||
Group: Fleet, | ||
Stack: &define.Stack{}, | ||
Local: false, // requires Agent installation | ||
Sudo: true, // requires Agent installation | ||
OS: []define.OS{ | ||
{Type: define.Linux}, | ||
}, | ||
FIPS: true, | ||
}) | ||
|
||
// Select FIPS-capable local Agent artifact | ||
fixture, err := define.NewFixtureFromLocalFIPSBuild(t, define.Version()) | ||
require.NoError(t, err) | ||
|
||
// Enroll Agent | ||
policyUUID := uuid.Must(uuid.NewV4()).String() | ||
basePolicy := kibana.AgentPolicy{ | ||
Name: "test-policy-" + policyUUID, | ||
Namespace: "default", | ||
Description: "Test policy " + policyUUID, | ||
MonitoringEnabled: []kibana.MonitoringEnabledOption{ | ||
kibana.MonitoringEnabledLogs, | ||
kibana.MonitoringEnabledMetrics, | ||
}, | ||
} | ||
|
||
installOpts := atesting.InstallOpts{ | ||
NonInteractive: true, | ||
Force: true, | ||
Privileged: true, | ||
} | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute) | ||
defer cancel() | ||
|
||
policyResp, _, err := tools.InstallAgentWithPolicy(ctx, t, installOpts, fixture, info.KibanaClient, basePolicy) | ||
require.NoError(t, err) | ||
|
||
// Install system integration | ||
_, err = tools.InstallPackageFromDefaultFile(ctx, info.KibanaClient, "system", preinstalledPackages["system"], "system_integration_setup.json", uuid.Must(uuid.NewV4()).String(), policyResp.ID) | ||
require.NoError(t, err) | ||
|
||
// Ensure data from system integration shows up in Elasticsearch | ||
status, err := fixture.ExecStatus(ctx) | ||
require.NoError(t, err) | ||
|
||
docs, err := estools.GetResultsForAgentAndDatastream(ctx, info.ESClient, "system.cpu", status.Info.ID) | ||
assert.NoError(t, err, "error fetching system metrics") | ||
assert.Greater(t, docs.Hits.Total.Value, 0, "could not find any matching system metrics for agent ID %s", status.Info.ID) | ||
t.Logf("Generated %d system events", docs.Hits.Total.Value) | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Where is the part that defines this enrollment to happen to the Fleet Server as part of the Integrations Server on ECH? I checked the code and understand it is enrolling to the default Fleet Server, but I don't easily spot where the connection to Integrations Server is made.