This documentation is for a release that is no longer maintained
See documentation for the latest supported version 3 or the latest supported version 4.1.9. Customizing security in a Service Mesh
If your service mesh application is constructed with a complex array of microservices, you can use Red Hat OpenShift Service Mesh to customize the security of the communication between those services. The infrastructure of OpenShift Container Platform along with the traffic management features of Service Mesh can help you manage the complexity of your applications and provide service and identity security for microservices.
1.9.1. Enabling mutual Transport Layer Security (mTLS) 复制链接链接已复制到粘贴板!
Mutual Transport Layer Security (mTLS) is a protocol where two parties authenticate each other at the same time. It is the default mode of authentication in some protocols (IKE, SSH) and optional in others (TLS).
MTLS can be used without changes to the application or service code. The TLS is handled entirely by the service mesh infrastructure and between the two sidecar proxies.
By default, Red Hat OpenShift Service Mesh is set to permissive mode, where the sidecars in Service Mesh accept both plain-text traffic and connections that are encrypted using mTLS. If a service in your mesh is communicating with a service outside the mesh, strict mTLS could break communication between those services. Use permissive mode while you migrate your workloads to Service Mesh.
1.9.1.1. Enabling strict mTLS across the mesh 复制链接链接已复制到粘贴板!
If your workloads do not communicate with services outside your mesh and communication will not be interrupted by only accepting encrypted connections, you can enable mTLS across your mesh quickly. Set spec.istio.global.mtls.enabled to true in your ServiceMeshControlPlane resource. The operator creates the required resources.
You can also configure mTLS for individual services or namespaces by creating a policy.
1.9.1.2. Configuring sidecars for outgoing connections 复制链接链接已复制到粘贴板!
Create a destination rule to configure Service Mesh to use mTLS when sending requests to other services in the mesh.
If your environment has specific requirements for encrypted traffic in your service mesh, you can control the cryptographic functions that are allowed by setting the spec.istio.global.tls.minProtocolVersion or spec.istio.global.tls.maxProtocolVersion in your ServiceMeshControlPlane resource. Those values, configured in your control plane resource, define the minimum and maximum TLS version used by mesh components when communicating securely over TLS.
The default is TLS_AUTO and does not specify a version of TLS.
| Value | Description |
|---|---|
|
| default |
|
| TLS version 1.0 |
|
| TLS version 1.1 |
|
| TLS version 1.2 |
|
| TLS version 1.3 |
1.9.2. Configuring cipher suites and ECDH curves 复制链接链接已复制到粘贴板!
Cipher suites and Elliptic-curve Diffie–Hellman (ECDH curves) can help you secure your service mesh. You can define a comma separated list of cipher suites using spec.istio.global.tls.cipherSuites and ECDH curves using spec.istio.global.tls.ecdhCurves in your ServiceMeshControlPlane resource. If either of these attributes are empty, then the default values are used.
The cipherSuites setting is effective if your service mesh uses TLS 1.2 or earlier. It has no effect when negotiating with TLS 1.3.
Set your cipher suites in the comma separated list in order of priority. For example, ecdhCurves: CurveP256, CurveP384 sets CurveP256 as a higher priority than CurveP384.
You must include either TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 or TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 when you configure the cipher suite. HTTP/2 support requires at least one of these cipher suites.
The supported cipher suites are:
- TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
- TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256
- TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
- TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384
- TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
- TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
- TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
- TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
- TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
- TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
- TLS_RSA_WITH_AES_128_GCM_SHA256
- TLS_RSA_WITH_AES_256_GCM_SHA384
- TLS_RSA_WITH_AES_128_CBC_SHA256
- TLS_RSA_WITH_AES_128_CBC_SHA
- TLS_RSA_WITH_AES_256_CBC_SHA
- TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA
- TLS_RSA_WITH_3DES_EDE_CBC_SHA
The supported ECDH Curves are:
- CurveP256
- CurveP384
- CurveP521
- X25519
By default, Red Hat OpenShift Service Mesh 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 Service Mesh.
Prerequisites
- You must have installed Red Hat OpenShift Service Mesh with mutual TLS enabled to configure certificates.
- This example uses the certificates from the 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.
1.9.3.1. 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 Service Mesh by following these steps. Save the example certificates from the Maistra repository locally and replace <path> with the path to your certificates.
Create a secret
cacertthat includes the input filesca-cert.pem,ca-key.pem,root-cert.pemandcert-chain.pem.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$ 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.pemCopy to Clipboard Copied! Toggle word wrap Toggle overflow In the
ServiceMeshControlPlaneresource setglobal.mtls.enabledtotrueandsecurity.selfSignedset tofalse. Service Mesh reads the certificates and key from the secret-mount files.Copy to Clipboard Copied! Toggle word wrap Toggle overflow To make sure the workloads add the new certificates promptly, delete the secrets generated by Service Mesh, named
istio.*. In this example,istio.default. Service Mesh issues new certificates for the workloads.oc delete secret istio.default
$ oc delete secret istio.defaultCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.9.3.2. 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.RATINGSPOD=`oc get pods -l app=ratings -o jsonpath='{.items[0].metadata.name}'`$ RATINGSPOD=`oc get pods -l app=ratings -o jsonpath='{.items[0].metadata.name}'`Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the following commands to retrieve the certificates mounted on the proxy.
oc exec -it $RATINGSPOD -c istio-proxy -- /bin/cat /etc/certs/root-cert.pem > /tmp/pod-root-cert.pem
$ oc exec -it $RATINGSPOD -c istio-proxy -- /bin/cat /etc/certs/root-cert.pem > /tmp/pod-root-cert.pemCopy to Clipboard Copied! Toggle word wrap Toggle overflow The file
/tmp/pod-root-cert.pemcontains the root certificate propagated to the pod.oc exec -it $RATINGSPOD -c istio-proxy -- /bin/cat /etc/certs/cert-chain.pem > /tmp/pod-cert-chain.pem
$ oc exec -it $RATINGSPOD -c istio-proxy -- /bin/cat /etc/certs/cert-chain.pem > /tmp/pod-cert-chain.pemCopy to Clipboard Copied! Toggle word wrap Toggle overflow The file
/tmp/pod-cert-chain.pemcontains 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.openssl x509 -in <path>/root-cert.pem -text -noout > /tmp/root-cert.crt.txt
$ openssl x509 -in <path>/root-cert.pem -text -noout > /tmp/root-cert.crt.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow openssl x509 -in /tmp/pod-root-cert.pem -text -noout > /tmp/pod-root-cert.crt.txt
$ openssl x509 -in /tmp/pod-root-cert.pem -text -noout > /tmp/pod-root-cert.crt.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow diff /tmp/root-cert.crt.txt /tmp/pod-root-cert.crt.txt
$ diff /tmp/root-cert.crt.txt /tmp/pod-root-cert.crt.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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.sed '0,/^-----END CERTIFICATE-----/d' /tmp/pod-cert-chain.pem > /tmp/pod-cert-chain-ca.pem
$ sed '0,/^-----END CERTIFICATE-----/d' /tmp/pod-cert-chain.pem > /tmp/pod-cert-chain-ca.pemCopy to Clipboard Copied! Toggle word wrap Toggle overflow openssl x509 -in <path>/ca-cert.pem -text -noout > /tmp/ca-cert.crt.txt
$ openssl x509 -in <path>/ca-cert.pem -text -noout > /tmp/ca-cert.crt.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow openssl x509 -in /tmp/pod-cert-chain-ca.pem -text -noout > /tmp/pod-cert-chain-ca.crt.txt
$ openssl x509 -in /tmp/pod-cert-chain-ca.pem -text -noout > /tmp/pod-cert-chain-ca.crt.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow diff /tmp/ca-cert.crt.txt /tmp/pod-cert-chain-ca.crt.txt
$ diff /tmp/ca-cert.crt.txt /tmp/pod-cert-chain-ca.crt.txtCopy to Clipboard Copied! Toggle word wrap Toggle overflow 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.head -n 21 /tmp/pod-cert-chain.pem > /tmp/pod-cert-chain-workload.pem
$ head -n 21 /tmp/pod-cert-chain.pem > /tmp/pod-cert-chain-workload.pemCopy to Clipboard Copied! Toggle word wrap Toggle overflow openssl verify -CAfile <(cat <path>/ca-cert.pem <path>/root-cert.pem) /tmp/pod-cert-chain-workload.pem
$ openssl verify -CAfile <(cat <path>/ca-cert.pem <path>/root-cert.pem) /tmp/pod-cert-chain-workload.pemCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
/tmp/pod-cert-chain-workload.pem: OK
/tmp/pod-cert-chain-workload.pem: OKCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.9.3.3. Removing the certificates 复制链接链接已复制到粘贴板!
To remove the certificates you added, follow these steps.
Remove the secret
cacerts.oc delete secret cacerts -n istio-system
$ oc delete secret cacerts -n istio-systemCopy to Clipboard Copied! Toggle word wrap Toggle overflow Redeploy Service Mesh with a self-signed root certificate in the
ServiceMeshControlPlaneresource.Copy to Clipboard Copied! Toggle word wrap Toggle overflow