jwtauthccl: check HTTP status code in getHttpResponse#158294
jwtauthccl: check HTTP status code in getHttpResponse#158294trunk-io[bot] merged 1 commit intocockroachdb:masterfrom
Conversation
|
Thank you for contributing to CockroachDB. Please ensure you have followed the guidelines for creating a PR. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
There was a problem hiding this comment.
Thanks for this contribution and apologies for the delay, @vxtls! This is a really clean change and the PR description is excellent -- the "before and after" is very clear.
The logic looks correct to me, and CI is fully green. A couple of small notes:
-
Rebase needed: It looks like there are merge conflicts with
master. Could you rebase your branch so we can get this mergeable? -
Release note: The commit will need a release note line. I'm happy to add that myself when we merge, so don't worry about it unless you'd like to write one.
-
I left one inline suggestion about the error construction pattern -- not a blocker, and I can amend it myself if you'd prefer.
Really appreciate you improving the debuggability here. The old behavior of silently passing non-2xx responses through to JSON parsing was a real pain point.
@pritesh-lahoti reviewed 2 files and all commit messages, and made 2 comments.
Reviewable status:complete! 0 of 0 LGTMs obtained (waiting on vxtls).
pkg/ccl/jwtauthccl/authentication_jwt.go line 524 at r1 (raw file):
bodySnippet = bodySnippet[:200] + "..." } return nil, errors.Newf("GET %s returned %s: %s", url, resp.Status, bodySnippet)
nit (happy to fix this myself before merging): The rest of this file uses errors.WithDetailf to keep internal details (like URLs and response content) in the error detail rather than the top-level error message. That pattern keeps those details out of client-facing error surfaces while still making them available in logs. Something like:
return nil, errors.WithDetailf(
errors.Newf("JWT authentication: HTTP request failed"),
"GET %s returned %s: %s", url, resp.Status, bodySnippet,
)This would be consistent with how the callers in ValidateJWTLogin and VerifyAndExtractIssuer handle errors from this function. Not a blocker -- I can amend this when merging if you'd like.
6ae4d4a to
8c13b52
Compare
|
Thank you for updating your pull request. Before a member of our team reviews your PR, I have some potential action items for you:
🦉 Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf. |
|
@pritesh-lahoti |
Previously, getHttpResponse would silently accept non-2xx HTTP responses when fetching JWKS or OpenID configuration, potentially leading to confusing downstream parse errors. Now, non-2xx responses return an error with the HTTP status and a truncated body snippet in the error details. Release note (bug fix): JWT authentication now returns a clear error when HTTP requests to fetch JWKS or OpenID configuration return non-2xx status codes, instead of silently passing the response body to the JSON parser. Co-Authored-By: roachdev-claude <roachdev-claude-bot@cockroachlabs.com>
8c13b52 to
2c21d3d
Compare
pritesh-lahoti
left a comment
There was a problem hiding this comment.
Squashed the commits and added the release note.
Will merge once the CI passes now (seemed to be flaky earlier).
Thanks again, @vxtls !
|
/trunk merge |
|
😎 Merged directly without going through the merge queue, as the queue was empty and the PR was up to date with the target branch - details. |
check HTTP status in getHttpResponse and include body snippet
Epic: None
Overview
Previously,
getHttpResponseignored non-2xx HTTP responses.As a result, JWKS/userinfo/discovery requests could return 4xx or 5xx pages,
and the caller would only fail when JSON parsing encountered an error.
This made it difficult to quickly identify the root cause of HTTP failures.
What this change does
Example
A 403 Forbidden response will now return an error like:
GET https://issuer.example.com/.well-known/jwks returned 403 Forbidden: <body snippet>Testing
TestGetHTTPResponseNon2xxto cover non-2xx responses.Why this is useful
This change improves debuggability and observability for JWT authentication issues.
Telemetry and logs will now clearly show the actual HTTP failure instead of failing later in JSON parsing.