From 32ecfe7ed8852f58d2eb65ecd9589d408939f629 Mon Sep 17 00:00:00 2001 From: "Daniel A. Wozniak" Date: Mon, 31 Aug 2026 18:52:57 -0700 Subject: [PATCH 1/3] Isolate salt daemon writable state under /var/lib/salt// (#70198) Default SALT_ONEDIR_HARDEN=1 on 3009.0+ so each daemon's writable state lives under per-daemon /var/lib/salt//{home,extras-} directories and /opt/saltstack/salt stays root:root 0755. Set SALT_ONEDIR_HARDEN=0 in /etc/default/salt-setup (DEB) or /etc/sysconfig/salt-minion-setup (RPM) to restore the legacy chown -R salt /opt/saltstack/salt behavior for one release; the opt-out is deprecated and will be removed in a future release. Runtime salt-pip and the onedir _salt_onedir_extras .pth hook honor SALT_EXTRAS_DIR so packages installed via salt-pip continue to be importable by the daemon after the packaging layer relocates the extras tree. Postinst / posttrans scriptlets migrate any populated legacy /opt/saltstack/salt/extras-/ contents into the per-daemon location once, idempotent no-op otherwise. --- changelog/70198.added.md | 1 + .../releases/templates/3009.0.md.template | 30 ++ pkg/common/onedir/_salt_onedir_extras.py | 18 +- pkg/debian/salt-api.postinst | 40 ++- pkg/debian/salt-api.preinst | 22 +- pkg/debian/salt-cloud.postinst | 40 ++- pkg/debian/salt-cloud.preinst | 52 ++++ pkg/debian/salt-common.dirs | 1 + pkg/debian/salt-common.preinst | 21 +- pkg/debian/salt-master.postinst | 53 +++- pkg/debian/salt-master.preinst | 22 +- pkg/debian/salt-minion.postinst | 63 ++++- pkg/debian/salt-minion.preinst | 25 +- pkg/debian/salt-syndic.postinst | 40 ++- pkg/debian/salt-syndic.preinst | 22 +- pkg/rpm/salt.spec | 263 ++++++++++++++++-- salt/scripts.py | 24 +- .../pkg/integration/test_onedir_harden.py | 169 +++++++++++ tests/pytests/unit/test_salt_onedir_extras.py | 103 +++++++ tests/pytests/unit/test_scripts.py | 48 +++- 20 files changed, 977 insertions(+), 80 deletions(-) create mode 100644 changelog/70198.added.md create mode 100755 pkg/debian/salt-cloud.preinst create mode 100644 tests/pytests/pkg/integration/test_onedir_harden.py create mode 100644 tests/pytests/unit/test_salt_onedir_extras.py diff --git a/changelog/70198.added.md b/changelog/70198.added.md new file mode 100644 index 000000000000..7eda00d92cf3 --- /dev/null +++ b/changelog/70198.added.md @@ -0,0 +1 @@ +Isolate salt daemon writable state under per-daemon `/var/lib/salt//` directories so the `/opt/saltstack/salt` onedir tree stays `root:root 0755`. `SALT_ONEDIR_HARDEN=1` is now the default on 3009.0+; `SALT_ONEDIR_HARDEN=0` restores the legacy `chown -R salt /opt/saltstack/salt` behavior for one release and emits a deprecation warning. `salt-pip` and `_salt_onedir_extras.py` honor `SALT_EXTRAS_DIR` at runtime so the relocated extras tree stays importable by the daemon. diff --git a/doc/topics/releases/templates/3009.0.md.template b/doc/topics/releases/templates/3009.0.md.template index 9df09f0899e9..27799792fdeb 100644 --- a/doc/topics/releases/templates/3009.0.md.template +++ b/doc/topics/releases/templates/3009.0.md.template @@ -6,6 +6,36 @@ Add release specific details below --> +## Hardened onedir layout (`SALT_ONEDIR_HARDEN=1` by default) + +Starting with 3009.0, the Linux packaging isolates each salt daemon's +writable state under per-daemon directories: + +- `/var/lib/salt/minion/{home,extras-}` for `salt-minion` +- `/var/lib/salt/master/{home,extras-}` for `salt-master` +- `/var/lib/salt/syndic/{home,extras-}` for `salt-syndic` +- `/var/lib/salt/api/{home,extras-}` for `salt-api` +- `/var/lib/salt/cloud/{home,extras-}` for `salt-cloud` + +The `/opt/saltstack/salt` onedir tree now stays owned by +`root:root` at `0755` — the packaging postinst / posttrans scriptlets +no longer chown the tree to the salt user. On upgrade from a legacy +install, the existing `/opt/saltstack/salt/extras-` contents are +migrated into the per-daemon `/var/lib/salt//extras-` +directory automatically. + +`salt-pip install` and the runtime `_salt_onedir_extras` import hook +honor the `SALT_EXTRAS_DIR` environment variable so packages installed +via `salt-pip` continue to be importable by the daemon at runtime. + +### Opting out for one release + +Set `SALT_ONEDIR_HARDEN=0` in `/etc/default/salt-setup` (DEB) or +`/etc/sysconfig/salt-minion-setup` (RPM) to keep the legacy +`chown -R salt /opt/saltstack/salt` behavior. This opt-out is available +for the 3009 release cycle only; the legacy layout will be removed in a +future release. See {issue}`70198`. +