Skip to content
Tutorials Center
My learning

Topics

Lesson 64 of 80 ยท Privacy, Cloud and Secure Design

Secure Architecture and Design Patterns

Learn secure SDLC, security requirements, shift-left and DevSecOps, secure-by-default design patterns and how to run a security design review.

Many serious security problems are not coding slips. They are design decisions: an admin interface exposed to the internet, a service that trusts every caller inside the network, a database that holds secrets in plain text because nobody asked who could read it. A bug can be patched in an afternoon. A flawed design may take months to rework, and by then thousands of customers depend on it.

That is why security work starts before the first line of code. In this lesson you will see how security fits into the software development life cycle, how to turn vague wishes into testable security requirements, what "shift left" and DevSecOps mean, which design patterns make systems safe by default, and how to run a design review. The demos are small checkers on invented data. They build on Threat Modeling with STRIDE and the principles in The CIA Triad and Core Principles.

Why design matters most

The cost of fixing a defect rises sharply the later you find it. A missing requirement caught in a design meeting costs a conversation. The same gap found in a penetration test after launch costs a redesign, a release and perhaps a notification to customers. Security reviews at the end of a project are therefore the most expensive place to learn bad news.

flowchart LR
    R["Requirements"] --> D["Design"]
    D --> I["Implementation"]
    I --> T["Testing"]
    T --> RE["Release"]
    RE --> O["Operations"]
    O -.-> R
    R -.- S1["Security requirements,<br/>abuse cases"]
    D -.- S2["Threat model,<br/>design review"]
    I -.- S3["Secure coding,<br/>code review, SAST"]
    T -.- S4["DAST, fuzzing,<br/>security tests"]
    RE -.- S5["Hardened config,<br/>signed builds"]
    O -.- S6["Monitoring,<br/>patching, response"]

A secure SDLC adds a security activity to every phase instead of one big check at the end.

The secure SDLC

A secure software development life cycle (SSDLC) weaves security tasks into each stage of building software, whatever the process is called (waterfall, agile, a mix). Well-known frameworks, such as Microsoft's SDL, OWASP SAMM and the US NIST Secure Software Development Framework (SSDF), describe similar practices:

  • Requirements: state security and privacy needs; write abuse cases next to use cases ("a user tries to read another user's invoice").
  • Design: model threats, choose proven components and patterns, review the architecture.
  • Implementation: follow secure coding rules (Secure Coding Principles), review code, use static analysis.
  • Verification: run security tests, dynamic scans, dependency checks and, for important systems, independent penetration tests.
  • Release: harden configuration, sign artifacts, keep a rollback plan.
  • Operations: monitor, patch, respond to incidents and feed lessons back into requirements.

Writing security requirements

"The system must be secure" cannot be tested. A good security requirement is specific and verifiable. Compare:

Vague Testable
Passwords must be strong Passwords are at least 12 characters, checked against a list of breached passwords, and stored with a slow salted hash
Data must be protected Personal data is encrypted in transit with TLS 1.2 or newer and at rest with AES-256
Only authorized users can see reports Every report endpoint checks the caller's role and the report's owner; requests without a valid session return 401
We need audit trails Logins, role changes and exports are logged with user, time and result; logs are kept 12 months and cannot be edited by application admins

Requirements come from several places: regulation and contracts (see Privacy and Data Protection and Compliance and Security Frameworks), your threat model, and the company's own policies. A standard such as OWASP's Application Security Verification Standard (ASVS) offers ready-made checklists to select from.

The next demo traces requirements to tests. A requirement without a test is a wish; a test without a requirement may be pointless. The report shows both gaps.

Python Requirement-to-test traceability report

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Shift left and DevSecOps

"Shift left" means moving security checks earlier on the timeline (to the left of a diagram like the one above) so that problems are found when they are cheapest. DevSecOps extends the DevOps idea of shared responsibility and automation: developers, operations and security work together, and security checks run automatically in the delivery pipeline instead of waiting for a gatekeeper.

Typical automated checks in a pipeline:

Gates should be fair and fast. A pipeline that fails randomly or takes an hour trains people to bypass it. Start by reporting findings, then block only on the clearly serious ones, and give developers fix guidance, not just a red cross.

Python A security gate for a delivery pipeline

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Secure-by-default design patterns

