Secure Architecture
Design the controls that make a system resilient: authentication, authorization, tenant isolation, data protection, secrets, network and platform hardening, secure integration with external services, and recorded security decisions.
Introduction
Some security problems cannot be fixed with a patch. If every endpoint is responsible for remembering to check which organization a record belongs to, someone will forget. If a service account can read the whole database, one compromised container exposes everything. These are architectural weaknesses, and the cheapest time to fix them is during design.
This lesson turns the threat model into architecture: a small number of strong, central controls that make the secure path the easy one.
Learning Objectives
- Apply security principles to architectural decisions.
- Design authentication, session management, and authorization.
- Enforce tenant isolation in a multi-tenant system.
- Protect data in transit, at rest, and in logs, with sound key and secret management.
- Harden the network, platform, and pipeline boundaries.
- Integrate external services, including AI model providers, safely.
- Record security decisions and verify the architecture against the threat model.
1. Design Controls Around Threats
Start from the threat register, not from a list of technologies. For each high-priority threat, ask which control prevents it, which detects it, and which limits the damage. Prefer controls that are:
- Central. One authorization layer, not a check in every handler.
- Default-on. Protection applies unless explicitly bypassed.
- Hard to bypass. Enforced on the server, at the data layer or gateway, not in the user interface.
- Observable. Failures and denials are logged.
- Testable. A test can show the control works.
The pattern to avoid is security by convention: “everyone knows to filter by organization.” Convention does not survive deadlines, new team members, or generated code.
2. Authentication and Sessions
Authentication answers “who are you?”
- Do not build your own cryptography or credential storage. Use a proven identity provider or a well-reviewed library for password hashing, token issuing, and verification.
- Store passwords only as salted hashes from a slow, purpose-built algorithm; never in reversible form, and never in logs.
- Offer multi-factor authentication, and require it for administrators.
- Protect against automated guessing: rate limits, lockout or delay, breached-password checks, and alerts on unusual patterns.
- Secure sessions: short-lived tokens, rotation on privilege change, secure and HTTP-only cookies where cookies are used, invalidation on sign-out and password change.
- Secure account recovery, which is often the weakest link: single-use, short-lived, rate-limited reset links; no user enumeration through different messages.
- Authenticate services as well as people: service-to-service calls use credentials or workload identity, not network location alone.
3. Authorization and Tenant Isolation
Authorization answers “what are you allowed to do?” and is the most commonly broken control in business applications. Broken access control, especially access to another user’s records by changing an identifier, consistently ranks among the most frequent serious weaknesses.
Principles
- Deny by default. A request is allowed only if a rule permits it.
- Check on the server, on every request, for the specific record and action: not only “is this user signed in?” but “may this user read this record?”
- Derive identity and tenant from the authenticated session, never from a client-supplied parameter.
- Use roles for coarse permissions and ownership checks for records.
- Keep authorization logic in one place that can be reviewed and tested.
Tenant isolation options for a multi-tenant database
| Approach | How | Strength | Cost |
|---|---|---|---|
| Separate databases per tenant | Each customer has its own database | Strongest isolation, simple restores per tenant | Operational overhead, cost |
| Separate schemas | One database, one schema per tenant | Strong logical separation | Migration complexity |
| Shared tables with a tenant column | All tenants in the same tables, every query filtered | Cheapest and simplest | Every query must filter correctly; one mistake leaks |
| Row-level security enforced by the database | The database applies the tenant filter automatically | Protects against forgotten filters | Setup and testing effort |
For a pilot, shared tables are reasonable only with a central data access layer that applies the tenant filter automatically, ideally backed by database row-level security as a second layer. Record the choice and the criteria for changing it (for example, a customer who requires dedicated storage).
Do not forget the other places tenant data lives: caches, search indexes, the queue, files in object storage, logs, backups, and exports. Each needs the same isolation.
4. Data Protection
Classify data first: what is public, internal, confidential, or regulated. Then apply controls proportionate to the class.
| Concern | Controls |
|---|---|
| In transit | TLS for every connection, including internal ones that cross hosts; current protocol versions; certificate management and renewal |
| At rest | Encryption of databases, storage, and backups with managed keys; restricted access to keys |
| In logs and errors | No credentials, tokens, or sensitive content in logs; redaction by default; error messages that do not reveal internals |
| Minimization | Collect and keep only what is needed; send only needed fields to external services |
| Retention and deletion | Defined retention periods, deletion on request and on contract end, including backups and derived data |
| Backups | Encrypted, access-controlled, restore-tested, covered by the same deletion rules |
| Test and non-production data | Synthetic or anonymized data (the environments lesson of the delivery course) |
Key and secret management matters as much as the encryption itself. Keep keys in a managed service, separate from the data they protect; rotate them on a schedule and after suspected exposure; limit who and what can use them; and log their use. Secrets follow the strategy from the delivery course: injected at runtime, never in code, images, or logs.
5. Network, Platform, and Pipeline Hardening
Assume an attacker will eventually reach something inside. Limit what they can do from there.
- Network segmentation. Only the web tier is public; the database and queue accept connections only from the services that need them. Deny by default between segments.
- Least privilege for workloads. Each service has its own identity and only the permissions it needs; the worker cannot read the web app’s secrets; no service has administrator rights to the cloud account.
- Container hardening. Run as a non-root user, use minimal images, read-only file systems where possible, drop unneeded capabilities, and set resource limits (continuing the containerization lesson).
- Secure defaults for infrastructure. No public storage buckets, no open management ports, no default credentials; enforced by policy checks on the infrastructure code.
- Pipeline as a target. The pipeline can deploy to production and holds powerful credentials. Protect it: branch protection, required reviews, short-lived credentials, separate permissions per stage, no secrets exposed to untrusted code (such as builds from forks), and an audit trail.
- Administrative access. Named accounts, multi-factor authentication, just-in-time elevation where possible, and logging of every privileged action.
- Rate limiting and quotas at the edge and per tenant, as defense against abuse and cost attacks.
6. Integrating External Services and AI Providers
Every third-party service is a trust boundary and a dependency.
General rules
- Minimize what you send. Send only fields required for the function; redact identifiers where possible.
- Know where data goes. Review the provider’s terms for retention, use of data for training, location, and sub-processors; check against customer commitments.
- Authenticate and encrypt every call; store provider keys as secrets with restricted scope.
- Validate responses. Treat provider output as untrusted: check size, format, and content; handle errors and timeouts; never let an outage take the whole application down.
- Limit blast radius. Use scoped keys, spending limits, and a way to disable the integration quickly (a feature flag).
- Have an exit. Avoid designs that make the provider impossible to change.
Additional rules for model integrations
- Build each request only from the requesting tenant’s data.
- Keep instructions separate from untrusted content and instruct the model to treat uploaded text as data; recognize that this reduces but does not eliminate injection risk.
- Give the model no tools or permissions beyond producing text; do not let output trigger actions without validation and authorization.
- Encode output before displaying it, and restrict links and embedded content.
- Log metadata (who, when, size, cost) and not necessarily the content.
- Let users and administrators control the feature (opt-in or opt-out per organization) if customers need that.
7. Record Security Decisions
Security architecture decisions are easily forgotten and often questioned later by customers and auditors. Record them as architecture decision records:
1
2
3
4
5
6
7
8
9
10
11
12
ADR-014: Tenant isolation by shared tables with enforced filtering
Status: Accepted
Context: Pilot with fewer than 50 organizations; small team; threat T-01
(cross-tenant read) rated High.
Decision: Shared tables with a mandatory tenant filter applied in the
data access layer, and database row-level security as a second layer.
Consequences: Simple operations; isolation depends on the layer and
policies being correct; requires isolation tests (lesson 8).
Revisit when: A customer requires dedicated storage, or tenants exceed
an agreed number.
Alternatives considered: Separate schemas; separate databases.
Each decision names the threats it addresses and the evidence that will verify it.
8. Review the Architecture
A secure architecture review compares the design to the threat model and the principles:
- Does every high-risk threat have at least one effective control, ideally two layers?
- Are there single points of failure in authentication, authorization, or secrets?
- Does any component have more access than it needs?
- Is every trust boundary crossing authenticated, encrypted, and validated?
- Which controls depend on people remembering to do something?
- What happens when a control fails? Does the system fail closed?
- Is there a way to detect an attacker who gets past the preventive controls?
Reviews work best with the people who built the system and someone who has not seen it before.
9. Using AI for Secure Architecture
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Act as a security architect reviewing a design against a threat model.
Inputs:
- Architecture documentation and deployment view: [paste]
- Threat register with ratings: [paste]
- Authentication, authorization, and tenant isolation approach:
[paste]
- Data classification and storage locations: [paste]
- External services and what data they receive: [paste]
Tasks:
1. For each high and critical threat, assess whether the
architecture prevents, detects, or only partly addresses it.
Name the control, or state that none is described.
2. Identify places where security depends on convention or on
developers remembering a check.
3. Identify components with more privilege or network reach than
needed.
4. Identify data stores or flows where tenant isolation is not
enforced.
5. Review the external service integrations against the rules of
minimization, validation, and containment.
6. Propose improvements ranked by risk reduction and effort, with
trade-offs.
Do not invent controls. If the documents are silent, say "not
described" and list it as a question.
Verify each claim against the system itself. Documentation can claim a control that was never built; confirm with configuration, code, or a test. Treat recommended products and settings as suggestions to check against current official documentation, not as facts.
10. Practical Exercise
For SignalDesk (or your project):
- For each high-priority threat from lesson 2, list the preventive, detective, and damage-limiting controls, and mark gaps.
- Document the authentication and session design and the authorization model, including where checks are enforced and how identity and tenant are derived.
- Choose and justify a tenant isolation approach, and list every place tenant data lives.
- Complete a data classification table with encryption, retention, and logging rules.
- Review network segments, workload permissions, container settings, and pipeline permissions for excess access.
- Write the integration rules for the model provider, including a way to switch the feature off.
- Record at least three security ADRs.
- Run the AI architecture review prompt, verify each finding, and update the design and backlog.
Verification
You are ready to continue when:
- Each high threat has a named control and evidence that will verify it.
- Authorization is central, deny-by-default, and based on server-side identity.
- Tenant isolation covers the database and every other place tenant data lives.
- Data classes have rules for transit, storage, logging, retention, and deletion.
- Workloads, people, and the pipeline have least-privilege access.
- Decisions, alternatives, and revisit conditions are recorded.
Key Takeaways
- Prefer central, default-on, testable controls to conventions that depend on memory.
- Authorization and tenant isolation deserve the most attention in business applications.
- Protect data where it moves, rests, and is logged, and manage keys separately.
- Treat the pipeline and every external service, including AI providers, as part of the attack surface.
- Record security decisions so they can be verified, questioned, and revisited.
What’s Next?
With controls designed, we look for the weaknesses that remain in what was actually built. The next lesson covers vulnerability analysis: classifying, scoring, and prioritizing findings by real risk.