Skip to content

stig-hardening: first-boot SELinux relabel + FIPS PAM (default and subrelease-90) - #1669

Open
dcasota wants to merge 2 commits into
vmware:5.0from
dcasota:fix-selinux-relabel
Open

stig-hardening: first-boot SELinux relabel + FIPS PAM (default and subrelease-90)#1669
dcasota wants to merge 2 commits into
vmware:5.0from
dcasota:fix-selinux-relabel

Conversation

@dcasota

@dcasota dcasota commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Add the first-boot SELinux relabel service and the FIPS PAM fixes to stig-hardening, across the maintained 5.0 subrelease variants:

  • SPECS/stig-hardening (subrelease ≥ 92; also used by 91) → 2.1-10
  • SPECS/90/stig-hardening (subrelease 90) → 2.1-5.1.3

Both add:

  • fix-selinux-relabel-first-boot.patch — first-boot SELinux relabel service for unlabeled filesystems.
  • fix-stig-playbook-fips-pam.patch — PHTN-50-000192 pam_faillock guard, FIPS module config, IMA hash.

Why the relabel service is needed

The installer kernel has SELinux compiled in but boots with no policy loaded, so lsetxattr for security.selinux returns EINVAL and install-time labeling is impossible. Every file the STIG Ansible playbook writes during installation therefore lands as unlabeled_t. When the installed system boots with SELINUX=enforcing, confined processes are denied access to those files.

Ordering fix — the relabel must run before the units that read those files

The service originally declared only:

Before=getty-pre.target sysinit.target

That is not sufficient. systemd-sysctl.service also sets DefaultDependencies=no and declares only Before=sysinit.target, so the two units are each ordered against that target but not against each other — systemd is free to run them in either order. On a measured STIG install it ran systemd-sysctl first:

18:19:23  Starting Apply Kernel Variables...
18:19:23  AVC denied { read } comm="systemd-sysctl"
              name="zz-stig-hardening.conf" tcontext=unlabeled_t permissive=0
18:19:23  systemd-sysctl: Failed to open file '/etc/sysctl.d/zz-stig-hardening.conf'
18:19:23  Failed to start Apply Kernel Variables.
18:19:24  Starting SELinux Relabel Filesystem (first boot)...   <- one second later

systemd-sysctl aborts on the first unreadable file, so every kernel parameter in zz-stig-hardening.conf is silently absent for the whole first boot. On a system installed specifically to be STIG-hardened that is a compliance gap, not the cosmetic first-boot noise the patch header previously described — so the "known limitation / a reboot resolves all failures" note has been replaced with the fix.

The service now also declares:

Before=systemd-sysctl.service auditd.service systemd-networkd.service

systemd-sysctl.service is DefaultDependencies=no, so an explicit Before= is the only thing that can constrain it. Applied to both the default and the subrelease-90 copies.

Testing

Reproduced and diagnosed on permutations k03 (minimal / POI 2.8 / STIG / ext4 / kickstart) and k04 (same, btrfs) — filesystem-independent, identical failure on both:

before
guest.failed_units 1systemd-sysctl.service failed
AVC denials on first boot 55 (auditctl 50, chmod 31, modprobe, iptables, sshd-session)
denials after the relabel completes 0

The relabel itself works correctly — zero denials after it runs, which is why a reboot cleared the symptom. Only the ordering was wrong.

Rebased onto current 5.0 (the earlier branch was ~124 commits behind, which made the diff noisy); the change touches only stig-hardening.

🤖 Generated with Claude Code

…brelease-90)

Rebased onto the current 5.0 head, clearing the conflict this PR had been
sitting in.

fix-selinux-relabel-first-boot.patch
  The installer kernel has SELinux compiled in but boots with no policy
  loaded, so lsetxattr for security.selinux returns EINVAL and install-time
  labeling is not possible. Files created by the STIG playbook during
  installation are therefore unlabeled_t, and confined processes are denied
  access to them once the installed system boots enforcing. Adds a oneshot
  selinux-relabel.service that runs restorecon -R / on first boot.

fix-stig-playbook-fips-pam.patch
  PAM faillock guard, FIPS module config, IMA hash.

Verified on a live install: SELinux comes up Enforcing, the playbook
completes with 0 failed tasks, and the second boot is clean - 0 failed
units, 0 AVC denials. The known first-boot race documented in the patch
header is reproduced exactly (57 denials against unlabeled_t, and
systemd-sysctl fails to read zz-stig-hardening.conf so the STIG sysctls are
not applied on boot 1); a reboot resolves it, as documented.

Change-Id: I5be0d139c84e5b6eb292684c6ed24552c534f377
Signed-off-by: Daniel Casota <dcasota@gmail.com>
…book files

selinux-relabel.service declared only Before=getty-pre.target
sysinit.target. systemd-sysctl.service also sets DefaultDependencies=no
and declares only Before=sysinit.target, so the two are each ordered
against that target but not against each other, and systemd is free to
run them in either order. Measured on a STIG install, it ran
systemd-sysctl first:

  18:19:23  Starting Apply Kernel Variables...
  18:19:23  AVC denied { read } comm="systemd-sysctl"
                name="zz-stig-hardening.conf" tcontext=unlabeled_t permissive=0
  18:19:23  Failed to start Apply Kernel Variables.
  18:19:24  Starting SELinux Relabel Filesystem (first boot)...

The playbook writes zz-stig-hardening.conf during installation, where the
installer kernel has SELinux compiled in but no policy loaded, so the file
is unlabeled_t. Under Enforcing, systemd_sysctl_t is denied read on it,
and systemd-sysctl aborts on the first unreadable file - so every kernel
parameter in that file is silently absent for the whole first boot. On a
system installed to be STIG-hardened that is a compliance gap, not the
cosmetic first-boot noise the patch header previously described.

Add an explicit Before= against the units that consume playbook-written
files. Both the default and the subrelease-90 copies are updated.

Change-Id: Iddb0543f8077297151d2d9da2b345eb4f9dc061f
Signed-off-by: Daniel Casota <dcasota@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants