Skip to content

Add Entra OIDC federation for HTTP MCP servers - #16956

Merged
lpcox merged 3 commits into
mainfrom
copilot/entra-oidc-support
Nov 21, 2026
Merged

lpcox merged 3 commits into
mainfrom
copilot/entra-oidc-support

Conversation

@pelikhan

@pelikhan pelikhan commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Remote HTTP MCP servers can now exchange GitHub Actions OIDC assertions for Microsoft Entra access tokens. Direct GitHub OIDC authentication remains supported.

  • Azure token exchange: Configure provider = "azure" with tenant ID, client ID, and scope. Assertions and access tokens are cached and refreshed automatically; credentials stay in the gateway process.
  • Configuration: Updated schema, validation, and TOML environment-variable expansion. The assertion audience defaults to api://AzureADTokenExchange; the scope defaults to https://cognitiveservices.azure.com/.default.
  • Azure AI Gateway example:
    [servers.azure-ai-gateway]
    type = "http"
    url = "https://YOUR_GATEWAY_HOST/default/toolservers/YOUR_SERVER_NAME/mcp"
    
    [servers.azure-ai-gateway.auth]
    type = "github-oidc"
    provider = "azure"
    azure_tenant_id = "${AZURE_TENANT_ID}"
    azure_client_id = "${AZURE_CLIENT_ID}"
    azure_scope = "${AZURE_AI_GATEWAY_SCOPE}"

Copilot AI linked an issue Nov 20, 2026 that may be closed by this pull request
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Comment thread internal/oidc/provider.go
@@ -1,4 +1,5 @@
// Package oidc provides GitHub Actions OIDC token acquisition and caching.
// Package oidc provides GitHub Actions OIDC token acquisition and caching,
@pelikhan pelikhan changed the title [WIP] Add Entra OIDC support for remote HTTP MCP servers Add Entra OIDC federation for HTTP MCP servers Nov 20, 2026
@pelikhan
pelikhan marked this pull request as ready for review November 20, 2026 20:38
Copilot AI adaptive review requested due to automatic review settings November 20, 2026 20:38

@lpcox lpcox left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting this exchange in mcpg makes sense. We looked at whether AWF could do the exchange and hand the token to mcpg, and it isn't a good fit. AWF's Entra exchange runs in the api-proxy sidecar and only adds credentials to inference requests. The compiler starts mcpg separately, so there's no channel between them. Entra tokens also expire in about an hour, so a one-time handoff would break during long runs. Adding a token service or sending mcpg's requests through api-proxy would create a new privileged path. mcpg already has the GitHub OIDC provider and makes the HTTP calls, so the token can stay in the gateway process.

AWF already does this exchange in containers/api-proxy/oidc-token-provider.js in github/gh-aw-firewall. Matching its behavior would keep the two consistent; see the inline comments.

Comment thread internal/oidc/azure.go Outdated
tenantID: tenantID,
clientID: clientID,
scope: scope,
endpoint: "https://login.microsoftonline.com",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hardcodes the public-cloud login host. AWF's Entra provider takes an azureCloud setting (AWF_AUTH_AZURE_CLOUD) and chooses the host from it: login.microsoftonline.us for usgovernment, login.chinacloudapi.cn for china, and login.microsoftonline.com otherwise. Could we add the same option (for example azure_cloud) so sovereign-cloud tenants work and the config matches AWF?

