Skip to content
/ server Public

MDEV-39057: systemd: Add low risk hardening to unit templates#4787

Open
aquilamacedo wants to merge 1 commit intoMariaDB:10.11from
aquilamacedo:systemd-hardening-safe-defaults
Open

MDEV-39057: systemd: Add low risk hardening to unit templates#4787
aquilamacedo wants to merge 1 commit intoMariaDB:10.11from
aquilamacedo:systemd-hardening-safe-defaults

Conversation

@aquilamacedo
Copy link
Contributor

Adds a handful of conservative systemd hardening defaults to the upstream unit templates (support-files/mariadb.service.in and support-files/mariadb@.service.in). The goal is to improve systemd-analyze security without changing normal MariaDB behavior.

Enabled in this change:

  • Kernel/cgroup protections: ProtectKernelTunables=true, ProtectKernelModules=true, ProtectControlGroups=true
  • Block realtime scheduling: RestrictRealtime=true
  • Lock personality: LockPersonality=true
  • Restrict namespace creation: RestrictNamespaces=true (easy to override via a systemd drop-in if someone really needs it)

Intentionally not enabled:

I'm intentionally not touching the knobs that have historically caused regressions across distros / SELinux / PAM setups:

Happy to follow up with a separate PR for NoNewPrivileges=true (and anything else stronger) once this lands and we get broader feedback.

Downstream note (Debian)
This exact set of directives has been carried in Debian for ~1 month with no regressions reported so far. Context: https://salsa.debian.org/mariadb-team/mariadb-server/-/merge_requests/152.

Tested

  • systemctl restart mariadb / mariadb@.service
  • Checked journalctl -u 'mariadb*' for new errors/denials
  • Compared systemd-analyze security mariadb.service before/after

Harden mariadb.service and mariadb@.service with low regression systemd
sandboxing defaults (kernel/cgroup protections, restrict namespaces,
disable realtime, lock personality, overrideable via drop-in).

Avoid historically problematic knobs (NoNewPrivileges, capability
bounding, PrivateDevices). Refs: MDEV-10404, MDEV-19878, MDEV-36591,
MDEV-36681
@grooverdan grooverdan self-assigned this Mar 12, 2026
@grooverdan
Copy link
Member

Thanks @aquilamacedo.

Due to a limitation of PR, they don't run the full package tests. So https://buildbot.mariadb.org/#/grid?branch=bb-10.11-pr4787-systemd-hardening-safe-defaults-pkgtest is the same thing there where we'll see in the autopkg-install tests how things go on native kernels.

I added a removal of NNP which I was pretty confident about.

Capabilities where cleaned up in c461188.

PrivateDevices=false remove MDEV-36721 680b0cd

@gkodinov gkodinov added the External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements. label Mar 12, 2026
@grooverdan
Copy link
Member

grooverdan commented Mar 13, 2026

So much for my NNP confidence. It was in dealing with selinux, however caused the PAMv2 test to fai.

Attempt 2 - https://buildbot.mariadb.org/#/grid?branch=bb-10.11-pr4787-systemd-hardening-safe-defaults-pkgtest2 - which is exactly this PR.

Seems its something in this basic hardening preventing the PAMv2 failures.

Are you able to replicate https://buildbot.mariadb.org/#/builders/599/builds/4510/steps/5/logs/stdio in a local instance:
1.

sudo tee /etc/pam.d/mariadb
auth required pam_unix.so audit
account required pam_unix.so audit
  1. using the credentials of a local account that exists in pam_unix instead of buildbot;
sudo mariadb -e 'INSTALL SONAME '\''auth_pam'\''; CREATE USER '\''buildbot'\''@'\''localhost'\'' IDENTIFIED VIA pam USING '\''mariadb'\'''
  1. with the user and password
mariadb -ubuildbot -ptest -e 'SHOW GRANTS'

Adjust low risk hardening until there's a SHOW GRANTS that succeeds showing the user.

@gkodinov gkodinov changed the title systemd: Add low risk hardening to unit templates MDEV-39057: systemd: Add low risk hardening to unit templates Mar 13, 2026
Copy link
Member

@gkodinov gkodinov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution! This is a preliminary review.

LGTM. Please stand by for the final review.

@gkodinov gkodinov requested a review from grooverdan March 13, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

External Contribution All PRs from entities outside of MariaDB Foundation, Corporation, Codership agreements.

Development

Successfully merging this pull request may close these issues.

3 participants