Skip to content

[Integration Test] Ensure that upgrading a FIPS-capable Agent results in a FIPS-capable Agent #7804

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
wants to merge 38 commits into
base: main
Choose a base branch
from

Conversation

ycombinator
Copy link
Contributor

@ycombinator ycombinator commented Apr 9, 2025

⚠️ Currently blocked on https://github.com/elastic/ingest-dev/issues/5264 and #8035 for CI being able to actually run these tests on a FIPS-configured VM. ⚠️

What does this PR do?

This PR allows a FIPS-capable Agent to upgrade to another FIPS-capable Agent.

It also adds three integration tests:

  • TestStandaloneUpgradeFIPStoFIPS: to check that a standalone FIPS-capable Agent will upgrade only to another FIPS-capable Agent. This test tests upgrades from and to various FIPS-capable Agent versions.
  • TestFleetManagedUpgradeUnprivilegedFIPS: to check that a Fleet-managed FIPS-capable unprivileged Agent will upgrade only to another FIPS-capable Agent.
  • TestFleetManagedUpgradePrivilegedFIPS: to check that a Fleet-managed FIPS-capable privileged Agent will upgrade only to another FIPS-capable Agent.

Why is it important?

To preserve FIPS-compliance across upgrades.

Checklist

  • I have read and understood the pull request guidelines of this project.
  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • I have added an integration test or an E2E test

Disruptive User Impact

None; this PR adds an integration test.

@ycombinator ycombinator requested a review from a team as a code owner April 9, 2025 21:04
Copy link
Contributor

mergify bot commented Apr 9, 2025

This pull request does not have a backport label. Could you fix it @ycombinator? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-./d./d is the label that automatically backports to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

@ycombinator ycombinator added Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team skip-changelog Testing backport-8.x Automated backport to the 8.x branch with mergify backport-9.0 Automated backport to the 9.0 branch labels Apr 9, 2025
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@ycombinator ycombinator removed the backport-9.0 Automated backport to the 9.0 branch label Apr 10, 2025
@ycombinator ycombinator force-pushed the it-upgrade-fips-to-fips branch from d71c0a5 to 1bf616f Compare April 11, 2025 19:54
Copy link
Contributor

@michel-laterman michel-laterman left a comment

Choose a reason for hiding this comment

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

testing looks good; should we also test a scenario where a failure is expected?

@ycombinator ycombinator force-pushed the it-upgrade-fips-to-fips branch from 917b25c to 2ced379 Compare April 18, 2025 00:03
@ycombinator ycombinator added backport-8.19 Automated backport to the 8.19 branch and removed backport-8.x Automated backport to the 8.x branch with mergify labels Apr 22, 2025
@ycombinator ycombinator enabled auto-merge (squash) April 22, 2025 23:26
@ycombinator ycombinator changed the title [Integration Test] Ensure that upgrading a FIPS-enabled Agent results in a FIPS-enabled Agent [Integration Test] Ensure that upgrading a FIPS-capable Agent results in a FIPS-capable Agent Apr 23, 2025
@ycombinator ycombinator force-pushed the it-upgrade-fips-to-fips branch from 2ced379 to da48fd6 Compare April 24, 2025 00:01
@ycombinator
Copy link
Contributor Author

It turns out we currently have no way of upgrade a FIPS-capable Agent to another version of a FIPS-capable Agent. I just tried this manually and it doesn't work:

$ sudo elastic-agent version
Binary: 9.0.0-SNAPSHOT (build: 4da779d1fac682d7189ab14f7e058e84d82c653a fips-distribution: true at 2025-04-25 12:38:25 +0000 UTC)
Daemon: 9.0.0-SNAPSHOT (build: 4da779d1fac682d7189ab14f7e058e84d82c653a at 2025-04-25 12:38:25 +0000 UTC)

$ sudo elastic-agent status
┌─ fleet
│  └─ status: (STOPPED) Not enrolled into Fleet
└─ elastic-agent
   └─ status: (HEALTHY) Running

$ pwd
/home/shaunak

$ ls -al elastic-agent-fips-9.1.0-SNAPSHOT-linux-arm64.tar.gz*
-rw-r--r-- 1 shaunak shaunak 207491829 Apr 25 07:35 elastic-agent-fips-9.1.0-SNAPSHOT-linux-arm64.tar.gz
-rw-r--r-- 1 shaunak shaunak       182 Apr 25 07:35 elastic-agent-fips-9.1.0-SNAPSHOT-linux-arm64.tar.gz.sha512

$ sudo elastic-agent upgrade --source-uri file:///home/shaunak/ --skip-verify 9.1.0-SNAPSHOT
Error: Failed trigger upgrade of daemon: failed download of agent binary: unable to download package: package '/home/shaunak/elastic-agent-9.1.0-SNAPSHOT-linux-arm64.tar.gz' not found: open /home/shaunak/elastic-agent-9.1.0-SNAPSHOT-linux-arm64.tar.gz: no such file or directory
For help, please see our troubleshooting guide at https://www.elastic.co/guide/en/fleet/9.0/fleet-troubleshooting.html

Moving this PR into draft while I implement the missing capability.

@ycombinator ycombinator marked this pull request as draft April 25, 2025 14:39
auto-merge was automatically disabled April 25, 2025 14:39

Pull request was converted to draft

@ycombinator ycombinator marked this pull request as ready for review April 28, 2025 16:14
@ycombinator ycombinator requested a review from kaanyalti April 28, 2025 16:14
@ycombinator
Copy link
Contributor Author

