Skip to content

fix(packaging): run maintainer scripts on rpm and fix SELinux label - #166

Merged
czerwonk merged 1 commit into
czerwonk:mainfrom
manduinca:fix/rpm-scriptlets-selinux-label
Sep 1, 2026
Merged

czerwonk merged 1 commit into
czerwonk:mainfrom
manduinca:fix/rpm-scriptlets-selinux-label

Conversation

@manduinca

Copy link
Copy Markdown
Contributor

Fixes #152

Two separate things are wrong with the RPM, and they compound.

No scriptlets. In .goreleaser.yml the scripts: block sits under overrides: deb:, so only the .deb gets postinstall/preremove/postremove. The RPM ships without any — rpm -q --scripts ping_exporter is empty, as the reporter shows. The ping_exporter user the unit requires is never created, the config is never chowned, and the systemd drop-ins are never copied. I moved the block up one level so it applies to every format, and dropped the # TODO: create pre/post install/remove scripts note next to rpm.

That only works if the scripts stop assuming dpkg, so:

  • the systemd version now comes from systemctl --version instead of dpkg-query. Same drop-in selection as before on Debian (252 picks 233/235/242/245, 232 picks none), and it also works on RHEL.
  • preremove/postremove accept rpm's numeric $1 (0 = uninstall) alongside dpkg's remove. Without this both would exit early on RPM and never stop the unit or remove the user.

Wrong SELinux label. This is what actually produces the 203/EXEC in the issue. Missing users fail earlier, at 217/USER; the audit log in the report points elsewhere:

avc: denied { execute_no_trans } for comm="(exporter)" path="/usr/bin/ping_exporter"
  scontext=system_u:system_r:init_t:s0 tcontext=system_u:object_r:ping_exec_t:s0

The base policy ships /bin/ping.* system_u:object_r:ping_exec_t:s0, and /usr/bin/ping_exporter matches that regex, so the binary inherits ping_exec_t, which systemd may not execute. postinstall now pins it to bin_t and relabels; postremove drops the file context on uninstall. Both are guarded on selinuxenabled/semanage/restorecon existing, so hosts without SELinux tooling are unaffected. I chose bin_t over leaving it in ping_t deliberately: the same audit log shows ping_t being denied listen on a tcp_socket, so the exporter could not serve metrics even if it did start.

Verified: shellcheck -s sh clean on all three scripts; the version parser checked against seven real systemctl --version formats (el8/el9, arch, deb11, ubuntu, 232); the $1 matrix for both package managers; and a dry run of postinstall with systemctl/semanage/restorecon mocked, confirming the Debian drop-in selection is unchanged.

Not verified: I have no goreleaser, nfpm or rpm locally and no enforcing RHEL host, so I could not build the packages or install one. The packaging change is the part that needs your CI.

The scripts block was nested under overrides.deb, so RPMs shipped without
any scriptlets: the ping_exporter user was never created, the config was
never chowned and the systemd drop-ins were never installed.

Moving it up makes it apply to every format, which in turn requires the
scripts to stop being dpkg-specific:

- derive the systemd version from systemctl --version instead of
  dpkg-query, so the drop-in selection works on both package managers
- accept rpm's numeric argument ("0") next to dpkg's "remove" when
  deciding whether this is a removal or an upgrade

On SELinux hosts the binary additionally matches the base policy entry
for /bin/ping.*, so it lands in ping_exec_t and systemd refuses to
execute it (AVC execute_no_trans, exit 203/EXEC). postinstall now pins
/usr/bin/ping_exporter to bin_t and relabels it; postremove drops the
file context again.

Fixes czerwonk#152
@manduinca
manduinca requested a review from czerwonk as a code owner August 25, 2026 05:32
@czerwonk
czerwonk merged commit 0fca332 into czerwonk:main Sep 1, 2026
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.

Systemd service fails on hosts with enforced SELinux

2 participants