blob: 55e4ace4b4f81960fd41db8b3917183dd4b5694c [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
Ievgeniia Zadorozhna1cb5b102024-01-19 04:31:09 +010019qemu-img convert -f qcow2 -O raw -p cvp.cirros.61 /var/tmp/cvp.cirros.61.raw
20qemu-img convert -f qcow2 -O raw -p cvp.cirros.62 /var/tmp/cvp.cirros.62.raw
Alexdb7786b2022-02-21 17:58:29 -060021
Alexf59c7392022-04-18 19:10:14 -050022echo "Signing images"
Ievgeniia Zadorozhna1cb5b102024-01-19 04:31:09 +010023openssl dgst -sha256 -sign image_key.pem -sigopt rsa_padding_mode:pss -out cvp.cirros.61.raw.signature /var/tmp/cvp.cirros.61.raw
24openssl 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 -060025openssl 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"
Ievgeniia Zadorozhna1cb5b102024-01-19 04:31:09 +010029base64 -w 0 cvp.cirros.61.raw.signature >cvp.cirros.61.raw.signature.b64
30base64 -w 0 cvp.cirros.62.raw.signature >cvp.cirros.62.raw.signature.b64
Alexdb7786b2022-02-21 17:58:29 -060031base64 -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"
Ievgeniia Zadorozhna1cb5b102024-01-19 04:31:09 +010035export cirros61_sign=$(cat cvp.cirros.61.raw.signature.b64)
36export cirros62_sign=$(cat cvp.cirros.62.raw.signature.b64)
Alexdb7786b2022-02-21 17:58:29 -060037export ubuntu1604_sign=$(cat cvp.ubuntu.1604.raw.signature.b64)
38export ubuntu2004_sign=$(cat cvp.ubuntu.2004.raw.signature.b64)
39
Ievgeniia Zadorozhna1cb5b102024-01-19 04:31:09 +010040echo "Uploading 'cvp.cirros.61.raw.signed''"
41glance 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
42echo "Uploading 'cvp.cirros.62.raw.signed''"
43glance 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 -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