Skip to main content
This guide walks through a common interview-style scenario and a practical, layered strategy to secure an internal-only microservice. Scenario
  • You run a payments service that should only be called by trusted internal services (for example, the order service).
  • Public users or anything on the internet must never reach the payments service directly.
  • When a user places an order, the order service calls the payments service to charge the card. That is the only legitimate caller.
Goal
  • Ensure the payments service has no public exposure.
  • Prevent lateral attacks inside the cluster.
  • Enforce cryptographic identity for services.
  • Apply fine-grained authorization so only intended callers reach specific endpoints.
Defense-in-depth: each layer reduces risk and compensates for gaps in others.
  1. Network exposure: remove any public address
  • First, ensure the payments service does not receive a public IP or direct internet exposure.
  • In Kubernetes, use a ClusterIP Service (the default) instead of LoadBalancer or NodePort so the service is not reachable from outside the cluster.
Example Service manifest (explicit ClusterIP):
This prevents external traffic from directly reaching the payments pods. However, most cluster overlay networks are “flat by default”: any pod can attempt to connect to any other pod unless additional controls are applied.
A diagram titled "FLAT BY DEFAULT" showing a Kubernetes cluster with pods/services labeled Marketing Web, Order Service, and Payments Service. A red arrow indicates an attacker entering via the Marketing Web pod and moving laterally toward the Order Service.
  1. NetworkPolicy: pod-level firewall to restrict which pods may connect
  • Kubernetes NetworkPolicy is an allow-list model. When you attach an ingress policy to the payments pods, only explicitly allowed sources can reach them.
  • NetworkPolicy blocks unwanted pod-to-pod connections at the network layer, reducing the blast radius if a frontend pod is compromised.
Example NetworkPolicy that permits only pods labeled app=order to talk to payments on port 8443:
With this policy, a compromised Marketing pod will have its traffic dropped at the cluster network layer—provided your CNI plugin enforces NetworkPolicy.
A dark-themed diagram showing a Kubernetes cluster with pods labeled "Marketing Web", "Order Service", and "Payments Service" and a network policy (netpol) icon. The title reads "Layer 2 · Network Policy" and a rule box on the right shows "ALLOW label = order-service."
NetworkPolicy limitations
  • NetworkPolicy enforces connectivity based on selectors that resolve to pod IPs; IPs are not strong cryptographic identities.
  • A network-level allow-list does not verify the caller at the application level (who is making the request and whether they are authorized to call a specific API).
A dark-themed diagram of a Kubernetes cluster showing pods (Marketing Web, Order Service, Payments Service) and a network policy (netpol) icon. The graphic emphasizes “IP is not identity,” illustrating an example IP (10.4.2.7) that can belong to different pods over time.
  1. Mutual TLS (mTLS): cryptographic service identity and transport security
  • mTLS ensures both client and server present and verify certificates. Every connection is authenticated and encrypted.
  • Use short-lived certificates issued to each service instance. With mTLS, attackers inside the cluster without valid certs cannot impersonate a legitimate service.
In practice, many teams use a service mesh to implement mTLS (examples: Istio, Linkerd). The mesh injects a sidecar proxy next to each pod. The sidecar handles certificate issuance, rotation, verification, and encryption so application code remains unchanged.
A stylized diagram titled "Layer 3 · Mutual TLS" showing a Kubernetes cluster with an Order Service (caller) and Payments Service (receiver) exchanging secured traffic. The graphic also depicts TLS certificates/locks and an attacker trying to intercept or spoof messages.
Who issues certificates?
  • The mesh control plane typically operates as a certificate authority (CA) or integrates with an internal CA. It issues short-lived identities (SPIFFE/SPIRE or an equivalent) to proxies and enforces mTLS automatically for service-to-service traffic.
  • Because certs rotate frequently and every connection validates identity, attackers cannot trivially replay or forge identities.
A stylized architecture diagram titled "Layer 3 · Service Mesh" showing a Kubernetes cluster with microservices (Order, Payments, Marketing Web) each paired with proxy sidecars, a trusted authority, network policies, and icons for user/internet; a note reads "App code unchanged."
  1. Authorization: fine-grained access control at the application layer
  • Even with mTLS proving a caller’s identity, you should limit which service identities can call which API endpoints.
  • Implement authorization policies in the mesh (or in the application) so the proxy checks identity and intended operation on each request.
Example Istio AuthorizationPolicy that allows only the order service account to POST to the /charge endpoint:
With this policy, the payments proxy enforces:
  • Who is calling (mTLS principal).
  • What operation they are allowed to perform (HTTP method + path).
If a request is from any other principal or targets an unauthorized endpoint (for example /refund), the proxy blocks it.
A stylized architecture diagram titled "Layer 4 · Authorization" showing a Kubernetes cluster with service pods (Marketing Web, Order Service, Payments Service, Refund, Support) and proxy icons. Arrows and badges indicate allowed and blocked connections, with a callout that explicitly allows "order-service → payments."
Checklist: two questions every request should answer
  • Is the caller who it claims to be? (mTLS identity)
  • Is that caller allowed to invoke this API/endpoint? (authorization policy)
Layered summary table References
Summary: Use a ClusterIP (no public endpoint), restrict ingress with Kubernetes NetworkPolicy, enforce cryptographic identities using mutual TLS (typically via a service mesh), and apply fine-grained authorization policies so only the intended service accounts can call specific endpoints.

Watch Video