OCPBUGS-100310: oc login --exec-plugin oc-oidc fails to refresh expired token against Microsoft Entra ID - #2332
Conversation
…en endpoint The go-oidc library's Endpoint() returns an oauth2.Endpoint without setting AuthStyle, defaulting to auto-detect. Auto-detect tries AuthStyleInHeader (HTTP Basic Auth) first, which omits client_id from the POST body. Microsoft Entra ID does not support client_secret_basic and rejects this with AADSTS900144. Explicitly set AuthStyle to AuthStyleInParams so that client_id is always sent in the POST body. This is correct per RFC 6749 §2.3.1 for public clients and is supported by all targeted OIDC providers (Keycloak, Entra ID, ADFS, GitLab, Google, Okta, Ping Identity). Signed-off-by: michaelryanmcneill <michael@michaelryanmcneill.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@michaelryanmcneill: This pull request references Jira Issue OCPBUGS-99757, which is valid. 3 validation(s) were run on this bug
The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
Walkthrough
ChangesOIDC authentication
Estimated code review effort: 1 (Trivial) | ~3 minutes Suggested labels: 🚥 Pre-merge checks | ✅ 14 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (14 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: michaelryanmcneill The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
@michaelryanmcneill: This pull request references Jira Issue OCPBUGS-100310, which is valid. The bug has been moved to the POST state. 3 validation(s) were run on this bug
The bug has been updated to refer to the pull request using the external bug tracker. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
@michaelryanmcneill: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
| } | ||
| } | ||
| endpoint := provider.Endpoint() | ||
| endpoint.AuthStyle = oauth2.AuthStyleInParams |
There was a problem hiding this comment.
What about mimicking behavior from https://github.com/int128/kubelogin/blob/db494e487f9769281401c3133e698b2e2c30a8d5/pkg/oidc/client/factory.go#L67-L69?
Summary
Fixes token refresh failures against Microsoft Entra ID when using
oc login --exec-plugin oc-oidc.The
go-oidclibrary'sEndpoint()returns anoauth2.Endpointwithout settingAuthStyle, which defaults to auto-detect. Thegolang.org/x/oauth2auto-detect mechanism triesAuthStyleInHeader(HTTP Basic Auth) first, sendingclient_idin the Authorization header rather than the POST body. Microsoft Entra ID does not supportclient_secret_basic— its discovery document only advertisesclient_secret_postandprivate_key_jwt— and rejects the request withAADSTS900144: The request body must contain the following parameter: 'client_id'.This only manifests when the cached ID token has expired, since that is the only time a POST to the token endpoint is required.
Changes
AuthStyle: oauth2.AuthStyleInParamson theoauth2.EndpointinNewAuthenticator()so thatclient_idis always sent in the POST body.This is correct per RFC 6749 §2.3.1 for public clients and is supported by all targeted OIDC providers. Verified that all seven supported providers advertise
client_secret_postin theirtoken_endpoint_auth_methods_supported:client_secret_postclient_secret_basicSteps to Reproduce
oc login <api-server> --exec-plugin oc-oidc --client-id <id> --issuer-url <entra-id-issuer>oc logincommand againAADSTS900144: The request body must contain the following parameter: 'client_id'Additional notes for reviewers
There are no existing unit tests in
pkg/cli/gettoken/orpkg/cli/gettoken/oidc/. Adding a meaningful unit test for this change would require significant test infrastructure that does not exist today: a mock OIDC discovery endpoint, a mock JWKS endpoint with test signing keys, a mock token endpoint that validates request format and returns signed JWTs, and JWT generation using the test keys. This is disproportionate to the two-line change, which sets a standard configuration property on theoauth2.Endpoint. The fix is validated by the manual test plan below (initial login and token refresh against Entra ID and a second provider).Test Plan
oc login --exec-plugin oc-oidcsucceeds on initial login against Entra IDoc loginrefreshes the token without error--client-secret) still worksSummary by CodeRabbit