feat: add support for external_account credentials#146
feat: add support for external_account credentials#146
Conversation
… Federation) This adds support for the `external_account` credential type, which is used by GCP Workload Identity Federation to authenticate from external identity providers such as GitHub Actions OIDC, AWS, Azure, etc. Changes: - Add `ExternalAccountCredentials` type in types.rs - Add `CredentialFile` enum to auto-detect credential types from GOOGLE_APPLICATION_CREDENTIALS - Add `ExternalAccount` provider that implements TokenProvider - Update `provider()` to handle all three credential types: - service_account (existing) - authorized_user (existing) - external_account (new) The external_account flow: 1. Read subject token from credential_source (file or URL) 2. Exchange it with GCP STS for a federated access token 3. Optionally impersonate a service account if configured This enables gcp_auth to work with GitHub Actions OIDC authentication without requiring service account keys.
|
Both the PR description and the code seems to be obviously LLM-generated. At the very least, edit your PR description down to a concise (that is, human) description of what you're trying to achieve and if/how this is supported by official Google SDKs. There's a lot of new code which, from a quick look, suffers from the typical verboseness exhibited by LLMs as well -- which means I don't want to maintain it. |
I am very sorry about this. But I did indeed carefully edit the description, and I believe that the parts retained are necessary for this PR. Thank you for your time. |
- Remove unused ExternalAccountCredentials::from_file method - Fix potential race condition in token caching by adding double-check after acquiring write lock - Simplify CustomServiceAccount::token by removing duplicate code - Remove unnecessary token_url.clone() in ExternalAccount
Summary
This PR adds support for the
external_accountcredential type, enabling authentication via GCP Workload Identity Federation from external identity providers such as GitHub Actions OIDC, AWS, Azure AD, and other OIDC/SAML providers.Motivation
Currently,
gcp_authonly supports:service_accountcredentialsauthorized_usercredentialsWhen using
GOOGLE_APPLICATION_CREDENTIALSwith anexternal_accounttype credential file (generated by tools likegoogle-github-actions/auth), the library fails with:This is because the library assumes all credential files are service account keys.
External Account Flow
sequenceDiagram participant ST as Subject Token<br/>(OIDC JWT) participant STS as GCP STS API<br/>/v1/token participant FT as Federated Token participant IAM as IAM Credentials<br/>:generateAccessToken participant AT as Access Token<br/>(SA Impersonated) ST->>STS: Exchange token STS->>FT: Return federated token alt Service Account Impersonation configured FT->>IAM: Request impersonation IAM->>AT: Return access token endRelated
private_key" error #56 (partial - adds support for external_account type)