Pyjo.GCP.Credentials.Pluggable - Credentials of an external account of an executable¶
import os
from Pyjo.GCP.Credentials.Pluggable import Pluggable
os.environ['GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES'] = '1'
provider = Pluggable(
audience='//iam.googleapis.com/projects/123/locations/global/workloadIdentityPools/pool/providers/oidc',
subject_token_type='urn:ietf:params:oauth:token-type:jwt',
command='/opt/bin/oidc-token --audience pool',
output_file='/var/cache/oidc-token.json',
)
print(provider.credentials().token)
Pyjo.GCP.Credentials.Pluggable is the provider of the credentials of
an external account whose subject token is the output of an executable, of a
file of the type external_account with executable of
credential_source, as
gcloud iam workload-identity-pools create-cred-config --executable-command
writes it:
{
"type": "external_account",
"audience": "//iam.googleapis.com/projects/123/locations/global/workloadIdentityPools/pool/providers/oidc",
"subject_token_type": "urn:ietf:params:oauth:token-type:jwt",
"token_url": "https://sts.googleapis.com/v1/token",
"credential_source": {
"executable": {
"command": "/opt/bin/oidc-token --audience pool",
"timeout_millis": 5000,
"output_file": "/var/cache/oidc-token.json"
}
}
}
The executable runs only with GOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES=1
in the environment, as google-auth has it, with the variables
GOOGLE_EXTERNAL_ACCOUNT_AUDIENCE, GOOGLE_EXTERNAL_ACCOUNT_TOKEN_TYPE,
GOOGLE_EXTERNAL_ACCOUNT_ID, GOOGLE_EXTERNAL_ACCOUNT_INTERACTIVE,
GOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAIL and
GOOGLE_EXTERNAL_ACCOUNT_OUTPUT_FILE, and its output is a JSON object of
version 1:
{
"version": 1,
"success": true,
"token_type": "urn:ietf:params:oauth:token-type:jwt",
"id_token": "eyJhbGciOiJSUzI1NiIs...",
"expiration_time": 1762261200
}
with id_token of the types of a JWT and an OIDC token, or
saml_response of SAML 2.0, or "success": false with code and
message. A token of output_file that has not expired is taken without
running the executable. The interactive mode of gcloud is not supported.
See also¶
Pyjo.GCP.Credentials.ExternalAccount,
Pyjo.GCP.Credentials.File, https://google.aip.dev/auth/4117,
https://cloud.google.com/iam/docs/workload-identity-federation-with-other-providers#executable-sourced-credentials.
Classes¶
- class Pyjo.GCP.Credentials.Pluggable.Pyjo_GCP_Credentials_Pluggable(*, command: str, timeout: float = 30, output_file: str | None = None, **kwargs: Any)[source]¶
Pyjo.GCP.Credentials.Pluggableinherits all attributes and methods fromPyjo.GCP.Credentials.ExternalAccountand implements the following new ones.- __init__(*, command: str, timeout: float = 30, output_file: str | None = None, **kwargs: Any) None[source]¶
provider = Pyjo.GCP.Credentials.Pluggable.new(audience=audience, subject_token_type=token_type, command='/opt/bin/oidc-token', timeout=5)
Construct a new
Pyjo.GCP.Credentials.Pluggableobject, with the options ofPyjo.GCP.Credentials.ExternalAccount, or aPyjo.Exceptionwithout a command, or of a timeout that is not of 5 to 120 seconds.
- command¶
command = provider.command
The command of the executable, with its arguments, split as a shell does.
- environment() dict[str, str][source]¶
env = provider.environment()
The environment of the executable, the one of the process with the variables of the external account.
- classmethod options_of(info: Mapping[str, Any]) dict[str, Any][source]¶
options = Pluggable.options_of(info)
The options of
executableofcredential_sourceof the JSON object of a file:command,timeout_millisandoutput_file.
- output_file¶
path = provider.output_file
The file where the executable keeps its output, of a token that is taken until it expires, or
None.
- async subject_token() str[source]¶
token = await provider.subject_token()
The subject token of
output_filethat has not expired, or of the output of the executable, or aPyjo.ExceptionwithoutGOOGLE_EXTERNAL_ACCOUNT_ALLOW_EXECUTABLES=1, of an executable that fails, or of an output without the token.
- timeout¶
seconds = provider.timeout
The number of seconds that the executable may run, 30 by default, of 5 to 120.
- Pyjo.GCP.Credentials.Pluggable.TIMEOUT = 30¶
The number of seconds that the executable may run by default, 30.