I seem to be having an inconsistent issue using aw...
# aws
s
I seem to be having an inconsistent issue using aws kms for my secrets provider on a new project that I don't remember hitting in the past. I'll often get an error like:
Copy code
Previewing update (svc-euw1):
error: constructing secrets manager of type "cloud": secrets (code=InvalidArgument): InvalidCiphertextException:
and retrying the pulumi command several times with nothing changing eventually works. From a little reading it might have something to do with how go-cloud handles chaining SSO auth. Has anyone seen this?
s
Hi @sticky-kitchen-61063 I haven't seen this before. Are you using the AWS KMS customer managed key with Pulumi? https://www.pulumi.com/docs/administration/security-compliance/customer-managed-keys/aws-kms/ If you've got a reproduction you can share, I'm happy to poke around a bit and see if there's a good workaround
s
@steep-plastic-74107 There's definitely something funky going on with go-cloud using kms keys with multiple encryption context keys. I create a brand new stack with:
Copy code
pulumi stack init svc-euw1 \
āˆ™   --secrets-provider "awskms:///arn:aws:kms:us-east-1:000000000000:alias/pulumi-management-admin?region=us-east-1&context_env=svc&context_stack=aws-eks-svc-euw1"
Created stack 'svc-euw1'
and get this in my stack file
Copy code
secretsprovider: awskms:///arn:aws:kms:us-east-1:000000000000:alias/pulumi-management-admin?region=us-east-1&context_env=svc&context_stack=aws-eks-svc-euw1
when I try to fetch and it sometimes works, in Cloudtrail the encryption context looks like this
Copy code
"requestParameters": {
        "encryptionContext": {
            "stack": "svc",
            "env": "svc"
        },
        "encryptionAlgorithm": "SYMMETRIC_DEFAULT"
    },
and sometimes it fails with cloudtrail showing both encryption context keys are the same:
Copy code
"errorCode": "InvalidCiphertextException",
    "requestParameters": {
        "encryptionContext": {
            "stack": "aws-eks-svc-euw1",
            "env": "aws-eks-svc-euw1"
        },
        "encryptionAlgorithm": "SYMMETRIC_DEFAULT"
    },
In both cases, it's incorrectly setting both encryption context keys to one value or the other. This is me trying it over and over until it works:
Copy code
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
error: secrets (code=InvalidArgument): InvalidCiphertextException: 
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
error: secrets (code=InvalidArgument): InvalidCiphertextException: 
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
error: secrets (code=InvalidArgument): InvalidCiphertextException: 
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
error: secrets (code=InvalidArgument): InvalidCiphertextException: 
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
error: secrets (code=InvalidArgument): InvalidCiphertextException: 
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
error: secrets (code=InvalidArgument): InvalidCiphertextException: 
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
error: secrets (code=InvalidArgument): InvalidCiphertextException: 
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
AWS_PROFILE=my_profile pulumi config get testSecret
error: secrets (code=InvalidArgument): InvalidCiphertextException: 
AWS_PROFILE=my_profile pulumi config get testSecret
error: secrets (code=InvalidArgument): InvalidCiphertextException: 
AWS_PROFILE=my_profile pulumi config get testSecret
foo
So it seems like it's luck of the draw which value both my encryption context keys get set to, and I think the only reason it works with
Copy code
"encryptionContext": {
            "stack": "svc",
            "env": "svc"
        },
is because that was just so happened to be what the encryption context was incorrectly set to when I encrypted the stack's encryptedkey.
I'm going to try to go back to a single encryption context key, and I bet this goes away.
In case it's not clear, the encryption context should be set as:
Copy code
"encryptionContext": {
            "stack": "aws-eks-svc-euw1",
            "env": "svc"
        },
s
Yea, that's interesting; it does seem like it's probably a bug then. You're using an environment with the stack that has a different encryption key?
s
I'm not sure I understand your question. I've been consistently using the same kms key.
s
I was wondering if you had an esc environment you were using with a different key https://www.pulumi.com/docs/esc/administration/customer-managed-keys/
s
This is using an s3 state bucket. I'm not using pulumi cloud.
s
Gotcha, so just passing different contexts to the same key?
šŸ‘ 1
s
With a single encryption context key it works every time as you wold expect:
Copy code
AWS_PROFILE=my_profile pulumi stack init svc-euw1 \
āˆ™   --secrets-provider "awskms:///arn:aws:kms:us-east-1:000000000000:alias/pulumi-management-admin?region=us-east-1&context_stack=aws-eks-svc-euw1"
Created stack 'svc-euw1'
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
AWS_PROFILE=my_profile pulumi config set --secret testSecret foo
AWS_PROFILE=my_profile pulumi config get testSecret
foo
AWS_PROFILE=my_profile pulumi config get testSecret
foo
AWS_PROFILE=my_profile pulumi config get testSecret
foo
AWS_PROFILE=my_profile pulumi config get testSecret
foo
The bug is when you use multiple encryption context keys, they randomly all get set to the same value per-request, but it will never correctly set them to their proper unique values.
So you have to keep running the commands over and over until your decrypt context happens to match the random context it chose when it encrypts.
Does that make sense?
s
Yea, thank you for clarifying!
Alright, I'm seeing the same thing and no obvious workarounds. I'm going to go ahead and open up a bug
ā¤ļø 1