|
1 | 1 | apiVersion: kuttl.dev/v1beta1 |
2 | 2 | kind: TestStep |
3 | | -timeout: 120 |
4 | 3 | commands: |
5 | 4 | - script: |- |
6 | 5 | set -o errexit |
7 | 6 | set -o xtrace |
8 | 7 |
|
9 | 8 | source ../../functions |
10 | 9 |
|
11 | | - verify_secret_data() { |
12 | | - local secret_name="$1" |
13 | | - shift |
14 | | - for key in "$@"; do |
15 | | - escaped_key="${key//./\\.}" |
16 | | - val=$(kubectl -n "$NAMESPACE" get secret "$secret_name" -o jsonpath="{.data.${escaped_key}}") |
17 | | - if [[ -z "$val" ]]; then |
18 | | - echo "Secret $secret_name is missing key: $key" |
19 | | - return 1 |
20 | | - fi |
21 | | - done |
22 | | - } |
| 10 | + ssl_info=$(run_psql_local "SHOW ssl;" "postgres:$(get_psql_user_pass cert-manager-tls-pguser-postgres)@$(get_psql_user_host cert-manager-tls-pguser-postgres)") |
23 | 11 |
|
24 | | - retry 12 5 verify_secret_data cert-manager-tls-cluster-ca-cert tls.crt tls.key ca.crt |
25 | | -
|
26 | | - ca_secret_type=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-cluster-ca-cert -o jsonpath='{.type}') |
27 | | - if [[ "$ca_secret_type" != "kubernetes.io/tls" ]]; then |
28 | | - echo "CA secret type is incorrect: $ca_secret_type (expected kubernetes.io/tls)" |
29 | | - exit 1 |
30 | | - fi |
31 | | -
|
32 | | - ca_issuer_name=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-cluster-ca-cert -o jsonpath='{.metadata.annotations.cert-manager\.io/issuer-name}') |
33 | | - if [[ "$ca_issuer_name" != "cert-manager-tls-ca-issuer" ]]; then |
34 | | - echo "CA secret issuer annotation is incorrect: $ca_issuer_name" |
35 | | - exit 1 |
36 | | - fi |
37 | | -
|
38 | | - retry 12 5 verify_secret_data cert-manager-tls-cluster-cert tls.crt tls.key ca.crt |
39 | | -
|
40 | | - cluster_secret_type=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-cluster-cert -o jsonpath='{.type}') |
41 | | - if [[ "$cluster_secret_type" != "kubernetes.io/tls" ]]; then |
42 | | - echo "Cluster TLS secret type is incorrect: $cluster_secret_type (expected kubernetes.io/tls)" |
43 | | - exit 1 |
44 | | - fi |
45 | | -
|
46 | | - cluster_issuer_name=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-cluster-cert -o jsonpath='{.metadata.annotations.cert-manager\.io/issuer-name}') |
47 | | - if [[ "$cluster_issuer_name" != "cert-manager-tls-tls-issuer" ]]; then |
48 | | - echo "Cluster TLS secret issuer annotation is incorrect: $cluster_issuer_name" |
49 | | - exit 1 |
50 | | - fi |
51 | | -
|
52 | | - retry 12 5 verify_secret_data cert-manager-tls-pgbouncer-frontend-tls tls.crt tls.key ca.crt |
53 | | -
|
54 | | - pgb_secret_type=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbouncer-frontend-tls -o jsonpath='{.type}') |
55 | | - if [[ "$pgb_secret_type" != "kubernetes.io/tls" ]]; then |
56 | | - echo "PgBouncer TLS secret type is incorrect: $pgb_secret_type (expected kubernetes.io/tls)" |
57 | | - exit 1 |
58 | | - fi |
59 | | -
|
60 | | - pgb_issuer_name=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbouncer-frontend-tls -o jsonpath='{.metadata.annotations.cert-manager\.io/issuer-name}') |
61 | | - if [[ "$pgb_issuer_name" != "cert-manager-tls-tls-issuer" ]]; then |
62 | | - echo "PgBouncer TLS secret issuer annotation is incorrect: $pgb_issuer_name" |
| 12 | + if [[ "$ssl_info" != *"on"* ]]; then |
| 13 | + echo "SSL is not enabled on PostgreSQL with internal PKI" |
63 | 14 | exit 1 |
64 | 15 | fi |
65 | 16 |
|
66 | | - retry 12 5 verify_secret_data cert-manager-tls-pgbackrest-client-tls tls.crt tls.key |
| 17 | + repl_ssl_count=$(run_psql_local \ |
| 18 | + "SELECT count(*) FROM pg_stat_ssl s JOIN pg_stat_replication r ON s.pid = r.pid WHERE s.ssl = true;" \ |
| 19 | + "postgres:$(get_psql_user_pass cert-manager-tls-pguser-postgres)@cert-manager-tls-primary") |
| 20 | + repl_ssl_count=$(echo "$repl_ssl_count" | tr -d '[:space:]') |
67 | 21 |
|
68 | | - pgbr_client_issuer=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbackrest-client-tls -o jsonpath='{.metadata.annotations.cert-manager\.io/issuer-name}') |
69 | | - if [[ "$pgbr_client_issuer" != "cert-manager-tls-tls-issuer" ]]; then |
70 | | - echo "pgBackRest client TLS secret issuer annotation is incorrect: $pgbr_client_issuer" |
| 22 | + if [[ "$repl_ssl_count" -lt 1 ]]; then |
| 23 | + echo "No SSL replication connections found with internal PKI, got: $repl_ssl_count" |
71 | 24 | exit 1 |
72 | 25 | fi |
73 | 26 |
|
74 | | - retry 12 5 verify_secret_data cert-manager-tls-pgbackrest-repo-tls tls.crt tls.key |
75 | | -
|
76 | | - pgbr_repo_issuer=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbackrest-repo-tls -o jsonpath='{.metadata.annotations.cert-manager\.io/issuer-name}') |
77 | | - if [[ "$pgbr_repo_issuer" != "cert-manager-tls-tls-issuer" ]]; then |
78 | | - echo "pgBackRest repo TLS secret issuer annotation is incorrect: $pgbr_repo_issuer" |
79 | | - exit 1 |
80 | | - fi |
81 | | -
|
82 | | - retry 12 5 verify_secret_data cert-manager-tls-pgbackrest pgbackrest.ca-roots pgbackrest-client.crt pgbackrest-client.key pgbackrest-repo-host.crt pgbackrest-repo-host.key |
83 | | -
|
84 | | - pgbr_client_cert_in_secret=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbackrest -o jsonpath='{.data.pgbackrest-client\.crt}') |
85 | | - pgbr_client_cert_from_cm=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbackrest-client-tls -o jsonpath='{.data.tls\.crt}') |
86 | | - if [[ "$pgbr_client_cert_in_secret" != "$pgbr_client_cert_from_cm" ]]; then |
87 | | - echo "pgBackRest main secret client cert does not match cert-manager-issued cert" |
88 | | - exit 1 |
89 | | - fi |
90 | | -
|
91 | | - pgbr_repo_cert_in_secret=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbackrest -o jsonpath='{.data.pgbackrest-repo-host\.crt}') |
92 | | - pgbr_repo_cert_from_cm=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbackrest-repo-tls -o jsonpath='{.data.tls\.crt}') |
93 | | - if [[ "$pgbr_repo_cert_in_secret" != "$pgbr_repo_cert_from_cm" ]]; then |
94 | | - echo "pgBackRest main secret repo cert does not match cert-manager-issued cert" |
95 | | - exit 1 |
96 | | - fi |
97 | | -
|
98 | | - retry 12 5 verify_secret_data cert-manager-tls-pgbouncer pgbouncer-frontend.crt pgbouncer-frontend.key pgbouncer-frontend.ca-roots |
99 | | -
|
100 | | - pgb_cert_in_secret=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbouncer -o jsonpath='{.data.pgbouncer-frontend\.crt}') |
101 | | - pgb_cert_from_cm=$(kubectl -n "$NAMESPACE" get secret cert-manager-tls-pgbouncer-frontend-tls -o jsonpath='{.data.tls\.crt}') |
102 | | - if [[ "$pgb_cert_in_secret" != "$pgb_cert_from_cm" ]]; then |
103 | | - echo "pgBouncer main secret frontend cert does not match cert-manager-issued cert" |
104 | | - exit 1 |
105 | | - fi |
106 | | -
|
107 | | - instance_sts=$(kubectl -n "$NAMESPACE" get sts -l postgres-operator.crunchydata.com/cluster=cert-manager-tls,postgres-operator.crunchydata.com/instance-set=instance1 -o jsonpath='{.items[*].metadata.name}') |
108 | | - for sts_name in $instance_sts; do |
109 | | - secret_name="${sts_name}-certs" |
110 | | -
|
111 | | - secret_type=$(kubectl -n "$NAMESPACE" get secret "$secret_name" -o jsonpath='{.type}') |
112 | | - if [[ "$secret_type" != "kubernetes.io/tls" ]]; then |
113 | | - echo "Instance secret $secret_name type is incorrect: $secret_type (expected kubernetes.io/tls)" |
114 | | - exit 1 |
115 | | - fi |
116 | | -
|
117 | | - issuer_name=$(kubectl -n "$NAMESPACE" get secret "$secret_name" -o jsonpath='{.metadata.annotations.cert-manager\.io/issuer-name}') |
118 | | - if [[ "$issuer_name" != "cert-manager-tls-tls-issuer" ]]; then |
119 | | - echo "Instance secret $secret_name issuer annotation is incorrect: $issuer_name" |
120 | | - exit 1 |
121 | | - fi |
| 27 | + pg_cert_serial=$(run_comand_on_pod "openssl s_client -connect cert-manager-tls-primary:5432 -starttls postgres <<< '' 2>/dev/null | openssl x509 -noout -serial" | tr -d '[:space:]') |
122 | 28 |
|
123 | | - verify_secret_data "$secret_name" tls.crt tls.key dns.crt dns.key patroni.ca-roots patroni.crt-combined pgbackrest-server.crt pgbackrest-server.key |
124 | | - echo "Instance secret $secret_name is valid" |
125 | | - done |
| 29 | + kubectl create configmap -n "${NAMESPACE}" internal-pki-cert-serial \ |
| 30 | + --from-literal=pg-serial="$pg_cert_serial" |
| 31 | + timeout: 30 |
0 commit comments