員工身分聯盟的記錄範例

員工身分聯盟可讓您授予第三方身分 Google Cloud 資源存取權,而不必使用服務帳戶金鑰。使用員工身分聯盟時,您可以查看產生的稽核記錄,監控員工集區管理、權杖交換、聯合登入事件和 Google Cloud API 呼叫。每個範例都只顯示記錄項目中最相關的欄位。

如要進一步瞭解如何啟用及查看稽核記錄,請參閱「IAM 稽核記錄」。

稽核記錄設定

建立及管理工作團隊集區時,IAM 可產生稽核記錄。如要在管理工作團隊集區時啟用稽核記錄,請啟用資料存取活動的稽核記錄,並指定下列 API:

  • Identity and Access Management (IAM) API (啟用「管理員讀取」記錄類型)

如要設定權杖交換程序或Google Cloud 控制台 (聯合) 登入程序的稽核記錄,您也必須為下列 API 啟用資料存取活動的稽核記錄:

  • Security Token Service (啟用「管理員讀取」記錄類型)
  • Cloud OAuth API (啟用「管理員讀取」記錄類型)

建立工作團隊集區的記錄

以下範例顯示建立工作團隊集區的記錄項目。在本範例中,使用者 sam@example.com 在 ID 為 123456789012 的組織下,建立了 ID 為 my-pool 的工作團隊集區。

{
  "logName": "organizations/123456789012/logs/cloudaudit.googleapis.com%2Factivity",
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "authenticationInfo": {
      "principalEmail": "sam@example.com",
    },
    "methodName": "google.iam.admin.v1.WorkforcePools.CreateWorkforcePool",
    "resourceName": "locations/global/workforcePools/my-pool",
    "serviceName": "iam.googleapis.com",
    "request": {
      "@type": "type.googleapis.com/google.iam.admin.v1.CreateWorkforcePoolRequest",
      "workforcePool": {
        "parent": "organizations/123456789012"
      },
      "workforcePoolId": "my-pool"
    }
  },
  "resource": {
    "type": "audited_resource"
  }
}

將 IdP 權杖交換為聯合權杖的記錄

設定員工身分集區和員工身分集區提供者後,您可以為識別資訊提供者 (IdP) 建立權杖,並將其兌換為聯合權杖。

啟用資料存取活動的 Cloud 稽核記錄後,每當主體交換權杖時,IAM 都會產生稽核記錄項目。記錄項目包含下列欄位:

  • protoPayload.authenticationInfo.principalSubject:IdP 權杖的主體。
    • 如果是 OIDC IdP,這個欄位會包含 OIDC 權杖中 sub (或主體) 宣告的值。
    • 如果是 SAML IdP,這個欄位會包含 SAML 宣告中 Subject 屬性的 NameID 子屬性值。
  • protoPayload.metadata.mapped_principal:權杖的主體,使用 IAM 語法識別主體:

    principal://iam.googleapis.com/locations/global/workforcePools/POOL_ID/subject/IDENTIFIER
    
  • protoPayload.resourceName:與權杖相關聯的工作團隊集區提供者。

使用 Security Token Service 成功交換權杖

以下範例顯示稽核記錄項目,記錄使用 Security Token Service (sts.googleapis.com) 交換權杖的要求。在這個範例中,OIDC 權杖會交換為聯合權杖:

{
  "logName": "organizations/123456789012/logs/cloudaudit.googleapis.com%2Fdata_access",
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "authenticationInfo": {
      "principalSubject": "b6112abb-5791-4507-adb5-7e8cc306eb2e"
    },
    "metadata": {
      "mapped_principal": "principal://iam.googleapis.com/locations/global/workforcePools/oidc-pool/subject/a1234bcd-5678-9012-efa3-4b5cd678ef9a"
    },
    "methodName": "google.identity.sts.v1.SecurityTokenService.ExchangeToken",
    "resourceName": "locations/global/workforcePools/oidc-pool/providers/oidc-provider",
    "serviceName": "sts.googleapis.com",
    "request": {
      "@type": "type.googleapis.com/google.identity.sts.v1.SecurityTokenService.ExchangeTokenRequest",
      "audience": "//iam.googleapis.com/locations/global/workforcePools/oidc-pool/providers/oidc-provider",
      "grantType": "urn:ietf:params:oauth:grant-type:token-exchange",
      "requestedTokenType": "urn:ietf:params:oauth:token-type:access_token",
      "subjectTokenType": "urn:ietf:params:oauth:token-type:id_token"
    }
  },
  "resource": {
    "type": "audited_resource"
  }
}

