Skip to content

[release-0.x] Fix Windows sudo detection to use IsInRole for effective elevation check#338

Merged
kke merged 3 commits intorelease-0.xfrom
fix/windows-sudo-elevation-0x
May 7, 2026
Merged

[release-0.x] Fix Windows sudo detection to use IsInRole for effective elevation check#338
kke merged 3 commits intorelease-0.xfrom
fix/windows-sudo-elevation-0x

Conversation

@kke
Copy link
Copy Markdown
Contributor

@kke kke commented May 7, 2026

Replace the three-step heuristic (whoami username check, net user Administrators group check, EnableLUA registry query) with a single PowerShell IsInRole call. WindowsPrincipal.IsInRole uses CheckTokenMembership and returns true only when the Administrators SID is present and not marked deny-only — the correct signal for an effectively elevated session. This handles SSH sessions (Windows OpenSSH always provides a full elevated token for Administrators group members, regardless of UAC), WinRM domain accounts, and local accounts with LocalAccountTokenFilterPolicy=1. Also updates the error message to accurately reflect what was detected.

Fixes #332

…e elevation check

Replace the three-step heuristic (whoami username check, net user Administrators
group check, EnableLUA registry query) with a single PowerShell IsInRole call.
WindowsPrincipal.IsInRole uses CheckTokenMembership and returns true only when
the Administrators SID is present and not marked deny-only — the correct signal
for an effectively elevated session. This handles SSH sessions (Windows OpenSSH
always provides a full elevated token for Administrators group members, regardless
of UAC), WinRM domain accounts, and local accounts with LocalAccountTokenFilterPolicy=1.
Also updates the error message to accurately reflect what was detected.

Fixes #332

Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Windows sudo detection in Connection.discoverSudo() by replacing a multi-step UAC/username/group-membership heuristic with a single PowerShell WindowsPrincipal.IsInRole(Administrator) check, aiming to correctly detect effective elevation for sessions such as OpenSSH/WinRM and avoid false “sudo required” failures.

Changes:

  • Replace Windows admin/elevation detection heuristic with an IsInRole-based privilege check.
  • Update the Windows ErrSudoRequired message to reflect missing administrator privileges for the current session.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread connection.go Outdated
Comment thread connection.go
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment thread connection.go Outdated
Signed-off-by: Kimmo Lehto <klehto@mirantis.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@kke kke merged commit 1ad8339 into release-0.x May 7, 2026
11 checks passed
@kke kke deleted the fix/windows-sudo-elevation-0x branch May 7, 2026 11:07
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