pulumi: Pulumi KMS secrets provider can't handle assumed web roles

What happened?

I am using GitLab with the following guide: https://docs.gitlab.com/ee/ci/cloud_services/aws/

It allows GitLab to use OpenId Connect to retrieve temporary AWS credentials by assuming a role. This is perfect, because it allows me to have GitLab runners which do not need permanent AWS credentials as variables in my project.

However, even though my script sets the AWS_ACCESS_KEY_ID, the AWS_SECRET_ACCESS_KEY and the AWS_SESSION_TOKEN of the temporary credentials, I get the following error when I try to run pulumi up:

error: constructing secrets manager of type “cloud”: secrets (code=Unknown): operation error KMS: Decrypt, https response error StatusCode: 400, RequestID: xxx, api error AccessDeniedException: The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access.

This is despite the fact that I can retrieve an encrypted Parameter Store parameter that has been encrypted with the same key, from the AWS CLI:

aws ssm get-parameter --name "some-encrypted-parameter" --with-decryption

This verifies that my temporary credentials are working, but not in Pulumi. It’s almost as if it doesn’t support assumed roles?

Here’s my code that sets up the temporary credentials (as per GitLab’s guide).

script:
  - >
    export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s"
    $(aws sts assume-role-with-web-identity
    --role-arn ${ROLE_ARN}
    --role-session-name "gitlab-session"
    --web-identity-token $CI_JOB_JWT_V2
    --duration-seconds 3600
    --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]'
    --output text))

Steps to reproduce

  1. Set up an encryption provider for Pulumi in KMS.
  2. Create a key policy for the key which allows full access for the role and assumed role.
  3. Assume the role and set environment variables based on the temporary AWS credentials.
  4. Verify that the key works with an assumed role (for instance, decrypt a dummy parameter store value) via the AWS CLI.
  5. Try doing any pulumi config operation or pulumi up, and see the error pop up.

Expected Behavior

I expected Pulumi to respect the credentials that are present in the environment variables, even when it’s for an assumed role (and with temporary credentials), also when using the secrets provider.

Actual Behavior

error: constructing secrets manager of type “cloud”: secrets (code=Unknown): operation error KMS: Decrypt, https response error StatusCode: 400, RequestID: xxx, api error AccessDeniedException: The ciphertext refers to a customer master key that does not exist, does not exist in this region, or you are not allowed to access.

Output of pulumi about

CLI          
Version      3.48.0
Go Version   go1.19.2
Go Compiler  gc

Plugins
NAME        VERSION
aws         5.20.0
aws-native  0.40.2
dotnet      unknown
random      4.8.2
tls         4.6.1

Host     
OS       darwin
Version  13.0.1
Arch     arm64

This project is written in dotnet: executable='/usr/local/share/dotnet/dotnet' version='7.0.100'

Dependencies:
NAME              VERSION
Newtonsoft.Json   13.0.1
Pulumi            3.46.1
Pulumi.Aws        5.20.0
Pulumi.AwsNative  0.40.2
Pulumi.Random     4.8.2
Pulumi.Tls        4.6.1

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction. To contribute a fix for this issue, leave a comment (and link to your pull request, if you’ve opened one already).

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 16 (15 by maintainers)

Commits related to this issue

Most upvoted comments

Maybe that last thing you describe with access denied is the true problem.

Well that was that I couldn’t get sts.AssumeRole to work that happens before any pulumi kms code runs. So won’t be the same issue you’ve got.