Pin SELinux module policy format to 19

What does this MR do?

Pins the SELinux policy module format to 19 so the shipped .pp files load on every supported minor release, and fails the package build if any module comes out in a different format.

The bug: checkmodule ran without -c, so it wrote whatever format the builder's libsepol supports. The rolling almalinux:10 builder now has libsepol 3.10 and writes format 24. AlmaLinux 10.1 (accepts 4-23) and 10.0 (accepts 4-22) cannot load that, so gitlab-ctl reconfigure aborts. This is the second time (format 23 on 18.9.0, format 24 on 19.2.7).

Changes:

  • config/software/gitlab-selinux.rb passes -c 19 to checkmodule, then runs a build step that checks every .pp and fails if any is not format 19.
  • New Build::SELinuxPolicy (lib/gitlab/build/selinux_policy.rb) holds the pinned version and reads the format out of a compiled .pp.
  • EL 8 gets no flag: its checkpolicy 2.9 has no -c option, but its default is already 19. The build check still covers it.

Tested: all 11 RHEL-family package builds pass. On a live AlmaLinux 10.1 enforcing host, the branch package installs, reconfigures and serves git over SSH with no AVC denials. Details below.

Why format 19
  • 19 (MOD_POLICYDB_VERSION_INFINIBAND) is the newest format EL 8's libsepol 2.9 supports, and every newer libsepol reads it. Upstream main has raised the minimum it reads to 18.
  • The .te sources only use type, require, optional, allow and type-to-attribute typeattribute, so nothing newer is needed.
  • Every platform now ships the same format.

Impact on existing hosts

  • Healthy hosts on EL 9, EL 10, AL2023: the shipped .pp bytes change, so the content guard reinstalls gitlab-10.5.0-ssh-authorized-keys (or the unified gitlab module) once. That reinstall now succeeds. No recipe changes are needed.
  • Hosts already broken on 19.3.0 or later: upgrading to a release with this fix resolves it.
  • Hosts already broken on 19.2.x (the reported case): must apply the workaround from the issue first. The package preinst runs the installed gitlab-ctl check-config. Before 9d65d795 (#9455 (closed), first shipped in 19.3.0), that command blocks any upgrade after a failed reconfigure. A 19.2.x backport would hit the same check.
  • Fresh installs of affected releases fail too, not only upgrades: 19.0.9 already ships format 24.

Test plan

Real builders: build-package-on-all-os, 11/11 green

AlmaLinux 8/9/10 (x86_64, arm64, FIPS) and Amazon Linux 2023 (x86_64, arm64, FIPS) all succeeded. Every job's log shows the step assert SELinux modules use the pinned policy format.

  • AlmaLinux 10: checkmodule -M -m -c 19 -o …
  • AlmaLinux 8: checkmodule -M -m -o … (no -c)

The first AlmaLinux 10 attempt hit a runner system failure (AlreadyExists: task … already exists) and passed on the automatic retry.

Live host: AlmaLinux 10.1, SELinux enforcing

A GCE VM matching the report: libsepol-3.9-1.el10, policycoreutils-3.9-1.el10, selinux-policy-targeted-42.1.7-1.el10_1.2. Repos were pinned to the 10.1 vault so libsepol stayed at 3.9.

Step Result
Fresh install of 19.0.9 ❌ reconfigure aborts at semodule -i gitlab-7.2.0-ssh-keygen.pp: policydb module version 24 does not match my version range 4-23
Install the pre-19.1 modules (built on the host from the 19.0.9+ee.0 .te), reconfigure 19.0.9 ✅ reproduces the reporter's starting state
Upgrade to 19.2.7 ❌ reconfigure aborts at gitlab::selinux line 78, gitlab-10.5.0-ssh-authorized-keys, same error as the issue
Install the branch RPM directly ❌ blocked by the 19.2.7 preinst check-config before any SELinux code runs (see Impact)
Apply the issue's workaround on 19.2.7, reconfigure ✅
Install the branch RPM (19.4.1+rfbranch.2914643226.8f79863c) ✅ execute[semodule -i …gitlab-10.5.0-ssh-authorized-keys.pp] ran successfully (content-guard reinstall, format 23 → 19)
Shipped .pp formats ✅ all five are format 19
Second gitlab-ctl reconfigure ✅ exit 0, no semodule -i
semodule -l ✅ ssh-authorized-keys, gitlab-shell, ssh-keygen, sshd-session
ssh -T git@localhost, git clone over SSH ✅ Welcome to GitLab, @root!, clone succeeds
AVC denials (/var/log/audit/audit.log) ✅ none

gitlab-19.4.0-sshd-session keeps the workaround's locally built copy, because its install step uses a name-only guard. That is existing behaviour, not changed here.

Local containers: build and load matrix (podman)

The five .te files were compiled exactly as the build does them, and the format was read with the new helper:

Builder image checkpolicy / libsepol Flags Format
almalinux:8 2.9 / 2.9 (max 19) none 19
almalinux:9 3.6 / 3.6 (max 21) -c 19 19
almalinux:10 3.10 / 3.10 (max 24) none (before) 24
almalinux:10 3.10 / 3.10 (max 24) -c 19 19
amazonlinux:2023 3.4 / 3.4 (max 21) -c 19 19

Each module was then converted with /usr/libexec/selinux/hll/pp, the child process that fails inside semodule -i, on the oldest minor of each major. Packages came from the AlmaLinux vault so libsepol was not upgraded:

Reader libsepol Unpinned (format 24) Pinned (format 19)
AlmaLinux 10.1 3.9 ❌ … does not match my version range 4-23 ✅ all 5
AlmaLinux 10.0 3.8 ❌ … does not match my version range 4-22 ✅ all 5
AlmaLinux 9.0 3.3 n/a ✅ all 5
AlmaLinux 8.10 2.9 n/a ✅ all 5
Amazon Linux 2023 3.4 n/a ✅ all 5

Build::SELinuxPolicy.verify! rejects the real unpinned EL 10 output with uses SELinux module format 24, expected 19.

Notes for reviewers

Danger warnings
  • "Job definition changes … only run in TAG and release pipelines": danger/tag_only_jobs matches every path under lib/gitlab/build. selinux_policy.rb is only used by the gitlab-selinux software definition during package builds, like glaz_ffi.rb for gitlab-kas. No CI job definition changed. Whether to backport to stable branches is a call for maintainers (see Impact for why it would not help 19.2.x hosts that are already broken).
  • docs-i18n-lint paths failure: unrelated. Master deleted doc/_index.md and doc/installation/_index.md in 76bd04a9 but kept their doc-locale/* translations. This MR does not touch doc/.

Follow-up: the issue also suggests shipping the .te sources alongside the .pp files. With the format pinned, nobody should need to rebuild locally, so that is left out.

Closes #10132 (closed)

Checklist

See Definition of done.

For anything in this list which will not be completed, please provide a reason in the MR discussion.

Required

  • MR title and description are up to date, accurate, and descriptive.
  • MR targeting the appropriate branch.
  • Latest Merge Result pipeline is green.
  • When ready for review, MR is labeled workflowready for review per the Distribution MR workflow.
  • The UBT version and corresponding checksum hash have been updated and referenced in the merge request if applicable. (n/a)
    • UBT EE pipeline (Trigger:ee-package-ubt) is green

For GitLab team members

If you don't have access to this, the reviewer should trigger these jobs for you during the review process.

  • The manual Trigger:ee-package jobs have a green pipeline running against latest commit.
  • If config/software or config/patches directories are changed, make sure the build-package-on-all-os job within the Trigger:ee-package downstream pipeline succeeded. (all 11 RHEL-family builds green, see test plan)
  • If you are changing anything SSL related, then the Trigger:package:fips manual job within the Trigger:ee-package downstream pipeline must succeed. (n/a)
  • If CI configuration is changed, the branch must be pushed to dev.gitlab.org to confirm regular branch builds aren't broken. (n/a)

Expected (please provide an explanation if not completing)

  • Test plan indicating conditions for success has been posted and passes.
  • Documentation created/updated. (files/gitlab-selinux/README.md)
  • Tests added.
  • Integration tests added to GitLab QA. (n/a, QA does not run SELinux-enforcing hosts)
  • Equivalent MR/issue for the GitLab Chart opened. (n/a)
  • Validate potential values for new configuration settings. (n/a)

🤖 Generated with Claude Code

Edited by Jason Plum

Merge request reports

Loading
Loading