You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
port='80'
header='HTTP/1.1 200 OK'
body='<!DOCTYPE html><html> <body> <h1>Example</h1> <p> This is a simple webserver running with <b>nc</b> </p> </body></html>'printf -v response "%s\n\n%s\n""${header}""${body}"whiletrue;do
/usr/bin/nc -l "${port}"<<<"${response}"done
GCP SDK Using Federated AWS Auth
fromboto3importSessionasBotoSessionfrombotocore.credentialsimportCredentialsasBotoCredentialsfrombotocore.exceptionsimportNoCredentialsErrorfromgoogle.authimport_helpersfromgoogle.auth.awsimportAwsSecurityCredentials, AwsSecurityCredentialsSupplierfromgoogle.auth.awsimportCredentialsasAwsFederatedGcpCredentialsfromgoogle.auth.external_accountimportSupplierContextfromgoogle.auth.transportimportRequestclassBotoCredentialsSupplier(AwsSecurityCredentialsSupplier):
""" Use boto to resolve the current session's AWS credentials rather than using the GCP SDK defaults: exposing them to the environment or using a metadata service """def__init__(self, aws_region: str, boto_session=None) ->None:
self.aws_region=aws_regionself.boto_session=boto_session@_helpers.copy_docstring(AwsSecurityCredentialsSupplier)defget_aws_security_credentials(
self,
context: SupplierContext,
request: Request,
) ->AwsSecurityCredentials:
boto_session=self.boto_sessionifself.boto_sessionelseBotoSession(region_name=self.aws_region)
boto_credentials: BotoCredentials|None=boto_session.get_credentials()
ifboto_credentialsisNone:
raiseNoCredentialsErrorfrozen_credentials=boto_credentials.get_frozen_credentials()
returnAwsSecurityCredentials(
frozen_credentials.access_key,
frozen_credentials.secret_key,
frozen_credentials.token,
)
@_helpers.copy_docstring(AwsSecurityCredentialsSupplier)defget_aws_region(
self,
context: SupplierContext,
request: Request,
) ->str:
returnself.aws_regiondefget_aws_federated_gcp_creds(
aws_region: str,
project_number: str|int,
pool_id: str,
org_uuid: str,
service_account_email: str,
) ->AwsFederatedGcpCredentials:
""" If AWS is properly federated as an identity provider in GCP, GCP session credentials can be obtained with AWS credentials. """provider_id=org_uuid.replace("-", "")
boto_credentials_supplier=BotoCredentialsSupplier(aws_region=aws_region)
returnAwsFederatedGcpCredentials(
audience=(
f"//iam.googleapis.com/projects/{project_number}/locations/global"f"/workloadIdentityPools/{pool_id}/providers/{provider_id}"
),
subject_token_type="urn:ietf:params:aws:token-type:aws4_request",
service_account_impersonation_url=(
"https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts"f"/{service_account_email}:generateAccessToken"
),
aws_security_credentials_supplier=boto_credentials_supplier,
)