aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

Add kms decrypt argument for base64 encoded input

Open theazureshadow opened this issue 10 years ago • 37 comments

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.

theazureshadow avatar Jul 11 '16 23:07 theazureshadow

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

kyleknap avatar Jul 12 '16 19:07 kyleknap

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.

theazureshadow avatar Jul 12 '16 22:07 theazureshadow

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.

w32-blaster avatar Aug 11 '16 09:08 w32-blaster

👍 to this.

ajlanghorn avatar Aug 30 '16 22:08 ajlanghorn

👍

iadknet avatar Sep 21 '16 04:09 iadknet

:+1:

wheresvic avatar Nov 15 '16 11:11 wheresvic

👍

rbm1337 avatar Jan 30 '17 09:01 rbm1337

+1

ghost avatar Mar 09 '17 06:03 ghost

+1

kid7st avatar Apr 25 '17 23:04 kid7st

+1

sinogermany avatar Jul 13 '17 00:07 sinogermany

+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

techypaul avatar Aug 09 '17 15:08 techypaul

+1

gonzaloserrano avatar Sep 07 '17 08:09 gonzaloserrano

+1

jordimirobruix avatar Sep 07 '17 08:09 jordimirobruix

+1

coboshm avatar Sep 07 '17 08:09 coboshm

+1

ryanskinner avatar Oct 31 '17 17:10 ryanskinner

+1

mlamothe-broadsoft avatar Oct 31 '17 19:10 mlamothe-broadsoft

+1

chi42 avatar Nov 15 '17 21:11 chi42

+1

nikhithn avatar Dec 29 '17 19:12 nikhithn

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 avatar Jan 29 '18 13:01 scf37

@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)

lcharkiewicz avatar Jan 29 '18 16:01 lcharkiewicz