Pyjo.AWS.Credentials.WebIdentity - Credentials of a role of a web identity

from Pyjo.AWS.Credentials.WebIdentity import WebIdentity

credentials = WebIdentity().credentials()

# Or import the module, as in Google Python Style Guide

import Pyjo.AWS.Credentials.WebIdentity

provider = Pyjo.AWS.Credentials.WebIdentity.new(
    role_arn='arn:aws:iam::123456789012:role/ci', token_file='/var/run/secrets/token', role_session_name='ci'
)
provider.credentials_p().then(lambda credentials: print(credentials.expiration)).wait()

Pyjo.AWS.Credentials.WebIdentity is the provider of the credentials of a role of AssumeRoleWithWebIdentity of STS, with the token of OpenID Connect of a file, as the service accounts of EKS and the OIDC of CI have it: of the AWS_WEB_IDENTITY_TOKEN_FILE, AWS_ROLE_ARN and AWS_ROLE_SESSION_NAME environment variables by default, or of web_identity_token_file and role_arn of a profile, of Pyjo.AWS.Credentials.Profile. The request is not signed, as the token is its proof, and the file is read each time, as the token is rotated.

A token file without a role, or a role without a token file, of the environment, is an error.

See also

Pyjo.AWS.Credentials.Provider, Pyjo.AWS.Credentials.AssumeRole, https://docs.aws.amazon.com/sdkref/latest/guide/feature-assume-role-credentials.html.

Classes

class Pyjo.AWS.Credentials.WebIdentity.Pyjo_AWS_Credentials_WebIdentity(*, role_arn: str | None = None, token_file: str | None = None, role_session_name: str | None = None, duration_seconds: int | None = None, region: str | None = None, config: Pyjo_AWS_Config | None = None, **kwargs: Any)[source]

Pyjo.AWS.Credentials.WebIdentity inherits all attributes and methods from Pyjo.AWS.Credentials.Provider and implements the following new ones.

__init__(*, role_arn: str | None = None, token_file: str | None = None, role_session_name: str | None = None, duration_seconds: int | None = None, region: str | None = None, config: Pyjo_AWS_Config | None = None, **kwargs: Any) → None[source]
provider = Pyjo.AWS.Credentials.WebIdentity.new()
provider = Pyjo.AWS.Credentials.WebIdentity.new(role_arn=arn, token_file='/var/run/secrets/token')

Construct a new Pyjo.AWS.Credentials.WebIdentity object, with the options of Pyjo.AWS.Credentials.Provider, and the role, the token file and the name of the session of the environment without role_arn and token_file.

config
config = provider.config

The shared files of the endpoint and the region of STS, a new Pyjo.AWS.Config object by default.

duration_seconds
seconds = provider.duration_seconds

The duration of the credentials, or None for the default of STS, one hour.

async fetch() → Pyjo_AWS_Credentials | None[source]
credentials = await provider.fetch()

The credentials of the role, of the token of the file, or None without a role and a token file.

region
region = provider.region

The region of STS, or None for the one of config, or us-east-1.

role_arn
arn = provider.role_arn

The ARN of the role, of the AWS_ROLE_ARN environment variable by default.

role_session_name
name = provider.role_session_name

The name of the session of the role, of the AWS_ROLE_SESSION_NAME environment variable by default, or None for pyjo-aws- and the time.

token_file
path = provider.token_file

The file of the token, of the AWS_WEB_IDENTITY_TOKEN_FILE environment variable by default.