Advanced Concepts · Concept lesson
Security: Trust Boundaries, Identity, and Safe Failure
Map who can do what across service boundaries, limit credential and data exposure, and ensure failures do not silently weaken authorization.
Written for readers who already know the basics. If the words here are new to you, read The request lifecycle and Capacity estimation first.
Original educational architecture · Version 2026-11-12.1 · Examples use stated hypothetical assumptions, not a company's actual design.
What you will be able to explain
- Identify assets, trust boundaries, principals, and authorization decisions.
- Apply least privilege and layered validation to synchronous and asynchronous paths.
- Design secrets, audit, privacy, and recovery controls as operational mechanisms.
Security begins with assets and trust boundaries
A security architecture should start with what needs protection: personal records, credentials, administrative actions, service availability, and the integrity of business state. Then identify actors and boundaries: browser to API, service to database, worker to broker, operator to production, and provider to your environment. A trust boundary is where assumptions change; data crossing it needs authentication, validation, authorization, and often audit. A network diagram alone is not a threat model. Ask what an attacker or misconfigured component can control, what they can observe, and how one compromised identity might move laterally. Threat modeling is iterative; it helps prioritize meaningful mitigations rather than claim that every imaginable risk is eliminated.
Authentication establishes who or what is acting; authorization decides what that principal may do to a specific resource under current policy. A valid session does not grant access to every record. Enforce authorization server-side at the resource boundary, scope tokens narrowly, and avoid trusting object IDs or tenant IDs supplied by a client. For service identities, use workload identity or short-lived credentials where available, separate permissions by task, and rotate or revoke credentials through an exercised process. A worker that only reads one queue and writes one result table should not hold administrator access to every database and storage bucket. Logging should record meaningful actor and decision context without copying credentials or sensitive payloads.
Make identity and authorization explicit on every path
For HTTP requests, validate issuer, audience, expiry, signature, and intended use of a token; then make an object-level permission check using current policy. For asynchronous jobs, the producer's authority does not automatically transfer to every downstream consumer. The event should carry a minimal subject and action, while the consumer checks whether that operation is still allowed under current rules. A queued job may outlive a user's permission change. Decide whether authorization is checked at enqueue, execution, or both, and make revocation behavior explicit. Multi-tenant storage keys, database predicates, and cache keys should include the isolation scope so accidental ID collisions do not cross tenants.
Secrets should not be embedded in source, images, logs, or long-lived client bundles. Use a managed secret store or workload identity, restrict read access, rotate credentials, and audit access. Encryption at rest protects storage media but does not stop an authorized application or operator from reading plaintext; transport encryption and key management need their own threat analysis. Input validation, parameterized queries, output encoding, request limits, and safe parser settings reduce attack surface but do not replace authorization. Error messages should help legitimate users without revealing stack traces, internal hostnames, tokens, or whether another tenant's object exists. Rate limits and quotas protect availability, but should account for shared NATs and legitimate bursts.
Trace an access decision across a document pipeline
Imagine an API accepts an upload request for a team document. The user token identifies a principal, but the API also checks the user's current membership and permission to create content in that team. It creates a random object key under a tenant-scoped prefix and returns a short-lived upload authorization restricted to that key and size. After upload, a worker scans and transforms the file under a separate workload identity with read access to quarantine and write access only to sanitized output. The search indexer receives a document ID and version, but before a query returns a private result the API validates current access. Each boundary has a distinct identity and permission set; a compromised transcoder cannot automatically read every user's records or issue a license.
Now a team administrator removes the uploader's membership while processing is queued. If the product requires authorization at execution time, the worker or orchestrator rechecks current policy before publishing the document. If an already authorized upload is permitted to finish despite membership removal, that is a documented rule and the final record remains scoped to the team. A unique request ID supports audit, but not as a metric label or bearer credential. A useful audit event records actor, resource, action, decision, policy version, and timestamp, with tamper-resistant retention. Do not store full file contents or session tokens in the audit log. Test the user removal race, cross-tenant key guessing, expired upload URL, and worker identity compromise.
Presents an authenticated session but does not choose authority by ID.
Validates token and checks current object-level policy.
Short-lived upload capability limited to one tenant key.
Distinct workload identity with narrow input/output permissions.
Minimal subject/action reference and version, not bearer credentials.
Rechecks access where revocation semantics require it.
Records actor, resource, action, decision, and policy version.
- User / client → API boundary: authenticated request
- API boundary → Policy authority: authorize resource action
- API boundary → Scoped object storage: scoped upload capability
- Scoped object storage → Durable job: validated object reference
- Durable job → Processing worker: minimal job
- Processing worker → Policy authority: recheck if required
- API boundary → Protected audit log: record decision
Choose controls by threat and failure consequence
Role-based access control is straightforward when users share stable roles; attribute-based rules can express resource and context conditions but are harder to audit; relationship-based authorization is useful when access follows graph relationships such as team membership. Many systems combine approaches. Choose the simplest model that can be checked consistently and explained to operators. Policy engines can centralize decision logic, but a remote policy service adds availability and latency dependencies. Cache decisions only with a clear invalidation and revocation bound. For highly sensitive actions, fail closed when current authorization cannot be established; for low-risk public content, a documented fallback may be acceptable.
Network segmentation and private endpoints reduce exposure, but identity and authorization still matter inside a network. Mutual TLS can authenticate workloads and encrypt links, but it does not prove a caller is authorized to read a given document. A service mesh can standardize transport policy but adds control-plane and certificate lifecycle complexity. WAF rules can block common traffic patterns but cannot fix a broken object-level permission check. Evaluate each layer as defense in depth, not as a substitute for correct application logic. Controls should be chosen with operational capabilities: unrotatable secrets or unreadable policies may become risks rather than protections.
Fail safely, audit changes, and recover credentials
Authorization-service failure is a design condition. Decide whether the operation fails closed, uses a short-lived cached decision, or offers a reduced public response. A stale allow decision can leak data after revocation; cache TTL should match the acceptable exposure window, and high-risk operations may bypass it. A token refresh failure should not silently extend privilege. Database row-level controls can provide defense in depth, but they must align with application tenant scoping and be tested under connection pooling. Background jobs should have expiration and cancellation semantics where user intent or permission may change.
Credential rotation requires overlapping old and new credentials or another controlled cutover, verification of consumers, and a rollback window. Revoke a suspected credential promptly, then inspect its use and rotate dependent secrets. Backups and telemetry may contain sensitive data, so deletion and incident response must cover those copies. Audit logs should be write-restricted, access-reviewed, and monitored for gaps; logs that are editable by the same compromised service are weak evidence. Test permission revocation during active sessions, leaked URL tokens, cross-tenant access, broker message tampering, replayed jobs, expired certificates, and backup restoration. Security controls fail in partial, inconvenient ways; runbooks should name who may decide to restore a restricted capability.
When a security mechanism can make the system less safe
Do not create a custom cryptographic protocol when a reviewed standard and managed library suffice. A bespoke token format or key derivation scheme is easy to get subtly wrong. Do not place a global administrator credential in a shared worker to avoid configuring per-service identities. More encryption layers do not compensate for broad plaintext access or poor key custody. Avoid long-lived bearer URLs when a short-lived scoped token meets the requirement. If the system cannot reliably rotate a secret, adding more static secrets increases the blast radius and operational burden.
Do not fail open on a security-critical authorization dependency merely to preserve a dashboard's availability. Conversely, do not add a remote authorization hop to public static content if no sensitive decision exists and the dependency would create needless outage risk. Match controls to sensitivity and threat model. Collecting additional audit data can create privacy harm, so retain only what supports the stated purpose, protect access, and document deletion. A control is not effective because a policy document says it exists; verify the deployed identity, permission, and alert behavior.
Senior questions for a security review
Ask what assets and actors matter, where trust changes, and which identities cross each boundary. Can a client choose another tenant's ID? Which operation performs the authoritative object-level check? How does access change propagate to caches, search, queues, and already-issued URLs? What does each service identity need, how long does the credential live, and how is it rotated during an incident? What is the consequence when the policy service, identity provider, or key service is unavailable?
Trace data beyond the happy path: logs, traces, dead letters, backups, replicas, support exports, and third-party processors. Who can access it, for how long, and how are deletion requests applied? Does the threat model include a compromised worker or operator account? Are audit records tamper-resistant enough for the intended purpose? Which controls prevent, detect, and recover from abuse, and which are only assumptions? Senior security reasoning distinguishes encryption from authorization, network identity from resource permission, and a claimed control from a tested one. It should include a concrete cross-tenant test and a controlled credential revocation drill.
Terms in plain language
- Threat model
- A structured account of assets, actors, trust boundaries, threats, and mitigations for a system.
- Least privilege
- Granting each identity only the permissions and duration required for its task.
- Fencing token
- A monotonically increasing authority value used to reject stale actors after ownership changes.
References and boundaries
Primary documentation supports the mechanisms described. It does not certify these hypothetical architectures, prices or sizing assumptions. Review platform-specific behavior before implementation.
Primary OWASP project standard for verifying application security controls, including access control and validation.
Primary NIST publication on resource-focused access decisions and zero-trust principles; implementation must still match system threat model.