Skip to main content

AWS-GCP Workload Identity Federation authentication for EKS, EC2, Lambda, and local development

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_gcp_wif_auth-0.2.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_gcp_wif_auth-0.2.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file aws_gcp_wif_auth-0.2.0.tar.gz.

File metadata

  • Download URL: aws_gcp_wif_auth-0.2.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for aws_gcp_wif_auth-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0f41c82ce6677ce77e55ee50f26bb544240b30d330dea87775bfb351f2346867
MD5 3320f701a399d27355c60662e753fb66
BLAKE2b-256 408c63280557e0d65b046b6707ec9ecb56f0d334445870ccc3a2690653716ecc

See more details on using hashes here.

File details

Details for the file aws_gcp_wif_auth-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_gcp_wif_auth-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 81fefd1e1279f4354961785437e242c3bae0ad5cd656cbfc8fab737874186d83
MD5 60805a8603ca155fce1caedab19a5e33
BLAKE2b-256 326cd559eb8d12e84a2e51685f758ff9e22acddf405f007288dd010c84205cff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page