Zero Trust, Segmentation, and Service-to-Service Security Questions
Designing network and service-communication trust models where no implicit trust is granted by network location. Covers zero-trust access, microsegmentation and identity-aware perimeters, least-privilege network access, lateral-movement prevention, and segmenting environments to contain blast radius, together with securing service-to-service communication in distributed and microservices architectures: mutual authentication between services, service mesh security, multi-tenancy isolation, east-west traffic, and the security implications of scale and geographic distribution. The architectural trust-boundary pattern and its enforcement across decomposed, high-scale systems, distinct from device-level firewall configuration.
Explain the roles of a Policy Decision Point (PDP) and a Policy Enforcement Point (PEP) in a zero-trust system. Walk through a concrete example: a user requests access to an internal API, the PEP collects attributes and forwards them to the PDP, the PDP evaluates policy, and the PEP enforces the decision. What caching and latency considerations does this introduce?
Sample Answer
Direct answer
A policy decision point (PDP) is the component that evaluates access policy and decides allow or deny; a policy enforcement point (PEP) sits in the request path, gathers the attributes the PDP needs, asks it for a decision, and then actually applies that decision. The PDP decides, the PEP enforces, and separating the two means you can change policy logic without touching every service that has to enforce it.
Structured elaboration
Walking through the concrete example:
- A user's client sends a request to an internal API.
- The PEP, commonly a sidecar proxy or an API gateway sitting in front of the service, intercepts the request before it reaches the API's own code.
- The PEP collects attributes: who is asking (identity or token), what they are asking for (resource, action), and context (device posture, time, source network).
- The PEP forwards those attributes to the PDP, either over the network or via a local policy evaluation call.
- The PDP evaluates the applicable policy against those attributes and returns a decision: allow, deny, or allow-with-conditions, such as requiring step-up authentication.
- The PEP enforces that decision, forwarding the request to the internal API if allowed, or returning an error response if denied.
Caching and latency considerations: every request that follows this flow adds at least one extra hop, PEP to PDP, before the real work even starts. If the PDP is remote and every decision requires a fresh network round trip, that hop can become the largest single contributor to the request's total latency, sometimes larger than the actual business logic. The standard fix is caching at the PEP: either the whole allow or deny result for a short time-to-live (TTL), or, more scalable, caching just the policy rules locally and evaluating them in-process without a network call at all. Caching introduces a staleness trade-off: a decision or policy cached for, say, 30 seconds can still honor a permission that was revoked seconds after the cache was populated, such as a terminated employee's access. The mitigation is either a short TTL for anything security-sensitive, or an active invalidation mechanism where the PDP pushes urgent changes to PEPs immediately rather than relying purely on expiry.
Worked example
Suppose a call to the PDP over the network takes a few milliseconds round trip. If a single user action fans out into three internal calls, each independently checked at its own PEP, that adds roughly three PDP round trips of latency stacked on top of the actual work, which can dominate the cost of an otherwise lightweight request. If each PEP instead evaluates policy against a locally cached policy set refreshed every few seconds, rather than calling the PDP synchronously per request, the per-call cost drops to an in-process check, and the three-hop request only pays for infrequent background policy refreshes instead of three live network round trips.
Trade-offs and pitfalls
Over-aggressive local caching without a way to push urgent revocations, a fired employee, a leaked service credential, is the most common mistake: a fast system enforcing a decision it has not actually re-checked recently is not doing continuous authorization, it is doing periodic authorization with a fast cache in front of it.
What are the trade-offs between enforcing authentication and authorization at a centralized API gateway versus distributing that check to each microservice? Discuss performance, consistency, and what happens when each option fails.
Sample Answer
Direct answer: a centralized gateway gives one place to get authentication and authorization right, at the cost of every internal call behind it being implicitly trusted once past the gateway, which recreates the flat-trust problem zero trust exists to remove. Distributed per-service checks avoid that blind spot, but only if every team actually implements them correctly and consistently.
Performance: a gateway does the identity and authorization check once, up front, so calls deeper in the system skip that cost, but it adds a mandatory hop at the edge and concentrates load there, so the gateway's own capacity and latency become a shared tax on every request. Distributed per-service checks spread that cost across every hop instead, more total verification work happens across a multi-hop call chain, but no single component carries all of it.
Consistency: a gateway enforces one policy in one codebase, easy to reason about and audit, but only for traffic that actually goes THROUGH it, anything reaching a service directly, another internal caller, a misconfigured route, bypasses the check entirely. Distributed checks mean every service must implement authorization correctly, consistency now depends on every team doing it right, a real and common source of drift, one service forgets a check or implements it slightly differently than its neighbors.
What happens when each fails: if the gateway goes down or is misconfigured, the choice is between failing CLOSED, every request behind it is blocked, an availability incident, or failing OPEN, every request behind it goes unchecked, a security incident, and gateways are frequently configured to fail open under load without anyone deciding that deliberately. If one service behind the gateway is compromised, it can typically call any other internal service freely, because internal traffic was never independently checked, exactly the scenario zero trust's "never trust the network, even the inside of it" principle targets.
Recommendation: use the gateway for coarse, perimeter-facing checks, who is allowed into the system at all, rate limiting, basic authentication, but still require every internal service to independently verify its caller's identity and check its own authorization rules, treating the gateway as one useful layer of defense, not the only layer.
Worked example: a request passes the gateway's authentication check and is forwarded to a billing-service, which in turn calls an accounts-service internally. If only the gateway checks identity, a compromised billing-service, say through an unrelated vulnerability, can call accounts-service with no additional check at all, since accounts-service was built assuming anything reaching it internally already passed the gateway. If accounts-service also independently verifies the caller's identity, for example via mutual TLS and its own authorization policy, rather than trusting that the call arrived from inside the network, the compromised billing-service is still constrained to only the specific calls accounts-service explicitly allows it to make.
Trade-offs & pitfalls: teams often adopt a gateway specifically to avoid writing per-service auth logic, so recommending both is a real cost, budget for it rather than assuming it is automatic. The most common actual failure is not choosing the wrong model, it is the silent gap where some internal path bypasses the gateway entirely and nobody separately checks it, leaving an unauthenticated hole neither layer covers.
How should an API gateway enforce zero-trust controls at the edge of a system: token validation, scope/claim-based authorization integrated with a policy decision point, input validation, and rate limiting? What must still be enforced by the backend services themselves?
Sample Answer
Direct answer
An API gateway should handle the checks that make sense to do once, at the edge, before a request reaches any backend service: validating the request's token, checking coarse-grained scopes or claims against a policy decision point, and applying input validation and rate limiting. It cannot be the only enforcement point, though; backend services still need to independently authorize the specific action being requested, because a gateway can't reason about business-logic-specific authorization that only the service itself understands.
Structured elaboration
- Token validation: the gateway verifies the request carries a valid, unexpired, correctly signed identity token before doing anything else, rejecting malformed or expired tokens immediately and cheaply at the edge, rather than every backend service redundantly re-implementing that same check.
- Scope or claim-based authorization integrated with a policy decision point (PDP): beyond confirming a token is valid, the gateway checks whether its claims and scopes are sufficient for the requested endpoint, in some designs by consulting the PDP directly, so coarse-grained access decisions, whether this identity can call this API at all, happen once at the gateway rather than being reimplemented per service.
- Input validation: the gateway rejects malformed requests, wrong types, oversized payloads, invalid characters, before they reach a backend service's own parsing logic, reducing the attack surface each service has to defend on its own.
- Rate limiting: the gateway throttles request volume per identity or client, protecting backend services from a misbehaving client or a deliberate abuse pattern, again more efficient to enforce once at a shared edge than duplicated everywhere.
What must still be enforced by the backend services themselves: the gateway can confirm identity and coarse access, that a token is allowed to call the orders API, for example, but it generally cannot know fine-grained, resource-specific, business-logic-dependent rules: whether this specific user may view this specific order they did not create, whether an account's current state permits a specific action, or anything that depends on data only the service has. Those checks have to happen in the service itself, at the point where it actually holds the relevant data. Otherwise you get a well-known class of bug where the gateway correctly confirms a request is allowed to call an endpoint, but the service forgets to check whether the specific resource in that request actually belongs to the caller, sometimes called broken object-level authorization, precisely because it's easy to assume the gateway already handled "authorization" when it only handled the coarser layer.
Worked example
A request arrives for a specific order's details, with a valid token belonging to user A. The gateway validates the token, confirms it is unexpired, checks that its scope includes reading orders, confirms the request is well-formed, and checks that user A hasn't exceeded their rate limit, then forwards the request to the orders service. All of that is legitimate and correctly enforced at the gateway. But the requested order actually belongs to user B, not user A. If the orders service assumes the gateway already handled authorization and simply returns whatever order matches the identifier in the request, user A can read user B's order despite every gateway-level check passing correctly, because the gateway had no way to know which specific order belongs to which specific user, only the orders service, with access to that data, can make that check.
Trade-offs and pitfalls
The most common and serious mistake is exactly the example above: treating gateway-level scope checks as equivalent to full authorization and skipping the service-level ownership check, which produces vulnerabilities that pass every gateway-level test because the gateway was never the layer that could have caught them.
Compare the main approaches for authenticating one service to another: mutual TLS via a service mesh with workload identities (e.g. SPIFFE/SPIRE), signed JWTs issued by a central authority, and cloud-native IAM roles or client certificates. What's the trust model, key-rotation story, and operational overhead for each, and how would you decide between them for a multi-team, multi-namespace environment?
Sample Answer
Direct answer: the three approaches sit on a spectrum from infrastructure-managed identity (mutual TLS via a mesh) to application-issued identity (signed tokens) to cloud-managed identity (native identity and access management, IAM, roles), and for a multi-team, multi-namespace environment the right choice usually is not picking one, it is using mesh-based mutual TLS for baseline service-to-service trust, then layering the other two in for specific needs like cross-cloud calls or user-context propagation.
Mutual TLS via service mesh with workload identities (for example SPIFFE/SPIRE, a standard and implementation for issuing cryptographic workload identities): trust is rooted in a shared certificate authority (CA) every workload and the mesh agree on, and each workload gets a short-lived certificate tied to its identity. Rotation is automatic and frequent, minutes to hours, handled transparently by sidecar proxies. Operational overhead is highest to stand up (control plane, CA infrastructure, sidecar injection) but lowest ongoing per call, since verification happens at the network layer with no app code changes.
Signed JSON Web Tokens (JWTs) from a central authority: a central issuer signs tokens, and any verifier trusting the issuer's public key validates a token locally, no callback needed. The issuer rotates its own signing key on a schedule, published via a key-set endpoint verifiers refresh; the tokens themselves are simply re-issued rather than "rotated." Operational overhead is low to start, but every service must correctly validate audience, expiry, and issuer itself, a per-service correctness burden instead of a centralized one.
Cloud-native IAM roles or client certificates: the cloud platform attests that a given piece of compute is who it claims to be, based on the platform's own control plane, and hands out short-lived credentials on request, fully managed rotation, no certificate files for engineers to touch. Overhead is lowest for workloads staying inside one cloud provider, but this does not natively extend across clouds or to on-premises workloads, and ties your identity model to that provider's semantics.
Deciding for a multi-team, multi-namespace environment: if most traffic is service-to-service inside one platform, mesh-based mutual TLS gives every team the same baseline identity and encryption without each team writing its own auth code, which matters more as team count grows. Add signed JWTs where a human user's identity or fine-grained claims need to travel through a call chain. Reach for native cloud IAM roles specifically at the boundary where a workload calls a CLOUD service, a storage bucket, a managed queue, not another one of your own services, since that is the boundary the cloud provider's identity model is actually built for.
Worked example (a cloud-IAM branch in practice): a nightly batch job running as a Kubernetes pod needs to read from a cloud storage bucket. Instead of embedding a static access key, the pod's service account is federated to a cloud IAM role, for example AWS's IAM Roles for Service Accounts (IRSA), and at startup the job exchanges a short-lived, automatically-rotated token for temporary credentials from the cloud's Security Token Service (STS), typically valid for under an hour. If the pod is compromised, the exposed credential expires within that window, rather than being a static key that works indefinitely until someone manually revokes it.
Trade-offs & pitfalls: mixing all three without a clear rule for which is used when is itself a common failure, teams pick whichever they found a tutorial for, and you end up auditing three inconsistent identity systems instead of one. Cloud-native IAM roles are the easiest of the three to reach for and the easiest to over-scope, since there is no mesh-level review step forcing a second set of eyes on the grant.
Compare JSON Web Tokens and opaque tokens for service authentication: local verification versus introspection, how each is revoked, size and transport considerations, and when you'd prefer one over the other. What common mistakes should a reviewer look for when a service validates a JWT (algorithm confusion, missing audience or expiry checks)?
Sample Answer
Direct answer: a JSON Web Token (JWT) is self-contained and verified locally with a signature check, fast, no network call needed, but hard to revoke early. An opaque token is a meaningless random string that must be looked up (introspected) against the issuing server on every use, slower and an added dependency, but instantly revocable by deleting it server-side.
Local verification versus introspection: a JWT's verifier checks its cryptographic signature against the issuer's public key locally, no network call per request. An opaque token carries no embedded meaning, so the verifier must call the issuing server's introspection endpoint to ask whether it is still valid, on every use.
Revocation: a JWT is hard to revoke before its natural expiry, since any verifier holding the issuer's public key validates it independently, options are keeping expiry very short, or maintaining a deny-list every verifier must also check, which erodes the "no network call" advantage. An opaque token is trivially revocable, delete or invalidate the record in the issuer's store and every future introspection call immediately reports it invalid.
Size and transport: a JWT is bigger, a header, a payload of claims, and a signature, all base64-encoded, and this adds up if it rides along on many internal calls. An opaque token is small, just an identifier, cheap to pass around.
When to prefer each: prefer JWTs when many verifiers need to check tokens fast and independently, without a hot-path dependency on a central auth server, and when the token's lifetime can be kept short enough that limited revocability is not a real risk. Prefer opaque tokens with introspection when you need to instantly kill a specific session or credential, a compromised account, a departed employee's access, or when you do not want token contents exposed to anyone who can read the token in transit or in logs.
Common JWT validation mistakes a reviewer should look for:
- Algorithm confusion: trusting the
algfield the token itself claims instead of pinning the expected algorithm, this is how a server ends up accepting a token signed withnone, or gets tricked into verifying a forged token using its OWN public key as if it were a shared secret. - Missing audience (
aud) check: without verifying the token was issued FOR this specific service, a valid token minted for one internal service can be replayed against a different service that trusts the same issuer. - Missing or ignored expiry (
exp) check: a technically expired token is still accepted because the timestamp claim is never checked. - Missing or mismatched issuer (
iss) check when multiple issuers are trusted: a token from a lower-trust issuer gets accepted where only a specific higher-trust issuer should be.
Worked example: a reviewer should specifically confirm the code hardcodes an expected algorithm, for example explicitly requiring RS256 rather than reading alg from the token, explicitly compares the aud claim against an expected value, and explicitly checks exp, rather than trusting a library's defaults without confirming what those defaults enforce. Library defaults on this have changed across versions and ecosystems, so "we used a JWT library" is not itself something you can verify without reading the actual validation call.
Trade-offs & pitfalls: teams sometimes treat "JWT" and "secure" as synonyms, an improperly validated JWT is not safer than an opaque token, it is often worse, because it looks cryptographically strong while actually accepting forged tokens. Long-lived JWTs adopted because "introspection was too slow" reintroduce the exact revocation problem opaque tokens exist to solve.
Unlock Full Question Bank
Get access to all 15 Zero Trust, Segmentation, and Service-to-Service Security interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.