Skip to content

Commit ff1f19f

Browse files
authored
Merge pull request #41446 from rh-tokeefe/OSSMDOC-406
OSSMDOC-406: Verify instructions in section "Verifying your certifica…
2 parents 333d6a9 + e2dd496 commit ff1f19f

File tree

1 file changed

+64
-42
lines changed

1 file changed

+64
-42
lines changed

modules/ossm-security-cert-manage.adoc

Lines changed: 64 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ By default, {SMProductName} generates a self-signed root certificate and key and
1212
* Install {SMProductName} with mutual TLS enabled to configure certificates.
1313
* This example uses the certificates from the link:https://github.com/maistra/istio/tree/maistra-{MaistraVersion}/samples/certs[Maistra repository]. For production, use your own certificates from your certificate authority.
1414
* Deploy the Bookinfo sample application to verify the results with these instructions.
15+
* OpenSSL is required to verify certificates.
1516

1617
[id="ossm-cert-manage-add-cert-key_{context}"]
1718
== Adding an existing certificate and key
1819

1920
To use an existing signing (CA) certificate and key, you must create a chain of trust file that includes the CA certificate, key, and root certificate. You must use the following exact file names for each of the corresponding certificates. The CA certificate is named `ca-cert.pem`, the key is `ca-key.pem`, and the root certificate, which signs `ca-cert.pem`, is named `root-cert.pem`. If your workload uses intermediate certificates, you must specify them in a `cert-chain.pem` file.
2021

21-
Add the certificates to {SMProductShortName} by following these steps. Save the example certificates from the link:https://github.com/maistra/istio/tree/maistra-{MaistraVersion}/samples/certs[Maistra repository] locally and replace `<path>` with the path to your certificates.
22+
. Save the example certificates from the link:https://github.com/maistra/istio/tree/maistra-{MaistraVersion}/samples/certs[Maistra repository] locally and replace `<path>` with the path to your certificates.
2223

23-
. Create a secret `cacert` that includes the input files `ca-cert.pem`, `ca-key.pem`, `root-cert.pem` and `cert-chain.pem`.
24+
. Create a secret named `cacert` that includes the input files `ca-cert.pem`, `ca-key.pem`, `root-cert.pem` and `cert-chain.pem`.
2425
+
2526
[source,terminal]
2627
----
@@ -29,7 +30,7 @@ $ oc create secret generic cacerts -n istio-system --from-file=<path>/ca-cert.pe
2930
--from-file=<path>/cert-chain.pem
3031
----
3132
+
32-
. In the `ServiceMeshControlPlane` resource set `spec.security.dataPlane.mtls: true` to `true` and configure your certificateAuthority like the following example. The default `rootCADir` is `/etc/cacerts`. You do not need to set the `privateKey` if the key and certs are mounted in the default location. {SMProductShortName} reads the certificates and key from the secret-mount files.
33+
. In the `ServiceMeshControlPlane` resource set `spec.security.dataPlane.mtls true` to `true` and configure the `certificateAuthority` field as shown in the following example. The default `rootCADir` is `/etc/cacerts`. You do not need to set the `privateKey` if the key and certs are mounted in the default location. {SMProductShortName} reads the certificates and key from the secret-mount files.
3334
+
3435
[source,yaml]
3536
----
@@ -44,97 +45,117 @@ spec:
4445
istiod:
4546
type: PrivateKey
4647
privateKey:
47-
rootCADir: /etc/cacerts
48+
rootCADir: /etc/cacerts
4849
----
4950

