Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 1 | #!/bin/bash |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 2 | |
| 3 | echo "Preparing certs" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 4 | openssl genrsa -out image_key.pem 1024 |
| 5 | openssl rsa -pubout -in image_key.pem -out image_key.pem.pub |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 6 | openssl req -new -key image_key.pem -out image_req.crt -config image_crt.cnf |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 7 | openssl x509 -req -days 180 -in image_req.crt -signkey image_key.pem -out image_cert.crt |
| 8 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 9 | echo "Save secret to Barbican storage" |
| 10 | openstack secret store --name cvp.images --algorithm RSA --expiration $(date +"%Y-%m-%d" -d "180 days") --secret-type certificate --payload-content-type "application/octet-stream" --payload-content-encoding base64 --payload "$(base64 image_cert.crt)" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 11 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 12 | echo "Exporting ID from 'Secret href' property" |
| 13 | export s_uuid=$(openstack secret list --name cvp.images -c "Secret href" -f value | rev | cut -d'/' -f1 | rev) |
| 14 | echo "Exported '$s_uuid'" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 15 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 16 | echo "Converting images to Raw" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 17 | qemu-img convert -f qcow2 -O raw -p cvp.ubuntu.2004 /var/tmp/cvp.ubuntu.2004.raw |
| 18 | qemu-img convert -f qcow2 -O raw -p cvp.ubuntu.1604 /var/tmp/cvp.ubuntu.1604.raw |
| 19 | qemu-img convert -f qcow2 -O raw -p cvp.cirros.51 /var/tmp/cvp.cirros.51.raw |
| 20 | qemu-img convert -f qcow2 -O raw -p cvp.cirros.52 /var/tmp/cvp.cirros.52.raw |
| 21 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 22 | echo "Signing images" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 23 | openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.cirros.51.raw.signature /var/tmp/cvp.cirros.51.raw |
| 24 | openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.cirros.52.raw.signature /var/tmp/cvp.cirros.52.raw |
| 25 | openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.ubuntu.1604.raw.signature /var/tmp/cvp.ubuntu.1604.raw |
| 26 | openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.ubuntu.2004.raw.signature /var/tmp/cvp.ubuntu.2004.raw |
| 27 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 28 | echo "Generating base64 equivalents" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 29 | base64 -w 0 cvp.cirros.51.raw.signature >cvp.cirros.51.raw.signature.b64 |
| 30 | base64 -w 0 cvp.cirros.52.raw.signature >cvp.cirros.52.raw.signature.b64 |
| 31 | base64 -w 0 cvp.ubuntu.1604.raw.signature >cvp.ubuntu.1604.raw.signature.b64 |
| 32 | base64 -w 0 cvp.ubuntu.2004.raw.signature >cvp.ubuntu.2004.raw.signature.b64 |
| 33 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 34 | echo "Exporting vars" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 35 | export cirros51_sign=$(cat cvp.cirros.51.raw.signature.b64) |
| 36 | export cirros52_sign=$(cat cvp.cirros.52.raw.signature.b64) |
| 37 | export ubuntu1604_sign=$(cat cvp.ubuntu.1604.raw.signature.b64) |
| 38 | export ubuntu2004_sign=$(cat cvp.ubuntu.2004.raw.signature.b64) |
| 39 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 40 | echo "Uploading 'cvp.cirros.51.raw.signed''" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 41 | glance image-create --name cvp.cirros.51.raw.signed --container-format bare --disk-format raw --property img_signature="$cirros51_sign" --property img_signature_certificate_uuid="$s_uuid" --property img_signature_hash_method='SHA-256' --property img_signature_key_type='RSA-PSS' < /var/tmp/cvp.cirros.51.raw |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 42 | echo "Uploading 'cvp.cirros.52.raw.signed''" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 43 | glance image-create --name cvp.cirros.52.raw.signed --container-format bare --disk-format raw --property img_signature="$cirros52_sign" --property img_signature_certificate_uuid="$s_uuid" --property img_signature_hash_method='SHA-256' --property img_signature_key_type='RSA-PSS' < /var/tmp/cvp.cirros.52.raw |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 44 | echo "Uploading 'cvp.ubuntu.1604.raw.signed''" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 45 | glance image-create --name cvp.ubuntu.1604.raw.signed --container-format bare --disk-format raw --property img_signature="$ubuntu1604_sign" --property img_signature_certificate_uuid="$s_uuid" --property img_signature_hash_method='SHA-256' --property img_signature_key_type='RSA-PSS' < /var/tmp/cvp.ubuntu.1604.raw |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 46 | echo "Uploading 'cvp.ubuntu.2004.raw.signed''" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 47 | glance image-create --name cvp.ubuntu.2004.raw.signed --container-format bare --disk-format raw --property img_signature="$ubuntu2004_sign" --property img_signature_certificate_uuid="$s_uuid" --property img_signature_hash_method='SHA-256' --property img_signature_key_type='RSA-PSS' < /var/tmp/cvp.ubuntu.2004.raw |