[google-auth-library-java] OAuthException.createFromHttpResponseException throws ClassCastException on a Google API error body, losing the HTTP status and body
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 72/100
- Issue 類型
- 缺陷
- 描述清晰度
- 基本清楚
- 活躍度
- 活躍
- 技術堆疊
- java
研究方向
Start with OAuthException.java:90 and run the deterministic createFromHttpResponseException reproduction using the supplied Google API error body. Trace its callers in StsRequestHandler.exchangeToken and ExternalAccountAuthorizedUserCredentials.java:204, then add regression coverage showing that the response status and body are retained without the ClassCastException, including a body without an error key.
由索引模型根據 Issue 內容生成。
描述
Environment details
- API: auth, workload identity federation (
AwsCredentials, STS token exchange during Cloud Storage calls) - OS type and version: Linux (AWS Lambda and AWS ECS)
- Java version: 25
- Version(s):
google-auth-library-oauth2-http1.50.0 (libraries-bom 26.86.0),google-http-client2.2.0.createFromHttpResponseExceptionis unchanged in 1.53.0 and onmain(05a998f).
Steps to reproduce
- Deterministic, no credentials needed: call
OAuthException.createFromHttpResponseExceptionwith anHttpResponseExceptionwhose content is a Google API error body (snippet below). It throwsClassCastException. - Against the real STS: an
AwsCredentialswhosetoken_urlishttps://sts.googleapis.com/v1/introspectgets HTTP 400 with{"error":{"code":400,"message":"Invalid JSON payload received. ...","status":"INVALID_ARGUMENT"}}and fails with the sameClassCastException. The misconfigured URL is only a way to get that body shape on demand; in production the same exception comes fromhttps://sts.googleapis.com/v1/token.
Code example
package com.google.auth.oauth2;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpResponseException;
class OAuthExceptionNestedErrorRepro {
public static void main(String[] args) throws Exception {
HttpResponseException e =
new HttpResponseException.Builder(400, "Bad Request", new HttpHeaders())
.setContent(
"{\"error\":{\"code\":400,\"message\":\"Request contains an invalid argument.\",\"status\":\"INVALID_ARGUMENT\"}}")
.build();
OAuthException.createFromHttpResponseException(e); // java.lang.ClassCastException
}
}
Stack trace
Production, workload identity federation from AWS, token exchange triggered by a Cloud Storage request:
java.lang.ClassCastException: class com.google.api.client.util.ArrayMap cannot be cast to class java.lang.String
at com.google.auth.oauth2.OAuthException.createFromHttpResponseException(OAuthException.java:90)
at com.google.auth.oauth2.StsRequestHandler.exchangeToken(StsRequestHandler.java:129)
at com.google.auth.oauth2.ExternalAccountCredentials.exchangeExternalCredentialForAccessToken(ExternalAccountCredentials.java:567)
at com.google.auth.oauth2.AwsCredentials.refreshAccessToken(AwsCredentials.java:132)
at com.google.auth.oauth2.OAuth2Credentials.getRequestMetadata(OAuth2Credentials.java:189)
External references such as API reference guides
- https://github.com/bazelbuild/bazel/issues/29600: the same exception from
IdentityPoolCredentials(GitLab CI, workload identity federation), closed as not reproducible. - https://github.com/googleapis/google-cloud-java/pull/14220: contains an equivalent guard in
createFromHttpResponseException, but targets theoauth2-bound-tokensbranch and does not mention this bug.
Any additional information below
OAuthException.java:90castserrortoString. The request-validation errors we could trigger on/v1/tokencome back in the OAuth form ({"error":"invalid_request","error_description":"..."}), but some production responses from/v1/tokencarryerroras an object (Google's API error format), which makes the cast throw. We could not capture those bodies because the library drops them.- The
ClassCastExceptionis thrown from insidecatch (HttpResponseException e)inStsRequestHandler.exchangeToken. It is aRuntimeException, so it escapes theIOExceptioncontract ofrefresh()/getRequestMetadata(), and it has no cause, so theHttpResponseExceptionholding the status and body is lost.LoggingUtilslogs the response only on success, so the body is not logged either. When this happened to us intermittently in production (a burst of failures across several independent GCP projects within minutes), we could not tell whether STS was rate limiting, unavailable, or refusing the credential. - Because the
ClassCastExceptionis not anIOException, google-cloud-storage classifies it as unretryable (Unretryable error (attempts: 1, maxAttempts: 6)), so a transient STS failure is not retried either. - The same method is also called from
ExternalAccountAuthorizedUserCredentials.java:204. - Related: a body without an
errorkey makes the constructor'scheckNotNull(errorCode)throwNullPointerException.
- 主要語言
- Java
- 星號
- 2.1k
- 分支
- 1.2k
- 平均合併
- 2 天 14 小時
- 30 天內合併 PR
- 192
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
googleapis/google-cloud-java 的其他 Issue
-
[java-core] Timestamp.of(java.sql.Timestamp) is one second late for a time less than a second before the epoch可能已有人在做 @Vcode2407 於 4 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
googleapis/google-cloud-java#14636 ·
維護者通常 1 天內回覆
-
[java-firestore] UserDataConverter encodes a pre-epoch Date with negative nanos, so the write is refused可能已有人在做 @wu-hui 於 23 天前認領。 未關閉priority: p2 type: bug
難度 2/5 1-3 小時 新手友好度 75/100
googleapis/google-cloud-java#14635 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[java-firestore] UserDataConverter throws IndexOutOfBoundsException on an empty __binary__ value可能已有人在做 @wu-hui 於 23 天前認領。 未關閉priority: p2 type: bug
難度 2/5 1-3 小時 新手友好度 74/100
googleapis/google-cloud-java#14634 · 1 則留言 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[java-firestore] CustomClassMapper.convertBigDecimal calls .abs() on Double, unintentionally flipping negative values to positive可能重新可做 @wu-hui 於 45 天前認領,目前沒有進行中的 PR。 未關閉
難度 2/5 1-3 小時 新手友好度 85/100
googleapis/google-cloud-java#14533 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
Github CI failing when trying to install xmllint可能已有人在做 @blakeli0 於 81 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 65/100
googleapis/google-cloud-java#14132 · 1 則留言 ·
維護者通常 1 天內回覆
查看 googleapis/google-cloud-java 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 80/100
finos/fluxnova-bpm-platform#387 ·
維護者通常 4 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
-
難度 2/5 1 小時以內 新手友好度 84/100
cpp-best-practices/project_validator#251 ·
維護者通常 1 天內回覆
-
backend enhancement
難度 2/5 半天 新手友好度 70/100
damodharg6/payledger#16 ·
-
[Bug]: An initiative list with no current entry logs an error on every change可能已有人在做 @dwizard0 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
維護者通常 1 天內回覆