-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add az CLI shim for Azure token acquisition via ado-codespaces-auth #95
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
37751ca
feat: add az CLI shim for Azure token acquisition via ado-codespaces-…
ansemb 83b1150
remove date
ansemb 9223123
rename
ansemb 1c1dfb2
Add az CLI shim for DefaultAzureCredential support in Codespaces
ansemb 279265f
readd , , and
ansemb ffcce70
Bump version to 3.0.3
ansemb 6d1fb8f
fix copilot suggestions
ansemb 2330272
add tests
ansemb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| #!/bin/bash | ||
| # Azure CLI shim for GitHub Codespaces | ||
| # Intercepts 'az account get-access-token' requests and uses azure-auth-helper | ||
| # to acquire tokens via the ado-codespaces-auth VS Code extension. | ||
| # | ||
| # This enables DefaultAzureCredential's AzureCliCredential to work in Codespaces | ||
| # without requiring 'az login' (which times out waiting for browser auth). | ||
| # | ||
| # To install: Copy this to /usr/local/share/codespace-shims/az | ||
| # The shims directory should already be in PATH for Codespaces. | ||
|
|
||
| # If ACTIONS_ID_TOKEN_REQUEST_URL is set, we're in GitHub Actions - skip interception | ||
| if [ -n "${ACTIONS_ID_TOKEN_REQUEST_URL}" ]; then | ||
| source "$(dirname $0)"/resolve-shim.sh | ||
| AZ_EXE="$(resolve_shim)" | ||
| exec "${AZ_EXE}" "$@" | ||
| fi | ||
|
|
||
| source "$(dirname $0)"/resolve-shim.sh | ||
|
ansemb marked this conversation as resolved.
Outdated
|
||
|
|
||
| # Well-known resource type mappings (az account get-access-token --resource-type) | ||
| declare -A RESOURCE_TYPE_MAP=( | ||
| ["arm"]="https://management.azure.com" | ||
| ["aad-graph"]="https://graph.windows.net" | ||
| ["ms-graph"]="https://graph.microsoft.com" | ||
| ["batch"]="https://batch.core.windows.net" | ||
| ["data-lake"]="https://datalake.azure.net" | ||
| ["media"]="https://rest.media.azure.net" | ||
| ["oss-rdbms"]="https://ossrdbms-aad.database.windows.net" | ||
| ) | ||
|
|
||
| # Check if this is a get-access-token request that we should intercept | ||
| if [[ "$1" == "account" && "$2" == "get-access-token" ]]; then | ||
| # Parse arguments to extract --resource, --scope, or --resource-type | ||
| resource="" | ||
| scope="" | ||
| resource_type="" | ||
| prev="" | ||
|
|
||
| for arg in "${@:3}"; do | ||
| case "$prev" in | ||
| --resource) | ||
| resource="$arg" | ||
| ;; | ||
| --scope) | ||
| scope="$arg" | ||
| ;; | ||
| --resource-type) | ||
| resource_type="$arg" | ||
| ;; | ||
| esac | ||
| prev="$arg" | ||
|
ansemb marked this conversation as resolved.
Outdated
|
||
| done | ||
|
|
||
| # Resolve resource-type to resource URL if specified | ||
| if [[ -n "$resource_type" && -z "$resource" ]]; then | ||
| resource="${RESOURCE_TYPE_MAP[$resource_type]}" | ||
|
markphip marked this conversation as resolved.
|
||
| fi | ||
|
|
||
| # Determine the scope to request | ||
| # Priority: explicit --scope > --resource/.default > --resource-type/.default | ||
| request_scope="" | ||
| if [[ -n "$scope" ]]; then | ||
| request_scope="$scope" | ||
| elif [[ -n "$resource" ]]; then | ||
| # Append /.default if not already present | ||
| if [[ "$resource" == *"/.default" ]]; then | ||
| request_scope="$resource" | ||
| else | ||
| request_scope="${resource}/.default" | ||
| fi | ||
| fi | ||
|
|
||
| # If we have a scope and azure-auth-helper exists, use it | ||
| if [[ -n "$request_scope" && -f "${HOME}/azure-auth-helper" ]]; then | ||
| # Get token from azure-auth-helper | ||
| token=$("${HOME}/azure-auth-helper" get-access-token "$request_scope" 2>/dev/null) | ||
| exit_code=$? | ||
|
|
||
| if [[ $exit_code -eq 0 && -n "$token" ]]; then | ||
| # Return in az CLI JSON format | ||
| cat <<EOF | ||
| { | ||
| "accessToken": "${token}", | ||
|
ansemb marked this conversation as resolved.
Outdated
|
||
| "tokenType": "Bearer" | ||
| } | ||
| EOF | ||
|
ansemb marked this conversation as resolved.
|
||
| exit 0 | ||
| fi | ||
| # Fall through to real az CLI if azure-auth-helper fails | ||
| fi | ||
| fi | ||
|
|
||
| # Fall through to real az CLI for all other commands | ||
| AZ_EXE="$(resolve_shim)" | ||
| if [[ -n "$AZ_EXE" ]]; then | ||
| exec "${AZ_EXE}" "$@" | ||
| else | ||
| echo "Error: Azure CLI not found in PATH" >&2 | ||
| exit 1 | ||
| fi | ||
|
ansemb marked this conversation as resolved.
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.