Skip to content

plugins/auth/pam: expose sudo prompt to PAM via SUDO_PROMPT env - #539

Merged
millert merged 1 commit into
sudo-project:mainfrom
3v1n0:expose-pam-prompt
Oct 12, 2026
Merged

millert merged 1 commit into
sudo-project:mainfrom
3v1n0:expose-pam-prompt

Conversation

@3v1n0

@3v1n0 3v1n0 commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Some PAM modules implementations do not use PAM conversations and instead present their own native client when they have access to the terminal. In those cases, modules cannot infer sudo's custom prompt text from the conversation callback path.

Set SUDO_PROMPT in the PAM environment before pam_authenticate(), so modules that render their own UI can combine:

  • PAM service identity (from the PAM transaction)
  • sudo's resolved prompt string (SUDO_PROMPT)

to display a consistent, context-aware prompt.

To avoid stale state, clear SUDO_PROMPT before authentication starts and clear it again after pam_authenticate() returns.

Allowing PAM modules in the stack to read (and potentially change) SUDO_PROMPT does not introduce a new trust boundary concern: PAM modules already control the conversation flow and can provide their own prompt text/messages through the standard PAM conversation mechanism.

Comment thread plugins/sudoers/auth/pam.c Outdated
debug_return_int(AUTH_ERROR);
}

if (def_prompt && ctx->user.prompt) {

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.

It's not possible for def_prompt to be NULL. I would change the conditional to be:

if (ctx->user.prompt || def_passprompt_override) {
    ...
}

That way SUDO_PROMPT will also be set if the "passprompt_override" sudoers option is enabled.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, good idea!

Some PAM implementations do not use PAM conversations and instead
present their own native client UI. In those cases, modules cannot
infer sudo's custom prompt text from the conversation callback path.

Set SUDO_PROMPT in the PAM environment before pam_authenticate(),
so modules that render their own UI can combine:
 - PAM service identity (from the PAM transaction)
 - sudo's resolved prompt string (SUDO_PROMPT)

to display a consistent, context-aware prompt.

To avoid stale state, clear SUDO_PROMPT before authentication starts
and clear it again after pam_authenticate() returns.

Allowing PAM modules in the stack to read (and potentially change)
SUDO_PROMPT does not introduce a new trust boundary concern:
PAM modules already control the conversation flow and can provide
their own prompt text/messages through the standard PAM conversation
mechanism.
@3v1n0
3v1n0 force-pushed the expose-pam-prompt branch from a8f777d to c2bc7d9 Compare October 9, 2026 12:37

@millert millert 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.

Looks good, thanks!

@millert
millert merged commit f2f3409 into sudo-project:main Oct 12, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants