File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -111,7 +111,17 @@ function setup_ephemeral_drives () {
111111 mkfs -q /dev/ram1 1024 || RC=1
112112 mkdir -p /root/keystore || RC=1
113113 mount /dev/ram1 /root/keystore || RC=1
114- dd if=/dev/urandom of=/root/keystore/keyfile bs=1024 count=4 || RC=1
114+ if [ "${cfn_ephemeral_kms_key_id}" != "NONE" ]; then
115+ # Use KMS for keyfile
116+ instanceId=$(curl -fs http://169.254.169.254/latest/meta-data/instance-id)
117+ kms_array=($(aws --region ${cfn_region} kms generate-data-key --key-id ${cfn_ephemeral_kms_key_id} --number-of-bytes 1024 --encryption-context InstanceId=${instanceId} --output text))
118+ echo -n ${kms_array[0]} > /root/keystore/keyfile || RC=1
119+ echo -n ${kms_array[2]} > /root/ephemeral_ciphertext.blob || RC=1
120+ chmod 0400 /root/ephemeral_ciphertext.blob || RC=1
121+ else
122+ # Use urandom for keyfile
123+ dd if=/dev/urandom of=/root/keystore/keyfile bs=1024 count=4 || RC=1
124+ fi
115125 chmod 0400 /root/keystore/keyfile || RC=1
116126 cryptsetup -q luksFormat /dev/vg.01/lv_ephemeral /root/keystore/keyfile || RC=1
117127 cryptsetup -d /root/keystore/keyfile luksOpen /dev/vg.01/lv_ephemeral ephemeral_luks || RC=1
You can’t perform that action at this time.
0 commit comments