As per the docs in chef it uses a shared secret to encrypt data bag items.
Shared secret is created with:
openssl rand -base64 512 | tr -d '\r\n' > encrypted_data_bag_secret
And the data is saved with below format.
id: mysql
pass:
cipher: aes-256-cbc
encrypted_data: JZtwXpuq4Hf5ICcepJ1PGQohIyqjNX6JBc2DGpnL2WApzjAUG9SkSdv75TfKSjX4
iv: VYY2qx9b4r3j0qZ7+RkKHg==
version: 1
user:
cipher: aes-256-cbc
encrypted_data: 10BVoNb/plkvkrzVdybPgFFII5GThZ3Op9LNkwVeKpA=
iv: uIqKHZ9skJlN2gpJoml6rQ==
version: 1
I was trying to decrypt one of the items using openssl but failing to get correct magic combination.
Using the above example data, the below is the best command i came up with that i think should work. The data is base64 decoded and from openssl man the iv
and key
should be in hex but i think think my conversions are feeding openssl with correct data.
cat 'JZtwXpuq4Hf5ICcepJ1PGQohIyqjNX6JBc2DGpnL2WApzjAUG9SkSdv75TfKSjX4' > encrypted_data
cat 'VYY2qx9b4r3j0qZ7+RkKHg==' > iv
openssl enc -d -aes-256-cbc -a \
-in encrypted_data \
-K $(cat encrypted_data_bag_secret|base64 -d|xxd -p) \
-iv $(cat iv|base64 -d|xxd -p)
Can anyone see what i'm doing wrong or have working example for manually decrypting chef data bag item with openssl and shared secret file ?
openssl
? – coderangerknife -z data bag show
is your friend :) – coderanger