Day 15: mTLS and authorization with Linkerd
Goal: Install Linkerd, bring Team Blue into the mesh, prove mutual TLS with identities and define who may call
podinfo– without locking out monitoring · Duration: approx. 75 min · Prerequisite: Day 14
Briefing
- NetworkPolicies (Day 1) decide by IP address. A service mesh decides by identity: every pod gets a certificate for its ServiceAccount, and every connection between two pods in the mesh is mTLS – encrypted, with both sides authenticated.
- Linkerd places a small proxy (written in Rust) next to every pod. The application doesn’t notice any of it.
- Authorization in Linkerd:
| Object | Meaning |
|---|---|
| Server | a port of a group of pods, with a default behaviour
(accessPolicy) |
| HTTPRoute | a path on this port |
| MeshTLSAuthentication | “callers with this identity” |
| NetworkAuthentication | “callers from this network” (also without the mesh) |
| AuthorizationPolicy | connects a target (Server or route) with allowed callers |
- Linkerd needs the CRDs of the Gateway API – at most version 1.5.1. The latest, 1.7.0, is not yet supported by Linkerd.
Drill 1: Gateway API and CLI
# on cp1
mkdir -p ~/cnpe/tag15 && cd ~/cnpe/tag15
# Gateway API CRDs, standard channel; --server-side because of the size of the CRDs
k apply --server-side -f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.5.1/standard-install.yaml
# Linkerd CLI directly from the GitHub release instead of "curl … | sh"
ARCH=$(dpkg --print-architecture)
curl -sSfL -o /tmp/linkerd \
https://github.com/linkerd/linkerd2/releases/download/edge-26.11.3/linkerd2-cli-edge-26.11.3-linux-$ARCH
# Compare the checksum with the one GitHub shows for the release asset
sha256sum /tmp/linkerd
sudo install -m 755 /tmp/linkerd /usr/local/bin/linkerd
linkerd version --client
# Pre-flight check of the cluster
linkerd check --pre | tail -2Expected (abridged):
...
validatingadmissionpolicybinding.admissionregistration.k8s.io/safe-upgrades.gateway.networking.k8s.io serverside-applied
474466af61cb16b1d411032e75fe758055c8f31354bbd54be658ea8ff9055cb0 /tmp/linkerd
Client version: edge-26.11.3
Status check results are √
The checksum is listed on the release page for every asset;
gh api repos/linkerd/linkerd2/releases/tags/edge-26.11.3 --jq '.assets[].digest'
shows it as well. The open Linkerd project now only publishes
edge releases; stable versions come from vendors.
Save your progress? Sign up for free
Drill 2: Install Linkerd
# on cp1
# first the CRDs, then the control plane
linkerd install --crds | k apply -f -
# controllerReplicas=1 one replica per component is enough in the lab
# priorityClassName=… platform service (Day 2)
linkerd install --set controllerReplicas=1 --set priorityClassName=plattform-kritisch | k apply -f -
linkerd check | tail -2
k -n linkerd get podsExpected (abridged):
Status check results are √
NAME READY STATUS RESTARTS AGE
linkerd-destination-b9d5976b8-c9cr8 4/4 Running 0 70s
linkerd-identity-7dbd49fd97-knx2p 2/2 Running 0 70s
linkerd-proxy-injector-866d94b9b-9t49r 2/2 Running 0 69s
identity issues certificates, destination tells the proxies where to go and under which rules, proxy-injector adds the proxy to every pod at creation time.
Save your progress? Sign up for free
Drill 3: Team Blue into the mesh
# on cp1
# all new pods in team-blue get a proxy
k annotate ns team-blue linkerd.io/inject=enabled
# restart existing pods so that the injector catches them
k -n team-blue rollout restart deploy/podinfo deploy/web
k -n team-blue rollout status deploy/podinfo --timeout=180s
k -n team-blue get events --field-selector reason=FailedCreate -o custom-columns=MSG:.message --no-headers | tail -1Expected:
namespace/team-blue annotated
deployment.apps/podinfo restarted
deployment.apps/web restarted
Waiting for deployment "podinfo" rollout to finish: 1 out of 2 new replicas have been updated...
error: timed out waiting for the condition
(combined from similar events): Error creating: pods "web-c68954b95-zdmqd" is forbidden: exceeded quota: team-quota, requested: limits.cpu=1, used: limits.cpu=3600m, limited: limits.cpu=4
The proxy is an additional container – without its own settings it gets the defaults of the LimitRange (500 m CPU limit). Suddenly every pod costs 0.5 CPU more quota. Linkerd takes resources for the proxy from annotations, including on the namespace:
# on cp1
k annotate ns team-blue config.linkerd.io/proxy-cpu-request=10m config.linkerd.io/proxy-cpu-limit=100m \
config.linkerd.io/proxy-memory-request=20Mi config.linkerd.io/proxy-memory-limit=64Mi
k -n team-blue rollout restart deploy/podinfo deploy/web
k -n team-blue rollout status deploy/podinfo --timeout=180s
k -n team-blue rollout status deploy/web --timeout=180s
P=$(k -n team-blue get pod -l app=podinfo -o jsonpath='{.items[0].metadata.name}')
# Containers and init containers with resources
k -n team-blue get pod $P \
-o jsonpath='{range .spec.initContainers[*]}init {.name}: {.resources}{"\n"}{end}{range .spec.containers[*]}{.name}: {.resources}{"\n"}{end}'Expected:
namespace/team-blue annotated
deployment.apps/podinfo restarted
deployment.apps/web restarted
deployment "podinfo" successfully rolled out
deployment "web" successfully rolled out
init linkerd-init: {"limits":{"cpu":"100m","memory":"64Mi"},"requests":{"cpu":"10m","memory":"20Mi"}}
init linkerd-proxy: {"limits":{"cpu":"100m","memory":"64Mi"},"requests":{"cpu":"10m","memory":"20Mi"}}
podinfo: {"limits":{"cpu":"200m","memory":"128Mi"},"requests":{"cpu":"20m","memory":"32Mi"}}
linkerd-proxy is listed among the init
containers – as a “native sidecar”
(restartPolicy: Always): it starts before the application
and keeps running alongside it.
Save your progress? Sign up for free
Drill 4: Prove mTLS
A client calls podinfo every two seconds, with its own
ServiceAccount – that is its identity:
# on cp1
cat > kunde.yaml <<'EOF'
apiVersion: v1
kind: ServiceAccount
metadata:
name: kunde
namespace: team-blue
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: kunde
namespace: team-blue
spec:
selector:
matchLabels: {app: kunde}
template:
metadata:
labels: {app: kunde}
spec:
serviceAccountName: kunde
containers:
- name: curl
image: curlimages/curl:8.17.0
command: ["sh", "-c", "while true; do curl -s -o /dev/null -w \"%{http_code}\\n\" http://podinfo:9898/; sleep 2; done"]
resources:
requests: {cpu: 10m, memory: 16Mi}
limits: {cpu: 50m, memory: 32Mi}
EOF
k apply -f kunde.yaml
k -n team-blue rollout status deploy/kunde --timeout=120s
sleep 20
k -n team-blue logs deploy/kunde -c curl --tail=2
# Metrics of podinfo's proxy: inbound requests on port 9898 with TLS status and sender
linkerd diagnostics proxy-metrics -n team-blue deploy/podinfo | grep '^request_total{direction="inbound"' | grep 9898 \
| grep -o -E 'tls="[a-z_]+"|client_id="[^"]*"' | sort | uniq -cExpected:
serviceaccount/kunde created
deployment.apps/kunde created
deployment "kunde" successfully rolled out
200
200
2 client_id="kunde.team-blue.serviceaccount.identity.linkerd.cluster.local"
2 tls="no_identity"
2 tls="true"
tls="true" with the client’s client_id:
mTLS, both sides authenticated. tls="no_identity" are the
scrapes from Prometheus – Prometheus is not in the mesh and speaks plain
text.
Save your progress? Sign up for free
Drill 5: Only the client may call
# on cp1
cat > autorisierung.yaml <<'EOF'
apiVersion: policy.linkerd.io/v1beta3
kind: Server
metadata:
name: podinfo-http
namespace: team-blue
spec:
podSelector:
matchLabels: {app: podinfo}
port: 9898
proxyProtocol: HTTP/1
accessPolicy: deny # without a matching rule: reject
---
apiVersion: policy.linkerd.io/v1alpha1
kind: MeshTLSAuthentication
metadata:
name: nur-kunde
namespace: team-blue
spec:
identityRefs:
- kind: ServiceAccount
name: kunde
---
apiVersion: policy.linkerd.io/v1alpha1
kind: AuthorizationPolicy
metadata:
name: podinfo-fuer-kunde
namespace: team-blue
spec:
targetRef: # applies to the whole Server
group: policy.linkerd.io
kind: Server
name: podinfo-http
requiredAuthenticationRefs:
- group: policy.linkerd.io
kind: MeshTLSAuthentication
name: nur-kunde
EOF
k apply -f autorisierung.yaml
sleep 10
k -n team-blue logs deploy/kunde -c curl --tail=2Expected:
server.policy.linkerd.io/podinfo-http created
meshtlsauthentication.policy.linkerd.io/nur-kunde created
authorizationpolicy.policy.linkerd.io/podinfo-fuer-kunde created
200
200
And a pod outside the mesh? Because of the quota it needs small limits, plus the annotation that prevents the proxy:
# on cp1
k -n team-blue run fremd --image=curlimages/curl:8.17.0 --restart=Never --overrides='{
"metadata":{"annotations":{"linkerd.io/inject":"disabled"}},
"spec":{"containers":[{"name":"fremd","image":"curlimages/curl:8.17.0",
"command":["curl","-s","-o","/dev/null","-w","%{http_code}\n","-m","5","http://podinfo:9898/"],
"resources":{"limits":{"cpu":"50m","memory":"32Mi"}}}]}}'
sleep 10
k -n team-blue logs fremd
k -n team-blue delete pod fremd --nowExpected:
pod/fremd created
403
pod "fremd" deleted from team-blue namespace
And monitoring?
# on cp1
sleep 40
curl -s 'http://172.16.0.126:30090/api/v1/targets?state=active' \
| jq -r '.data.activeTargets[] | select(.labels.job=="podinfo") | "\(.health) \(.lastError)"'Expected:
down server returned HTTP status 403 Forbidden
down server returned HTTP status 403 Forbidden
Prometheus is locked out – same port, same Server. A rule for the whole port is too coarse.
Save your progress? Sign up for free
Drill 6: Rules per path
Two HTTPRoutes split the port into
/metrics and the rest. For /metrics, origin
from the pod network is enough; for the application, the client’s
identity is required.
# on cp1
cat > metriken.yaml <<'EOF'
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: podinfo-metriken
namespace: team-blue
spec:
parentRefs: # route attaches to the Linkerd Server, not to a Gateway
- group: policy.linkerd.io
kind: Server
name: podinfo-http
rules:
- matches:
- path: {type: Exact, value: /metrics}
---
apiVersion: gateway.networking.k8s.io/v1
kind: HTTPRoute
metadata:
name: podinfo-anwendung
namespace: team-blue
spec:
parentRefs:
- group: policy.linkerd.io
kind: Server
name: podinfo-http
rules:
- matches:
- path: {type: PathPrefix, value: /}
---
apiVersion: policy.linkerd.io/v1alpha1
kind: NetworkAuthentication
metadata:
name: pod-netz
namespace: team-blue
spec:
networks:
- cidr: 10.244.0.0/16 # pod network from Day 0
---
apiVersion: policy.linkerd.io/v1alpha1
kind: AuthorizationPolicy
metadata:
name: metriken-fuer-prometheus
namespace: team-blue
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: podinfo-metriken
requiredAuthenticationRefs:
- group: policy.linkerd.io
kind: NetworkAuthentication
name: pod-netz
---
apiVersion: policy.linkerd.io/v1alpha1
kind: AuthorizationPolicy
metadata:
name: anwendung-fuer-kunde
namespace: team-blue
spec:
targetRef:
group: gateway.networking.k8s.io
kind: HTTPRoute
name: podinfo-anwendung
requiredAuthenticationRefs:
- group: policy.linkerd.io
kind: MeshTLSAuthentication
name: nur-kunde
EOF
k apply -f metriken.yaml
sleep 50
curl -s 'http://172.16.0.126:30090/api/v1/targets?state=active' \
| jq -r '.data.activeTargets[] | select(.labels.job=="podinfo") | "\(.health) \(.lastError)"'
k -n team-blue logs deploy/kunde -c curl --tail=2Expected:
httproute.gateway.networking.k8s.io/podinfo-metriken created
httproute.gateway.networking.k8s.io/podinfo-anwendung created
networkauthentication.policy.linkerd.io/pod-netz created
authorizationpolicy.policy.linkerd.io/metriken-fuer-prometheus created
authorizationpolicy.policy.linkerd.io/anwendung-fuer-kunde created
up
up
200
200
As soon as routes are attached to a Server, only the routes’ rules
apply – podinfo-fuer-kunde (on the Server) no longer plays
a role.
Save your progress? Sign up for free
Exercise: Who may do what?
Time limit: 5 minutes. Using the pod outside the mesh, test both
paths: / and /metrics.
Solution
# on cp1
for p in / /metrics; do
k -n team-blue run fremd --image=curlimages/curl:8.17.0 --restart=Never --overrides="{
\"metadata\":{\"annotations\":{\"linkerd.io/inject\":\"disabled\"}},
\"spec\":{\"containers\":[{\"name\":\"fremd\",\"image\":\"curlimages/curl:8.17.0\",
\"command\":[\"curl\",\"-s\",\"-o\",\"/dev/null\",\"-w\",\"%{http_code}\\\\n\",\"-m\",\"5\",\"http://podinfo:9898$p\"],
\"resources\":{\"limits\":{\"cpu\":\"50m\",\"memory\":\"32Mi\"}}}]}}" >/dev/null
sleep 10
echo "$p: $(k -n team-blue logs fremd)"
k -n team-blue delete pod fremd --now >/dev/null
doneExpected:
/: 403
/metrics: 200
/metrics is open to every pod in the pod network –
including the foreign one. It would be better to bring Prometheus into
the mesh and restrict /metrics to its identity (Enterprise
Note).
Save your progress? Sign up for free
Challenge
Time limit: 10 minutes. The NetworkPolicy
allow-same-namespace (Day 9) and the Linkerd rules both
allow something. Which layer decides first, and what happens when a pod
from team-green in the mesh calls podinfo?
Solution
First the NetworkPolicy (Cilium, layer 3/4): packets
from team-green never reach team-blue at all
(default-deny-ingress), and podinfo’s proxy
never sees the connection – a timeout instead of a 403. Only if the
NetworkPolicy lets the connection through does Linkerd (layer 7) decide
by identity and path. The two layers complement each other:
NetworkPolicy for coarse zones, Linkerd for fine-grained permissions
between services.
Save your progress? Sign up for free
Checkpoint
# on cp1
linkerd check --proxy -n team-blue | tail -1
k -n team-blue get server,authorizationpolicy,httproute -o name | wc -l
k -n team-blue logs deploy/kunde -c curl --tail=1
curl -s 'http://172.16.0.126:30090/api/v1/targets?state=active' | jq '[.data.activeTargets[] | select(.health!="up")] | length'Expected:
Status check results are √
6
200
0
Interview Note
- What does mTLS bring inside the cluster if the network is internal? Encryption against eavesdropping on nodes and in the network – and above all identity: permissions by “who is calling”, not by IP.
- NetworkPolicy or mesh authorization? Both: L3/L4 for coarse zones and as protection in case the proxy is bypassed; L7 for permissions per service and path.
- What does a mesh cost? One proxy per pod (CPU, memory, quota), some latency, another control plane – and certificate maintenance.
Enterprise Note
- Generate the trust anchor yourself and rotate it with cert-manager, instead of using the installation certificates.
- Bring Prometheus into the mesh and restrict
/metricsto its identity viaMeshTLSAuthentication. accessPolicy: denyas the default for whole namespaces (config.linkerd.io/default-inbound-policy) and rules via GitOps.- Set proxy resources centrally (Kyverno mutation or Helm values) so that mesh and quota fit together.