Este conteúdo não está disponível no idioma selecionado.
Chapter 5. OpenShift Service Mesh and cert-manager
The cert-manager tool is a solution for X.509 certificate management on Kubernetes. It delivers a unified API to integrate applications with private or public key infrastructure (PKI), such as Vault, Google Cloud Certificate Authority Service, Let’s Encrypt, and other providers.
The cert-manager tool ensures that the certificates are valid and up-to-date by attempting to renew certificates at a configured time before they expire.
The cert-manager tool must be installed before you create and install your Istio resource.
5.1. About the cert-manager Operator istio-csr agent Copiar o linkLink copiado para a área de transferência!
istio-csr integration for cert-manager Operator for Red Hat OpenShift is a Technology Preview feature only. Technology Preview features are not supported with Red Hat production service level agreements (SLAs) and might not be functionally complete. Red Hat does not recommend using them in production. These features provide early access to upcoming product features, enabling customers to test functionality and provide feedback during the development process.
For more information about the support scope of Red Hat Technology Preview features, see Technology Preview Features Support Scope.
The cert-manager Operator for Red Hat OpenShift enhances certificate management for securing workloads and control plane components in Red Hat OpenShift Service Mesh and Istio. It supports issuing, delivering, and renewing certificates used for mutual Transport Layer Security (mTLS) through cert-manager issuers.
By integrating Istio with the istio-csr agent that is managed by the cert-manager Operator, you enable Istio to request and manage the certificates directly. The integration simplifies security configuration and centralizes certificate management within the cluster.
The cert-manager Operator for Red Hat OpenShift must be installed before you create and install your Istio resource.
5.1.1. Integrating Service Mesh with the cert-manager Operator by using the istio-csr agent Copiar o linkLink copiado para a área de transferência!
You can integrate the cert-manager Operator with OpenShift Service Mesh by deploying the istio-csr agent and configuring an Istio resource that uses the istio-csr agent to process workload and control plane certificate signing requests. The following procedure creates a self-signed issuer object.
Prerequisites
- You have installed the cert-manager Operator for Red Hat OpenShift version 1.15.1.
- You are logged in to OpenShift Container Platform 4.14 or later.
- You have installed the OpenShift Service Mesh Operator.
-
You have a
IstioCNIinstance running in the cluster. -
You have installed the
istioctlcommand.
Procedure
Create the
istio-systemnamespace by running the following command:oc create namespace istio-system
$ oc create namespace istio-systemCopy to Clipboard Copied! Toggle word wrap Toggle overflow Patch the cert-manager Operator to install the
istio-csragent by running the following command:oc -n cert-manager-operator patch subscription openshift-cert-manager-operator \ --type='merge' -p \ '{"spec":{"config":{"env":[{"name":"UNSUPPORTED_ADDON_FEATURES","value":"IstioCSR=true"}]}}}'$ oc -n cert-manager-operator patch subscription openshift-cert-manager-operator \ --type='merge' -p \ '{"spec":{"config":{"env":[{"name":"UNSUPPORTED_ADDON_FEATURES","value":"IstioCSR=true"}]}}}'Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the root certificate authority (CA) issuer by creating an
Issuerobject for theistio-csragent:Create a new project for installing the
istio-csragent by running the following command:oc new-project istio-csr
$ oc new-project istio-csrCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create an
Issuerobject similar to the following example:NoteThe
selfSignedissuer is intended for demonstration, testing, or proof-of-concept environments. For production deployments, use a secure and trusted CA.Example
issuer.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the objects by running the following command:
oc apply -f issuer.yaml
$ oc apply -f issuer.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Wait for the
istio-cacertificate to contain the "Ready" status condition by running the following command:oc wait --for=condition=Ready certificates/istio-ca -n istio-system
$ oc wait --for=condition=Ready certificates/istio-ca -n istio-systemCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Create the
IstioCSRcustom resource:Create the
IstioCSRcustom resource similar to the following example:Example
istioCSR.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
istio-csragent by by running the following command:oc create -f istioCSR.yaml
$ oc create -f istioCSR.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the
istio-csrdeployment is ready by running the following command:oc get deployment -n istio-csr
$ oc get deployment -n istio-csrCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Install the
istioresource:NoteThe configuration disables the built-in CA server for Istio and forwards certificate signing requests from
istiodto theistio-csragent. Theistio-csragent obtains certificates for bothistiodand mesh workloads from the cert-manager Operator. TheistiodTLS certificate that is generated by theistio-csragent is mounted into the pod at a known location for use.Create the
Istioobject similar to the following example:Example
istio.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
Istioresource by running the following command:oc apply -f istio.yaml
$ oc apply -f istio.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the
istioresource displays the "Ready" status condition by running the following command:oc wait --for=condition=Ready istios/default -n istio-system
$ oc wait --for=condition=Ready istios/default -n istio-systemCopy to Clipboard Copied! Toggle word wrap Toggle overflow
5.1.2. Verifying Service Mesh with the cert-manager Operator using the istio-csr agent Copiar o linkLink copiado para a área de transferência!
You can use the sample httpbin service and sleep application to verify traffic between workloads. Check the workload proxy certificate to verify that the cert-manager Operator is installed correctly.
Create the namespaces:
Create the
apps-1namespace by running the following command:oc new-project apps-1
$ oc new-project apps-1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
apps-2namespace by running the following command:oc new-project apps-2
$ oc new-project apps-2Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Add the
istio-injection=enabledlabel on the namespaces:Add the
istio-injection=enabledlabel on theapps-1namespace by running the following command:oc label namespaces apps-1 istio-injection=enabled
$ oc label namespaces apps-1 istio-injection=enabledCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the
istio-injection=enabledlabel on theapps-2namespace by running the following command:oc label namespaces apps-2 istio-injection=enabled
$ oc label namespaces apps-2 istio-injection=enabledCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Deploy the
httpbinapp in the namespaces:Deploy the
httpbinapp in theapps-1namespace by running the following command:oc apply -n apps-1 -f https://raw.githubusercontent.com/openshift-service-mesh/istio/release-1.24/samples/httpbin/httpbin.yaml
$ oc apply -n apps-1 -f https://raw.githubusercontent.com/openshift-service-mesh/istio/release-1.24/samples/httpbin/httpbin.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the
httpbinapp in theapps-2namespace by running the following command:oc apply -n apps-2 -f https://raw.githubusercontent.com/openshift-service-mesh/istio/release-1.24/samples/httpbin/httpbin.yaml
$ oc apply -n apps-2 -f https://raw.githubusercontent.com/openshift-service-mesh/istio/release-1.24/samples/httpbin/httpbin.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Deploy the
sleepapp in the namespaces:Deploy the
sleepapp in theapps-1namespace by running the following command:oc apply -n apps-1 -f https://raw.githubusercontent.com/openshift-service-mesh/istio/release-1.24/samples/sleep/sleep.yaml
$ oc apply -n apps-1 -f https://raw.githubusercontent.com/openshift-service-mesh/istio/release-1.24/samples/sleep/sleep.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Deploy the
sleepapp in theapps-2namespace by running the following command:oc apply -n apps-2 -f https://raw.githubusercontent.com/openshift-service-mesh/istio/release-1.24/samples/sleep/sleep.yaml
$ oc apply -n apps-2 -f https://raw.githubusercontent.com/openshift-service-mesh/istio/release-1.24/samples/sleep/sleep.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verify that the created apps have sidecars injected:
Verify that the created apps have sidecars injected for
apps-1namespace by running the following command:oc get pods -n apps-1
$ oc get pods -n apps-1Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the created apps have sidecars injected for
apps-2namespace by running the following command:oc get pods -n apps-2
$ oc get pods -n apps-2Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Create a mesh-wide strict mutual Transport Layer Security (mTLS) policy similar to the following example:
NoteEnabling
PeerAuthenticationin strict mTLS mode verifies that certificates are distributed correctly and that mTLS communication functions between workloads.Example
peer_auth.yamlfileCopy to Clipboard Copied! Toggle word wrap Toggle overflow Apply the mTLS policy by running the following command:
oc apply -f peer_auth.yaml
$ oc apply -f peer_auth.yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the
apps-1/sleepapp can access theapps-2/httpbinservice by running the following command:oc -n apps-1 exec "$(oc -n apps-1 get pod \ -l app=sleep -o jsonpath={.items..metadata.name})" \ -c sleep -- curl -sIL http://httpbin.apps-2.svc.cluster.local:8000$ oc -n apps-1 exec "$(oc -n apps-1 get pod \ -l app=sleep -o jsonpath={.items..metadata.name})" \ -c sleep -- curl -sIL http://httpbin.apps-2.svc.cluster.local:8000Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the
apps-2/sleepapp can access theapps-1/httpbinservice by running the following command:oc -n apps-2 exec "$(oc -n apps-1 get pod \ -l app=sleep -o jsonpath={.items..metadata.name})" \ -c sleep -- curl -sIL http://httpbin.apps-2.svc.cluster.local:8000$ oc -n apps-2 exec "$(oc -n apps-1 get pod \ -l app=sleep -o jsonpath={.items..metadata.name})" \ -c sleep -- curl -sIL http://httpbin.apps-2.svc.cluster.local:8000Copy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Verify that the
httpbinworkload certificate matches as expected by running the following command:istioctl proxy-config secret -n apps-1 \ $(oc get pods -n apps-1 -o jsonpath='{.items..metadata.name}' --selector app=httpbin) \ -o json | jq -r '.dynamicActiveSecrets[0].secret.tlsCertificate.certificateChain.inlineBytes' \ | base64 --decode | openssl x509 -text -noout$ istioctl proxy-config secret -n apps-1 \ $(oc get pods -n apps-1 -o jsonpath='{.items..metadata.name}' --selector app=httpbin) \ -o json | jq -r '.dynamicActiveSecrets[0].secret.tlsCertificate.certificateChain.inlineBytes' \ | base64 --decode | openssl x509 -text -nooutCopy to Clipboard Copied! Toggle word wrap Toggle overflow Example output
... Issuer: O = cert-manager + O = cluster.local, CN = istio-ca ... X509v3 Subject Alternative Name: URI:spiffe://cluster.local/ns/apps-1/sa/httpbin
... Issuer: O = cert-manager + O = cluster.local, CN = istio-ca ... X509v3 Subject Alternative Name: URI:spiffe://cluster.local/ns/apps-1/sa/httpbinCopy to Clipboard Copied! Toggle word wrap Toggle overflow
5.1.3. Uninstalling Service Mesh with the cert-manager Operator by using the istio-csr agent Copiar o linkLink copiado para a área de transferência!
You can uninstall the cert-manager Operator with OpenShift Service Mesh by completing the following procedure. Before you remove the following resources, verify that no Red Hat OpenShift Service Mesh or Istio components reference the Istio-CSR agent or the certificates it issued. Removing these resources while they are still in use might disrupt mesh functionality.
Procedure
Remove the
IstioCSRcustom resource by running the following command:oc -n <istio-csr_project_name> delete istiocsrs.operator.openshift.io default
$ oc -n <istio-csr_project_name> delete istiocsrs.operator.openshift.io defaultCopy to Clipboard Copied! Toggle word wrap Toggle overflow Remove the related resources:
List the cluster scoped-resources by running the following command:
oc get clusterrolebindings,clusterroles -l "app=cert-manager-istio-csr,app.kubernetes.io/name=cert-manager-istio-csr"
$ oc get clusterrolebindings,clusterroles -l "app=cert-manager-istio-csr,app.kubernetes.io/name=cert-manager-istio-csr"Copy to Clipboard Copied! Toggle word wrap Toggle overflow Save the names of the listed resources for later reference.
List the resources in
istio-csragent deployed namespace by running the following command:oc get certificate,deployments,services,serviceaccounts -l "app=cert-manager-istio-csr,app.kubernetes.io/name=cert-manager-istio-csr" -n <istio_csr_project_name>
$ oc get certificate,deployments,services,serviceaccounts -l "app=cert-manager-istio-csr,app.kubernetes.io/name=cert-manager-istio-csr" -n <istio_csr_project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Save the names of the listed resources for later reference.
List the resources in Red Hat OpenShift Service Mesh or Istio deployed namespaces by running the following command:
oc get roles,rolebindings \ -l "app=cert-manager-istio-csr,app.kubernetes.io/name=cert-manager-istio-csr" \ -n <istio_csr_project_name>
$ oc get roles,rolebindings \ -l "app=cert-manager-istio-csr,app.kubernetes.io/name=cert-manager-istio-csr" \ -n <istio_csr_project_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Save the names of the listed resources for later reference.
For each resource listed in previous steps, delete the resources by running the following command:
oc -n <istio_csr_project_name> delete <resource_type>/<resource_name>
$ oc -n <istio_csr_project_name> delete <resource_type>/<resource_name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow