-
Notifications
You must be signed in to change notification settings - Fork 160
Add Administrator Protection Compatibility with Windows Hello Authentication #131
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add Administrator Protection Compatibility with Windows Hello Authentication #131
Conversation
…ication - Added core library for Sudo Elevation Broker with modules for audit logging, elevation handling, and service management. - Implemented audit logging to Windows Event Log for elevation requests, successes, failures, and authentication issues. - Developed ElevationHandler to create elevated processes in System Managed Administrator Account context. - Created PipeServer to handle client connections and elevation requests via named pipes. - Established BrokerService to manage service lifecycle and control requests. - Configured logging to file in ProgramData with daily rotation. - Implemented security checks to ensure only authorized clients can request elevation. - Added configuration loading functionality with default values. - Added support for Windows Administrator Protection. - Added support for Windows Hello. Fixes microsoft#125 Signed-off-by: Giovanni Magliocchetti <giovimag123@gmail.com>
There was a problem hiding this 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 implements comprehensive Windows 11 Administrator Protection (AP) compatibility for sudo through a broker service pattern with Windows Hello authentication. It automatically detects the elevation environment and routes requests accordingly - using traditional UAC for standard environments or the new broker service for AP-enabled systems.
Key changes include:
- AP environment detection with automatic routing between legacy UAC and broker-based elevation
- Windows Hello authentication with HMAC-SHA256 signed tokens for audit trail integrity
- Named pipe-based IPC with three-layer security (DACL, client identity verification, cryptographic tokens)
Reviewed Changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
sudo_ap_broker/src/service.rs |
Windows service implementation with lifecycle management and status reporting |
sudo_ap_broker/src/pipe_server.rs |
Named pipe server with security verification and client handling |
sudo_ap_broker/src/main.rs |
Service entry point with logging configuration |
sudo_ap_broker/src/lib.rs |
Library exports and default service configuration |
sudo_ap_broker/src/elevation.rs |
Process elevation handler using SMAA with Windows Hello token validation |
sudo_ap_broker/src/audit_logger.rs |
Windows Event Log integration for security audit trail |
sudo_ap_broker/Cargo.toml |
Broker service dependencies and Windows API features |
sudo/src/run_handler.rs |
Smart routing logic between legacy UAC and AP broker elevation paths |
sudo/src/main.rs |
Added new module declarations for AP functionality |
sudo/src/lib.rs |
Public API exports for broker client and AP detection |
sudo/src/hello_auth.rs |
Windows Hello authentication with HMAC-SHA256 token generation |
sudo/src/broker_protocol.rs |
Binary protocol definition with versioning and validation |
sudo/src/broker_client.rs |
Named pipe client with connection retry logic and timeout handling |
sudo/src/ap_detection.rs |
AP environment detection via registry and system capability checks |
sudo/Cargo.toml |
Added dependencies for crypto operations and Windows Hello APIs |
scripts/install-broker-service.ps1 |
PowerShell installation script with service configuration |
Cargo.toml |
Workspace-level dependencies for serialization and crypto |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…signatures, and clean up imports Signed-off-by: Giovanni Magliocchetti <giovimag123@gmail.com>
|
@DHowett pinging you for a review since @obrobrio2000 put a lot of work into this, would be nice if someone could look at it. |
Thank you @floh96 ! |
Fixes #125
Summary
This PR implements complete Windows 11 Administrator Protection (AP) compatibility for sudo. The solution uses a broker service pattern to enable elevation through System Managed Administrator Accounts (SMAA) with Windows Hello authentication.
Problem Statement
Windows 11's Administrator Protection feature introduces SMAA with strict security boundaries where only whitelisted SYSTEM processes can create elevated logon sessions. This causes
sudo.exeto fail withAccess Denied (0x80070005)errors, completely breaking elevation functionality for users with AP enabled.Solution Overview
Architecture
The solution implements a service broker pattern with automatic environment detection:
Key Components
AP Detection Module (
sudo/src/ap_detection.rs)FilterAdministratorTokenElevationCapabilitiesstructBroker Protocol (
sudo/src/broker_protocol.rs)Broker Client (
sudo/src/broker_client.rs)\\.\pipe\SudoElevationBroker)Windows Hello Authentication (
sudo/src/hello_auth.rs)UserConsentVerifierintegrationblock_on_async)COINIT_MULTITHREADEDGetTokenInformation)GetComputerNameExW)MachineGuidBroker Service (
sudo_ap_broker/)D:(A;;GA;;;SY)(A;;GA;;;BA))ImpersonateNamedPipeClient+CheckTokenMembershipCreateProcessAsUserWRevertGuard,SidGuard)Smart Routing Integration (
sudo/src/run_handler.rs- modified)do_request()ElevationEnvironment:StandardUAC→ Legacy UAC path (ShellExecute/RPC)AdminProtectionWithHello→ Hello auth → Broker serviceAdminProtectionWithoutHello→ Error with setup instructionsNoAdminPrivileges→ Error messageUnknown→ Fallback to legacy with warninguse_legacy_elevation(),use_ap_broker_elevation()Smart Routing Decision Flow
Features
Automatic Environment Detection
FilterAdministratorToken)Windows Hello Authentication
Named Pipe IPC
Audit Logging
Multiple Execution Modes
Error Handling
tracing::trace_log_message()Backward Compatibility
✅ Fully backward compatible:
Installation
Automated Installation
Manual Installation
Configuration
Service configuration file:
C:\ProgramData\Microsoft\Sudo\config.tomlDocumentation
Comprehensive Guides
Key Documentation Sections
Testing
Comprehensive Test Suite
Test Coverage Highlights
✅ Security validation: Token signature verification, tamper detection, replay protection
✅ Edge cases: Oversized messages (>16MB), invalid serialization data, corrupted tokens
✅ Boundary values: Timeout limits (1000ms minimum), message size limits, nonce uniqueness
✅ Error handling: Non-admin connections, service unavailable, Hello not configured
✅ Internationalization: Unicode in commands/arguments (Japanese, Cyrillic, emoji)
✅ RAII validation: Automatic cleanup in error paths (RevertGuard, SidGuard)
Test Scenarios to Run
sudo whoami,sudo echo testsudo notepad C:\Windows\System32\drivers\etc\hostssudo ping localhost -n 10sudo cmd--new-window,--hidden, inlineTest Matrix
Remaining Work
Dependencies Added
Workspace-Level (
Cargo.toml)New Windows Features
Foundation(WinRT async operations)Security_Credentials_UI(Windows Hello)Win32_System_Com(COM initialization)Win32_System_IO(Named pipes)Win32_System_PipesWin32_System_ServicesWin32_System_EventLogSecurity Considerations
Authentication
MachineGuidAuthorization
CheckTokenMembershipRevertToSelf,FreeSid) in all code pathsAudit Trail
Process Isolation
Performance
Overhead
Resource Usage
Breaking Changes
None - This PR is fully backward compatible. StandardUAC environments continue to use the existing elevation path with no behavioral changes.
Migration Guide
For End Users
winget upgrade Microsoft.SudoFor Enterprise
config.tomlValidation Checklist
Future Enhancements (Not in This PR)
Cryptographic Auth Tokens: Replace timestamp-based tokens with HMAC/JWT✅ COMPLETED in this PRReferences
Reviewer Notes
Key Areas for Review
Security:
Architecture:
Performance: