Pyjo.GCP.Credentials.ExternalAccount - Credentials of an external account

from Pyjo.GCP.Credentials.ExternalAccount import ExternalAccount

class Supplier(ExternalAccount):
    async def subject_token(self):
        return await my_token_of_another_identity_provider()

provider = Supplier(
    audience='//iam.googleapis.com/projects/123/locations/global/workloadIdentityPools/pool/providers/oidc',
    subject_token_type='urn:ietf:params:oauth:token-type:jwt',
)
print(provider.credentials().token)

Pyjo.GCP.Credentials.ExternalAccount is the base class of the providers of the credentials of an external account of Workload Identity Federation and Workforce Identity Federation, of a file of the type external_account, of AIP-4117: the token of another identity provider, a subject token, which the Security Token Service of Google exchanges for an access token, as RFC 8693 has it, and which a subclass gets in subject_token():

With service_account_impersonation_url, the token is the one of the service account that the federated token impersonates, of Pyjo.GCP.Credentials.Impersonated, and the federated token has the scope of IAM, as google-auth has them.

The project is the one of the number of the project of the audience, or of the workforce pool user project, of Cloud Resource Manager, which the provider asks once, with its token, as google-auth does, or of its emulator of CLOUDRESOURCEMANAGER_EMULATOR_HOST without a token, as Pyjo.GCP.Client calls an emulator. The impersonation of service_account_impersonation_url goes to the emulator of IAMCREDENTIALS_EMULATOR_HOST of Pyjo.GCP.Credentials.Impersonated, but the exchange goes to token_url, which no emulator replaces.

See also

Pyjo.GCP.Credentials.Provider, Pyjo.GCP.Credentials.File, https://google.aip.dev/auth/4117, https://cloud.google.com/iam/docs/workload-identity-federation, https://cloud.google.com/iam/docs/reference/sts/rest/v1/TopLevel/token.

Classes

Pyjo.GCP.Credentials.ExternalAccount.GRANT_TYPE = 'urn:ietf:params:oauth:grant-type:token-exchange'

The grant type of the token exchange of RFC 8693.

Pyjo.GCP.Credentials.ExternalAccount.PROJECT_URL = 'https://cloudresourcemanager.googleapis.com/v1/projects/'

The URL of the projects of Cloud Resource Manager, of the project of a number, as google-auth has it.

class Pyjo.GCP.Credentials.ExternalAccount.Pyjo_GCP_Credentials_ExternalAccount(*, audience: str, subject_token_type: str, token_url: str | None = None, service_account_impersonation_url: str | None = None, lifetime: int | None = None, client_id: str | None = None, client_secret: str | None = None, scopes: Sequence[str] | None = None, quota_project: str | None = None, workforce_pool_user_project: str | None = None, universe_domain: str | None = None, project_url: str | None = None, **kwargs: Any)[source]

Pyjo.GCP.Credentials.ExternalAccount inherits all attributes and methods from Pyjo.GCP.Credentials.Provider and implements the following new ones.

__init__(*, audience: str, subject_token_type: str, token_url: str | None = None, service_account_impersonation_url: str | None = None, lifetime: int | None = None, client_id: str | None = None, client_secret: str | None = None, scopes: Sequence[str] | None = None, quota_project: str | None = None, workforce_pool_user_project: str | None = None, universe_domain: str | None = None, project_url: str | None = None, **kwargs: Any) → None[source]
provider = Pyjo.GCP.Credentials.IdentityPool.new(audience=audience, subject_token_type=token_type,
                                                 file='/var/run/secrets/token')

Construct a new provider of an external account, with the options of Pyjo.GCP.Credentials.Provider, or a Pyjo.Exception of a workforce pool user project of an audience that is not of a workforce pool.

audience
audience = provider.audience

The resource name of the provider of the pool, as //iam.googleapis.com/projects/123/locations/global/workloadIdentityPools/pool/providers/oidc.

client_id
client_id = provider.client_id

The ID of the OAuth client of a workforce pool, of the basic authentication of the exchange, or None.

client_secret
secret = provider.client_secret

The secret of the OAuth client, or None.

async exchange(scopes: Sequence[str] | None = None) → Pyjo_GCP_Credentials[source]
credentials = await provider.exchange()

The federated token of the exchange of the subject token, with the scopes, scopes by default.

exchange_options() → dict[str, str][source]
options = provider.exchange_options()

The options of the exchange, userProject of the workforce pool user project without a client, as google-auth has them.

async fetch() → Pyjo_GCP_Credentials[source]
credentials = await provider.fetch()

The federated token, or the token of the impersonated service account, with the project of Cloud Resource Manager.

classmethod from_info(info: Mapping[str, Any], **kwargs: Any) → Self[source]
provider = IdentityPool.from_info(info)
provider = IdentityPool.from_info(info, scopes=scopes, ua=ua)

A new provider of the JSON object of a file of the type external_account, with the fields of the file and the arguments over them, or a Pyjo.Exception of a file without audience or subject_token_type.

impersonated() → Pyjo_GCP_Credentials_Impersonated[source]
provider = provider.impersonated()

The provider of the impersonated service account of service_account_impersonation_url, whose source is the federated token of the scope of IAM, made once, or a Pyjo.Exception of a URL without a service account.

is_workforce_pool() → bool[source]
boolean = provider.is_workforce_pool()

Whether audience is the one of a workforce pool, of Workforce Identity Federation of users.

lifetime
seconds = provider.lifetime

The number of seconds that the token of the impersonated service account is valid, or None, for an hour.

classmethod options_of(info: Mapping[str, Any]) → dict[str, Any][source]
options = IdentityPool.options_of(info)

The options of the provider of credential_source of the JSON object of a file, or a Pyjo.Exception of an invalid one. A subclass implements it; this one has none.

project: str | None
project = provider.project

The project of the number of the project, once the provider has asked for it, or None.

project_number() → str | None[source]
number = provider.project_number()

The number of the project of audience, after projects/, or None.

project_url
url = provider.project_url

The URL of the projects of Cloud Resource Manager, which comes over the emulator of CLOUDRESOURCEMANAGER_EMULATOR_HOST, or None, for PROJECT_URL, https://cloudresourcemanager.googleapis.com/v1/projects/.

quota_project
project = provider.quota_project

The quota project of the credentials, or None.

scopes
scopes = provider.scopes

The scopes of the token, https://www.googleapis.com/auth/cloud-platform by default.

service_account() → str | None[source]
email = provider.service_account()

The email of the service account of service_account_impersonation_url, between its last / and :generateAccessToken, or None.

service_account_impersonation_url
url = provider.service_account_impersonation_url

The URL of generateAccessToken of a service account that the federated token impersonates, or None.

async subject_token() → str[source]
token = await provider.subject_token()

The subject token of the other identity provider, a coroutine that awaits what it waits for, as fetch() does. A subclass implements it; this one raises a Pyjo.Exception.

subject_token_type
token_type = provider.subject_token_type

The type of the subject token, as urn:ietf:params:oauth:token-type:jwt.

token_url
url = provider.token_url

The token endpoint of the exchange, of the Security Token Service of universe_domain by default, https://sts.googleapis.com/v1/token.

universe_domain
domain = provider.universe_domain

The universe domain, googleapis.com by default.

workforce_pool_user_project
project = provider.workforce_pool_user_project

The project of the quota of the exchange of a workforce pool without a client_id, or None.

Pyjo.GCP.Credentials.ExternalAccount.REQUESTED_TOKEN_TYPE = 'urn:ietf:params:oauth:token-type:access_token'

The type of the token that the exchange gives, an access token.

Pyjo.GCP.Credentials.ExternalAccount.TOKEN_URL = 'https://sts.{universe_domain}/v1/token'

The token endpoint of the Security Token Service of Google, of a universe domain.