Skip to content
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

Conversation

neverpanic
Copy link

For a system that uses crypto-policies to be switched to FIPS mode correctly, it needs to be

  • booted with fips=1 on the kernel command line
  • switched to the FIPS crypto-policy (or a policy derived from it)
  • have the fips dracut module enabled

On older systems, there were additional steps, for example, creating /etc/system-fips.

We have repeatedly seen inconsistencies between those different toggles, either because the user space tooling to switch between those does not (for reliability, maintainability, and compliance reasons) undo some of the steps it does when disabling FIPS mode, or because other installation methods (bootc, containers, image builder) independently do some of those steps. Eventually, all of these ended with user confusion.

We can avoid this situation by eleminating the difference by treating the fips=1 kernel command line switch as a single source of truth, and making all others follow automatically. This module provides this for crypto-policies, by adding bind-mounts before pivot if the system has not already been switched to a FIPS-based crypto-policy.

This requires some support from the crypto-policies package (because it needs to deal with the bind mounts when a user calls update-crypto-policies --set), so make it a no-op unless

  • fips=1 is on the kernel command line
  • crypto-policies is installed
  • crypto-policies supports the bind-mounts (indicated by the presence of the default-fips-config file)
  • the policy isn't already FIPS

These checks should make this safe to add to the initramfs on all current systems.

The bind-mounts also need to happen in the initramfs already, because systemd links against OpenSSL, and doing them later means that systemd will start with an OpenSSL configuration that isn't tailored for FIPS.

See also 1, which adds the user space support to crypto-policies, along with a systemd service that does the same steps in case dracut hasn't already done them (which is useful for environments that don't use an initramfs like containers).

This pull request changes...

Changes

  • modules.d/01fips-crypto-policies

Checklist

  • I have tested it locally (using clean CentOS 10 Stream VMs with this PR on top, in various configurations of fipsness and crypto-policy)
  • I have reviewed and updated any documentation if relevant
  • I am providing new code…
  • … and test(s) for it

Can you point me to documentation on how to write a dracut test? I'd be happy to provide tests.

@github-actions github-actions bot added the modules Issue tracker for all modules label Aug 8, 2024

type getarg > /dev/null 2>&1 || . /lib/dracut-lib.sh

if ! fipsmode=$(getarg fips) || [ "$fipsmode" = "0" ] || [ -z "$fipsmode" ]; then
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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

modules.d/01fips-crypto-policies/fips-crypto-policies.sh Outdated Show resolved Hide resolved
For a system that uses crypto-policies to be switched to FIPS mode
correctly, it needs to be

- booted with `fips=1` on the kernel command line
- switched to the FIPS crypto-policy (or a policy derived from it)
- have the fips dracut module enabled

On older systems, there were additional steps, for example, creating
`/etc/system-fips`.

We have repeatedly seen inconsistencies between those different toggles,
either because the user space tooling to switch between those does not
(for reliability, maintainability, and compliance reasons) undo some of
the steps it does when disabling FIPS mode, or because other
installation methods (bootc, containers, image builder) independently do
some of those steps. Eventually, all of these ended with user confusion.

We can avoid this situation by eliminating the difference by treating
the `fips=1` kernel command line switch as a single source of truth, and
making all others follow automatically. This module provides this for
crypto-policies, by adding bind-mounts before pivot if the system has
not already been switched to a FIPS-based crypto-policy.

This requires some support from the crypto-policies package (because it
needs to deal with the bind mounts when a user calls
`update-crypto-policies --set`), so make it a no-op unless

 - `fips=1` is on the kernel command line
 - crypto-policies is installed
 - crypto-policies supports the bind-mounts (indicated by the presence
   of the `default-fips-config` file)
 - the policy isn't already FIPS

These checks should make this safe to add to the initramfs on all
current systems.

The bind-mounts also need to happen in the initramfs already, because
systemd links against OpenSSL, and doing them later means that systemd
will start with an OpenSSL configuration that isn't tailored for FIPS.

See also [1], which adds the user space support to crypto-policies,
along with a systemd service that does the same steps in case dracut
hasn't already done them (which is useful for environments that don't
use an initramfs like containers).

  [1]: https://gitlab.com/redhat-crypto/fedora-crypto-policies/-/merge_requests/191

Signed-off-by: Clemens Lang <[email protected]>
@t184256
Copy link
Contributor

t184256 commented Aug 8, 2024

LGTMy naked eye

@jozzsi
Copy link

jozzsi commented Aug 9, 2024

Fedora is using https://github.com/dracut-ng/dracut-ng . Would you consider uploading it there. Thanks !

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

Successfully merging this pull request may close these issues.

3 participants