Skip to content

Make salt user home and extras dir configurable (#69402) - #69403

Merged
dwoz merged 15 commits into
saltstack:3006.xfrom
dwoz:fix/issue-69402
Jun 10, 2026
Merged

dwoz merged 15 commits into
saltstack:3006.xfrom
dwoz:fix/issue-69402

Conversation

@dwoz

@dwoz dwoz commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Makes the salt system user's home directory and the relenv extras-<py-ver> directory configurable across both Linux packaging stacks. Every DEB preinst (and salt-minion.postinst) now sources /etc/default/salt-setup and /etc/sysconfig/salt-minion-setup before applying the SALT_HOME/SALT_USER/SALT_GROUP/SALT_NAME defaults, mirroring the existing RPM %pre/%post minion behavior. A new SALT_EXTRAS_DIR override is honored by both stacks so the extras tree can be relocated outside /opt/saltstack/salt.

What issues does this PR fix or reference?

Fixes #69402

Previous Behavior

  • DEB preinst scripts only honored SALT_HOME/SALT_USER/SALT_GROUP/SALT_NAME exported in the environment before apt install. There was no equivalent of RPM's /etc/sysconfig/salt-minion-setup config-file override.
  • The extras directory chown path in pkg/rpm/salt.spec (%post minion upgrade branch) was hardcoded to discover any extras-* directory under /opt/saltstack/salt via find(1) and offered no relocation knob. The DEB salt-minion.postinst had no extras handling at all.

New Behavior

  • /etc/default/salt-setup (DEB-conventional) or /etc/sysconfig/salt-minion-setup (RPM-conventional, accepted on DEB for cross-distro parity) can be pre-created with SALT_HOME=..., SALT_USER=..., etc. and is picked up at install time on either stack. The historical "export the var before apt install" path still works.
  • A new SALT_EXTRAS_DIR knob is honored by the RPM %post minion upgrade chown and the DEB salt-minion.postinst configure step. When unset, the previous behavior (RPM: find(1) discovery under /opt/saltstack/salt; DEB: chown /opt/saltstack/salt recursively) is preserved.

Test plan

  • New tests/pytests/unit/test_pkg_scripts.py runs each DEB preinst's override-resolution prelude under bash with a redirected /etc, asserting the defaults, env-var override, /etc/default/salt-setup override, and /etc/sysconfig/salt-minion-setup override all resolve correctly. Two grep-based regression assertions cover the RPM SALT_EXTRAS_DIR knob and the preserved find(1) fallback.

Merge requirements satisfied?

  • Docs (no documented behavior changes; config-file paths and env-var names are install-time hooks)
  • Changelog
  • Tests written/updated

Commits signed with GPG?

No

@dwoz
dwoz requested a review from a team as a code owner June 9, 2026 01:32
@dwoz dwoz added this to the Sulphur v3006.26 milestone Jun 9, 2026
@dwoz dwoz added the test:full Run the full test suite label Jun 9, 2026
@dwoz

dwoz commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Added package-level integration tests at tests/pytests/pkg/integration/config_overrides/ (commit 6b7d3b4). Four parameterizations exercise the four override channels against a freshly installed DEB/RPM package:

  1. test_env_var_overrides — SALT_USER=alt_salt SALT_GROUP=alt_salt SALT_HOME=/var/lib/alt_salt SALT_EXTRAS_DIR=/opt/alt-extras exported to the package-manager call; no override file.
  2. test_deb_default_file_override — /etc/default/salt-setup pre-created with the alt_salt values; skipped on RPM systems.
  3. test_rpm_sysconfig_file_override — /etc/sysconfig/salt-minion-setup pre-created with the alt_salt values; runs on both stacks since the DEB preinst now sources it too.
  4. test_default_no_overrides — baseline: no env vars, no file. Confirms the historical salt:salt user, /opt/saltstack/salt home, and the find-discovered extras dir still work, and that alt_salt / /var/lib/alt_salt / /opt/alt-extras are NOT created.

Each test spins up its own function-scoped SaltPkgInstall so the install/uninstall cycle runs fresh per case. The cleanup_override_state fixture wipes both override files, the alt_salt user/group, and the alt home / extras dirs between tests.

The original unit-level tests/pytests/unit/test_pkg_scripts.py stays — the two layers are complementary: the unit test pins down the override-resolution prelude under bash with a redirected /etc, the package tests verify the same logic round-trips through a real apt/yum install.

@dwoz

dwoz commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Diagnosed the CI red and pushed 785d458. Three real bugs surfaced by the new package tests:

Bug 1 (DEB): Fresh install with SALT_USER=alt_salt created the alt_salt user via salt-common.preinst but the master/api/syndic/cloud postinst scripts still tried chown -R salt:salt … because nothing ran db_set <pkg>/user on the install) branch. The debconf template default Default: salt leaked through, the chown failed, dpkg left the packages in X not fully installed or removed, and the session-scoped install_salt fixture in the parent conftest then couldn't recover — cascading into 50+ sibling-test errors per DEB job.

Fix: every DEB preinst's install) branch now db_set <pkg>/user $SALT_USER so the postinst's db_get returns the resolved override.

Bug 2 (RPM): The RPM %pre common scriptlet hardcoded the rpm-build-time macros %{_SALT_USER} / %{_SALT_GROUP} / %{_SALT_HOME}, so neither env vars nor /etc/sysconfig/salt-minion-setup were consulted before the user/group was created. Same story in %posttrans cloud/master/syndic/api — chown targets were baked in at build time. (This is why Photon 5 was failing the override tests even though the file existed.)

