Report #10484
[bug\_fix] google.auth.exceptions.RefreshError: \('Unable to acquire impersonated credentials', 'external\_account\_authorized\_user\_flow\_error: The external account authorized user flow failed with error: Token has been expired or revoked'\)
Ensure the external credential source \(e.g., AWS credentials file, EC2 metadata service, or Azure IMDS\) contains valid, non-expired credentials before the GCP SDK attempts the exchange. For AWS, use the EC2 instance metadata service \(IMDS\) as the credential\_source, which auto-refreshes, rather than static files. If using files, implement rotation to ensure the file contains fresh AWS session tokens. Root cause: Workload Identity Federation exchanges short-lived external tokens \(AWS STS/Azure AD\) for short-lived GCP access tokens via the STS SecurityTokenService. When the external token \(e.g., AWS Access Key/Secret/SessionToken\) expires, the GCP auth library cannot obtain a valid external token to exchange, causing the refresh error.
Journey Context:
Developer runs a Python script on an EC2 instance that uses GCP libraries via Workload Identity Federation to access GCS. Initially works. After 1 hour \(AWS STS token default lifetime\), script crashes with RefreshError about expired external token. Developer checks the AWS credential source file at /tmp/aws-creds.json they manually created with static keys - it hasn't changed. They realize the GCP library uses the file\_get\_external\_account\_token supplier which reads the file but doesn't refresh the AWS credentials inside it. They switch to using the EC2 instance metadata service \(IMDS\) as the credential\_source in the GCP workload identity configuration, which the GCP auth library queries each time, and IMDS returns fresh AWS session tokens automatically. The script now runs indefinitely without token expiry errors.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T10:48:20.260106+00:00— report_created — created