Good designs make the secure path the easy path. Patterns that appear again and again:

  • Deny by default. Access is refused unless a rule grants it. New endpoints, new roles and new network paths start closed.
  • Least privilege. Every user, service and process gets only the permissions its task needs, for only as long as it needs them. Give each microservice its own credentials with narrow rights.
  • Defense in depth. Layer controls (network segmentation, authentication, authorization, validation, encryption, monitoring) so that one failure is not fatal.
  • Fail securely. On error, deny access and show a generic message. Do not fall back to "allow".
  • Complete mediation. Check authorization on every request on the server, not once at login or only in the user interface.
  • Separation of duties. The person who writes a change should not be the only one who approves it into production.
  • Minimize attack surface. Remove unused features, ports, accounts and dependencies. What does not exist cannot be attacked.
  • Trust boundaries and validation at the boundary. Treat everything crossing a boundary (user input, another service, a file) as untrusted (Input Validation and Sanitization).
  • Zero trust. Authenticate and authorize each request, whether it comes from inside or outside the network (Firewalls, Segmentation and Zero Trust).
  • Use proven components. Do not invent your own authentication, session handling or cryptography (Cryptography in Plain Language).
  • Secure defaults, explicit opt-out. Cookies are HttpOnly and Secure unless there is a documented reason; new accounts have no admin rights; debug mode is off.
  • Keep secrets out of the application. Use a vault or a managed identity, and rotate credentials.
  • Design for recovery. Assume a breach will happen; keep tested backups, audit logs and a way to revoke credentials quickly.

Running a security design review

A design review examines a proposed or existing architecture and asks: what could go wrong, and are the controls adequate? A practical lightweight format for a one-hour meeting:

  1. Describe the system on a diagram: components, data stores, data flows and trust boundaries.
  2. Identify assets and data classification. What is valuable? What personal data is involved?
  3. Walk through threats, for example with STRIDE per component and per data flow.
  4. Check the controls: authentication, authorization, input validation, encryption, logging, secrets, dependencies, backup.
  5. Record decisions and actions with owners and dates. Note accepted risks explicitly.
  6. Revisit when the design changes significantly.

Checklists make reviews consistent. The demo encodes a few secure-by-default rules and applies them to two invented service designs, the kind of output a review template or a policy-as-code tool can produce.

Python Check two service designs against secure-by-default rules

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Automated checks catch the mechanical problems. They cannot tell whether the design is right for the business, so keep a human conversation in the loop. Most valuable findings come from asking "what if this component is compromised?" rather than from ticking boxes.

Common design mistakes

  • Trusting the network. "It is internal, so no authentication is needed" fails the first time someone gets a foothold.
  • Security through obscurity. Hidden URLs and secret algorithms are not controls.
  • One shared super-credential used by every service, so one leak exposes everything.
  • Client-side-only checks. Anything enforced only in a browser or app can be bypassed.
  • Ignoring abuse cases. Features are designed for the happy path; attackers use the other paths.
  • Unowned risk. Findings without an owner and deadline never get fixed.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What does 'shift left' mean in secure development?

    Earlier timelines are drawn left to right, so shifting left means finding and fixing problems sooner, during requirements, design and coding.
  2. 2. Which is a testable security requirement?

    A testable requirement is specific enough that a test or review can show whether it is met.
  3. 3. What is the idea behind 'deny by default'?

    Starting closed means a forgotten rule leaves a feature unusable rather than exposed.
  4. 4. Why is a purely client-side authorization check a design flaw?

    Controls must be enforced on the server, where the attacker has no influence over the code that runs.
  5. 5. What should happen to a finding in a design review that the team decides not to fix right now?

    Accepting risk is legitimate if it is a conscious, documented decision with an owner and an expiry, not silent neglect.

Summary

  • Many vulnerabilities are design flaws, and they are cheapest to fix early.
  • A secure SDLC adds security activities to every phase: requirements, design, coding, testing, release and operations.
  • Write security requirements that are specific and testable, and trace them to tests.
  • Shift left and DevSecOps automate checks (secrets, SAST, SCA, scans, gates) inside the delivery pipeline.
  • Prefer secure-by-default patterns: deny by default, least privilege, defense in depth, fail securely, complete mediation, minimal attack surface and proven components.
  • Run regular design reviews with a diagram, a threat walk-through, a controls checklist and recorded decisions.

Next: Cloud and Container Security, which applies these design ideas to cloud platforms.