如要診斷及解決 Workload Identity Federation 中的驗證問題,請查看常見的錯誤回應和提供者設定。您可以檢查權杖宣告、組織政策和網路連線,找出根本原因,並還原外部工作負載的存取權。
Google Cloud API 不接受 SecurityTokenService 核發的憑證
SecurityTokenService API 傳回的存取權杖是聯合存取權杖。雖然大多數 Google Cloud API 都支援身分聯盟,但某些 API 方法可能有限制。如需限制清單,請參閱「身分聯盟:產品和限制」。
如果遇到下列錯誤,表示您可能嘗試將聯合存取權杖用於不支援這類權杖的服務。
{
"error": {
"code": 401,
"message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
"status": "UNAUTHENTICATED",
}
}
如要解決這項錯誤,請呼叫 GenerateAccessToken,將聯合存取權杖換成不受限制的存取權杖。詳情請參閱「透過身分聯盟取得短期憑證」。
將識別資訊提供者加入許可清單,以便與 Workload Identity Federation 搭配使用
如果您嘗試將不允許的識別資訊提供者設為 workload identity pool 提供者,會發生下列錯誤:
FAILED_PRECONDITION: Precondition check failed.
- '@type': type.googleapis.com/google.rpc.PreconditionFailure
violations:
- description: "Org Policy violated for value: '{PROVIDER}'."
subject: orgpolicy:projects/{PROJECT}/locations/global/workloadIdentityPools/{POOL}
type: constraints/iam.workloadIdentityPoolProviders
如要解決這個問題,請按照「限制識別資訊提供者設定」一文中的指示,將識別資訊提供者加入許可清單,以便與 Workload Identity Federation 搭配使用。
輸入的 JWK 不是有效的 JSON 格式
如果您在設定 OIDC 供應商時收到 Input JWK is
not in a valid json format 錯誤,可能是因為 Google Cloud不支援以自行簽署憑證保護的端點。具體來說,系統不支援 x5c 和 x5t 欄位,因此必須從 OIDC JWK 中移除。
如要解決 JWK 相關問題,請按照下列步驟操作:
編輯 JWK,並移除
x5c(X.509 憑證鏈結) 和x5t(X.509 憑證 SHA-1 指紋) 欄位。{ "kty": "RSA", "use": "sig", "kid": "example-key-id", "alg": "RS256", "n": "base64url-modulus", "e": "AQAB" }確認其餘 JWK 欄位的格式正確,如 OIDC 規格所述。
使用更新後的 JWK 設定 OIDC 提供者。
連線至指定憑證的核發者時發生錯誤
如果收到下列錯誤訊息,可能是因為 Google Cloud 無法擷取 IdP 的 OIDC 中繼資料文件或 JWKS:
{
"error": "invalid_grant",
"error_description":"Error connecting to the given credential's issuer."
}
這項錯誤通常是因為端點未設為可從公開網際網路存取。如要解決這個錯誤,請確認 OIDC 端點可公開存取,且符合 OIDC 規格。詳情請參閱「準備外部身分識別資訊提供者」。
如果仍收到錯誤訊息,請確認權杖核發者和權杖中的 iss 宣告是否正確。
指定的 AWS 要求未包含所有必要標頭
如果向 SecurityTokenService API 要求權杖時收到下列錯誤訊息,表示 AWS GetCallerIdentity 權杖中的 headers 欄位缺少必要標頭,或包含不支援的標頭:
{
"error": "invalid_grant",
"error_description": "The given AWS request doesn't contain all the required headers."
}
GetCallerIdentity 權杖的 headers 欄位只能包含下列 HTTP 要求標頭:
Authorization:要求簽章。host:url欄位的主機名稱,例如sts.amazonaws.com。x-amz-date:傳送要求的時間,格式為 ISO 8601 基本字串。x-goog-cloud-target-resource:workload identity pool 提供者的完整資源名稱。x-amz-security-token:工作階段符記。只有在使用暫時安全憑證時才需要提供。
如果 Signature 第 4 版簽署者在經簽署的要求中加入額外的標頭 (例如 x-amz-content-sha256),也會發生這項錯誤。如要解決這個問題,請確認 GetCallerIdentity 要求的內文空白,且已簽署要求的 headers 欄位和 SignedHeaders 欄位僅包含支援的標頭。詳情請參閱「使用 REST API 驗證工作負載」。
對應的 google.subject 附加資訊超過 127 個位元組
如果收到下列錯誤,表示 SecurityTokenService API 接收的傳入憑證產生的 google.subject 宣告超過字元限制:
{
"error": "invalid_request",
"error_description":"The size of mapped attribute google.subject exceeds the 127 bytes limit. Either modify your attribute mapping or the incoming assertion to produce a mapped attribute that is less than 127 bytes."
}
如要解決這個問題,請使用 extract 函式移除不必要的字元,並從較長的宣告中擷取專屬主體 ID,例如:
google.subject=assertion.sub.extract('/users/{sub_claim}')
錯誤 429:要求數量過多
如果向 SecurityTokenService API 要求權杖時收到 429 Too Many Requests 錯誤,表示 Google Cloud 專案已超過 API 的頻率配額限制。
錯誤訊息大致如下:
{
"error": "quota_exceeded",
"error_description":"The request was throttled due to rate limit: sts.googleapis.com/requests. Please retry after a few seconds."
}
如要解決這個問題,請找出錯誤訊息中提供的 sts.googleapis.com/requests 指標名稱,在 IAM 配額頁面中找到對應的指標名稱,確認用量百分比超過配額,然後要求提高配額。