Skip to content

Skip saltutil runner/wheel privilege drop on invalid user (#69600) - #69609

Merged
dwoz merged 1 commit into
saltstack:3006.xfrom
dwoz:dwoz/fix/issue-69600-runas-invalid-user
Jul 1, 2026
Merged

Skip saltutil runner/wheel privilege drop on invalid user (#69600)#69609
dwoz merged 1 commit into
saltstack:3006.xfrom
dwoz:dwoz/fix/issue-69600-runas-invalid-user

Conversation

@dwoz

@dwoz dwoz commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Make saltutil.runner / saltutil.wheel skip the master-user privilege drop
when the configured user is not a real account on the system, falling back
to the historical in-process behavior.

What issues does this PR fix or reference?

Fixes #69600 (regression from #69240 / #67716)

Previous Behavior

Running an orchestration under sudo -- e.g.

sudo salt-run state.orchestrate orch.os_updates pillar='{"env":"mgmt"}'

-- whose rendered SLS called salt.saltutil.runner('cache.grains', ...)
from Jinja failed with:

Failed to run 'cache.grains' as user 'sudo_alice':
KeyError: "getpwnam(): name not found: 'sudo_alice'"

state.orchestrate overwrites __opts__["user"] with __user__ (the
publishing user, salt.utils.user.get_specific_user(), which returns
"sudo_<login>" when invoked under sudo). The privilege-drop helper
introduced in #69240 read that value as the runas target and asked
chugid to switch to it, raising KeyError from pwd.getpwnam.

New Behavior

_master_user_runas now validates the candidate against the passwd
database and returns None (skip the drop) when it does not resolve to
a real user. Orchestrations launched under sudo therefore keep
working; the privilege drop still triggers when the master is genuinely
configured to run as a different real user (the case the original fix
intended to cover).

Merge requirements satisfied?

  • Changelog
  • Tests written/updated

Commits signed with GPG?

No

state.orchestrate overwrites __opts__["user"] with __user__ (the
publishing user, salt.utils.user.get_specific_user(), which returns
"sudo_<login>" when salt-run was launched under sudo). The post-saltstack#67716
privilege-drop path in saltutil.runner/saltutil.wheel reads that value
as the runas target and asks chugid to switch to it, which then raises
KeyError from pwd.getpwnam wrapped in CommandExecutionError:

    Failed to run 'cache.grains' as user 'sudo_alice':
    KeyError: "getpwnam(): name not found: 'sudo_alice'"

Validate the candidate against the passwd database in
_master_user_runas and skip the privilege drop when it does not
resolve to a real account, falling back to historical in-process
behavior.

Fixes saltstack#69600
@dwoz
dwoz requested a review from a team as a code owner June 30, 2026 22:12
@dwoz dwoz added this to the Sulphur v3006.27 milestone Jun 30, 2026
@dwoz dwoz added the test:full Run the full test suite label Jun 30, 2026
@dwoz
dwoz merged commit 7ec32d6 into saltstack:3006.x Jul 1, 2026
861 of 870 checks passed
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.

2 participants