Skip to content

Authentication: Add Service Principal and Azure CLI support#17

Open
ZanattaMichael wants to merge 1 commit into
mainfrom
claude/add-azure-auth-methods-hwqtD
Open

Authentication: Add Service Principal and Azure CLI support#17
ZanattaMichael wants to merge 1 commit into
mainfrom
claude/add-azure-auth-methods-hwqtD

Conversation

@ZanattaMichael

Copy link
Copy Markdown
Owner

Pull Request (PR) description

This PR extends the authentication capabilities of AzureDevOpsDsc by adding support for three new authentication methods:

  1. Service Principal with Client Secret - OAuth 2.0 client credentials flow
  2. Service Principal with Certificate - JWT assertion-based authentication using X.509 certificates
  3. Azure CLI - Token acquisition via the Azure CLI (az account get-access-token)

These methods complement the existing Personal Access Token and Managed Identity authentication options, providing more flexible authentication scenarios for Azure DevOps DSC in different environments.

Key Changes:

  • New Token Classes: Added ServicePrincipalToken and CertificateToken classes to represent and manage tokens from these authentication methods, with automatic expiration tracking and refresh capabilities
  • New Token Acquisition Functions:
    • Get-AzServicePrincipalToken - Acquires tokens using client credentials
    • Get-AzServicePrincipalCertificateToken - Acquires tokens using certificate-based JWT assertions
    • Get-AzCliToken - Acquires tokens via Azure CLI
    • Build-JWTAssertion - Constructs signed JWT assertions for certificate authentication
  • Token Refresh Functions: Added Update-AzServicePrincipal, Update-AzServicePrincipalCertificate, and Update-AzCliToken for automatic token refresh when expired
  • Enhanced New-AzDoAuthenticationProvider: Extended with new parameter sets to support all three authentication methods with both plain-text and SecureString credential variants
  • Updated Add-AuthenticationHTTPHeader: Enhanced to handle token refresh for the new authentication types
  • TokenType Enum: Updated to include ServicePrincipal and AzureCLI token types

Testing:

  • Added comprehensive unit tests for all new token classes and functions
  • Added integration tests for Service Principal, Certificate, and Azure CLI authentication methods
  • Added integration tests for token auto-refresh behavior
  • Updated existing authentication tests to cover new authentication types

This Pull Request (PR) fixes the following issues

None

Task list

  • Added an entry to the change log under the Unreleased section of the file CHANGELOG.md
  • Comment-based help updated, including parameter descriptions
  • Unit tests updated
  • Integration tests added
  • Code changes adhere to DSC Community Style Guidelines

https://claude.ai/code/session_019ZwHAq4fwLyDgMU59mmDwd

- Fix existing bug: Update-AzManagedIdentity now returns the token so
  Add-AuthenticationHTTPHeader's assignment captures it correctly
- Add ServicePrincipal and AzureCLI to TokenType enum; Certificate was
  already defined but unimplemented
- Add three new token classes: ServicePrincipalToken, CertificateToken,
  AzureCliToken — each inherits AuthenticationToken with expiry checking
- ServicePrincipalToken.GetClientSecret() enforces call stack restriction
  so only Update-AzServicePrincipal can retrieve the stored secret
- Add OAuth 2.0 client credentials flow for service principals
  (Get-AzServicePrincipalToken, Update-AzServicePrincipal)
- Add JWT assertion signing with X.509 certificate for cert-based SP auth
  (Build-JWTAssertion, Get-AzServicePrincipalCertificateToken,
  Update-AzServicePrincipalCertificate); supports cert store thumbprint
  and cross-platform PFX file loading
- Add Azure CLI token acquisition via az account get-access-token
  (Get-AzCliToken, Update-AzCliToken) with mockable Invoke-AzCLICommand
- Update Add-AuthenticationHTTPHeader with auto-refresh for new types
- Update New-AzDoAuthenticationProvider with new parameter sets:
  ServicePrincipal, SecureStringServicePrincipal, Certificate,
  CertificateFile, AzureCLI
- Update AzDevOpsDscResourceBase.Construct() to restore each new token
  type from serialized ModuleSettings.clixml
- Add unit tests for all new classes and functions
- Add integration tests for each auth method (skip if env vars absent)

https://claude.ai/code/session_019ZwHAq4fwLyDgMU59mmDwd
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