-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Manual cherry pick #27812 to 4.5 branch. #27888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
// Module included in the following assemblies: | ||
// | ||
// * service_mesh/v1x/ossm-security.adoc | ||
|
||
|
||
[id="ossm-cert-manage_{context}"] | ||
= Adding an external certificate authority key and certificate | ||
|
||
By default, {ProductName} generates self-signed root certificate and key, and uses them to sign the workload certificates. You can also use the user-defined certificate and key to sign workload certificates, with user-defined root certificate. This task demonstrates an example to plug certificates and key into {ProductShortName}. | ||
|
||
.Prerequisites | ||
|
||
* You must have installed {ProductName} with mutual TLS enabled to configure certificates. | ||
* This example uses the certificates from the link:https://github.com/maistra/istio/tree/maistra-2.0/samples/certs[Maistra repository]. For production, use your own certificates from your certificate authority. | ||
* You must deploy the Bookinfo sample application to verify the results with these instructions. | ||
|
||
[id="ossm-cert-manage-add-cert-key_{context}"] | ||
== Adding an existing certificate and key | ||
|
||
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 called `ca-cert.pem`, the key is `ca-key.pem`, and the root certificate, which signs `ca-cert.pem`, is called `root-cert.pem`. If your workload uses intermediate certificates, you must specify them in a `cert-chain.pem` file. | ||
|
||
Add the certificates to {ProductShortName} by following these steps. Save the example certificates from the link:https://github.com/maistra/istio/tree/maistra-1.1/samples/certs[Maistra repo] locally and replace `<path>` with the path to your certificates. | ||
|
||
. Create a secret `cacert` that includes the input files `ca-cert.pem`, `ca-key.pem`, `root-cert.pem` and `cert-chain.pem`. | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc create secret generic cacerts -n istio-system --from-file=<path>/ca-cert.pem \ | ||
--from-file=<path>/ca-key.pem --from-file=<path>/root-cert.pem \ | ||
--from-file=<path>/cert-chain.pem | ||
---- | ||
+ | ||
. In the `ServiceMeshControlPlane` resource set `global.mtls.enabled` to `true` and `security.selfSigned` set to `false`. {ProductShortName} reads the certificates and key from the secret-mount files. | ||
+ | ||
[source,yaml] | ||
---- | ||
apiVersion: maistra.io/v1 | ||
kind: ServiceMeshControlPlane | ||
spec: | ||
istio: | ||
global: | ||
mtls: | ||
enabled: true | ||
security: | ||
selfSigned: false | ||
---- | ||
+ | ||
. To make sure the workloads add the new certificates promptly, delete the secrets generated by {ProductShortName}, named `istio.*`. In this example, `istio.default`. {ProductShortName} issues new certificates for the workloads. | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc delete secret istio.default | ||
---- | ||
|
||
[id="ossm-cert-manage-verify-cert_{context}"] | ||
== Verifying your certificates | ||
|
||
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. | ||
|
||
. Store the pod name in the variable `RATINGSPOD`. | ||
+ | ||
[source,terminal] | ||
---- | ||
$ RATINGSPOD=`oc get pods -l app=ratings -o jsonpath='{.items[0].metadata.name}'` | ||
---- | ||
+ | ||
. Run the following commands to retrieve the certificates mounted on the proxy. | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc exec -it $RATINGSPOD -c istio-proxy -- /bin/cat /etc/certs/root-cert.pem > /tmp/pod-root-cert.pem | ||
---- | ||
+ | ||
The file `/tmp/pod-root-cert.pem` contains the root certificate propagated to the pod. | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc exec -it $RATINGSPOD -c istio-proxy -- /bin/cat /etc/certs/cert-chain.pem > /tmp/pod-cert-chain.pem | ||
---- | ||
+ | ||
The file `/tmp/pod-cert-chain.pem` contains the workload certificate and the CA certificate propagated to the pod. | ||
+ | ||
. Verify the root certificate is the same as the one specified by the Operator. Replace `<path>` with the path to your certificates. | ||
+ | ||
[source,terminal] | ||
---- | ||
$ openssl x509 -in <path>/root-cert.pem -text -noout > /tmp/root-cert.crt.txt | ||
---- | ||
+ | ||
[source,terminal] | ||
---- | ||
$ openssl x509 -in /tmp/pod-root-cert.pem -text -noout > /tmp/pod-root-cert.crt.txt | ||
---- | ||
+ | ||
[source,terminal] | ||
---- | ||
$ diff /tmp/root-cert.crt.txt /tmp/pod-root-cert.crt.txt | ||
---- | ||
+ | ||
Expect the output to be empty. | ||
+ | ||
. Verify the CA certificate is the same as the one specified by Operator. Replace `<path>` with the path to your certificates. | ||
+ | ||
[source,terminal] | ||
---- | ||
$ sed '0,/^-----END CERTIFICATE-----/d' /tmp/pod-cert-chain.pem > /tmp/pod-cert-chain-ca.pem | ||
---- | ||
+ | ||
[source,terminal] | ||
---- | ||
$ openssl x509 -in <path>/ca-cert.pem -text -noout > /tmp/ca-cert.crt.txt | ||
---- | ||
+ | ||
[source,terminal] | ||
---- | ||
$ openssl x509 -in /tmp/pod-cert-chain-ca.pem -text -noout > /tmp/pod-cert-chain-ca.crt.txt | ||
---- | ||
+ | ||
[source,terminal] | ||
---- | ||
$ diff /tmp/ca-cert.crt.txt /tmp/pod-cert-chain-ca.crt.txt | ||
---- | ||
+ | ||
Expect the output to be empty. | ||
+ | ||
. Verify the certificate chain from the root certificate to the workload certificate. Replace `<path>` with the path to your certificates. | ||
+ | ||
[source,terminal] | ||
---- | ||
$ head -n 21 /tmp/pod-cert-chain.pem > /tmp/pod-cert-chain-workload.pem | ||
---- | ||
+ | ||
[source,terminal] | ||
---- | ||
$ openssl verify -CAfile <(cat <path>/ca-cert.pem <path>/root-cert.pem) /tmp/pod-cert-chain-workload.pem | ||
---- | ||
+ | ||
.Example output | ||
[source,terminal] | ||
---- | ||
/tmp/pod-cert-chain-workload.pem: OK | ||
---- | ||
|
||
[id="ossm-cert-cleanup_{context}"] | ||
== Removing the certificates | ||
|
||
To remove the certificates you added, follow these steps. | ||
|
||
. Remove the secret `cacerts`. | ||
+ | ||
[source,terminal] | ||
---- | ||
$ oc delete secret cacerts -n istio-system | ||
---- | ||
+ | ||
. Redeploy {ProductShortName} with a self-signed root certificate in the `ServiceMeshControlPlane` resource. | ||
+ | ||
[source,yaml] | ||
---- | ||
apiVersion: maistra.io/v1 | ||
kind: ServiceMeshControlPlane | ||
spec: | ||
istio: | ||
global: | ||
mtls: | ||
enabled: true | ||
security: | ||
selfSigned: true | ||
---- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this ossm-security-cert-manage-1x.adoc and not ossm-security-cert-manage.adoc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figure that checking in changes like this can help reduce manual cherry picks in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JStickler I think you're right. This works for me.