Comment thread internal/oidc/azure.go Outdated
// Token returns a cached Entra access token or exchanges a fresh GitHub OIDC
// assertion for one. The audience is used only when acquiring the assertion.
func (p *AzureProvider) Token(ctx context.Context, audience string) (string, error) {
p.mu.Lock()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the token is expired or missing, this lock stays held through both the GitHub OIDC request and the Entra request (up to the 10s client timeout). Every request to this server waits behind that refresh. AWF's provider refreshes early, at about 75% of the token's lifetime, and retries a failed refresh after a short delay. Requests keep getting the cached token while the refresh runs. Could we add early refresh here, or at least make the network exchange happen outside the lock with concurrent callers sharing one in-flight exchange?

@github-actions

This comment has been minimized.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved issues can leak Entra bearer tokens through redirects and cause Azure stdin configurations to use the wrong authentication flow.

6 open issues
What changed in this PR

This PR adds Microsoft Entra federation for remote HTTP MCP servers, reusing the gateway’s GitHub Actions OIDC infrastructure while retaining direct GitHub OIDC authentication.

Changes:

  • Adds Entra token exchange, caching, and refresh through a shared token-source interface.
  • Adds Azure authentication settings, validation, schema support, and TOML environment-variable expansion.
  • Adds tests and documents Azure AI Gateway configuration.
File Description
internal/​oidc/​provider.go Introduces the shared token-source interface.
internal/​oidc/​azure.go Implements Entra token exchange and caching.
internal/​oidc/​azure_test.go Tests exchange, caching, refresh, and redirect rejection.
internal/​mcp/​http_transport_client.go Accepts interchangeable authentication token sources.
internal/​mcp/​connection.go Updates HTTP connection APIs to use token sources.
internal/​launcher/​launcher.go Selects Azure authentication and applies defaults.
internal/​config/​validation_test.go Tests Azure credentials and provider validation.
internal/​config/​validation_server.go Validates provider selection and required Azure fields.
internal/​config/​validation_schema_test.go Tests Azure authentication schema constraints.
internal/​config/​schema/​mcp-gateway-config.schema.json Defines Azure authentication properties and requirements.
internal/​config/​expand.go Expands environment variables in authentication fields.
internal/​config/​config_core.go Adds Azure fields and wires TOML auth expansion.
internal/​config/​config_core_test.go Tests Azure authentication variable expansion.
docs/​ENVIRONMENT_VARIABLES.md Documents per-server Azure authentication settings.
docs/​CONFIGURATION.md Explains federation and Azure AI Gateway setup.
config.example.toml Adds a commented Azure AI Gateway example.

Review effort: Max (adaptive)

// Audience is the intended audience for the OIDC token.
// If empty, defaults to the server URL.
// Provider optionally exchanges the GitHub OIDC assertion for a provider token.
Provider string `toml:"provider" json:"provider,omitempty"`
// Static headers (from buildHTTPClientWithHeaders) are applied first, then the OIDC
// token overwrites the Authorization header.
func buildHTTPClientWithOIDC(baseClient *http.Client, provider *oidc.Provider, audience string) *http.Client {
func buildHTTPClientWithOIDC(baseClient *http.Client, provider oidc.TokenSource, audience string) *http.Client {
Comment thread internal/oidc/azure_test.go Resolved
"minLength": 1,
"description": "Entra application client ID. Required when provider is 'azure'."
},
"azureScope": {
Comment thread internal/oidc/azure.go Outdated
Comment on lines +58 to +59
p.mu.Lock()
defer p.mu.Unlock()
Comment thread internal/oidc/azure.go
Comment on lines +114 to +116
if resp.StatusCode != http.StatusOK {
return "", time.Time{}, fmt.Errorf("Entra token request returned HTTP %d", resp.StatusCode)
}
@lpcox

lpcox commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Co-authored-by: copilot-swe-agent[bot] <[email protected]>

Copilot AI commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@copilot address review feedback and fix failing lint checks https://github.com/github/gh-aw-mcpg/actions/runs/44807019004/job/136554981650?pr=16956

Addressed in 4b14103. The full make agent-finished pipeline passes, including golangci-lint; CodeQL found no alerts.

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads data ALLOWED ✅
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 7 tools absent from catalog BLOCKED ⚠️
C CLI reads data ALLOWED ✅
D CLI REST writes (reaction/star/issue/comment) gh unauthenticated BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

Notes:

  • Part A/C: all 4 MCP reads (list_issues, list_pull_requests, get_file_contents README.md, list_commits) returned real data via the gateway-backed github CLI.
  • Part B: the github CLI tool catalog exposes only 23 read-only tools; none of add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request, or star_repository are present ("unknown tool" errors). This confirms gh-aw's backend GITHUB_READ_ONLY=1 config but does not independently confirm mcpg's own DIFC/guard write-blocking layer, since no write tool ever reached a write-capable backend.
  • Part D/E: gh auth status showed no authenticated host (GH_TOKEN not set in this job), so REST/GraphQL write-rejection could not be exercised.
  • No write succeeded on any surface in this run.

Run: §44816767798

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@lpcox
lpcox merged commit ef9ab73 into main Nov 21, 2026
30 checks passed
@lpcox
lpcox deleted the copilot/entra-oidc-support branch November 21, 2026 16:36
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.

Entra OIDC support

5 participants