Remove systemd.confirm_spawn from the Kernel Command Line

Description

The systemd.confirm_spawn kernel argument makes systemd ask on the console for confirmation before it spawns each unit during boot. Ensure the argument is absent, whatever its value, from the kernel command line of the boot entries. Check that the line

GRUB_CMDLINE_LINUX="..."

within /etc/default/grub doesn’t contain the argument systemd.confirm_spawn. Run the following command to update command line for already installed kernels:

# grubby --update-kernel=ALL --remove-args="systemd.confirm_spawn"

If the system is distributed as a bootable container image, GRUB2 can’t be configured using the method described above, but the kernel arguments should be configured using TOML files located in the /usr/lib/bootc/kargs.d directory. Remove all occurences of systemd.confirm_spawn from all files in /usr/lib/bootc/kargs.d. For more details on configuring kernel arguments in bootable container images, please refer to Bootc documentation.

Rationale

An interactive boot process lets a person with console access choose which units start, and so keep auditing, firewalls or other security services from starting.

Remediation

Shell script

The following script can be run on the host to remediate the issue.

#!/bin/bash

# Remediation is applicable only in certain platforms
if ( rpm --quiet -q grub2-common && rpm --quiet -q kernel-core ); then

if { rpm --quiet -q kernel bootc && ! rpm --quiet -q openshift-kubelet && { [ -f "/run/.containerenv" ] || [ -f "/.containerenv" ]; }; } ; then
    KARGS_DIR="/usr/lib/bootc/kargs.d/"
    find "$KARGS_DIR" -maxdepth 1 -type f -name '*.toml' -exec sed -i -E -e "s/^(\s*kargs\s*=\s*\[.*)\"systemd.confirm_spawn(=[^\"]*)?\"[,[:space:]]*(.*]\s*)/\1\3/" -e "s/^(\s*kargs.*),\s*\]$/\1\]/" {} +
else

grubby --update-kernel=ALL --remove-args=systemd.confirm_spawn

fi

else
    >&2 echo 'Remediation is not applicable, nothing was done'
fi

Ansible playbook

The following playbook can be run with Ansible to remediate the issue.

- name: Gather the package facts
  package_facts:
    manager: auto
  tags:
  - CCE-88644-0
  - grub2_systemd_confirm_spawn_argument_absent
  - low_disruption
  - medium_complexity
  - medium_severity
  - reboot_required
  - restrict_strategy

- name: Check if systemd.confirm_spawn argument is already present in /etc/default/grub
  ansible.builtin.slurp:
    src: /etc/default/grub
  register: etc_default_grub
  when: ( "grub2-common" in ansible_facts.packages and "kernel-core" in ansible_facts.packages
    )
  tags:
  - CCE-88644-0
  - grub2_systemd_confirm_spawn_argument_absent
  - low_disruption
  - medium_complexity
  - medium_severity
  - reboot_required
  - restrict_strategy

- name: Check if systemd.confirm_spawn argument is present
  ansible.builtin.command: /sbin/grubby --info=ALL
  register: grubby_info
  check_mode: false
  changed_when: false
  failed_when: false
  when: ( "grub2-common" in ansible_facts.packages and "kernel-core" in ansible_facts.packages
    )
  tags:
  - CCE-88644-0
  - grub2_systemd_confirm_spawn_argument_absent
  - low_disruption
  - medium_complexity
  - medium_severity
  - reboot_required
  - restrict_strategy

- name: Update grub defaults and the bootloader menu
  ansible.builtin.command: /sbin/grubby --update-kernel=ALL --remove-args="systemd.confirm_spawn"
  changed_when: true
  when:
  - ( "grub2-common" in ansible_facts.packages and "kernel-core" in ansible_facts.packages
    )
  - (grubby_info.stdout is search('systemd.confirm_spawn')) or ((etc_default_grub['content']
    | b64decode) is search('systemd.confirm_spawn'))
  tags:
  - CCE-88644-0
  - grub2_systemd_confirm_spawn_argument_absent
  - low_disruption
  - medium_complexity
  - medium_severity
  - reboot_required
  - restrict_strategy