AWS Credentials and AWS Signature V4 Request Signer.
This module provides credentials to access Google Cloud resources from Amazon Web Services (AWS) workloads. These credentials are recommended over the use of service account credentials in AWS as they do not involve the management of long-live service account private keys.
AWS Credentials are initialized using external_account arguments which are typically loaded from the external credentials JSON file.
This module also provides a definition for an abstract AWS security credentials supplier. This supplier can be implemented to return valid AWS security credentials and an AWS region and used to create AWS credentials. The credentials will then call the supplier instead of using pre-defined methods such as calling the EC2 metadata endpoints.
This module also provides a basic implementation of the AWS Signature Version 4 request signing algorithm.
AWS Credentials use serialized signed requests to the AWS STS GetCallerIdentity API that can be exchanged for Google access tokens via the GCP STS endpoint.
Bases: object
Implements an AWS request signer based on the AWS Signature Version 4 signing process. https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html
Instantiates an AWS request signer used to compute authenticated signed requests to AWS APIs based on the AWS Signature Version 4 signing process.
region_name (str) – The AWS region to use.
Generates the signed request for the provided HTTP request for calling an AWS API. This follows the steps described at: https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
aws_security_credentials (AWSSecurityCredentials) – The AWS security credentials.
url (str) – The AWS service URL containing the canonical URI and query string.
method (str) – The HTTP method used to call this API.
request_payload (Optional
str
) – The optional request payload if available.
additional_headers (Optional
Mapping
str
, str
) – The optional additional headers needed for the requested AWS API.
The AWS signed request dictionary object.
Bases: object
A class that models AWS security credentials with an optional session token.
The AWS security credentials access key id.
The AWS security credentials secret access key.
Bases: object
Base class for AWS security credential suppliers. This can be implemented with custom logic to retrieve AWS security credentials to exchange for a Google Cloud access token. The AWS external account credential does not cache the AWS security credentials, so caching logic should be added in the implementation.
Returns the AWS security credentials for the requested context.
context (google.auth.externalaccount.SupplierContext) – The context object containing information about the requested audience and subject token type.
request (google.auth.transport.Request) – The object used to make HTTP requests.
google.auth.exceptions.RefreshError – If an error is encountered during security credential retrieval logic.
The requested AWS security credentials.
Returns the AWS region for the requested context.
context (google.auth.externalaccount.SupplierContext) – The context object containing information about the requested audience and subject token type.
request (google.auth.transport.Request) – The object used to make HTTP requests.
google.auth.exceptions.RefreshError – If an error is encountered during region retrieval logic.
The AWS region.
Bases: Credentials
AWS external account credentials. This is used to exchange serialized AWS signature v4 signed requests to AWS STS GetCallerIdentity service for Google access tokens.
Instantiates an AWS workload external account credentials object.
audience (str) – The STS audience field.
subject_token_type (str) –
The subject token type based on the Oauth2.0 token exchange spec. Expected values include:
“urn:ietf:params:aws:token-type:aws4_request”
token_url (Optional [str]) – The STS endpoint URL. If not provided, will default to “https://sts.googleapis.com/v1/token”.
credential_source (Optional [Mapping]) –
The credential source dictionary used to provide instructions on how to retrieve external credential to be exchanged for Google access tokens. Either a credential source or an AWS security credentials supplier must be provided.
Example credential_source for AWS credential:
{ "environment_id": "aws1", "regional_cred_verification_url": "https://sts.{region}.amazonaws.com?Action=GetCallerIdentity&Version=2011-06-15", "region_url": "http://169.254.169.254/latest/meta-data/placement/availability-zone", "url": "http://169.254.169.254/latest/meta-data/iam/security-credentials", imdsv2_session_token_url": "http://169.254.169.254/latest/api/token" }
aws_security_credentials_supplier (Optional [AwsSecurityCredentialsSupplier]) – Optional AWS security credentials supplier. This will be called to supply valid AWS security credentails which will then be exchanged for Google access tokens. Either an AWS security credentials supplier or a credential source must be provided.
args (List) – Optional positional arguments passed into the underlying __init__()
method.
kwargs (Mapping) – Optional keyword arguments passed into the underlying __init__()
method.
google.auth.exceptions.RefreshError – If an error is encountered during access token retrieval logic.
ValueError – For invalid parameters.
Note
Typically one of the helper constructors from_file()
or from_info()
are used instead of calling the constructor directly.
Retrieves the subject token using the credential_source object. The subject token is a serialized AWS GetCallerIdentity signed request.
The logic is summarized as:
Retrieve the AWS region from the AWS_REGION or AWS_DEFAULT_REGION environment variable or from the AWS metadata server availability-zone if not found in the environment variable.
Check AWS credentials in environment variables. If not found, retrieve from the AWS metadata server security-credentials endpoint.
When retrieving AWS credentials from the metadata server security-credentials endpoint, the AWS role needs to be determined by calling the security-credentials endpoint without any argument. Then the credentials can be retrieved via: security-credentials/role_name
Generate the signed request to AWS STS GetCallerIdentity action.
Inject x-goog-cloud-target-resource into header and serialize the signed request. This will be the subject-token to pass to GCP STS.
request (google.auth.transport.Request) – A callable used to make HTTP requests.
The retrieved subject token.
Apply the token to the authentication header.
Performs credential-specific before request logic.
Refreshes the credentials if necessary, then calls apply()
to apply the token to the authentication header.
request (google.auth.transport.Request) – The object used to make HTTP requests.
method (str) – The request’s HTTP method or the RPC method being invoked.
url (str) – The request’s URI or the RPC service’s URI.
headers (Mapping) – The request’s headers.
Checks if the credentials are expired.
Note that credentials can be invalid but not expired because Credentials with expiry
set to None is considered to never expire.
Deprecated since version v2.24.0: Prefer checking token_state
instead.
Creates an AWS Credentials instance from parsed external account info.
The constructed credentials.
ValueError – For invalid parameters.
The credential information JSON.
The credential information will be added to auth related error messages by client library.
Retrieves the project ID corresponding to the workload identity or workforce pool. For workforce pool credentials, it returns the project ID corresponding to the workforce_pool_user_project.
When not determinable, None is returned.
This is introduced to support the current pattern of using the Auth library:
credentials, project_id = google.auth.default()
The resource may not have permission (resourcemanager.projects.get) to call this API or the required scopes may not be selected: https://cloud.google.com/resource-manager/reference/rest/v1/projects/get#authorization-scopes
request (google.auth.transport.Request) – A callable used to make HTTP requests.
or workforce pool if determinable.
Checks if the credentials have the given scopes.
Generates the dictionary representation of the current credentials.
reverse of “from_info” defined on the subclasses of this class. It is useful for serializing the current credentials so it can deserialized later.
Mapping
Returns whether the credentials represent a user (True) or workload (False). Workloads behave similarly to service accounts. Currently workloads will use service account impersonation but will eventually not require impersonation. As a result, this property is more reliable than the service account email property in determining if the credentials represent a user or workload.
workload.
Returns whether the credentials represent a workforce pool (True) or workload (False) based on the credentials’ audience.
This will also return True for impersonated workforce pool credentials.
represent a workload.
The project number corresponding to the workload identity pool.
Project to use for quota and billing purposes.
Refreshes the access token.
request (google.auth.transport.Request) – The object used to make HTTP requests.
google.auth.exceptions.RefreshError – If the credentials could not be refreshed.
Checks if the credentials requires scopes.
True if there are no scopes set otherwise False.
Returns the service account email if service account impersonation is used.
See :obj:`TokenState
The universe domain value.
Checks the validity of the credentials.
This is True if the credentials have a token
and the token is not expired
.
Deprecated since version v2.24.0: Prefer checking token_state
instead.
Returns a copy of these credentials with a modified quota project.
quota_project_id (str) – The project to use for quota and billing purposes
A new credentials instance.
Create a copy of these credentials with the specified scopes.
scopes (Sequence
str
) – The list of scopes to attach to the current credentials.
NotImplementedError – If the credentials’ scopes can not be changed. This can be avoided by checking requires_scopes
before calling this method.
Returns a copy of these credentials with a modified token uri.
token_uri (str) – The uri to use for fetching/exchanging tokens
A new credentials instance.
Returns a copy of these credentials with a modified universe domain.
universe_domain (str) – The universe domain to use
A new credentials instance.
When the token expires and is no longer valid. If this is None, the token is assumed to never expire.
Creates an AWS Credentials instance from an external account json file.
filename (str) – The path to the AWS external account json file.
kwargs – Additional arguments to pass to the constructor.
The constructed credentials.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4