50-
[id="ossm-cert-manage-verify-cert_{context}"]
51-
== Verifying your certificates
52-
53-
Use the Bookinfo sample application to verify your certificates are mounted correctly. First, retrieve the mounted certificates. Then, verify the certificates mounted on the pod.
54-
55-
. Store the pod name in the variable `RATINGSPOD`.
51+
. After creating/changing/deleting the `cacert` secret, the control plane `istiod` and `gateway` pods must be restarted so the changes go into effect. Use the following command to restart the pods:
5652
+
5753
[source,terminal]
5854
----
59-
$ RATINGSPOD=`oc get pods -l app=ratings -o jsonpath='{.items[0].metadata.name}'`
55+
$ $ oc -n istio-system delete pods -l 'app in (istiod,istio-ingressgateway, istio-egressgateway)'
6056
----
6157
+
62-
. Run the following commands to retrieve the certificates mounted on the proxy.
58+
The Operator will automatically recreate the pods after they have been deleted.
59+
60+
. Restart the bookinfo application pods so that the sidecar proxies pick up the secret changes. Use the following command to restart the pods:
6361
+
6462
[source,terminal]
6563
----
66-
$ oc exec -it $RATINGSPOD -c istio-proxy -- /bin/cat /var/run/secrets/istio/root-cert.pem > /tmp/pod-root-cert.pem
64+
$ oc -n bookinfo delete pods --all
6765
----
6866
+
69-
The file `/tmp/pod-root-cert.pem` contains the root certificate propagated to the pod.
67+
You should see output similar to the following:
7068
+
69+
7170
[source,terminal]
7271
----
73-
$ oc exec -it $RATINGSPOD -c istio-proxy -- /bin/cat /etc/certs/cert-chain.pem > /tmp/pod-cert-chain.pem
72+
pod "details-v1-6cd699df8c-j54nh" deleted
73+
pod "productpage-v1-5ddcb4b84f-mtmf2" deleted
74+
pod "ratings-v1-bdbcc68bc-kmng4" deleted
75+
pod "reviews-v1-754ddd7b6f-lqhsv" deleted
76+
pod "reviews-v2-675679877f-q67r2" deleted
77+
pod "reviews-v3-79d7549c7-c2gjs" deleted
7478
----
79+
80+
. Verify that the pods were created and are ready with the following command:
7581
+
76-
The file `/tmp/pod-cert-chain.pem` contains the workload certificate and the CA certificate propagated to the pod.
77-
+
78-
. Verify the root certificate is the same as the one specified by the Operator. Replace `<path>` with the path to your certificates.
79-
+
82+
8083
[source,terminal]
8184
----
82-
$ openssl x509 -in <path>/root-cert.pem -text -noout > /tmp/root-cert.crt.txt
85+
$ oc get pods -n bookinfo
8386
----
87+
88+
[id="ossm-cert-manage-verify-cert_{context}"]
89+
== Verifying your certificates
90+
91+
Use the Bookinfo sample application to verify that the workload certificates are signed by the certificates that were plugged into the CA. This requires you have `openssl` installed on your machine
92+
93+
. To extract certificates from bookinfo workloads use the following command:
8494
+
8595
[source,terminal]
8696
----
87-
$ openssl x509 -in /tmp/pod-root-cert.pem -text -noout > /tmp/pod-root-cert.crt.txt
97+
$ sleep 60
98+
$ oc -n bookinfo exec "$(oc -n bookinfo get pod -l app=productpage -o jsonpath={.items..metadata.name})" -c istio-proxy -- openssl s_client -showcerts -connect details:9080 > bookinfo-proxy-cert.txt
99+
$ sed -n '/-----BEGIN CERTIFICATE-----/{:start /-----END CERTIFICATE-----/!{N;b start};/.*/p}' bookinfo-proxy-cert.txt > certs.pem
100+
$ awk 'BEGIN {counter=0;} /BEGIN CERT/{counter++} { print > "proxy-cert-" counter ".pem"}' < certs.pem
88101
----
89102
+
103+
After running the command, you should have three files in your working directory: `proxy-cert-1.pem`, `proxy-cert-2.pem` and `proxy-cert-3.pem`.
104+
105+
. Verify that the root certificate is the same as the one specified by the administrator. Replace `<path>` with the path to your certificates.
106+
+
90107
[source,terminal]
91108
----
92-
$ diff /tmp/root-cert.crt.txt /tmp/pod-root-cert.crt.txt
109+
$ openssl x509 -in <path>/root-cert.pem -text -noout > /tmp/root-cert.crt.txt
93110
----
94111
+
95-
Expect the output to be empty.
96-
+
97-
. Verify the CA certificate is the same as the one specified by Operator. Replace `<path>` with the path to your certificates.
112+
Run the following syntax at the terminal window.
98113
+
99114
[source,terminal]
100115
----
101-
$ sed '0,/^-----END CERTIFICATE-----/d' /tmp/pod-cert-chain.pem > /tmp/pod-cert-chain-ca.pem
116+
$ openssl x509 -in ./proxy-cert-3.pem -text -noout > /tmp/pod-root-cert.crt.txt
102117
----
103118
+
104-
[source,terminal]
105-
----
106-
$ openssl x509 -in <path>/ca-cert.pem -text -noout > /tmp/ca-cert.crt.txt
107-
----
119+
Compare the certificates by running the following syntax at the terminal window.
108120
+
109121
[source,terminal]
110122
----
111-
$ openssl x509 -in /tmp/pod-cert-chain-ca.pem -text -noout > /tmp/pod-cert-chain-ca.crt.txt
123+
$ diff -s /tmp/root-cert.crt.txt /tmp/pod-root-cert.crt.txt
112124
----
113125
+
126+
You should see the following result:
127+
`Files /tmp/root-cert.crt.txt and /tmp/pod-root-cert.crt.txt are identical`
128+
129+
130+
. Verify that the CA certificate is the same as the one specified by the administrator. Replace `<path>` with the path to your certificates.
131+
+
114132
[source,terminal]
115133
----
116-
$ diff /tmp/ca-cert.crt.txt /tmp/pod-cert-chain-ca.crt.txt
134+
$ openssl x509 -in <path>/ca-cert.pem -text -noout > /tmp/ca-cert.crt.txt
117135
----
118-
+
119-
Expect the output to be empty.
120-
+
121-
. Verify the certificate chain from the root certificate to the workload certificate. Replace `<path>` with the path to your certificates.
136+
Run the following syntax at the terminal window.
122137
+
123138
[source,terminal]
124139
----
125-
$ head -n 21 /tmp/pod-cert-chain.pem > /tmp/pod-cert-chain-workload.pem
140+
$ openssl x509 -in ./proxy-cert-2.pem -text -noout > /tmp/pod-cert-chain-ca.crt.txt
126141
----
142+
Compare the certificates by running the following syntax at the terminal window.
127143
+
128144
[source,terminal]
129145
----
130-
$ openssl verify -CAfile <(cat <path>/ca-cert.pem <path>/root-cert.pem) /tmp/pod-cert-chain-workload.pem
146+
$ diff -s /tmp/ca-cert.crt.txt /tmp/pod-cert-chain-ca.crt.txt
131147
----
148+
You should see the following result:
149+
`Files /tmp/ca-cert.crt.txt and /tmp/pod-cert-chain-ca.crt.txt are identical.`
150+
151+
. Verify the certificate chain from the root certificate to the workload certificate. Replace `<path>` with the path to your certificates.
132152
+
133-
.Example output
134153
[source,terminal]
135154
----
136-
/tmp/pod-cert-chain-workload.pem: OK
155+
$ openssl verify -CAfile <(cat <path>/ca-cert.pem <path>/root-cert.pem) ./proxy-cert-1.pem
137156
----
157+
You should see the following result:
158+
`./proxy-cert-1.pem: OK`
138159

139160
[id="ossm-cert-cleanup_{context}"]
140161
== Removing the certificates
@@ -155,6 +176,7 @@ $ oc delete secret cacerts -n istio-system
155176
apiVersion: maistra.io/v2
156177
kind: ServiceMeshControlPlane
157178
spec:
158-
dataPlane:
159-
mtls: true
179+
security:
180+
dataPlane:
181+
mtls: true
160182
----

0 commit comments

Comments
 (0)