Skip to content

🚀 [Feature]: Adding functionality to sign JWTs via Key Vault Keys #481

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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

MariusStorhaug
Copy link
Member

@MariusStorhaug MariusStorhaug commented Jul 17, 2025

Description

This pull request introduces support for signing GitHub App JSON Web Tokens (JWTs) using Azure Key Vault in addition to local RSA private keys. It also refactors and enhances existing JWT-related functionality to improve maintainability and clarity. The most significant changes include the addition of Azure Key Vault integration, refactoring of JWT signing methods, and updates to related utility functions.

Improvements to Authentication Logic

  • Enhanced Connect-GitHubAccount to support both private key and Azure Key Vault-based authentication for GitHub Apps, introducing new parameter sets and validation for KeyVaultKeyReference.

Azure Key Vault Integration

  • Added a new KeyVaultKeyReference property to the GitHubAppContext class for specifying Azure Key Vault keys as an alternative to local private keys.
  • Introduced the Add-GitHubKeyVaultJWTSignature function to sign JWTs using Azure Key Vault keys, supporting both Azure CLI and Az PowerShell authentication.
  • Added utility functions Test-GitHubAzureCLI and Test-GitHubAzPowerShell to check for Azure CLI and Az PowerShell module installation and authentication.

Refactoring of JWT Signing

  • Renamed Add-GitHubJWTSignature to Add-GitHubLocalJWTSignature for clarity and updated it to use the new GitHubJWTComponent helper for base64 URL encoding.
  • Updated Update-GitHubAppJWT to conditionally use either Add-GitHubLocalJWTSignature or Add-GitHubKeyVaultJWTSignature based on the presence of PrivateKey or KeyVaultKeyReference in the context.

Enhancements to JWT Utility Functions

  • Added GitHubJWTComponent class to centralize base64 URL encoding logic and simplify JWT creation.
  • Updated New-GitHubUnsignedJWT to use GitHubJWTComponent for encoding JWT headers and payloads.

Type of change

  • 📖 [Docs]
  • 🪲 [Fix]
  • 🩹 [Patch]
  • ⚠️ [Security fix]
  • 🚀 [Feature]
  • 🌟 [Breaking change]

Checklist

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

…WTSignature` functions; update `Update-GitHubAppJWT` to use local signing method
…r JWT signing functions and update authentication methods in `Connect-GitHubAccount`
@MariusStorhaug MariusStorhaug self-assigned this Jul 17, 2025
@Copilot Copilot AI review requested due to automatic review settings July 17, 2025 15:58
@MariusStorhaug MariusStorhaug requested a review from a team as a code owner July 17, 2025 15:58
Copy link
Contributor

@Copilot 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 pull request introduces Azure Key Vault integration for GitHub App JWT signing, enabling secure storage and usage of private keys through Azure Key Vault as an alternative to local private key files. The changes enhance security by eliminating the need to store sensitive private keys locally while maintaining backward compatibility with existing private key authentication.

  • Adds support for Azure Key Vault key references in GitHub App authentication flows
  • Refactors JWT signing functionality to support both local private keys and Key Vault-based signing
  • Introduces new utility functions to validate Azure CLI and Azure PowerShell authentication states

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
Connect-GitHubAccount.ps1 Enhanced to support Key Vault key references with new parameter sets and validation
Test-GitHubAzureCLI.ps1 New utility function to verify Azure CLI installation and authentication status
Test-GitHubAzPowerShell.ps1 New utility function to verify Azure PowerShell module availability and authentication
Update-GitHubAppJWT.ps1 Modified to conditionally use either local or Key Vault JWT signing based on context
New-GitHubUnsignedJWT.ps1 Refactored to use new GitHubJWTComponent class for base64 URL encoding
Add-GitHubLocalJWTSignature.ps1 Renamed from Add-GitHubJWTSignature and updated to return secure string
Add-GitHubKeyVaultJWTSignature.ps1 New function implementing Key Vault-based JWT signing with Azure authentication
GitHubJWTComponent.ps1 New utility class centralizing base64 URL encoding logic for JWT operations
GitHubAppContext.ps1 Extended to include KeyVaultKeyReference property for Key Vault authentication
README.md Updated documentation with Key Vault authentication examples and prerequisites

… in `Update-GitHubAppJWT` and adding `Test-GitHubJWTRefreshRequired` function for refresh validation
…T` and `Update-GitHubUserAccessToken` to use hyphens instead of slashes for improved compatibility
…ired` to use `JwtTimeTolerance` instead of `JwtRefreshThreshold` for improved accuracy
- Created TEMPLATE.ps1 for Pester tests with default configurations.
- Added Teams.Tests.ps1 to test GitHub Teams API functionalities including team creation, retrieval, updating, and deletion.
- Introduced Users.Tests.ps1 to validate user-related API calls such as user retrieval and updates.
- Implemented Variables.Tests.ps1 to cover GitHub variable management including setting, updating, and removing variables for users, organizations, and repositories.
…matting context display for better readability
…ed` and improve error handling in `Test-GitHubAccessTokenRefreshRequired`
- Created TEMPLATE.ps1 for structuring Pester tests with authentication cases.
- Added Teams.Tests.ps1 to test GitHub Teams API functionalities, including team creation, retrieval, updating, and deletion.
- Introduced Users.Tests.ps1 to validate user-related API calls, including user retrieval and updates.
- Implemented Variables.Tests.ps1 to test GitHub variable management, covering organization and repository scopes, variable creation, updates, and deletions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

🚀[Feature]: Support KeyVault-based signing for GitHub App JWTs
1 participant