Skip to main content

No project description provided

Project description

GCP Impersonation wrapper

The gcp-impersonation-wrapper is a small util used to impersonate service accounts using service account. We pass the main credentials, list service accounts we can impersonate and then actually impersonate like so:

#!/usr/bin/env python3
from src.service_account import ServiceAccount


if __name__ == "__main__":
    # Insert credentials here
    credentials = None

    service_account = ServiceAccount(
        project_id="your-project-id",
        impersonator_credentials=credentials
    )

    # Can be used in a with statement
    with service_account.impersonate(
        service_account_email="your-service-account-email",
        target_scopes=["https://www.googleapis.com/auth/cloud-platform"],
        service="iam",
        version="v1"
    ) as impersonated_service_account:
        # do something with the impersonated service account
        service_accounts_the_impersonated_sacc_can_see = impersonated_service_account.service.projects(
        ).serviceAccounts().list().execute()
        print(service_accounts_the_impersonated_sacc_can_see)

    # Or as a variable
    impersonated_service_account = service_account.impersonate(
        service_account_email="your-service-account-email",
        target_scopes=["https://www.googleapis.com/auth/cloud-platform"],
        service="iam",
        version="v1"
    )
    service_accounts_the_impersonated_sacc_can_see = impersonated_service_account.service.projects(
    ).serviceAccounts().list().execute()

To list the impersonatable service accounts we do:

#!/usr/bin/env python3
from src.service_account import ServiceAccount


if __name__ == "__main__":
    # Insert credentials here
    credentials = None

    service_account = ServiceAccount(
        project_id="your-project-id",
        impersonator_credentials=credentials
    )

    # This returns a list of email like ["john@doe.com", "jane@doe.com", ....]
    service_account_emails_we_can_impersonate = service_account.list_all_impersonatable_service_account_emails() 

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

gcp-impersonation-wrapper-0.0.3.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

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

gcp_impersonation_wrapper-0.0.3-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file gcp-impersonation-wrapper-0.0.3.tar.gz.

File metadata

  • Download URL: gcp-impersonation-wrapper-0.0.3.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for gcp-impersonation-wrapper-0.0.3.tar.gz
Algorithm Hash digest
SHA256 7742aa403084f340ce64754d9d0aea722610fed6cf5861af243d8f588819c9e8
MD5 4fef001f1f5f9ae6734fe90b007f967e
BLAKE2b-256 beaafaac917fde01957876454ca198a18ba95c58e870ab2981d404bc5cb4268e

See more details on using hashes here.

File details

Details for the file gcp_impersonation_wrapper-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: gcp_impersonation_wrapper-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 3.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for gcp_impersonation_wrapper-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 a70592d9c2a16cdf4579b97a7f12ff29a8e3fef20d72113ffe69e73809cf9fdf
MD5 ac23506a73ca958ae3f68841114b7580
BLAKE2b-256 d08d1eb7b7493062f7ec8b006ba749158ef0d25311d57e3721dc10d6bc052901

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