In .gitlab-ci.yml file I have the command aws sts assume-role-with-web-identity
that return this error:
An error occurred (InvalidIdentityToken) when calling the AssumeRoleWithWebIdentity operation: Issuer must start with https://
This is deploy script:
deploy:
stage: deploy
id_tokens:
GITLAB_OIDC_TOKEN:
aud: https://git.mydomain.com
script:
- STS=($(aws sts assume-role-with-web-identity --role-arn ${ROLE_ARN} --role-session-name "gitlab-${CI_PROJECT_ID}-${CI_PIPELINE_ID}" --web-identity-token $GITLAB_OIDC_TOKEN --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' --output text))
- export AWS_ACCESS_KEY_ID="${STS[0]}"
- export AWS_SECRET_ACCESS_KEY="${STS[1]}"
- export AWS_SESSION_TOKEN="${STS[2]}"
- aws sts get-caller-identity
only:
- main
I`m trying to write a gitlab-ci script that assumes AWS Role with web-identity
Ensure you've configured your OIDC Identity provider in AWS accordingly as well as the trust policy of the role you're trying to assume. Your GitLab instance itself must also be configured with a URL (
external_url
in thegitlab.rb
config file) that begins withhttps://
and be accessible from the internet.If you receive this error, it's likely because your GitLab server's
external_url
configuration value is not set correctly or you are not using HTTPS, which is required.You must also ensure your IAM OIDC Identity Provider is configured correctly, as well as your IAM role, and your pipeline configuration:
First, configure the OIDC provider:
https://gitlab.example.com
.sts.amazonaws.com
-- you can use pretty much any value you wish, but you'll need to use the same value for your GitLab ID token'saud
claim -- GitLab suggests using your GitLab instance URL here (e.g.,https://gitlab.example.com
)The setup wizard will connect to your GitLab instance to correctly set the public key fingerprint.
Second, your IAM role must have a trust policy document that allows the role to be assumed using a web identity under correct conditions. For example, you may make a condition on the
sub
claim matching your repository path.You will need the ARN of the provider you created in the first step.
Lastly, configure your pipeline, ensuring
aud
for your ID token is set to the same "Audience" value used in the first step: