Identity & Zero Trust for Platform Engineers›06 · Service-to-service authorization

Lesson 06 of 14 · Workload identity

Service-to-service authorization

Decide which service may call which, and how. Compare network-level policy (NetworkPolicy) with identity-based, L7 policy from a mesh, avoid the selector trap that silently opens access, and layer both so one mistake does not expose a service.

Advanced
Key wordsauthorizationNetworkPolicyAuthorizationPolicydefault denyidentity-based policyL7 policynamespaceSelector AND podSelectorAdminNetworkPolicyCiliumdefence in depth

Two questions, two layers

Service-to-service authorisation answers: may this caller reach this service, and may it perform this operation? Kubernetes platforms usually answer it at two layers:

NetworkPolicy (L3/L4) Mesh authorisation (L7, identity)
Question Can these pods' IPs reach those pods on port 8080? May spiffe://…/sa/orders call POST /charge?
Identity used Labels, translated to IPs by the CNI The caller's mTLS-verified SPIFFE ID, plus JWT claims
Enforced by CNI in the kernel (iptables, eBPF) The proxy (sidecar, waypoint)
Can see IPs, ports, protocol Methods, paths, headers, end-user token claims
Failure looks like Timeout (packets dropped) Fast HTTP 403 / RBAC denied

NetworkPolicy is the corridor door: only pupils from certain classes can walk down this corridor at all. Mesh authorisation is the teacher at the classroom door who checks your ID card and the reason you came: "you may hand in homework, but you may not take the register".

NetworkPolicy, done right

Default-deny per namespace, allow DNS, then allow exactly the flows you need (the Kubernetes Security track covers the basics). The trap that catches experienced engineers is the AND/OR selector rule:

# AND: only pods labelled app=orders that are ALSO in namespaces labelled team=shop
ingress:
- from:
  - namespaceSelector: { matchLabels: { team: shop } }
    podSelector: { matchLabels: { app: orders } }
---
# OR: ANY pod in a team=shop namespace, OR any pod labelled app=orders in THIS namespace
ingress:
- from:
  - namespaceSelector: { matchLabels: { team: shop } }
  - podSelector: { matchLabels: { app: orders } }

One dash makes the difference between "one service" and "a whole team's namespaces". Review policies with this in mind, and test them.

Limits of the standard API: no explicit deny, no priorities, no L7, no DNS names, no logging, namespace-scoped only. Extensions fill the gaps:

  • Cilium: identity-aware policy (labels, not IPs), L7 rules for HTTP/gRPC/Kafka, toFQDNs egress, flow logs with Hubble.
  • Calico: global policies, ordered rules with deny.
  • AdminNetworkPolicy / BaselineAdminNetworkPolicy (a SIG Network API): cluster-admin policies with priorities and explicit deny that tenants cannot override, for guard-rails such as "no namespace may reach the metadata service".

Identity-based policy in the mesh

With strict mTLS, every request arrives with a verified caller identity. Make the namespace default-deny, then allow by identity and operation:

apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: allow-nothing
  namespace: shop
spec: {}
---
apiVersion: security.istio.io/v1
kind: AuthorizationPolicy
metadata:
  name: payments-from-orders
  namespace: shop
spec:
  selector:
    matchLabels: { app: payments }
  action: ALLOW
  rules:
  - from:
    - source:
        principals: [ "cluster.local/ns/shop/sa/orders" ]
    to:
    - operation:
        methods: [ "POST" ]
        paths: [ "/charge" ]

The same policy can also require a valid end-user token (RequestAuthentication plus a when condition on claims), combining "which workload is calling" with "on behalf of which user".

Layer them

request from orders → payments
  1. NetworkPolicy:          is orders' pod allowed to reach payments:8080 at all?
  2. mTLS (strict):          is the caller presenting a valid workload certificate?
  3. AuthorizationPolicy:    may sa/orders POST /charge?
  4. Application:            may THIS user charge THIS tenant's account? (business rules)

Each layer catches different mistakes. An attacker with a shell in a pod that has no proxy is stopped by layer 1; a pod with a proxy but the wrong identity by layer 3; a stolen user token for another tenant by layer 4.

Generate the defaults

Make default-deny automatic: a policy engine (Kyverno generate, for example) creates the default-deny NetworkPolicy, the allow-DNS policy and the mesh allow-nothing policy in every new namespace. Teams then add only their allows, through the golden path.

Try it

Deploy orders, payments and a stranger pod in one namespace with a mesh. Apply the two policies above. From orders, POST /charge succeeds and GET /admin returns 403. From stranger, everything returns 403. Then add a NetworkPolicy allowing only orders to reach payments: stranger now times out instead of getting 403. Explain why the symptom changed.

Why the symptom changed

Before the NetworkPolicy, packets from stranger reached the payments proxy, which understood the HTTP request and denied it (403). After it, the CNI drops the packets before any proxy sees them, so the client just waits (timeout).

Recap

  • NetworkPolicy controls reachability (L3/L4); mesh policy authorises verified identities and operations (L7).
  • Watch the AND/OR selector rule; use Cilium, Calico or AdminNetworkPolicy for deny, priorities, L7 and FQDNs.
  • Default-deny at both layers, generated automatically; allow by identity and operation; keep business rules in the app.

This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.