Skip to content

Conversation

openshift-cherrypick-robot

This is an automated cherry-pick of #4181

/assign aaradhak

Ensure that setting up a LUKS device with FIPS incompatible algorithms
will fail when FIPS mode is enabled.

Only run this on QEMU as it should behave the same way on all platforms.
Copy link

openshift-ci bot commented Aug 14, 2025

Hi @openshift-cherrypick-robot. Thanks for your PR.

I'm waiting for a coreos member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a new test case to verify that cryptsetup fails with non-FIPS-compliant algorithms when FIPS mode is enabled. The overall approach and implementation are sound. I have a couple of suggestions to improve code readability and maintainability by refactoring two functions for conciseness and clarity.

Comment on lines +103 to +119
// Read file and verify if it contains a pattern
// 1. Read file, make sure it exists
// 2. regex for pattern
func fileContainsPattern(path string, searchPattern string) (bool, error) {
file, err := os.ReadFile(path)
if err != nil {
return false, err
}
// File has content, but the pattern is not present
match := regexp.MustCompile(searchPattern).Match(file)
if match {
// Pattern found
return true, nil
}
// Pattern not found
return false, nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The fileContainsPattern function can be made more concise. The current comments are not very descriptive, and the logic can be simplified. A clearer function comment and a more direct implementation would improve readability.

// fileContainsPattern reads a file and reports whether it contains a match for a regex.
func fileContainsPattern(path string, searchPattern string) (bool, error) {
	file, err := os.ReadFile(path)
	if err != nil {
		return false, err
	}
	return regexp.MustCompile(searchPattern).Match(file), nil
}

Comment on lines +134 to +152
resultingError := inst.WaitAll(ctx)
if resultingError == nil {
resultingError = fmt.Errorf("ignition unexpectedly succeeded")
} else if resultingError == platform.ErrInitramfsEmergency {
// Expected initramfs failure, checking the console file to ensure
// that it failed the expected way
found, err := fileContainsPattern(builder.ConsoleFile, searchPattern)
if err != nil {
resultingError = errors.Wrapf(err, "looking for pattern '%s' in file '%s' failed", searchPattern, builder.ConsoleFile)
} else if !found {
resultingError = fmt.Errorf("pattern '%s' in file '%s' not found", searchPattern, builder.ConsoleFile)
} else {
// The expected case
resultingError = nil
}
} else {
resultingError = errors.Wrapf(resultingError, "expected initramfs emergency.target error")
}
errchan <- resultingError
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The error handling logic within this goroutine can be simplified. Using guard clauses with early returns for error conditions would make the code flatter and easier to follow, which is a common practice in Go for improving readability.

resultingError := inst.WaitAll(ctx)
		if resultingError == nil {
			errchan <- fmt.Errorf("ignition unexpectedly succeeded")
			return
		}
		if resultingError != platform.ErrInitramfsEmergency {
			errchan <- errors.Wrap(resultingError, "expected initramfs emergency.target error")
			return
		}

		// Expected initramfs failure, checking the console file to ensure
		// that it failed the expected way
		found, err := fileContainsPattern(builder.ConsoleFile, searchPattern)
		if err != nil {
			errchan <- errors.Wrapf(err, "looking for pattern '%s' in file '%s' failed", searchPattern, builder.ConsoleFile)
			return
		}
		if !found {
			errchan <- fmt.Errorf("pattern '%s' in file '%s' not found", searchPattern, builder.ConsoleFile)
			return
		}

		// The expected case
		errchan <- nil

@aaradhak
Copy link
Member

/ok-to-test

Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

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

/lgtm

@jlebon
Copy link
Member

jlebon commented Aug 20, 2025

Hmm, Prow CI is failing on the new test. But because test result archiving is/was not setup properly, we don't actually have logs. Were you able to sanity-check that this new test passes locally against 4.15?

@mike-nguyen
Copy link
Member

/retest

Copy link

openshift-ci bot commented Aug 28, 2025

@openshift-cherrypick-robot: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/rhcos 6157bac link true /test rhcos

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@aaradhak
Copy link
Member

I will test this locally and confirm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants