forked from 9652040795/aws-policies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkms-encryption-key-creation
41 lines (26 loc) · 2.75 KB
/
kms-encryption-key-creation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Create a Key from AWS Console
ALIAS_NAME_KMS_KEY_ID='27c3b11a-eda4-444d-9b1d-721ed053e00d'
mkdir -p /root/secrets/mariadb
mkdir -p /root/secrets/wordpress
# Encryption
aws kms encrypt --region us-east-1 --key-id $ALIAS_NAME_KMS_KEY_ID --plaintext abc --output text --query CiphertextBlob | base64 --decode > /root/secrets/wordpress/wordpress-database-password.txt
aws kms encrypt --region us-east-1 --key-id $ALIAS_NAME_KMS_KEY_ID --plaintext bitnami_wordpress --output text --query CiphertextBlob | base64 --decode > /root/secrets/wordpress/wordpress-database-name.txt
aws kms encrypt --region us-east-1 --key-id $ALIAS_NAME_KMS_KEY_ID --plaintext asim.arain --output text --query CiphertextBlob | base64 --decode > /root/secrets/wordpress/wordpress-database-user.txt
aws kms encrypt --region us-east-1 --key-id $ALIAS_NAME_KMS_KEY_ID --plaintext mariadb --output text --query CiphertextBlob | base64 --decode > /root/secrets/wordpress/wordpress-database-host.txt
# Decryption
aws kms decrypt --region us-east-1 --ciphertext-blob fileb:///root/secrets/wordpress/wordpress-database-password.txt --output text --query Plaintext | base64 --decode
aws kms decrypt --region us-east-1 --ciphertext-blob fileb:///root/secrets/wordpress/wordpress-database-name.txt --output text --query Plaintext | base64 --decode
aws kms decrypt --region us-east-1 --ciphertext-blob fileb:///root/secrets/wordpress/wordpress-database-user.txt --output text --query Plaintext | base64 --decode
aws kms decrypt --region us-east-1 --ciphertext-blob fileb:///root/secrets/wordpress/wordpress-database-host.txt --output text --query Plaintext | base64 --decode
#END
WORDPRESS_DATABASE_PASSWORD=`aws kms decrypt --region us-east-1 --ciphertext-blob fileb:///root/secrets/wordpress/wordpress-database-password.txt --output text --query Plaintext | base64 --decode`
WORDPRESS_DATABASE_NAME=`aws kms decrypt --region us-east-1 --ciphertext-blob fileb:///root/secrets/wordpress/wordpress-database-name.txt --output text --query Plaintext | base64 --decode`
WORDPRESS_DATABASE_USER=`aws kms decrypt --region us-east-1 --ciphertext-blob fileb:///root/secrets/wordpress/wordpress-database-user.txt --output text --query Plaintext | base64 --decode`
WORDPRESS_DATABASE_HOST=`aws kms decrypt --region us-east-1 --ciphertext-blob fileb:///root/secrets/wordpress/wordpress-database-host.txt --output text --query Plaintext | base64 --decode`
echo "\n"
echo "Credentials Decrypted"
echo " This is Wordpress Database Password = $WORDPRESS_DATABASE_PASSWORD "
echo " This is Wordpress Database Name = $WORDPRESS_DATABASE_NAME "
echo " This is Wordpress Database User = $WORDPRESS_DATABASE_USER "
echo " This is Wordpress Database Host ---> POD = $WORDPRESS_DATABASE_HOST "