blob: ee596b56139b53a93e43819c56ffb2d37168d326 [file] [log] [blame]
Alexdb7786b2022-02-21 17:58:29 -06001#!/bin/bash
Alexf59c7392022-04-18 19:10:14 -05002
3echo "Preparing certs"
Alexdb7786b2022-02-21 17:58:29 -06004openssl genrsa -out image_key.pem 1024
5openssl rsa -pubout -in image_key.pem -out image_key.pem.pub
Alexf59c7392022-04-18 19:10:14 -05006openssl req -new -key image_key.pem -out image_req.crt -config image_crt.cnf
Alexdb7786b2022-02-21 17:58:29 -06007openssl x509 -req -days 180 -in image_req.crt -signkey image_key.pem -out image_cert.crt
8
Alexf59c7392022-04-18 19:10:14 -05009echo "Save secret to Barbican storage"
10openstack 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)"
Alexdb7786b2022-02-21 17:58:29 -060011
Alexf59c7392022-04-18 19:10:14 -050012echo "Exporting ID from 'Secret href' property"
13export s_uuid=$(openstack secret list --name cvp.images -c "Secret href" -f value | rev | cut -d'/' -f1 | rev)
14echo "Exported '$s_uuid'"
Alexdb7786b2022-02-21 17:58:29 -060015
Alexf59c7392022-04-18 19:10:14 -050016echo "Converting images to Raw"
Alexdb7786b2022-02-21 17:58:29 -060017qemu-img convert -f qcow2 -O raw -p cvp.ubuntu.2004 /var/tmp/cvp.ubuntu.2004.raw
18qemu-img convert -f qcow2 -O raw -p cvp.ubuntu.1604 /var/tmp/cvp.ubuntu.1604.raw
19qemu-img convert -f qcow2 -O raw -p cvp.cirros.51 /var/tmp/cvp.cirros.51.raw
20qemu-img convert -f qcow2 -O raw -p cvp.cirros.52 /var/tmp/cvp.cirros.52.raw
21
Alexf59c7392022-04-18 19:10:14 -050022echo "Signing images"
Alexdb7786b2022-02-21 17:58:29 -060023openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.cirros.51.raw.signature /var/tmp/cvp.cirros.51.raw
24openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.cirros.52.raw.signature /var/tmp/cvp.cirros.52.raw
25openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.ubuntu.1604.raw.signature /var/tmp/cvp.ubuntu.1604.raw
26openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.ubuntu.2004.raw.signature /var/tmp/cvp.ubuntu.2004.raw
27
Alexf59c7392022-04-18 19:10:14 -050028echo "Generating base64 equivalents"
Alexdb7786b2022-02-21 17:58:29 -060029base64 -w 0 cvp.cirros.51.raw.signature >cvp.cirros.51.raw.signature.b64
30base64 -w 0 cvp.cirros.52.raw.signature >cvp.cirros.52.raw.signature.b64
31base64 -w 0 cvp.ubuntu.1604.raw.signature >cvp.ubuntu.1604.raw.signature.b64
32base64 -w 0 cvp.ubuntu.2004.raw.signature >cvp.ubuntu.2004.raw.signature.b64
33
Alexf59c7392022-04-18 19:10:14 -050034echo "Exporting vars"
Alexdb7786b2022-02-21 17:58:29 -060035export cirros51_sign=$(cat cvp.cirros.51.raw.signature.b64)
36export cirros52_sign=$(cat cvp.cirros.52.raw.signature.b64)
37export ubuntu1604_sign=$(cat cvp.ubuntu.1604.raw.signature.b64)
38export ubuntu2004_sign=$(cat cvp.ubuntu.2004.raw.signature.b64)
39
Alexf59c7392022-04-18 19:10:14 -050040echo "Uploading 'cvp.cirros.51.raw.signed''"
Alexdb7786b2022-02-21 17:58:29 -060041glance 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
Alexf59c7392022-04-18 19:10:14 -050042echo "Uploading 'cvp.cirros.52.raw.signed''"
Alexdb7786b2022-02-21 17:58:29 -060043glance 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
Alexf59c7392022-04-18 19:10:14 -050044echo "Uploading 'cvp.ubuntu.1604.raw.signed''"
Alexdb7786b2022-02-21 17:58:29 -060045glance 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
Alexf59c7392022-04-18 19:10:14 -050046echo "Uploading 'cvp.ubuntu.2004.raw.signed''"
Alexdb7786b2022-02-21 17:58:29 -060047glance 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