Configure transport security
You can secure inter-service traffic in Cloud Service Mesh with Istio APIs by enforcing strict mutual TLS (mTLS). In Kubernetes workloads, auto mTLS is enabled by default: client sidecar proxies automatically send mTLS traffic to sidecars, but destination services still accept both plaintext and encrypted requests.
PeerAuthentication policies let you restrict services to only accept mTLS. You
can apply a policy mesh-wide, to a specific namespace, or to an individual workload.
For supported fields across platforms, see Supported features.
Enable mutual TLS per namespace
To enable mTLS for all workloads within a particular namespace, use a
namespace-wide authentication policy. You specify the namespace it applies to
under metadata.
kubectl apply -f - <<EOF
apiVersion: "security.istio.io/v1beta1"
kind: "PeerAuthentication"
metadata:
name: "AUTH_POLICY_NAME"
namespace: "NAMESPACE"
spec:
mtls:
mode: STRICT
EOF
Expected output:
peerauthentication.security.istio.io/AUTH_POLICY_NAME created
Enable mutual TLS per workload
To set a PeerAuthentication policy for a specific workload, you must configure
the selector section and specify the labels that match the targeted workload.
However, Cloud Service Mesh can't aggregate workload-level policies for
outbound mTLS traffic to a service. You need to configure a destination rule to
manage that behavior.
Apply an authentication policy to a specific workload in your namespace:
cat <<EOF | kubectl apply -n NAMESPACE -f - apiVersion: "security.istio.io/v1beta1" kind: "PeerAuthentication" metadata: name: "AUTH_POLICY_NAME" namespace: "NAMESPACE" spec: selector: matchLabels: app: WORKLOAD mtls: mode: STRICT EOFExpected output:
peerauthentication.security.istio.io/AUTH_POLICY_NAME created
Configure a matching destination rule:
cat <<EOF | kubectl apply -n NAMESPACE -f - apiVersion: "networking.istio.io/v1alpha3" kind: "DestinationRule" metadata: name: "DEST_RULE_NAME" spec: host: "WORKLOAD.NAMESPACE.svc.cluster.local" trafficPolicy: tls: mode: ISTIO_MUTUAL EOFExpected output:
destinationrule.networking.istio.io/WORKLOAD created
Enforce mesh-wide mTLS
To prevent all your services in the mesh from accepting plain-text traffic, set
a mesh-wide PeerAuthentication policy with the mTLS mode set to STRICT (the
default is PERMISSIVE). The mesh-wide PeerAuthentication policy shouldn't
have a selector and must be applied in the root namespace, istio-system. When
you deploy the policy, the control plane automatically provisions TLS
certificates so that workloads can authenticate with each other.
To enforce mesh-wide mTLS:
kubectl apply -f - <<EOF
apiVersion: "security.istio.io/v1beta1"
kind: "PeerAuthentication"
metadata:
name: "AUTH_POLICY_NAME"
namespace: "istio-system"
spec:
mtls:
mode: STRICT
EOF
Expected output:
peerauthentication.security.istio.io/AUTH_POLICY_NAME created
Disabling mTLS for Managed CSM
Cloud Service Mesh does not support the mtls.mode: DISABLE value in a
PeerAuthentication resource.
To successfully disable mTLS in Cloud Service Mesh, you must explicitly
define the client's behavior with the server's requirements by using the
DestinationRule API.
Conceptual Overview
- Server-Side: You use a
PeerAuthenticationresource to set the server-side proxy default value. - Client-Side Approach: You use a
DestinationRuleresource to explicitly tell the client-side proxies to use plaintext when communicating with that specific server.
Examples
Step 1: Configure PeerAuthentication
In this example we will use the default policy of PERMISSIVE and so don't need to explicitly define the policy.
Step 2: Configure Client-Side DestinationRule
This configuration tells clients to use plaintext when calling httpbin.
apiVersion: networking.istio.io/v1beta1
kind: DestinationRule
metadata:
name: "DEST_RULE_NAME"
namespace: sample-namespace
spec:
host: "WORKLOAD.NAMESPACE.svc.cluster.local"
trafficPolicy:
tls:
mode: DISABLE
Find and delete PeerAuthentication policies
For a list of all the PeerAuthentication policies in the service mesh:
kubectl get peerauthentication --all-namespaces
If there is a PeerAuthentication policy in force, you can delete it with
kubectl delete:
kubectl delete peerauthentication -n NAMESPACE AUTH_POLICY_NAME