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 | echo "Preparing certs" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 3 | openssl genrsa -out image_key.pem 1024 |
| 4 | openssl rsa -pubout -in image_key.pem -out image_key.pem.pub |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 5 | 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] | 6 | openssl x509 -req -days 180 -in image_req.crt -signkey image_key.pem -out image_cert.crt |
| 7 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 8 | echo "Save secret to Barbican storage" |
| 9 | 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] | 10 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 11 | echo "Exporting ID from 'Secret href' property" |
| 12 | export s_uuid=$(openstack secret list --name cvp.images -c "Secret href" -f value | rev | cut -d'/' -f1 | rev) |
| 13 | echo "Exported '$s_uuid'" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 14 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 15 | echo "Converting images to Raw" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 16 | qemu-img convert -f qcow2 -O raw -p cvp.ubuntu.2004 /var/tmp/cvp.ubuntu.2004.raw |
| 17 | qemu-img convert -f qcow2 -O raw -p cvp.ubuntu.1604 /var/tmp/cvp.ubuntu.1604.raw |
Ievgeniia Zadorozhna | 78ada71 | 2024-02-23 17:23:38 +0100 | [diff] [blame] | 18 | qemu-img convert -f qcow2 -O raw -p cvp.cirros.61 /var/tmp/cvp.cirros.61.raw |
| 19 | qemu-img convert -f qcow2 -O raw -p cvp.cirros.62 /var/tmp/cvp.cirros.62.raw |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 20 | |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 21 | echo "Signing images" |
Ievgeniia Zadorozhna | 78ada71 | 2024-02-23 17:23:38 +0100 | [diff] [blame] | 22 | openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.cirros.61.raw.signature /var/tmp/cvp.cirros.61.raw |
| 23 | openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.cirros.62.raw.signature /var/tmp/cvp.cirros.62.raw |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 24 | openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.ubuntu.1604.raw.signature /var/tmp/cvp.ubuntu.1604.raw |
| 25 | openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.ubuntu.2004.raw.signature /var/tmp/cvp.ubuntu.2004.raw |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 26 | echo "Generating base64 equivalents" |
Ievgeniia Zadorozhna | 78ada71 | 2024-02-23 17:23:38 +0100 | [diff] [blame] | 27 | base64 -w 0 cvp.cirros.61.raw.signature >cvp.cirros.61.raw.signature.b64 |
| 28 | base64 -w 0 cvp.cirros.62.raw.signature >cvp.cirros.62.raw.signature.b64 |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 29 | base64 -w 0 cvp.ubuntu.1604.raw.signature >cvp.ubuntu.1604.raw.signature.b64 |
| 30 | base64 -w 0 cvp.ubuntu.2004.raw.signature >cvp.ubuntu.2004.raw.signature.b64 |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 31 | echo "Exporting vars" |
Ievgeniia Zadorozhna | 78ada71 | 2024-02-23 17:23:38 +0100 | [diff] [blame] | 32 | export cirros61_sign=$(cat cvp.cirros.61.raw.signature.b64) |
| 33 | export cirros62_sign=$(cat cvp.cirros.62.raw.signature.b64) |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 34 | export ubuntu1604_sign=$(cat cvp.ubuntu.1604.raw.signature.b64) |
| 35 | export ubuntu2004_sign=$(cat cvp.ubuntu.2004.raw.signature.b64) |
| 36 | |
Ievgeniia Zadorozhna | 78ada71 | 2024-02-23 17:23:38 +0100 | [diff] [blame] | 37 | echo "Uploading 'cvp.cirros.61.raw.signed''" |
| 38 | glance image-create --name cvp.cirros.61.raw.signed --container-format bare --disk-format raw --property img_signature="$cirros61_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.61.raw |
| 39 | echo "Uploading 'cvp.cirros.62.raw.signed''" |
| 40 | glance image-create --name cvp.cirros.62.raw.signed --container-format bare --disk-format raw --property img_signature="$cirros62_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.62.raw |
Alex | f59c739 | 2022-04-18 19:10:14 -0500 | [diff] [blame] | 41 | echo "Uploading 'cvp.ubuntu.1604.raw.signed''" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 42 | 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] | 43 | echo "Uploading 'cvp.ubuntu.2004.raw.signed''" |
Alex | db7786b | 2022-02-21 17:58:29 -0600 | [diff] [blame] | 44 | 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 |