The TestStandaloneUpgradeFIPStoNonFIPS/Upgrade_8.19.0-SNAPSHOT_to_9.0.0-SNAPSHOT_(privileged) and TestStandaloneUpgradeFIPStoNonFIPS/Upgrade_8.19.0-SNAPSHOT_to_9.0.0-SNAPSHOT_(unprivileged) FIPS upgrade integration tests are failing CI. The failures look like this:

upgrade_standalone_test.go:78:
--
  | Error Trace:	/opt/buildkite-agent/builds/bk-agent-prod-gcp-1745886251557149484/elastic/elastic-agent/testing/integration/upgrade_standalone_test.go:78
  | /opt/buildkite-agent/builds/bk-agent-prod-gcp-1745886251557149484/elastic/elastic-agent/testing/integration/upgrade_standalone_test.go:58
  | /opt/buildkite-agent/builds/bk-agent-prod-gcp-1745886251557149484/elastic/elastic-agent/testing/integration/upgrade_standalone_fips_test.go:146
  | Error:      	Received unexpected error:
  | could not unmarshal agent version output: error: exit status 2, output: panic: opensslcrypto: FIPS mode requested (requirefips tag set) but not available in OpenSSL 3.0.13 30 Jan 2024
  |  
  | goroutine 1 [running]:
  | crypto/internal/backend.init.1()
  | crypto/internal/backend/openssl_linux.go:40 +0x9f
  |  
  | yaml: mapping values are not allowed in this context
  | Test:       	TestStandaloneUpgradeFIPStoNonFIPS/Upgrade_8.19.0-SNAPSHOT_to_9.0.0-SNAPSHOT_(privileged)

@michel-laterman @simitt I think we need https://github.com/elastic/ingest-dev/issues/5264 for these tests?

@simitt
Copy link
Contributor

simitt commented Apr 29, 2025

@michel-laterman @simitt I think we need https://github.com/elastic/ingest-dev/issues/5264 for these tests?

Agree

@ycombinator ycombinator force-pushed the it-upgrade-fips-to-fips branch from 0f2c12a to 142ec35 Compare May 8, 2025 21:10
Copy link

@ycombinator
Copy link
Contributor Author

ycombinator commented May 9, 2025

The TestFleetManagedUpgradeUnprivilegedFIPS integration test is failing in CI like so:

=== FAIL: testing/integration TestFleetManagedUpgradeUnprivilegedFIPS (0.17s)
--
  | upgrade_fleet_test.go:157:
  | Error Trace:	/opt/buildkite-agent/builds/bk-agent-prod-gcp-1746743140257113053/elastic/elastic-agent/testing/integration/upgrade_fleet_test.go:157
  | /opt/buildkite-agent/builds/bk-agent-prod-gcp-1746743140257113053/elastic/elastic-agent/testing/integration/upgrade_fleet_test.go:103
  | Error:      	Received unexpected error:
  | failed to find build at /opt/buildkite-agent/builds/bk-agent-prod-gcp-1746743140257113053/elastic/elastic-agent/build/distributions: stat /opt/buildkite-agent/builds/bk-agent-prod-gcp-1746743140257113053/elastic/elastic-agent/build/distributions/elastic-agent-fips-9.1.0-SNAPSHOT-linux-x86_64.tar.gz: no such file or directory
  | Test:       	TestFleetManagedUpgradeUnprivilegedFIPS

The TestFleetManagedUpgradePrivilegedFIPS integration test also fails with the same error.

If I look at the build artifacts from the "Packaging: Ubuntu x86_64 FIPS" CI step, I see that build/distributions/elastic-agent-fips-9.1.0-SNAPSHOT-linux-x86_64.tar.gz artifact is being built.

But I think this build artifact is on a different Buildkite Agent from the ones that are running the TestFleetManagedUpgradeUnprivilegedFIPS and TestFleetManagedUpgradePrivilegedFIPS tests, as seen in the log output of the packaging step:

--
~/builds/bk-agent-prod-gcp-1746738804551933315/elastic/elastic-agent

@michel-laterman is this gap something the BK pipeline changes in #8035 will address?

@ycombinator ycombinator marked this pull request as ready for review May 20, 2025 23:56
@cmacknz
Copy link
Member

cmacknz commented May 23, 2025

The tests are still failing trying to find the FIPS artifacts, but just going off the description I think we are over testing this between all three of these cases:

  • TestStandaloneUpgradeFIPStoFIPS: to check that a standalone FIPS-capable Agent will upgrade only to another FIPS-capable Agent. This test tests upgrades from and to various FIPS-capable Agent versions.
  • TestFleetManagedUpgradeUnprivilegedFIPS: to check that a Fleet-managed FIPS-capable unprivileged Agent will upgrade only to another FIPS-capable Agent.
  • TestFleetManagedUpgradePrivilegedFIPS: to check that a Fleet-managed FIPS-capable privileged Agent will upgrade only to another FIPS-capable Agent.

What coverage are we gaining by testing this in privileged and unprivileged mode? Is there even any difference between privileged and unprivileged with respect to FIPS?

What are we gaining by testing Fleet and Standalone? I would expect if we do a single Fleet managed upgrade test we would have effectively smoke tested all of this.

All FIPS does is substitute out the implementation of crypto package and change crypto related code. Why do we need to test three variants of an upgrade because of this?

@@ -583,3 +583,164 @@ func TestLess(t *testing.T) {
})
}
}

func TestEqual(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Instead of duplicating all the test cases from TestLess, maybe easier to just test both things in the same test? Maybe with a different sub-test?

I think maintaining the test cases is most of the work in here so we are better off duplicating them less.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.19 Automated backport to the 8.19 branch skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team Testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants