blob: 269c97728ae261b85872b7ce679292e73ee89bed [file] [log] [blame]
Alexdb7786b2022-02-21 17:58:29 -06001#!/bin/bash
Alexf59c7392022-04-18 19:10:14 -05002echo "Preparing certs"
Alexdb7786b2022-02-21 17:58:29 -06003openssl genrsa -out image_key.pem 1024
4openssl rsa -pubout -in image_key.pem -out image_key.pem.pub
Alexf59c7392022-04-18 19:10:14 -05005openssl req -new -key image_key.pem -out image_req.crt -config image_crt.cnf
Alexdb7786b2022-02-21 17:58:29 -06006openssl x509 -req -days 180 -in image_req.crt -signkey image_key.pem -out image_cert.crt
7
Alexf59c7392022-04-18 19:10:14 -05008echo "Save secret to Barbican storage"
9openstack 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 -060010
Alexf59c7392022-04-18 19:10:14 -050011echo "Exporting ID from 'Secret href' property"
12export s_uuid=$(openstack secret list --name cvp.images -c "Secret href" -f value | rev | cut -d'/' -f1 | rev)
13echo "Exported '$s_uuid'"
Alexdb7786b2022-02-21 17:58:29 -060014
Alexf59c7392022-04-18 19:10:14 -050015echo "Converting images to Raw"
Alexdb7786b2022-02-21 17:58:29 -060016qemu-img convert -f qcow2 -O raw -p cvp.ubuntu.2004 /var/tmp/cvp.ubuntu.2004.raw
17qemu-img convert -f qcow2 -O raw -p cvp.ubuntu.1604 /var/tmp/cvp.ubuntu.1604.raw
Ievgeniia Zadorozhna78ada712024-02-23 17:23:38 +010018qemu-img convert -f qcow2 -O raw -p cvp.cirros.61 /var/tmp/cvp.cirros.61.raw
19qemu-img convert -f qcow2 -O raw -p cvp.cirros.62 /var/tmp/cvp.cirros.62.raw
Alexdb7786b2022-02-21 17:58:29 -060020
Alexf59c7392022-04-18 19:10:14 -050021echo "Signing images"
Ievgeniia Zadorozhna78ada712024-02-23 17:23:38 +010022openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.cirros.61.raw.signature /var/tmp/cvp.cirros.61.raw
23openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.cirros.62.raw.signature /var/tmp/cvp.cirros.62.raw
Alexdb7786b2022-02-21 17:58:29 -060024openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.ubuntu.1604.raw.signature /var/tmp/cvp.ubuntu.1604.raw
25openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.ubuntu.2004.raw.signature /var/tmp/cvp.ubuntu.2004.raw
Alexf59c7392022-04-18 19:10:14 -050026echo "Generating base64 equivalents"
Ievgeniia Zadorozhna78ada712024-02-23 17:23:38 +010027base64 -w 0 cvp.cirros.61.raw.signature >cvp.cirros.61.raw.signature.b64
28base64 -w 0 cvp.cirros.62.raw.signature >cvp.cirros.62.raw.signature.b64
Alexdb7786b2022-02-21 17:58:29 -060029base64 -w 0 cvp.ubuntu.1604.raw.signature >cvp.ubuntu.1604.raw.signature.b64
30base64 -w 0 cvp.ubuntu.2004.raw.signature >cvp.ubuntu.2004.raw.signature.b64
Alexf59c7392022-04-18 19:10:14 -050031echo "Exporting vars"
Ievgeniia Zadorozhna78ada712024-02-23 17:23:38 +010032export cirros61_sign=$(cat cvp.cirros.61.raw.signature.b64)
33export cirros62_sign=$(cat cvp.cirros.62.raw.signature.b64)
Alexdb7786b2022-02-21 17:58:29 -060034export ubuntu1604_sign=$(cat cvp.ubuntu.1604.raw.signature.b64)
35export ubuntu2004_sign=$(cat cvp.ubuntu.2004.raw.signature.b64)
36
Ievgeniia Zadorozhna78ada712024-02-23 17:23:38 +010037echo "Uploading 'cvp.cirros.61.raw.signed''"
38glance 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
39echo "Uploading 'cvp.cirros.62.raw.signed''"
40glance 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
Alexf59c7392022-04-18 19:10:14 -050041echo "Uploading 'cvp.ubuntu.1604.raw.signed''"
Alexdb7786b2022-02-21 17:58:29 -060042glance 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 -050043echo "Uploading 'cvp.ubuntu.2004.raw.signed''"
Alexdb7786b2022-02-21 17:58:29 -060044glance 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