- Custom CA Integration using Kubernetes CSR
- Deploy custom CA controller in the Kubernetes cluster
- Verify secrets are created for each cluster issuer
- Export root certificates for each cluster issuer
- Deploy Istio with default cert-signer info
- Verify the network connectivity between
httpbinandsleepwithin the same namespace - Cleanup
- Reasons to use this feature
Custom CA Integration using Kubernetes CSR
This feature is actively in development and is considered experimental.
This feature requires Kubernetes version >= 1.18.
This task shows how to provision workload certificates using a custom certificate authority that integrates with the Kubernetes CSR API. Different workloads can get their certificates signed from different cert-signers. Each cert-signer is effectively a different CA. It is expected that workloads whose certificates are issued from the same cert-signer can talk mTLS to each other while workloads signed by different signers cannot. This feature leverages Chiron, a lightweight component linked with Istiod that signs certificates using the Kubernetes CSR API.
For this example, we use open-source cert-manager. Cert-manager has added experimental Support for Kubernetes CertificateSigningRequests starting with version 1.4.
Deploy custom CA controller in the Kubernetes cluster
Deploy cert-manager according to the installation doc.
Make sure to enable feature gate:
--feature-gates=ExperimentalCertificateSigningRequestControllers=true$ helm repo add jetstack https://charts.jetstack.io$ helm repo update$ helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --set featureGates="ExperimentalCertificateSigningRequestControllers=true" --set installCRDs=true
Create three self signed cluster issuers
istio-system,fooandbarfor cert-manager. Note: Namespace issuers and other types of issuers can also be used.$ cat <<EOF > ./selfsigned-issuer.yamlapiVersion: cert-manager.io/v1kind: ClusterIssuermetadata:name: selfsigned-bar-issuerspec:selfSigned: {}---apiVersion: cert-manager.io/v1kind: Certificatemetadata:name: bar-canamespace: cert-managerspec:isCA: truecommonName: barsecretName: bar-ca-selfsignedissuerRef:name: selfsigned-bar-issuerkind: ClusterIssuergroup: cert-manager.io---apiVersion: cert-manager.io/v1kind: ClusterIssuermetadata:name: barspec:ca:secretName: bar-ca-selfsigned---apiVersion: cert-manager.io/v1kind: ClusterIssuermetadata:name: selfsigned-foo-issuerspec:selfSigned: {}---apiVersion: cert-manager.io/v1kind: Certificatemetadata:name: foo-canamespace: cert-managerspec:isCA: truecommonName: foosecretName: foo-ca-selfsignedissuerRef:name: selfsigned-foo-issuerkind: ClusterIssuergroup: cert-manager.io---apiVersion: cert-manager.io/v1kind: ClusterIssuermetadata:name: foospec:ca:secretName: foo-ca-selfsigned---apiVersion: cert-manager.io/v1kind: ClusterIssuermetadata:name: selfsigned-istio-issuerspec:selfSigned: {}---apiVersion: cert-manager.io/v1kind: Certificatemetadata:name: istio-canamespace: cert-managerspec:isCA: truecommonName: istio-systemsecretName: istio-ca-selfsignedissuerRef:name: selfsigned-istio-issuerkind: ClusterIssuergroup: cert-manager.io---apiVersion: cert-manager.io/v1kind: ClusterIssuermetadata:name: istio-systemspec:ca:secretName: istio-ca-selfsignedEOF$ kubectl apply -f ./selfsigned-issuer.yaml
Verify secrets are created for each cluster issuer
$ kubectl get secret -n cert-manager -l controller.cert-manager.io/fao=trueNAME TYPE DATA AGEbar-ca-selfsigned kubernetes.io/tls 3 3m36sfoo-ca-selfsigned kubernetes.io/tls 3 3m36sistio-ca-selfsigned kubernetes.io/tls 3 3m38s
Export root certificates for each cluster issuer
$ export ISTIOCA=$(kubectl get clusterissuers istio-system -o jsonpath='{.spec.ca.secretName}' | xargs kubectl get secret -n cert-manager -o jsonpath='{.data.ca\.crt}' | base64 -d | sed 's/^/ /')$ export FOOCA=$(kubectl get clusterissuers foo -o jsonpath='{.spec.ca.secretName}' | xargs kubectl get secret -n cert-manager -o jsonpath='{.data.ca\.crt}' | base64 -d | sed 's/^/ /')$ export BARCA=$(kubectl get clusterissuers bar -o jsonpath='{.spec.ca.secretName}' | xargs kubectl get secret -n cert-manager -o jsonpath='{.data.ca\.crt}' | base64 -d | sed 's/^/ /')
Deploy Istio with default cert-signer info
Deploy Istio on the cluster using
istioctlwith the following configuration. TheISTIO_META_CERT_SIGNERis the default cert-signer for workloads.$ cat <<EOF > ./istio.yamlapiVersion: install.istio.io/v1alpha1kind: IstioOperatorspec:values:pilot:env:EXTERNAL_CA: ISTIOD_RA_KUBERNETES_APImeshConfig:defaultConfig:proxyMetadata:ISTIO_META_CERT_SIGNER: istio-systemcaCertificates:- pem: |$ISTIOCAcertSigners:- clusterissuers.cert-manager.io/istio-system- pem: |$FOOCAcertSigners:- clusterissuers.cert-manager.io/foo- pem: |$BARCAcertSigners:- clusterissuers.cert-manager.io/barcomponents:pilot:k8s:env:- name: CERT_SIGNER_DOMAINvalue: clusterissuers.cert-manager.io- name: PILOT_CERT_PROVIDERvalue: k8s.io/clusterissuers.cert-manager.io/istio-systemoverlays:- kind: ClusterRolename: istiod-clusterrole-istio-systempatches:- path: rules[-1]value: |apiGroups:- certificates.k8s.ioresourceNames:- clusterissuers.cert-manager.io/foo- clusterissuers.cert-manager.io/bar- clusterissuers.cert-manager.io/istio-systemresources:- signersverbs:- approveEOF$ istioctl install --skip-confirmation -f ./istio.yaml
Create the
barandfoonamespaces.$ kubectl create ns bar$ kubectl create ns foo
Deploy the
proxyconfig-bar.yamlin thebarnamespace to define cert-signer for workloads in thebarnamespace.$ cat <<EOF > ./proxyconfig-bar.yamlapiVersion: networking.istio.io/v1beta1kind: ProxyConfigmetadata:name: barpcnamespace: barspec:environmentVariables:ISTIO_META_CERT_SIGNER: barEOF$ kubectl apply -f ./proxyconfig-bar.yaml
Deploy the
proxyconfig-foo.yamlin thefoonamespace to define cert-signer for workloads in thefoonamespace.$ cat <<EOF > ./proxyconfig-foo.yamlapiVersion: networking.istio.io/v1beta1kind: ProxyConfigmetadata:name: foopcnamespace: foospec:environmentVariables:ISTIO_META_CERT_SIGNER: fooEOF$ kubectl apply -f ./proxyconfig-foo.yaml
Deploy the
httpbinandsleepsample applications in thefooandbarnamespaces.$ kubectl label ns foo istio-injection=enabled$ kubectl label ns bar istio-injection=enabled$ kubectl apply -f samples/httpbin/httpbin.yaml -n foo$ kubectl apply -f samples/sleep/sleep.yaml -n foo$ kubectl apply -f samples/httpbin/httpbin.yaml -n bar
Verify the network connectivity between httpbin and sleep within the same namespace
When the workloads are deployed, they send CSR requests with related signer info. Istiod forwards the CSR request to the custom CA for signing. The custom CA will use the correct cluster issuer to sign the cert back. Workloads under foo namespace will use foo cluster issuers while workloads under bar namespace will use the bar cluster issuers. To verify that they have indeed been signed by correct cluster issuers, we can verify workloads under the same namespace can communicate while workloads under the different namespace cannot communicate.
Set the
SLEEP_POD_FOOenvironment variable to the name ofsleeppod.$ export SLEEP_POD_FOO=$(kubectl get pod -n foo -l app=sleep -o jsonpath={.items..metadata.name})
Check network connectivity between service
sleepandhttpbinin thefoonamespace.$ kubectl exec "$SLEEP_POD_FOO" -n foo -c sleep -- curl http://httpbin.foo:8000/html<!DOCTYPE html><html><head></head><body><h1>Herman Melville - Moby-Dick</h1><div><p>Availing himself of the mild...</p></div></body>
Check network connectivity between service
sleepin thefoonamespace andhttpbinin thebarnamespace.$ kubectl exec "$SLEEP_POD_FOO" -n foo -c sleep -- curl http://httpbin.bar:8000/htmlupstream connect error or disconnect/reset before headers. reset reason: connection failure, transport failure reason: TLS error: 268435581:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
Cleanup
Remove the namespaces and uninstall Istio and cert-manager:
$ kubectl delete ns foo$ kubectl delete ns bar$ istioctl uninstall --purge -y$ helm delete -n cert-manager cert-manager$ kubectl delete ns istio-system cert-manager$ unset ISTIOCA FOOCA BARCA$ rm -rf istio.yaml proxyconfig-foo.yaml proxyconfig-bar.yaml selfsigned-issuer.yaml
Reasons to use this feature
Custom CA Integration - By specifying a Signer name in the Kubernetes CSR Request, this feature allows Istio to integrate with custom Certificate Authorities using the Kubernetes CSR API interface. This does require the custom CA to implement a Kubernetes controller to watch the
CertificateSigningRequestResources and act on them.Better multi-tenancy - By specifying a different cert-signer for different workloads, certificates for different tenant’s workloads can be signed by different CAs.