Repository navigation
Add Entra OIDC federation for HTTP MCP servers - #16956
Conversation
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
| @@ -1,4 +1,5 @@ | |||
| // Package oidc provides GitHub Actions OIDC token acquisition and caching. | |||
| // Package oidc provides GitHub Actions OIDC token acquisition and caching, | |||
lpcox
left a comment
There was a problem hiding this comment.
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.
| tenantID: tenantID, | ||
| clientID: clientID, | ||
| scope: scope, | ||
| endpoint: "https://login.microsoftonline.com", |
There was a problem hiding this comment.
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?
| // 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() |
There was a problem hiding this comment.
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?
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
🟡 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
Preserve Azure auth fields during stdin conversion · New Prevent authenticated redirects from leaking Entra tokens · New Avoid require assertions in HTTP handler goroutines · New Validate auth keys in stdin configuration · New Make refresh waiting cancelable by the caller context · New Include safe Entra diagnostics in exchange errors · New
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 { |
| "minLength": 1, | ||
| "description": "Entra application client ID. Required when provider is 'azure'." | ||
| }, | ||
| "azureScope": { |
| p.mu.Lock() | ||
| defer p.mu.Unlock() |
| if resp.StatusCode != http.StatusOK { | ||
| return "", time.Time{}, fmt.Errorf("Entra token request returned HTTP %d", resp.StatusCode) | ||
| } |
|
@copilot address review feedback and fix failing lint checks https://github.com/github/gh-aw-mcpg/actions/runs/44807019004/job/136554981650?pr=16956 |
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Addressed in |
🔒 mcpg Read-Only Stress — defaultSurface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Overall: INCONCLUSIVE Notes:
Run: §44816767798
|


Remote HTTP MCP servers can now exchange GitHub Actions OIDC assertions for Microsoft Entra access tokens. Direct GitHub OIDC authentication remains supported.
provider = "azure"with tenant ID, client ID, and scope. Assertions and access tokens are cached and refreshed automatically; credentials stay in the gateway process.api://AzureADTokenExchange; the scope defaults tohttps://cognitiveservices.azure.com/.default.