diff --git a/.github/workflows/shared/azure-auth.md b/.github/workflows/shared/azure-auth.md new file mode 100644 index 00000000000..da99e0a09ec --- /dev/null +++ b/.github/workflows/shared/azure-auth.md @@ -0,0 +1,173 @@ +--- +description: Azure CLI OIDC re-authentication for agentic workflows. +import-schema: + azure-client-id: + type: string + required: true + description: Azure App (client) ID for OIDC authentication + azure-tenant-id: + type: string + required: true + description: Azure tenant ID + +permissions: + id-token: write + +env: + AZURE_CONFIG_DIR: /tmp/gh-aw/agent/.azure + +network: + allowed: + - login.microsoftonline.com + - management.azure.com + +pre-steps: + - name: Fetch Azure OIDC token + id: azure-oidc + run: | + OIDC_TOKEN=$(curl -sS --max-time 30 \ + -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \ + "${ACTIONS_ID_TOKEN_REQUEST_URL}&audience=api://AzureADTokenExchange" \ + | jq -r '.value') + if [ -z "$OIDC_TOKEN" ] || [ "$OIDC_TOKEN" = "null" ]; then + echo "::error::Failed to obtain Azure OIDC token — ensure id-token: write permission is granted" + exit 1 + fi + echo "::add-mask::$OIDC_TOKEN" + TOKEN_DIR="${RUNNER_TEMP:-/tmp}/gh-aw/azure" + mkdir -p "$TOKEN_DIR" + TOKEN_FILE=$(mktemp "$TOKEN_DIR/oidc-token.XXXXXX") + chmod 600 "$TOKEN_FILE" + printf '%s' "$OIDC_TOKEN" > "$TOKEN_FILE" + echo "GH_AW_AZURE_OIDC_TOKEN_FILE=$TOKEN_FILE" >> "$GITHUB_ENV" + +pre-agent-steps: + - name: Re-authenticate Azure CLI with OIDC + env: + GH_AW_AZURE_CLIENT_ID: ${{ github.aw.import-inputs.azure-client-id }} + GH_AW_AZURE_TENANT_ID: ${{ github.aw.import-inputs.azure-tenant-id }} + run: | + if [ -z "$GH_AW_AZURE_OIDC_TOKEN_FILE" ] || [ ! -f "$GH_AW_AZURE_OIDC_TOKEN_FILE" ]; then + echo "::error::Azure OIDC token file not found — the Fetch Azure OIDC token step may have failed" + exit 1 + fi + mkdir -p "$AZURE_CONFIG_DIR" + chmod 700 "$AZURE_CONFIG_DIR" + cleanup() { + rm -f "$GH_AW_AZURE_OIDC_TOKEN_FILE" + } + trap cleanup EXIT + az login --service-principal \ + --username "$GH_AW_AZURE_CLIENT_ID" \ + --tenant "$GH_AW_AZURE_TENANT_ID" \ + --federated-token "$(cat "$GH_AW_AZURE_OIDC_TOKEN_FILE")" \ + --output none \ + --only-show-errors + az account show --output table +--- + + diff --git a/.github/workflows/shared/mcp/azure-devops.md b/.github/workflows/shared/mcp/azure-devops.md new file mode 100644 index 00000000000..4ed28fe1aa8 --- /dev/null +++ b/.github/workflows/shared/mcp/azure-devops.md @@ -0,0 +1,86 @@ +--- +description: Azure DevOps MCP server for agentic workflows. +import-schema: + organization: + type: string + required: true + description: Azure DevOps organization name only (the subdomain in https://dev.azure.com/, not a full URL) + +network: + allowed: + - "*.dev.azure.com" + - "*.visualstudio.com" + - "*.microsoftonline.com" + - app.vssps.visualstudio.com + +mcp-servers: + azure-devops: + url: "https://mcp.dev.azure.com/${{ github.aw.import-inputs.organization }}" + headers: + Authorization: "****** secrets.ADO_MCP_AUTH_TOKEN }}" + allowed: + - "*" +--- + + diff --git a/.github/workflows/shared/mcp/azure.md b/.github/workflows/shared/mcp/azure.md index d6ae938c0c9..ab70a02fa2c 100644 --- a/.github/workflows/shared/mcp/azure.md +++ b/.github/workflows/shared/mcp/azure.md @@ -20,6 +20,12 @@ mcp-servers: - "group_get" - "resource_list" - "resource_get" + +network: + allowed: + - login.microsoftonline.com + - management.azure.com + - "*.azure.com" ---