sops: Decryption failed when different aws-profile names used
This is a strange one, I seem to only be able to decrypt files that are made by the user that created the file.
If I try and decrypt another file it fails. Even though both files are encrypted with the same KMS key and both users have permissions to access the key within AWS.
sops --verbose --aws-profile saml -d madebyme.yaml
[AWSKMS] INFO[0000] Decryption succeeded arn="arn:aws:kms:us-west-2:123456:key/123123123123"
[SOPS] INFO[0000] Data key recovered successfully
[SOPS] DEBU[0000] Decrypting tree
hello: Welcome to SOPS! Edit this file as you please!
sops --verbose --aws-profile saml -d madebyanother.yaml
[AWSKMS] INFO[0012] Decryption failed arn="arn:aws:kms:us-west-2:123456:key/123123123123"
[AWSKMS] INFO[0024] Decryption failed arn="arn:aws:kms:us-east-2:123456:key/456456456456"
Failed to get the data key required to decrypt the SOPS file.
Group 0: FAILED
arn:aws:kms:us-west-2:123456:key/123123123123: FAILED
- | Error decrypting key: NoCredentialProviders: no valid
| providers in chain. Deprecated.
| For verbose messaging see
| aws.Config.CredentialsChainVerboseErrors
arn:aws:kms:us-east-2:123456:key/456456456456: FAILED
- | Error decrypting key: NoCredentialProviders: no valid
| providers in chain. Deprecated.
| For verbose messaging see
| aws.Config.CredentialsChainVerboseErrors
Recovery failed because no master key was able to decrypt the file. In
order for SOPS to recover the file, at least one key has to be successful,
but none were.
If I use the AWS CLI I can also encrypt and decrypt files manually. Any ideas what else I should try?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 9
- Comments: 24 (6 by maintainers)
Why? It’s stored exclusively to use the same profile (by name) every time you decrypt.
I think
--aws-profile
should just not work unless you’re creating a file. Similar to--pgp
or--kms
, I guess.Well then shouldn’t
--aws-profile
override whatever profile name the user that created the file used.?Otherwise all users in a company would need to make sure they use the exact same AWS profile name when working with sops. Which seems silly because the profile name is totally arbitrary and has no impact on whether they can access the same KMS keys or not.
Having the same issue.
I was having a similar issue. I was able to get around needing to use any aws-profile name but running
aws sts assume-role --role-arn [rolearn] --role-session-name [name]
.The
AWS_PROFILE
env var behaves the same - it will only decrypt the file if the same profile name was used that encrypted the file.The docs say that “Similarly the --aws-profile flag can be set with the command line with any of the KMS commands.” And earlier in this ticket you agreed that the name should not matter. 😃
May be worth adding something to do the docs saying that you have to use the same AWS Profile name for both encrypting and decrypting. That is not clear, and in all other AWS operations the profile name is totally arbitrary and local to your machine, the name alone shouldn’t impact your access/permissions/ability to do something.
In that case there is a bug. Reproduce with:
Even though both computers/users are using the same KMS ARN it will fail
For me assuming of aws roles did not work in any way through a profile. I found the following workaround for the assuming role:
I have this issue when I configure sops with
.sops.yaml
to use a specific AWS_PROFILE but it seems to break whenAWS_PROFILE
is not set in my bash. Once I runexport AWS_PROFILE=$myprofile
it does work.According to this documentation https://github.com/mozilla/sops#25kms-aws-profiles I understand that this value should be taken from the sops configuration.
Example file:
@richstokes seem to be running into this too. I don’t know what changed. I was working with a developer the other day and nothing would work until added a role into the .sops.yaml and/or the encrypted file. Simply would not assume a role no matter what env vars we set.
OK I found something else, if I manually edit the encrypted file and edit the
aws_profile: <name>
field to match my local AWS profile name (instead of the AWS profile name used by the file creator) I am able to decrypt it!So this is definitely a bug. sops should ignore that field when decrypting, and/or override it when the --aws-profile flag is set on the command line. So long as both users have access to the same KMS keys it should work regardless of their local aws-profile name.
Before manually editing the
aws_profile:
field:After manually editing the
aws_profile:
field:I tried reauthing, and can encrypt and decrypt my own files OK. I only see the problem when trying to decrypt files created by another user (even though we both use the same KMS keys).
And they see the reverse, they are unable to decrypt my files.
However if we both establish our AWS Credential file (
~/.aws/credentials
) using the “default” profile instead of a named one, everything works fine.The profiles are different - they are different users who have named their block of credentials differently