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.6.tar.gz (2.8 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.6-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for gcp-impersonation-wrapper-0.0.6.tar.gz
Algorithm Hash digest
SHA256 659702e2970c5aa24b97e8624d7047a7755582292667df1184727cea525652a3
MD5 37ac2b586fe0c8d16b197b8ed624a5eb
BLAKE2b-256 f7f55cd4fae8c6434c1259a2d2267f4239ae911a2ada709cc09271b2238ff785

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gcp_impersonation_wrapper-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 52a7d34dbd6a910592632aa230ce50e46eb7c563922984c5aebb61e2bcb40c7a
MD5 c25ebf8b5028502dc5b9c51d57e68ae1
BLAKE2b-256 b027591fd30473d35c6bfc8af8d1ff24f718cc3cfc2b23fa4a347119cf42e448

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