Add kms decrypt argument for base64 encoded input
The output for aws kms encrypt is a base64-encoded string. The input for aws kms decrypt is a binary string, which is not particularly bash-friendly. See #1100.
It would be useful if there was an additional --ciphertext-base64 argument that could take that same base64 blob from encrypt and decrypt it correctly.
Marking as a feature request.
Are you blocked on this? Could you chain the commands with base64 to handle your use case? Like I do in this blog post
I'm not blocked, but it is really non-obvious what's going wrong. We lost a bit of time when trying to validate that we'd encoded our data correctly. Seems like an easy win to be able to specify base64-encoded ciphertext.
I agree with this. There are use cases where it's not trivial to chain commands to get the correct result. It would help in many cases.
👍 to this.
👍
:+1:
👍
+1
+1
+1
+1, in the meantime for anyone else looking:
echo AQICAHhb....ZClShBC8dZpCg== | base64 --decode > /tmp/temp.enc
DB_PASS=$(aws kms decrypt --region eu-west-1 --ciphertext-blob fileb:///tmp/temp.enc --query Plaintext --output text | base64 --decode)
sed -i -e "s/<<DB_PASS>>/${DB_PASS}/g" /var/www/mysite/DbSettings.php
+1
+1
+1
+1
+1
+1
+1
AFAIK there is no way to call aws kms decrypt from bash with binary string as parameter. So the only way to avoid writing secrets to disk is to use Python and boto.
@scf37 there is a way. You need to use process substitution for --ciphertext-blob parameter. Example:
echo $(aws kms decrypt --ciphertext-blob fileb://<(echo -n "$YOUR_BASE64_CIPHERTEXT" | base64 --decode) --output text --query Plaintext | base64 --decode)