Fix: source /etc/sysconfig/salt-minion-setup in %pre and every %posttrans block, then fall back to the macro defaults via [ -n "$VAR" ] || VAR=%{_DEFAULT}. The %post minion fresh-install chown path also now honors SALT_USER (in addition to the pre-existing SALT_MINION_USER knob) and chowns the explicit SALT_EXTRAS_DIR target when set.

Bug 3 (Windows collection): module-level import grp / import pwd broke the test_writable_dir_overrides.py collection on Windows runners even though pytestmark = skip_unless_on_linux was set — the marker can't fire until after import. Guarded behind sys.platform != "win32".

Test hardening:

  • cleanup_override_state now force-purges every salt package (dpkg --purge --force-all + apt-get purge, or dnf/yum remove), wipes debconf db entries via debconf-communicate PURGE, removes both the alt_salt AND salt users. Idempotent — the session install_salt that fires after my tests now starts from a known-clean state regardless of how my tests exit.
  • _install_salt_with wraps the SaltPkgInstall context manager in contextlib.ExitStack so even if __enter__ raises (broken install), the system gets purged before re-raising.
  • test_env_var_overrides now skips on RPM — yum/dnf does not forward env vars to scriptlets, so the env-var channel is intrinsically DEB-only. test_rpm_sysconfig_file_override covers the RPM equivalent through the file channel.
  • _assert_extras_dir_owned_correctly asserts ownership at whatever path the extras tree actually exists at — SALT_EXTRAS_DIR doesn't relocate the tree on its own, only chowns the configured location.

The 27 unit-level tests in tests/pytests/unit/test_pkg_scripts.py still pass locally; the prelude-extraction logic stops at case "$1" in so the new db_set lines don't affect that coverage.

New SHA: 785d458

Redact HTTP credentials in get_source_sum errors and prefix early
get_managed failures with "Unable to manage file" so test_issue_60203
passes. Skip distro-wide upgrades during --no-install pkg sessions so
yum/apt cannot replace the onedir under test, and always run the package
upgrade in test_salt_upgrade even when the pre-upgrade pip check fails.
Daniel A. Wozniak added 2 commits June 9, 2026 15:37
Import escape from rich.markup and wrap pprint output so PR merge refs
against current 3006.x no longer crash Prepare Workflow Run.
Resolve tools/ci.py quote-style conflicts while keeping the escape
import and pprint logging wrappers needed for workflow-config.
Daniel A. Wozniak added 8 commits June 9, 2026 18:38
yum update -y and apt upgrade -y can replace the onedir under test with
a newer Salt release from the Salt repos (e.g. 3008.0), causing
test_salt_upgrade to fail because the installed version exceeds the
artifact version. Exclude salt* from yum and hold/unhold salt packages
on Debian so the system upgrade only touches non-Salt packages.

Verified in a Rocky Linux 8 container: yum update -y upgrades
salt-minion 3006.25 to 3008.0; yum update -y --exclude=salt* leaves
salt-minion at 3006.25.
install_previous() downloads salt.repo from salt-install-guide which
enables both salt-repo-3006-lts and salt-repo-3008-lts by default. When
yum install runs without version pinning, it picks 3008.0 from the
3008-lts repo (newer than 3006.25), causing test_salt_upgrade to fail
with: assert Version('3008.0') <= Version('3006.25+107.ga508051fad').

The existing code only disabled salt-repo-3007-sts but left 3008-lts
enabled. Add symmetric handling to disable salt-repo-3008-lts unless
the target prev_version is 3008.x.

Reproduced in ghcr.io/saltstack/salt-ci-containers/testing:rockylinux-9:
- Without fix: yum install salt* installs 3008.0 from salt-repo-3008-lts
- With fix: yum install salt* installs 3006.25 from salt-repo-3006-lts
Commit 09cd140 changed managed() to prefix error messages from
file.get_managed with 'Unable to manage file:' to fix test_issue_60203.
This broke two tests that expected the raw message without the prefix:

- test_patch_saltenv: patch() calls managed() internally and returns
  its result directly. The comment now includes the prefix.

- test_managed: the mock for file.get_managed returns True as the comment
  value; managed() now wraps it as 'Unable to manage file: True'.
…nges

After a password change on Windows, the post-change comparison detects
that user.info's password_changed timestamp and shadow.info's lstchg
field both changed. These are side effects of the password change and
are already captured by passwd: XXX-REDACTED-XXX. Reporting them
separately makes ret.changes wider than intended and breaks the
test_win_user_present_new_password assertion.

Pop password_changed and lstchg from ret.changes when on Windows and
_passwd_changed is True so the only reported change is passwd.
…hive tarball path

The commit 8bfd5c4 on 3006.x added a `git add -f salt/_version.txt`
step before pip install in salt_onedir(), but passed cwd=str(salt_archive)
where salt_archive is the path to the .tar.gz file, not a directory.
This caused `NotADirectoryError` at runtime.

Fix by passing cwd=str(tools.utils.REPO_ROOT) so git runs in the repository
root where the tracked file actually lives.

@sujitdb sujitdb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

This branch was previously deployed

1 inactive deployment
ci — 29762c4b Deployed Jun 10, 2026 by dwoz via Build Onedir Packages / Windows (amd64) #23853
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test:full Run the full test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants