Skip to content

Commit

Permalink
Merge pull request #128 from roosterfish/cert_checks_followup
Browse files Browse the repository at this point in the history
Test: Cert checks followup
  • Loading branch information
tomponline authored Apr 4, 2024
2 parents b48619b + c1bfa62 commit 84767f2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
10 changes: 10 additions & 0 deletions bin/helpers
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,16 @@ createCertificateAndKey() (
openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:secp384r1 -sha384 -keyout "${key_file}" -nodes -out "${crt_file}" -days 1 -subj "/CN=${cn}"
)

# certificateFingerprint: returns the certificate's fingerprint.
certificateFingerprint() (
openssl x509 -in "${1}" -outform der | sha256sum
)

# certificateFingerprintShort: returns the certificate's fingerprint in short form as used by LXD.
certificateFingerprintShort() (
certificateFingerprint "${1}" | head -c12
)

# cleanup: report if the test passed or not and return the appropriate return code.
cleanup() {
set +e
Expand Down
8 changes: 4 additions & 4 deletions tests/cluster
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ createCertificateAndKey "${tmp_cert_dir}/cert.key" "${tmp_cert_dir}/cert.crt" "c
createCertificateAndKey "${tmp_cert_dir}/cert-restricted.key" "${tmp_cert_dir}/cert-restricted.crt" "cert-restricted.local"
lxc config trust add "${tmp_cert_dir}/cert.crt"
lxc config trust add "${tmp_cert_dir}/cert-restricted.crt" --restricted --projects default
unrestricted_fingerprint="$(openssl x509 -in "${tmp_cert_dir}/cert.crt" -outform der | sha256sum | head -c12)"
restricted_fingerprint="$(openssl x509 -in "${tmp_cert_dir}/cert-restricted.crt" -outform der | sha256sum | head -c12)"
unrestricted_fingerprint="$(certificateFingerprintShort "${tmp_cert_dir}/cert.crt")"
restricted_fingerprint="$(certificateFingerprintShort "${tmp_cert_dir}/cert-restricted.crt")"

echo "==> Check the certificates for its permissions"
lxc query "/1.0/certificates/${unrestricted_fingerprint}" | jq -r ".restricted" | grep -xF false
Expand All @@ -112,8 +112,8 @@ createCertificateAndKey "${tmp_cert_dir}/metrics.key" "${tmp_cert_dir}/metrics.c
createCertificateAndKey "${tmp_cert_dir}/metrics-restricted.key" "${tmp_cert_dir}/metrics-restricted.crt" "metrics-restricted.local"
lxc config trust add "${tmp_cert_dir}/metrics.crt" --type metrics
lxc config trust add "${tmp_cert_dir}/metrics-restricted.crt" --type metrics --restricted --projects default
unrestricted_metrics_fingerprint="$(openssl x509 -in "${tmp_cert_dir}/metrics.crt" -outform der | sha256sum | head -c12)"
restricted_metrics_fingerprint="$(openssl x509 -in "${tmp_cert_dir}/metrics-restricted.crt" -outform der | sha256sum | head -c12)"
unrestricted_metrics_fingerprint="$(certificateFingerprintShort "${tmp_cert_dir}/metrics.crt")"
restricted_metrics_fingerprint="$(certificateFingerprintShort "${tmp_cert_dir}/metrics-restricted.crt")"

echo "==> Check the metrics certificates for its permissions"
lxc query "/1.0/certificates/${unrestricted_metrics_fingerprint}" | jq -r ".restricted" | grep -xF false
Expand Down

0 comments on commit 84767f2

Please sign in to comment.