5.1 Defense in Depth
Security is layered across every tier—no single perimeter control is trusted as the sole line of defense; each inner layer assumes that all outer layers could be compromised.
flowchart TD
Internet(["Public Internet Traffic"])
subgraph EdgeLayer["1. Edge & Perimeter"]
WAF["Web Application Firewall (WAF)\n(SQLi, XSS, OWASP Top 10)"]
CDN["CDN & DDoS Shield\n(Cloudflare / AWS Shield)"]
GW["API Gateway\n(Rate Limiting & AuthN Verification)"]
end
subgraph NetworkLayer["2. Network Segmentation (VPC)"]
PublicSubnet["Public Subnet\n(Ingress ALBs / NAT Gateways)"]
PrivateSubnet["Private Subnet\n(App Microservices / Containers)"]
DataSubnet["Data Subnet (Isolated)\n(RDS / Redis - No Internet Egress)"]
end
subgraph DataSec["3. Cryptography & Compliance"]
KMS["Key Management Service (KMS)\n(Envelope Encryption at Rest)"]
Audit["Audit Trails & Flow Logs\n(SIEM / GuardDuty / Splunk)"]
end
Internet --> WAF --> CDN --> GW
GW --> PublicSubnet --> PrivateSubnet --> DataSubnet
DataSubnet -.-> KMS
PrivateSubnet -.-> Audit
DataSubnet -.-> Audit
5.2 Zero Trust Architecture
Zero Trust discards the outdated “trusted corporate network vs. untrusted outside world” model. In modern Zero Trust, every request is untrusted by default, regardless of originating IP or internal network location.
Core Tenets:
- Never Trust, Always Verify: Explicitly authenticate and authorize every RPC hop between internal microservices.
- Least Privilege Enforcement: Grant minimal time-bounded permissions (RBAC / ABAC) and eliminate standing administrative privileges.
- Assume Breach: Architect components with microscopic blast radiuses through VPC micro-segmentation and strict firewall boundaries.
- Context-Driven Verification: Evaluate multi-factor attributes (token signatures, device health posture, telemetry, client certificate validity) on each access request.
5.3 OAuth 2.0 / OIDC (OpenID Connect)
sequenceDiagram
autonumber
actor User
participant Client as SPA / Mobile App
participant IdP as Identity Provider (IdP / OIDC)
participant GW as API Gateway
participant Backend as Microservice
User->>Client: Log In
Client->>IdP: Redirect to Auth Endpoint
IdP-->>Client: Returns ID Token + Access Token (JWT)
Client->>GW: API Request + Bearer JWT
Note over GW: Validates Signature (JWKS), Expiry, & Audience
GW->>Backend: Forward Authorized Request + User Context Header
Backend-->>GW: Business Data Response
Backend-->>Client: HTTP 200 OK
Key JWT Validation Checks:
- Signature Integrity: Verifies HMAC/RSA cryptographic signature against the IdP’s JSON Web Key Set (
/.well-known/jwks.json). - Expiration (
exp): Enforces short-lived token lifetimes (e.g., 15 minutes) with clock-skew buffer limits. - Audience (
aud): Confirms the token was explicitly generated for this target API resource. - Issuer (
iss): Ensures trust originates only from authorized enterprise identity authorities. - Claims & Roles (
scp/roles): Validates fine-grained tenant boundaries and caller permissions.
// JWT validation in ASP.NET Core
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.Authority = "https://login.identityprovider.com/{tenantId}/v2.0";
options.Audience = "api://my-api-client-id";
options.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidateAudience = true,
ValidateLifetime = true,
ClockSkew = TimeSpan.FromMinutes(1)
};
});
[Authorize(Roles = "Admin,Manager")]
[HttpDelete("orders/{id}")]
public async Task<IActionResult> DeleteOrder(int id) { /* ... */ }
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("CanManageOrders", policy =>
policy.RequireClaim("department", "operations").RequireRole("Manager"));
});
OAuth 2.0 vs. OIDC Distinction:
- OAuth 2.0: Framework for Authorization (“What actions is this client allowed to perform?”).
- OIDC: Protocol layer atop OAuth 2.0 for Authentication (“Who is the human identity using this client?”).
5.4 mTLS (Mutual TLS)
Standard TLS exclusively authenticates the server to the client. Mutual TLS (mTLS) mandates bidirectional certificate exchange: both client and server validate each other’s cryptographic certificates.
flowchart LR
subgraph PodA["Service Pod A"]
SvcA["Service A Code"]
EnvoyA["Envoy Sidecar Proxy"]
SvcA -->|Localhost Plain HTTP| EnvoyA
end
subgraph MeshNetwork["Service Mesh (Istio / Linkerd)"]
EnvoyA <-->|mTLS Encrypted & Mutually Authenticated Wire| EnvoyB
end
subgraph PodB["Service Pod B"]
EnvoyB["Envoy Sidecar Proxy"]
SvcB["Service B Code"]
EnvoyB -->|Localhost Plain HTTP| SvcB
end
5.5 Security Architecture Reference Table
| Control | Layer | Purpose |
|---|---|---|
| WAF | Edge | Block known web attack signatures |
| CDN / Anti-DDoS | Edge | Absorb volumetric attacks, shield origin |
| API Gateway auth | Perimeter | Centralized JWT/OAuth validation, rate limiting |
| Network segmentation (public/private/data subnets) | Network | Limit blast radius, no direct DB internet access |
| mTLS / Service Mesh | Service-to-service | Zero Trust internal communication |
| KMS / encryption at rest | Data | Protect data even if storage is exfiltrated |
| RBAC / ABAC | Application | Least-privilege authorization |
| Audit logging / SIEM | Cross-cutting | Detection, forensics, compliance evidence |
5.6 Section 5 — Interview Q&A
Q1: Explain Zero Trust and how it changes microservices design compared to a traditional perimeter security model.
A: Traditional perimeter security assumes anything inside the network boundary is trusted — a service behind the firewall can call another service with little or no additional authentication. Zero Trust removes that assumption entirely: every call, including internal service-to-service calls, must be authenticated and authorized on its own merits, because the model assumes the perimeter will eventually be breached and a compromised internal component shouldn’t automatically gain trust everywhere else. In practice, this means every microservice presents and validates identity via mTLS (usually via a service mesh sidecar so it’s not bolted onto each service individually), every call carries a token that’s checked against fine-grained authorization policy, and network segmentation limits lateral movement so a compromised service can’t freely reach services it has no legitimate reason to call. The operational cost is real — certificate management, policy definition, more moving parts — but for anything handling sensitive data, it’s the right default in 2026.
Q2: What’s the difference between OAuth 2.0 and OIDC, and where does JWT fit in?
A: OAuth 2.0 is fundamentally about authorization — it defines how a client can obtain a token that grants scoped access to a resource on a user’s behalf, without ever handling the user’s credentials directly. It doesn’t, by itself, tell the client who the user is. OpenID Connect is an identity layer built on top of OAuth 2.0 — it adds an ID token (typically a JWT) that carries verified claims about the authenticated user’s identity. JWT is just the token format both commonly use — a signed, self-contained token with claims like issuer, audience, expiry, and scopes, which lets a resource server validate the token cryptographically without a round trip back to the identity provider for every request. In an interview I always clarify: OAuth answers “what can this token do,” OIDC answers “who is this.”
Q3: How would you design defense in depth for an API that handles sensitive financial data?
A: Layer by layer from the edge inward: a WAF and DDoS protection at the edge to filter obvious attack traffic before it reaches anything meaningful; an API gateway that terminates TLS, validates JWTs, enforces per-client rate limits, and rejects malformed requests before they hit application code; network segmentation so the application tier has no direct internet ingress and the database tier is reachable only from the application tier’s specific security group; mTLS between every internal service so a compromised service can’t silently impersonate another; encryption at rest via a managed key service with regular key rotation, so a storage-level breach doesn’t expose plaintext data; and comprehensive audit logging of every authentication event and sensitive data access, feeding into a SIEM with alerting on anomalous patterns. No single layer is assumed sufficient — the goal is that a failure at any one layer is caught by the next.
Q4: Why is mTLS important in a service mesh, and what’s the operational cost of adopting it?
A: mTLS ensures both sides of a service-to-service call cryptographically verify each other’s identity, not just the caller verifying the server as in standard one-way TLS — this is essential for Zero Trust because it means a service can only be called by services explicitly authorized to present a valid certificate, closing the gap where an attacker who’s gained a foothold inside the network could otherwise freely call any internal service. The operational cost is certificate issuance, distribution, and rotation at scale — doing this manually per service is impractical, which is exactly why service meshes like Istio exist: the mesh’s control plane automates certificate issuance and rotation transparently via sidecar proxies, so application code never has to handle certificates directly. The trade-off is added infrastructure complexity and a small latency/resource overhead per call, which is why I recommend adopting a service mesh only once the service count and compliance requirements justify it — for a handful of services, application-level mTLS or even just strong network segmentation may be sufficient.