Skip to content

Enable unit tests with -tags=requirefips#43611

Merged
michel-laterman merged 15 commits intoelastic:mainfrom
michel-laterman:unit-test-fips
Apr 7, 2025
Merged

Enable unit tests with -tags=requirefips#43611
michel-laterman merged 15 commits intoelastic:mainfrom
michel-laterman:unit-test-fips

Conversation

@michel-laterman
Copy link
Copy Markdown
Contributor

Proposed commit message

Enable unit tests with -tags=requirefips for auditbeat, filebeat, and metricbeat.

Checklist

  • 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.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Disruptive User Impact

N/A

How to test this PR locally

FIPS=true mage unitTest

@michel-laterman michel-laterman added :Testing release-note:skip The PR should be ignored when processing the changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-8.x Automated backport to the 8.x branch with mergify labels Mar 31, 2025
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Mar 31, 2025
@michel-laterman michel-laterman marked this pull request as ready for review April 1, 2025 14:50
@michel-laterman michel-laterman requested review from a team as code owners April 1, 2025 14:50
@elasticmachine
Copy link
Copy Markdown
Contributor

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

@pierrehilbert pierrehilbert added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Security-Linux Platform Linux Platform Team in Security Solution Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution labels Apr 1, 2025
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/sec-linux-platform (Team:Security-Linux Platform)

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/sec-deployment-and-devices (Team:Security-Deployment and Devices)

@michel-laterman
Copy link
Copy Markdown
Contributor Author

@elastic/sec-linux-platform, @elastic/observablt-ci can I please get a review for this PR?

@ebeahan ebeahan requested a review from andrewkroh April 2, 2025 18:37
Copy link
Copy Markdown
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

I'm very curious to see if we can implement some of the conditional testing via runtime checks rather than build-time tags. There may be cases where this is unavoidable if the tests themselves have direct dependencies on crypto functions, but I imagine most of this can be done via runtime checks (e.g., if fips140.Enabled() { t.Skip() }).

As we have seen with the integration build tags, this pattern can make maintenance/refactoring more difficult and may also hide errors.

// specific language governing permissions and limitations
// under the License.

//go:build requirefips
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there way to accomplish the variant testing without utilizing build tags? Minimizing the amount of code behind build tags makes maintenance easier. Build tags can hide errors.

For example, is there some runtime method of checking if the binary is in FIPS mode (akin to https://pkg.go.dev/crypto/fips140#Enabled) that we can use to skip tests at runtime instead of using build tags?

Copy link
Copy Markdown
Contributor Author

@michel-laterman michel-laterman Apr 4, 2025

Choose a reason for hiding this comment

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

fips140.Enabled() returns true if fips140 is set to on, or only.
On enables FIPS compliant algorithms, and will allow you to use non-FIPS algorithms (such as SHA1)
Only forces you to use FIPS (fips 140-3) compliance, without using non-FIPS algorithms.

Our current binaries (built with microsoft/go target fips 140-2) function the same as if the flag has an on value.

The next step in our FIPS testing will be to run these unit tests with fips140=only just to make sure we don't accidentally add non compliant algorithms in the future.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I didn't mean to use fips140.Enabled() directly, but was asking if there was something similar in nature that we could use to minimize the amount code hidden behind build tags? One possible example would be to have a very slim package that exports a constant based on the build tag used, e.g.

//go:build requirefips

const FIPS = true
//go:build !requirefips

const FIPS = false

Then utilize this value to control the expectations set by the tests.

Copy link
Copy Markdown
Contributor Author

@michel-laterman michel-laterman Apr 7, 2025

Choose a reason for hiding this comment

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

Currently we don't have anything available in beats.
I'll create an issue to discuss this; enabling test coverage is our priority at the moment

@michel-laterman michel-laterman merged commit 01ae298 into elastic:main Apr 7, 2025
167 of 170 checks passed
@michel-laterman michel-laterman deleted the unit-test-fips branch April 7, 2025 22:13
mergify bot pushed a commit that referenced this pull request Apr 7, 2025
Enable unit tests with -tags=requirefips for auditbeat, filebeat, metricbeat, and libbeat.

(cherry picked from commit 01ae298)
michel-laterman added a commit that referenced this pull request Apr 17, 2025
* Enable unit tests with -tags=requirefips (#43611)

Enable unit tests with -tags=requirefips for auditbeat, filebeat, metricbeat, and libbeat.

(cherry picked from commit 01ae298)

* Split up root_test for FIPS TLS changes

---------

Co-authored-by: Michel Laterman <82832767+michel-laterman@users.noreply.github.com>
Co-authored-by: michel-laterman <michel.laterman@elastic.co>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-8.x Automated backport to the 8.x branch with mergify release-note:skip The PR should be ignored when processing the changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team Team:Security-Deployment and Devices Deployment and Devices Team in Security Solution Team:Security-Linux Platform Linux Platform Team in Security Solution :Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants