/
githubmirror
/
salt
Обзор
Документация
Войти
/
githubmirror
/
salt
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
pkg/debian/salt-master.preinst
109 строк
4 KB
Daniel A. Wozniak
Fix salt-master package upgrade resetting non-root user ownership
17 июн 2026, 13:43
17 июн 2026, 13:43
f6fd9ed
Код
Авторство
О чём код?
#!/bin/sh # preinst script for salt-master. # # See: dh_installdeb(1). set -e # Summary of how this script can be called: # * <new-preinst> 'install' # * <new-preinst> 'install' <old-version> # * <new-preinst> 'upgrade' <old-version> # * <old-preinst> 'abort-upgrade' <new-version> # for details, see https://www.debian.org/doc/debian-policy/ or # the debian-policy package. # Source setup configuration if present. The DEB-conventional location is # /etc/default/salt-setup; /etc/sysconfig/salt-minion-setup is honored as # well for cross-distro parity with the RPM packaging. Either file may # pre-set SALT_HOME, SALT_USER, SALT_GROUP, SALT_NAME, or SALT_EXTRAS_DIR. # Values in the sourced files win over inherited env vars; the [ -n ... ] # || guards below preserve whatever was set, falling back to the hardcoded # defaults only when nothing was supplied. if [ -f /etc/default/salt-setup ]; then . /etc/default/salt-setup fi if [ -f /etc/sysconfig/salt-minion-setup ]; then . /etc/sysconfig/salt-minion-setup fi [ -n "$SALT_HOME" ] || SALT_HOME=/opt/saltstack/salt [ -n "$SALT_USER" ] || SALT_USER=salt [ -n "$SALT_NAME" ] || SALT_NAME="Salt" [ -n "$SALT_GROUP" ] || SALT_GROUP=salt case "$1" in install) # Propagate the resolved SALT_USER (from /etc/default/salt-setup, # /etc/sysconfig/salt-minion-setup, or the env var) into debconf so # the postinst's `db_get salt-master/user` returns the override # instead of the template default ``salt``. Without this, a fresh # install with SALT_USER=alt_salt would create the alt_salt user # but the postinst would still try ``chown -R salt:salt ...`` and # fail. . /usr/share/debconf/confmodule db_set salt-master/user $SALT_USER ;; upgrade) . /usr/share/debconf/confmodule # Determine the current master user. The configured user in # /etc/salt/master (or a drop-in under /etc/salt/master.d) is the # authoritative source; only fall back to filesystem ownership and # then the package default if no user is configured. The previous # logic looked only at filesystem ownership of /run/salt-master.pid, # which caused upgrades to reset state directory ownership (and the # debconf-stored user) back to the package default when the master # was configured to run as a non-root user but the pid file was # absent or root-owned between systemd restarts. CFG_USER="" if [ -f /etc/salt/master ]; then CFG_USER=$(grep -E "^[[:space:]]*user:" /etc/salt/master 2>/dev/null \ | head -1 | cut -d ':' -f 2 | tr -d '[:space:]') fi if [ -z "$CFG_USER" ] && [ -d /etc/salt/master.d ]; then CFG_USER=$(grep -r -h -E "^[[:space:]]*user:" /etc/salt/master.d/ 2>/dev/null \ | head -1 | cut -d ':' -f 2 | tr -d '[:space:]') fi if [ -n "$CFG_USER" ]; then CUR_USER=$CFG_USER CUR_GROUP=$(id -gn "$CFG_USER" 2>/dev/null || echo "$CFG_USER") elif [ -f /run/salt-master.pid ]; then CUR_USER=$(ls -dl /run/salt-master.pid | cut -d ' ' -f 3) CUR_GROUP=$(ls -dl /run/salt-master.pid | cut -d ' ' -f 4) else CUR_USER=$SALT_USER CUR_GROUP=$SALT_GROUP fi db_set salt-master/user $CUR_USER chown -R $CUR_USER:$CUR_GROUP /etc/salt/pki/master /etc/salt/master.d \ /var/log/salt/master /var/log/salt/key \ /var/cache/salt/master /var/run/salt/master \ || true if [ ! -f /var/lib/systemd/deb-systemd-helper-enabled/salt-master.service.dsh-also ] then # Workaround service status detection echo /etc/systemd/system/multi-user.target.wants/salt-master.service > /var/lib/systemd/deb-systemd-helper-enabled/salt-master.service.dsh-also fi ;; abort-upgrade) ;; *) echo "preinst called with unknown argument '$1'" >&2 exit 1 ;; esac # remove incorrectly installed ufw salt-master directory - issue 57712 test -d /etc/ufw/applications.d/salt-master && rm -rf /etc/ufw/applications.d/salt-master || /bin/true # dh_installdeb will replace this with shell code automatically # generated by other debhelper scripts. #DEBHELPER# exit 0