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

[draft] feat: warn/confirm with user if enabling fips downgrades the kernel #2745

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion features/enable_fips_pro.feature
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Feature: FIPS enablement in PRO cloud based machines
| focal | FIPS | fips |https://esm.ubuntu.com/fips/ubuntu focal/main |
| focal | FIPS Updates | fips-updates |https://esm.ubuntu.com/fips/ubuntu focal/main |


@wip
@slow
@series.bionic
@series.focal
Expand All @@ -142,6 +142,10 @@ Feature: FIPS enablement in PRO cloud based machines
When I run `pro enable <fips-service> --assume-yes` with sudo
Then stdout matches regexp:
"""
This will downgrade the kernel from X to new_version.
Warning: Downgrading the kernel may cause hardware failures. Please ensure the
hardware is compatible with the new kernel version before proceeding.
Are you sure? (y/N)
Updating <fips-name> package lists
Installing <fips-name> packages
<fips-name> enabled
Expand Down
30 changes: 29 additions & 1 deletion uaclient/entitlements/fips.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import logging
import os
import re
from itertools import groupby
from typing import List, Optional, Tuple # noqa: F401
from typing import Callable, List, Optional, Tuple, Union # noqa: F401

import pkg_resources

from uaclient import apt, event_logger, exceptions, messages, system, util
from uaclient.clouds.identity import NoCloudTypeReason, get_cloud_type
Expand Down Expand Up @@ -167,6 +170,31 @@ def install_packages(
:param cleanup_on_failure: Cleanup apt files if apt install fails.
:param verbose: If true, print messages to stdout
"""

# Prior to installing packages, check if the kernel is being downgraded
# and if so verify that the user wants to continue
our_kernel_version_str = (
system.get_kernel_info().proc_version_signature_version
)
fips_kernel_policy = apt.get_apt_cache_policy_for_package("linux-fips")
m = re.search(
r"Candidate: (?P<kernel_version>\d+\.\d+\.\d+)", fips_kernel_policy
)
LOG.warning(f"Checking kernel versions: {our_kernel_version_str}")
if m is not None:
fips_kernel_version_str = m.group("kernel_version")
our_version = pkg_resources.parse_version(fips_kernel_version_str)
fips_version = pkg_resources.parse_version(our_kernel_version_str)
if fips_version < our_version:
if not util.prompt_for_confirmation(
msg=messages.PROMPT_KERNEL_DOWNGRADE.format(
current_version=our_kernel_version_str,
new_version=fips_kernel_version_str,
),
assume_yes=self.assume_yes,
):
return

if verbose:
event.info(
messages.INSTALLING_SERVICE_PACKAGES.format(title=self.title)
Expand Down
7 changes: 6 additions & 1 deletion uaclient/entitlements/tests/test_fips.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ def test_enable_configures_apt_sources_and_auth_files(
retry_sleeps=apt.APT_RETRIES,
override_env_vars=None,
),
mock.call(
["apt-cache", "policy", "linux-fips"],
capture=True,
retry_sleeps=apt.APT_RETRIES,
override_env_vars=None,
),
]
subp_calls += install_cmd

Expand Down Expand Up @@ -1104,7 +1110,6 @@ def test_install_packages_dont_fail_if_conditional_pkgs_not_installed(
fips_entitlement_factory,
event,
):

conditional_pkgs = ["b", "c"]
m_installed_pkgs.return_value = conditional_pkgs
packages = ["a"]
Expand Down
10 changes: 10 additions & 0 deletions uaclient/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,6 +1295,16 @@ class TxtColor:
)
+ PROMPT_YES_NO
)
PROMPT_KERNEL_DOWNGRADE = (
t.gettext(
"""\
This will downgrade the kernel from {current_version} to {new_version}.
Warning: Downgrading the kernel may cause hardware failures. Please ensure the
hardware is compatible with the new kernel version before proceeding.
"""
+ PROMPT_YES_NO
)
)
FIPS_SYSTEM_REBOOT_REQUIRED = t.gettext(
"FIPS support requires system reboot to complete configuration."
)
Expand Down
Loading