權杖交換失敗:群組過多

以下範例記錄說明權杖交換失敗,因為群組數量超過上限 400 個。

如要記錄員工身分聯盟收到的屬性,您必須在建立員工身分集區提供者時,啟用詳細稽核記錄功能。

如要瞭解如何透過詳細的稽核記錄排解屬性對應錯誤,請參閱「一般屬性對應錯誤」。

在以下範例中,mappedAttributes 包含從 IdP 接收的屬性,包括群組清單。在這種情況下,群組數量超過了員工身分聯盟限制。

{
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "status": {
      "code": 3,
      "message": "The current count of 800 mapped attribute google.groups exceeds the 400 count limit. Either modify your attribute mapping or the incoming assertion to produce a mapped attribute that is less than 400."
    },
    "authenticationInfo": {
      "principalSubject": "3Kn-kJQal4N-WXVjxMqcOF1tQcCdBliu97lV-2P-Khc"
    },
    "requestMetadata": {
      "callerIp": "2601:647:4680:9140:9d68:88c9:cab9:a908",
      "callerSuppliedUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36",
      "requestAttributes": {
        "time": "2025-04-09T18:32:34.979311Z",
        "auth": {}
      },
      "destinationAttributes": {}
    },
    "serviceName": "sts.googleapis.com",
    "methodName": "google.identity.sts.SecurityTokenService.WebSignIn",
    "authorizationInfo": [
      {
        "permission": "sts.identityProviders.checkLogging",
        "granted": false,
        "permissionType": "ADMIN_READ"
      }
    ],
    "resourceName": "locations/global/workforcePools/my-pool/providers/my-provider",
    "request": {
      "@type": "type.googleapis.com/google.identity.sts.SecurityTokenService.WebSignInRequest",
      "provider": "//iam.googleapis.com/locations/global/workforcePools/my-pool/providers/my-provider",
      "host": "auth-staging.corp.cloud.google"
    },
    "metadata": {
      "mappedAttributes": {
        "google.subject": "3Nk-kJQal4N-WXVjxMqcOF1tQcCdBliu97lV-2P-Khc",
        "google.providerId": "my-provider-id",
        "google.groups": "[group-claim-1, group-claim-2, ..., group-claim-800]"
      }
    }
  },
  "insertId": "-llnhbmck3a",
  "resource": {
    "type": "audited_resource",
    "labels": {
      "service": "sts.googleapis.com",
      "method": "google.identity.sts.SecurityTokenService.WebSignIn"
    }
  },
  "timestamp": "2025-04-09T18:32:34.208412Z",
  "severity": "ERROR",
  "logName": "organizations/123456789012/logs/cloudaudit.googleapis.com%2Fdata_access",
  "receiveTimestamp": "2025-04-09T18:32:35.059811619Z"
}

已簽署及加密 SAML 宣告的記錄

本節說明 Security Token Service 嘗試驗證已簽署的 SAML 斷言,或解密從 IdP 傳送的加密斷言時,建立的 Cloud 稽核記錄項目。

如果是員工身分聯盟,相關記錄項目會類似下列內容:

"keyInfo": [
  {
    "use": "verify"
    "fingerprint": "3C:B2:47:F8:A5:9A:8A:52:BD:1C:BC:96:B5:45:C1:8D:A7:F1:73:2D"
  },
  {
    "use": "decrypt"
    "resourceName": "//iam.googleapis.com/locations/global/workforcePools/WORKFORCE_POOL_NAME/providers/PROVIDER_NAME/keys/KEY_NAME"
  }
]

