AWS-GCP Workload Identity Federation Auth
Python library for exchanging AWS credentials for GCP credentials using Workload Identity Federation. Works with EKS, EC2, Lambda, and local development.
Installation
pip install aws-gcp-wif-auth
Authentication Flow
┌─────────────────────────────────────────────────────────────────┐
│ AWS Environment (EKS/EC2/Lambda) │
│ │
│ ┌──────────────┐ │
│ │ IAM Role │ 1. Provides AWS credentials │
│ │ (Pod/EC2/ │ (Access Key, Secret, Token) │
│ │ Lambda) │ │
│ └──────┬───────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ aws_gcp_wif_auth.get_credentials() │ │
│ │ • Fetches AWS credentials via boto3 │ │
│ │ • Auto-refreshes when expired │ │
│ └──────┬───────────────────────────────────────────────────┘ │
└─────────┼───────────────────────────────────────────────────────┘
│
│ 2. Exchange AWS credentials for GCP token
▼
┌─────────────────────────────────────────────────────────────────┐
│ GCP Workload Identity Federation │
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ STS Token Exchange (sts.googleapis.com) │ │
│ │ • Validates AWS credentials │ │
│ │ • Issues federated GCP token │ │
│ └──────┬───────────────────────────────────────────────────┘ │
│ │ │
│ │ 3. Impersonate service account │
│ ▼ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ Service Account Impersonation │ │
│ │ • Uses federated token │ │
│ │ • Returns service account credentials │ │
│ └──────┬───────────────────────────────────────────────────┘ │
└─────────┼───────────────────────────────────────────────────────┘
│
│ 4. Access GCP APIs
▼
┌─────────────────────────────────────────────────────────────────┐
│ GCP Services │
│ • Vertex AI • Cloud Storage • BigQuery │
│ • Pub/Sub • Cloud Run • Any GCP API │
└─────────────────────────────────────────────────────────────────┘
Usage
Auto-detect Environment (Recommended)
from aws_gcp_wif_auth import get_credentials
# Automatically uses WIF in AWS, ADC locally
credentials = get_credentials(
project_number="123456789",
pool_id="my-wif-pool",
provider_id="my-wif-provider",
service_account_email="my-sa@project.iam.gserviceaccount.com"
)
Explicit WIF (AWS Environments)
from aws_gcp_wif_auth import get_wif_credentials
credentials = get_wif_credentials(
project_number="123456789",
pool_id="my-wif-pool",
provider_id="my-wif-provider",
service_account_email="my-sa@project.iam.gserviceaccount.com",
aws_region="us-east-1"
)
Local Development (ADC)
from aws_gcp_wif_auth import get_adc_credentials
# Uses: gcloud auth application-default login
credentials = get_adc_credentials()
Authenticated Session
from aws_gcp_wif_auth import get_authed_session
# Get session with auto-refreshing credentials
session = get_authed_session(
project_number="123456789",
pool_id="my-wif-pool",
provider_id="my-wif-provider",
service_account_email="my-sa@project.iam.gserviceaccount.com"
)
# Make API requests
response = session.get("https://storage.googleapis.com/storage/v1/b")
Environment Detection
from aws_gcp_wif_auth import is_eks_environment
if is_eks_environment():
print("Running in AWS (EKS/EC2/Lambda)")
else:
print("Running locally")
Use with Google Cloud Libraries
from google.cloud import storage
from aws_gcp_wif_auth import get_credentials
credentials = get_credentials(
project_number="123456789",
pool_id="my-pool",
provider_id="my-provider",
service_account_email="sa@project.iam.gserviceaccount.com"
)
client = storage.Client(credentials=credentials)
buckets = list(client.list_buckets())
Supported AWS Environments
- EKS (Elastic Kubernetes Service) - IAM roles for service accounts
- EC2 - Instance profiles with IAM roles
- Lambda - Execution roles
- Local Development - Application Default Credentials (ADC)
API Reference
get_credentials()
Auto-detect environment and return appropriate credentials.
Parameters:
project_number: GCP project number (required for WIF)pool_id: Workload Identity Pool ID (required for WIF)provider_id: Workload Identity Provider ID (required for WIF)service_account_email: GCP service account email (required for WIF)aws_region: AWS region (default: "us-east-1")scopes: OAuth scopes list (default: cloud-platform)use_adc: Force ADC instead of auto-detection (default: False)
get_wif_credentials()
Explicitly use Workload Identity Federation.
get_adc_credentials()
Explicitly use Application Default Credentials.
get_authed_session()
Get authenticated session with auto-refreshing credentials.
is_eks_environment()
Check if running in AWS environment (EKS/EC2/Lambda).
Requirements
- Python 3.8+
- AWS environment with IAM role (for WIF)
- GCP Workload Identity Pool configured for AWS (for WIF)
gcloud auth application-default login(for local ADC)
License
MIT
Metadata
Release files for aws-gcp-wif-auth 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| aws_gcp_wif_auth-0.2.1.tar.gz | 5.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aws_gcp_wif_auth-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.8 kB
Release files / aws_gcp_wif_auth-0.2.1.tar.gz
| Download URL | aws_gcp_wif_auth-0.2.1.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
59961a1a6ff75c25dfebd8a10e16fb17f925167ef52144ec9829a6a36c50fe66
|
|
BLAKE2b-256 checksum How to use checksums |
8dd676a27b0c5660fc8502b9ddaa6bfee873090e89032badf8d0f88d06e29eb3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / aws_gcp_wif_auth-0.2.1-py3-none-any.whl
| Download URL | aws_gcp_wif_auth-0.2.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b61308cb9f50dc6b0d3008783ed1860abc44c3fad88964bacbbf24ef509670a8
|
|
BLAKE2b-256 checksum How to use checksums |
09d4aafb4cbe5f538a0e5b14a92c205962ed7eb6c75b1a332506c82aa37617e4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for aws-gcp-wif-auth 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.