I would like to access AWS resource with GCP credentials from my local computer. My code works fine if I run everything in GCP from a cloud function, but this also should work locally.
If I run my code locally I got the following error which says taht my generated JWT token is invalid.
An error occurred (InvalidIdentityToken) when calling the AssumeRoleWithWebIdentity operation: Error normalizing issuer
I have a service Account keyfile on my local machine. I create a JWT token from this file:
def create_jwt_token(keyfile: str, audience: str):
jwt_creds = google_auth_jwt.Credentials.from_service_account_file(
keyfile, audience=audience)
request = ga_requests.Request()
jwt_creds.refresh(request)
return jwt_creds.token.decode('utf-8')
The issuer is equal the serviceaccount email address. Fore the audience I set the gcp project-id.
Here is the code for generating AWS credentials:
def generate_aws_credentials(arn: str, token: str, role_session_name: str):
sts = boto3.client('sts', region_name="eu-west-1")
try:
result = sts.assume_role_with_web_identity(
RoleArn=arn,
WebIdentityToken=token,
RoleSessionName=role_session_name)
except Exception as ex:
raise Exception(f"unable to create aws identity token. {ex}")
return result
As I said, the code works from within gcp but not locally. I am not able to see the difference between the tokens in gcp and local.