這項輸出內容包含下列值:

  • fingerprint:X.509 憑證的 SHA-256 雜湊十六進位表示法,用於驗證 SAML 憑證上的簽章。X.509 憑證是從附加至工作團隊身分集區提供者的 SAML XML 中繼資料擷取而來。
  • resourceName:用於解密已加密 SAML 斷言的 Workforce Identity Pool Provider 金鑰資源名稱。只有在身分聯合從 IdP 收到加密的 SAML 回應時,才會顯示這個欄位。

使用聯合權杖呼叫 Google Cloud API 的記錄

將 IdP 的權杖換成聯合權杖後,您可以使用聯合權杖呼叫 Google Cloud API。您呼叫的某些方法可能會產生稽核記錄。

以下範例顯示稽核記錄項目,記錄使用聯合權杖列出專案中 Cloud Storage bucket 的要求。

{
  "logName": "projects/my-project/logs/cloudaudit.googleapis.com%2Fdata_access",
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "authenticationInfo": {
      "principalSubject": "principal://iam.googleapis.com/locations/global/workforcePools/oidc-pool/subject/kalani@altostrat.com"
    },
    "methodName": "storage.buckets.list",
    "serviceName": "storage.googleapis.com",
  },
  "resource": {
    "type": "gcs_bucket"
  }
}

Google Cloud 控制台 (聯合) 登入記錄

設定員工身分集區和其 IdP 後,使用者可以使用控制台 (聯合) 登入 Google Cloud 。

成功登入的記錄

本節提供 Cloud 稽核記錄項目範例,記錄因成功登入而產生的項目。在本例中,使用者 user@example.com 使用供應商 locations/global/workforcePools/my-pool/providers/my-provider 登入。在這種情況下,系統會產生下列 Cloud 稽核記錄項目:

{
  "logName": "organizations/my-organization-id/logs/cloudaudit.googleapis.com%2Fdata_access",
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "authenticationInfo": {
      "principalSubject": "user@example.com",
    },
    "serviceName": "sts.googleapis.com",
    "methodName": "google.identity.sts.SecurityTokenService.WebSignIn",
    "resourceName": "locations/global/workforcePools/my-pool/providers/my-provider",
    "request": {
      "@type": "type.googleapis.com/google.identity.sts.SecurityTokenService.WebSignInRequest",
      "provider": "//iam.googleapis.com/locations/global/workforcePools/my-pool/providers/my-provider",
      "continueUrl": "https://console.cloud.google",
      "host": "http://auth.cloud.google",
    },
    "metadata": {
       "mappedPrincipal": "principal://iam.googleapis.com/locations/global/workforcePools/my-pool/subject/user@example.com",
    }
  },
  "resource": {
    "type": "audited_resource",
    "labels": {
      "service": "sts.googleapis.com",
      "method": "google.identity.sts.SecurityTokenService.WebSignIn",
    }
  },
}

SAML 供應商的 Cloud 稽核記錄項目,可能還會在中繼資料欄位中包含簽署金鑰資訊。

{
  "metadata": {
    "mappedPrincipal": "principal://iam.googleapis.com/locations/global/workforcePools/my-pool/subject/user@example.com",
    "keyInfo": [
      {
        "use": "verify",
        "fingerprint": "AE:CK:LM:EF:LK:OG:EH:IJ:KN:AL:OM:AD:NO",
      }
    ],
  }
}

登入失敗記錄

本節提供 Cloud 稽核記錄項目範例,記錄因登入失敗而產生的結果。在這個範例中,使用者 user@example.com 嘗試使用供應商 locations/global/workforcePools/my-pool/providers/my-provider 登入,但因不符合屬性條件而遭拒。在這種情況下,系統會產生下列 Cloud 稽核記錄項目:

{
  "logName": "organizations/my-organization-id/logs/cloudaudit.googleapis.com%2Fdata_access",
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "authenticationInfo": {
      "principalSubject": "user@example.com",
    },
    "status": {
      "code": 3,
      "message": "The given credential is rejected by the attribute condition.",
    },
    "serviceName": "sts.googleapis.com",
    "methodName": "google.identity.sts.SecurityTokenService.WebSignIn",
    "resourceName": "locations/global/workforcePools/my-pool/subject/user@example.com",
    "request": {
      "@type": "type.googleapis.com/google.identity.sts.SecurityTokenService.WebSignInRequest",
      "provider": "//iam.googleapis.com/locations/global/workforcePools/my-pool/providers/my-provider",
      "host": "http://auth.cloud.google",
    },
    "metadata": {
      "mappedPrincipal": "principal://iam.googleapis.com/locations/global/workforcePools/my-pool/subject/user@example.com",
    }
  },
  "resource": {
    "type": "audited_resource",
    "labels": {
      "service": "sts.googleapis.com",
      "method": "google.identity.sts.SecurityTokenService.WebSignIn",
    }
  },
}

登出記錄

本節提供 Cloud 稽核記錄項目範例,該項目是因登出事件而記錄。在本例中,使用者 user@example.com 使用供應商 locations/global/workforcePools/my-pool/providers/my-provider 登入,並啟動登出程序。在這種情況下,系統會產生下列 Cloud 稽核記錄項目:

{
  "logName": "organizations/my-organization-id/logs/cloudaudit.googleapis.com%2Fdata_access",
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "authenticationInfo": {
      "principalSubject": "user@example.com",
    },
    "serviceName": "sts.googleapis.com",
    "methodName": "google.identity.sts.SecurityTokenService.WebSignOut",
    "resourceName": "locations/global/workforcePools/my-pool/providers/my-provider",
    "request": {
      "@type": "type.googleapis.com/google.identity.sts.SecurityTokenService.WebSignOutRequest",
      "provider": "//iam.googleapis.com/locations/global/workforcePools/my-pool/providers/my-provider",
      "host": "http://auth.cloud.google"
    },
    "metadata": {
      "mappedPrincipal": "principal://iam.googleapis.com/locations/global/workforcePools/my-pool/subject/user@example.com",
    }
  },
  "resource": {
    "type": "audited_resource",
    "labels": {
      "service": "sts.googleapis.com",
      "method": "google.identity.sts.SecurityTokenService.WebSignOut"
    }
  },
}

使用 OAuth 流程登入的記錄

設定工作團隊身分集區和工作團隊身分集區提供者後,您可以使用 OAuth 流程存取 Google Cloud 資源。

為資料存取稽核記錄活動啟用 Cloud 稽核記錄後,每當主體使用 OAuth 流程登入時,IAM 都會產生稽核記錄項目。記錄項目包含下列欄位:

  • protoPayload.authenticationInfo.principalSubject:IdP 權杖的主體。
    • 如果是 OIDC IdP,這個欄位會包含 OIDC 權杖中 sub (或主體) 宣告的值。
    • 如果是 SAML IdP,這個欄位會包含 SAML 宣告中 Subject 屬性的 NameID 子屬性值。
  • protoPayload.metadata.mapped_principal:權杖的主體,使用 IAM 語法識別主體:

    principal://iam.googleapis.com/locations/global/workforcePools/POOL_ID/subject/IDENTIFIER
    
  • protoPayload.resourceName:與權杖相關聯的工作團隊集區提供者。

以下範例顯示交換權杖要求的稽核記錄項目。在本範例中,主體是使用 OIDC 供應商進行聯合:

{
  "logName": "organizations/123456789012/logs/cloudaudit.googleapis.com%2Fdata_access",
  "protoPayload": {
    "@type": "type.googleapis.com/google.cloud.audit.AuditLog",
    "authenticationInfo": {
      "principalSubject": "b6112abb-5791-4507-adb5-7e8cc306eb2e"
    },
    "metadata": {
      "mapped_principal": "principal://iam.googleapis.com/locations/global/workforcePools/POOL_ID/subject/IDENTIFIER"
    },
    "methodName": "google.identity.sts.v1.SecurityTokenService.ExchangeOauthToken",
    "resourceName": "locations/global/workforcePools/POOL_ID/providers/WORKFORCE_PROVIDER_ID",
    "serviceName": "sts.googleapis.com",
    "request": {
      "@type": "type.googleapis.com/google.identity.sts.v1.SecurityTokenService.ExchangeOauthTokenRequest",
      "grantType": "authorization_code",
    }
  },
  "resource": {
    "type": "audited_resource"
  }
}

後續步驟