-
Notifications
You must be signed in to change notification settings - Fork 400
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
feat(fips-crypto-policies): Make c-p follow FIPS mode automatically #2670
Closed
Closed
Changes from all commits
Commits
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 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,52 @@ | ||
#!/usr/bin/sh | ||
|
||
type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh | ||
|
||
if ! fipsmode=$(getarg fips) || [ "$fipsmode" = "0" ] || [ -z "$fipsmode" ]; then | ||
# Do nothing if not in FIPS mode | ||
exit 0 | ||
fi | ||
|
||
policyfile=/etc/crypto-policies/config | ||
fipspolicyfile=/usr/share/crypto-policies/default-fips-config | ||
backends=/etc/crypto-policies/back-ends | ||
fipsbackends=/usr/share/crypto-policies/back-ends/FIPS | ||
|
||
# When in FIPS mode, check the active crypto policy by reading the | ||
# $root/etc/crypto-policies/config file. If it is not "FIPS", or does not start | ||
# with "FIPS:", automatically switch to the FIPS policy by creating | ||
# bind-mounts. | ||
|
||
if ! [ -r "${NEWROOT}${policyfile}" ]; then | ||
# No crypto-policies configured, possibly not a system that uses | ||
# crypto-policies? | ||
exit 0 | ||
fi | ||
|
||
if ! [ -f "${NEWROOT}${fipspolicyfile}" ]; then | ||
# crypto-policies is too old to deal with automatic bind-mounting of the | ||
# FIPS policy over the normal policy, do not attempt to do the bind-mount. | ||
exit 0 | ||
fi | ||
|
||
policy=$(cat "${NEWROOT}${policyfile}") | ||
|
||
# Remove the largest suffix pattern matching ":*" from the string (i.e., the | ||
# complete list of active policy modules), then check for FIPS. This is part of | ||
# POSIX sh (https://pubs.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_02). | ||
if [ "${policy%%:*}" = "FIPS" ]; then | ||
neverpanic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
exit 0 | ||
fi | ||
|
||
# Current crypto policy is not FIPS or FIPS-based, but the system is in FIPS | ||
# mode; this is an inconsistent configuration. Automatically bind-mount a FIPS | ||
# configuration over this. | ||
if ! mount -o bind,ro "${NEWROOT}${fipsbackends}" "${NEWROOT}${backends}"; then | ||
warn "Failed to bind-mount FIPS policy over ${backends} (the system is in FIPS mode, but the crypto-policy is not)." | ||
# If this bind-mount failed, don't attempt to do the other one to avoid | ||
# a system that seems to be in FIPS crypto-policy but actually is not. | ||
exit 0 | ||
fi | ||
|
||
mount -o bind,ro "${NEWROOT}${fipspolicyfile}" "${NEWROOT}${policyfile}" \ | ||
|| warn "Failed to bind-mount FIPS crypto-policy state file over ${policyfile} (the system is in FIPS mode, but the crypto-policy is not)." |
This file contains 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,27 @@ | ||
#!/usr/bin/bash | ||
|
||
# called by dracut | ||
check() { | ||
# only enable on systems that use crypto-policies | ||
[ -d "$dracutsysrootdir/etc/crypto-policies" ] && return 0 | ||
|
||
# include when something else depends on it or it is explicitly requested | ||
return 255 | ||
} | ||
|
||
# called by dracut | ||
depends() { | ||
return 0 | ||
} | ||
|
||
# called by dracut | ||
installkernel() { | ||
return 0 | ||
} | ||
|
||
# called by dracut | ||
install() { | ||
inst_hook pre-pivot 01 "$moddir/fips-crypto-policies.sh" | ||
|
||
inst_multiple mount | ||
} |
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.
should the script proceed on anything but 1 there?
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.
I copied and modified this from the existing
01fips
module, so it's consistent with that. I don't believe we should introduce a difference between those two.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.
can't argue with that