SecurityVol. 10 · Part X
0 / 0

Shelves / Security

SE·106

Security Foundations

The concepts every other security topic builds on: confidentiality, integrity and availability (and their extensions: authenticity, non-repudiation, privacy), authentication, authorisation and accounting, the principles from Saltzer and Schroeder (least privilege, fail-safe defaults, complete mediation, economy of mechanism, separation of privilege), defence in depth, zero trust architecture, risk and its management, the attacker's view (vulnerability, threat, exploit, attack surface), secure-by-design practices, and how security fits into the software lifecycle.

22 topics · ~15 min read · 30-question quiz
Updated Suggest a correction

Start here: principles you can see in action

Least privilege: give a process only what it needs

A web service almost never needs to be root. Here the same reader program runs three ways, trying to read a confidential file (mode 640, owned by root) and to bind port 80:

Text
as root (no privileges dropped):                 read secret.txt: YES   bind port 80: YES
as 'nobody', all capabilities cleared:           read secret.txt: denied  bind port 80: denied
as 'nobody' + only CAP_NET_BIND_SERVICE:         read secret.txt: denied  bind port 80: YES

Root can do everything, so a bug in a root process is a catastrophe. Dropping to an unprivileged user removed both powers. Capabilities then hand back exactly one: CAP_NET_BIND_SERVICE lets the process bind a low port without being able to read root's files. That is least privilege: the process keeps the one power it needs and loses the rest, so a compromise of it buys the attacker very little.

Defence in depth: layers multiply

No single control is certain, so you stack independent ones. If each layer independently has some chance of stopping an attack, the chance of getting through them all is the product:

Text
layer                        stops attack   chance the attack still succeeds
  input validation               70%             30.000%
  parameterised queries          95%              1.500%
  low-privilege DB user          60%              0.600%
  network policy                 50%              0.300%
  monitoring + alert             40%              0.180%

Any one layer alone leaves 30–60% through; five independent layers leave under 0.2%. The crucial words are independent: if two layers rely on the same library, the same token, or the same assumption, they fail together and the multiplication is a lie. Much of security design is making layers genuinely independent.

The vocabulary

  • A vulnerability is a weakness; an exploit is a way to use it; a threat is who might; risk combines likelihood and impact.
  • The CIA triad names what you protect: confidentiality, integrity, availability.
  • Authentication proves who you are; authorisation decides what you may do; accounting/audit records what happened.

How deep to go in security foundations

Volume 17 defines six mastery levels. For this chapter they look like this; the chapter aims at L3 everywhere, and its lab at L4.

Level What you can do
L1 Explain CIA, AAA, least privilege, defence in depth and risk
L2 Apply least privilege and layered controls to a service you run
L3 Explain the Saltzer–Schroeder principles and zero-trust model and why they hold
L4 Find privilege and trust-boundary weaknesses in a design or a running system
L5 Design a security architecture for a system, choosing proportionate controls
L6 Set security principles, standards and culture across an organisation

What security means

The CIA triad

Security protects assets (data, systems, money, reputation, people's safety) from threats. The classic properties:

Property Meaning Violated by Typical controls
Confidentiality Information is disclosed only to those authorised Data breaches, eavesdropping, leaked logs, misconfigured buckets Access control, encryption in transit and at rest, data minimisation
Integrity Information and systems are accurate and unmodified except by authorised means Tampering, injection, corrupted data, malicious updates Validation, MACs and signatures, access control, audit, checksums
Availability Systems and data are accessible when needed DDoS, ransomware, resource exhaustion, outages Redundancy, rate limiting, backups, capacity, incident response

Extensions often added:

  • Authenticity: you can verify who created or sent something (signatures, authenticated channels).
  • Non-repudiation: the author can't credibly deny an action (digital signatures, tamper-evident audit logs).
  • Privacy: personal data is collected and used only as appropriate (a related but distinct goal, with legal frameworks: GDPR, India's DPDP Act, CCPA).
  • Safety: in cyber-physical systems, security failures can hurt people.

Security trades off against other properties: usability, cost, performance, and sometimes availability (locking accounts after failed logins protects confidentiality but enables denial of service). Good security engineering makes those trade-offs explicit.

AAA: authentication, authorisation, accounting

Question Examples
Authentication (AuthN) Who are you? Verify an identity claim Passwords + MFA, passkeys (WebAuthn), client certificates, OIDC tokens, workload identity
Authorisation (AuthZ) What may you do? Decide whether this principal may perform this action on this resource RBAC, ABAC, ACLs, IAM policies, OAuth scopes, policy engines
Accounting / audit What did you do? Record actions for accountability, detection and forensics Audit logs, CloudTrail, database audit, SIEM

Authentication without authorisation is a common bug: "the user is logged in" isn't the same as "the user may access this order". Most real-world breaches of web applications are authorisation failures (OWASP's #1 risk, Broken Access Control).

Vocabulary of attacks

Term Meaning
Asset Something of value to protect
Threat A potential cause of harm (an actor with motivation, or an event)
Threat actor Who might attack: opportunistic criminals, organised crime (ransomware), insiders, competitors, hacktivists, nation states
Vulnerability A weakness that could be exploited (a bug, a misconfiguration, a design flaw)
Exploit A concrete method or code that uses a vulnerability
Attack surface All the points where an attacker can try to interact with or extract data from the system
Attack vector The path used (phishing email, exposed API, malicious dependency)
Risk Likelihood × impact of a threat exploiting a vulnerability
Control / mitigation A measure reducing likelihood or impact (preventive, detective, corrective)
CVE / CVSS / CWE CVE: identifier for a publicly known vulnerability; CVSS: severity score (0–10); CWE: category of weakness (e.g. CWE-79 XSS); EPSS estimates exploitation likelihood; CISA's KEV catalogue lists vulnerabilities known to be exploited

Risk management

You can't eliminate risk; you manage it:

  • Mitigate: add controls.
  • Avoid: don't do the risky thing (don't store card numbers; use a payment provider).
  • Transfer: insurance, contracts, managed services.
  • Accept: documented, by someone with authority, for low risks or when mitigation costs more than the risk.

Prioritise by risk, not by alarm: a "critical" CVSS score in a library function you never call is less urgent than a "medium" authorisation bug on your public API. Use exploitability signals (KEV, EPSS, reachability analysis) alongside severity.

Design principles

Saltzer and Schroeder (1975)

Jerome Saltzer and Michael Schroeder's principles, written for operating systems, remain the backbone of secure design:

Principle Meaning Modern example
Economy of mechanism Keep the design simple and small Less code and fewer features means fewer bugs; use a well-reviewed library rather than custom auth
Fail-safe defaults Base access decisions on permission, not exclusion; default is deny IAM default deny; allow-lists over deny-lists; new S3 buckets block public access
Complete mediation Check every access to every object Authorise each request (not just at login); check object ownership on every read
Open design Security shouldn't depend on secrecy of the design (Kerckhoffs's principle) Public crypto algorithms; secret keys, not secret algorithms
Separation of privilege Require multiple conditions or parties MFA; two-person approval for production changes; separate deploy and approve roles
Least privilege Every program and user operates with the minimum privileges needed Narrow IAM roles; containers as non-root with no capabilities; short-lived tokens
Least common mechanism Minimise shared mechanisms between users Per-tenant isolation; separate credentials per service
Psychological acceptability Security must be usable, or people will bypass it Passkeys and SSO instead of password rotation rules; sensible defaults

Least privilege in practice

Least privilege applies to every principal:

  • Humans: role-based access, just-in-time elevation, no standing admin, separate accounts for admin tasks.
  • Services: one identity per service, scoped to exact resources and actions (Vol. 7 ch. 89).
  • Processes: non-root users, dropped capabilities, read-only filesystems, seccomp (Vol. 6 ch. 80–81).
  • Data: column- and row-level access, views exposing only what's needed.
  • Time: privileges that expire (temporary credentials, time-bound access grants).
  • Network: only the connections required (network policies, security groups).

Least privilege limits the blast radius of every compromise: an attacker who takes over a service gets only that service's narrow permissions.

Defence in depth

Defence in depth layers independent controls so that a single failure doesn't lead to compromise:

edge: WAF · DDoS protection · rate limits network: segmentation · private subnets · policies identity: MFA · least privilege app: validation · authz dataencryption · access · backups detect &respondaudit logsalerts · SIEManomaly detectionincident responsebackups / recovery
Defence in depth. An attacker must get through several independent layers (edge protections, network segmentation, identity and authorisation, application validation, data encryption and access controls), while detection and response watch every layer. Any one layer may fail; the combination makes a successful attack much harder and more visible.

Examples of independent layers protecting customer data:

  1. WAF and rate limiting block bulk scraping and common injection payloads.
  2. The API requires an authenticated session with MFA.
  3. Every endpoint checks that the caller owns the requested object.
  4. Queries are parameterised, so injection doesn't work even if validation misses something.
  5. The database user for the service can only access its own tables; the database is in a private subnet.
  6. Sensitive columns are encrypted with keys in a KMS, accessible only to the service's role.
  7. Audit logs and anomaly detection alert on unusual access volumes.

Layers should be independent (different mechanisms, different failure modes): two WAFs from the same vendor with the same rules aren't depth.

Zero trust

From perimeters to identities

The traditional perimeter model ("castle and moat") trusted anything inside the corporate network: VPN in, and you could reach everything. It fails because:

  • attackers who get inside (phishing, a compromised laptop, a vulnerable server) can move laterally freely;
  • there's no single inside anymore: cloud services, SaaS, remote work, partners, mobile devices.

Zero trust (Forrester's John Kindervag, 2010; Google's BeyondCorp, 2014; NIST SP 800-207, 2020) replaces location-based trust with continuous, per-request verification:

Never trust, always verify. Assume breach.

Core tenets (from NIST SP 800-207):

Tenet Meaning
All data sources and computing services are resources Including SaaS, devices, APIs
All communication is secured regardless of network location Encrypt and authenticate internal traffic too (mTLS)
Access is granted per session No standing broad network access
Access is determined by dynamic policy Identity, device health, location, behaviour, resource sensitivity
The enterprise monitors the integrity and posture of all assets Device management, patch status
Authentication and authorisation are dynamic and strictly enforced before access Continuous re-evaluation
The enterprise collects information to improve its security posture Telemetry feeding policy
user + deviceMFA · posture workloadSPIFFE / mTLS enforcement pointproxy · mesh · gateway decision pointpolicy + signals internal app database / API SaaS per request: allow / deny
Zero trust access. Instead of trusting anything inside a network, every request from a user or workload goes through a policy decision point that evaluates identity, device posture and context against policy; a policy enforcement point (identity-aware proxy, service mesh sidecar, API gateway) allows or denies each request to each resource.

Zero trust in practice:

  • For people: SSO with phishing-resistant MFA (passkeys, FIDO2 security keys), device management and posture checks, identity-aware proxies (Google IAP / BeyondCorp Enterprise, Cloudflare Access, Zscaler Private Access, Tailscale, AWS Verified Access) instead of VPNs to reach internal apps, conditional access policies.
  • For workloads: strong workload identities (SPIFFE/SPIRE, cloud workload identity), mTLS between services (service mesh), per-request authorisation policies, network segmentation as an extra layer (Vol. 6 ch. 82–83).
  • For data: classification, encryption, fine-grained access, monitoring.

Zero trust is a direction, not a product: you migrate step by step, starting with the most valuable resources and the most exposed access paths.

Secure by design

Security across the lifecycle

Security is cheapest when built in early, a practice often called shifting left (while still running controls in production):

Phase Activities
Requirements Security and privacy requirements, abuse cases, compliance needs (PCI DSS, HIPAA, SOC 2, ISO 27001, DPDP, GDPR)
Design Threat modelling (chapter 113), secure architecture patterns, choosing proven components
Implementation Secure coding standards, safe-by-default libraries and frameworks, code review, secret scanning, SAST
Build Dependency scanning, SBOMs, signed artefacts, hardened pipelines (chapter 112)
Test DAST, fuzzing, security unit tests, penetration testing for significant changes
Deploy Hardened configurations, policy as code, least-privilege identities
Operate Patching, monitoring, detection, incident response, vulnerability management, bug bounty

Frameworks: OWASP SAMM (Software Assurance Maturity Model), NIST SSDF (Secure Software Development Framework, SP 800-218), Microsoft SDL, and CISA's Secure by Design pledge (eliminate classes of vulnerabilities, secure defaults, MFA by default, transparency).

Eliminating classes of bugs

The most effective security work removes entire classes of vulnerabilities rather than fixing instances:

Class Structural fix
Memory corruption (buffer overflows, use-after-free) Memory-safe languages (Rust, Go, Java, C#, Python, Swift); in C/C++: hardened allocators, bounds-checked containers, sanitizers, compiler hardening flags. Industry data (Microsoft, Google) attribute ~70% of severe security bugs in large C/C++ codebases to memory safety
SQL injection Parameterised queries and query builders only; ban string-concatenated SQL in review/linting
XSS Auto-escaping templates and frameworks (React, Angular), strict Content Security Policy, Trusted Types
Secrets in code Secret managers, push protection, pre-commit scanning
Broken access control Centralised authorisation (policy engines, framework annotations) with deny-by-default and tests
Weak crypto Vetted high-level libraries (libsodium, Tink) with safe defaults

Security culture

Technology alone doesn't secure systems:

  • Everyone owns security: security champions in teams, threat modelling as a normal design activity, security review in pull requests.
  • Make the secure path the easy path: paved roads (golden templates, platform defaults) beat policies people have to remember.
  • Assume breach and practise: tabletop exercises, incident response runbooks, red/purple team exercises.
  • Learn blamelessly from security incidents and near misses (Vol. 9 ch. 103).
  • Vulnerability disclosure: publish security.txt (RFC 9116) and a disclosure policy; consider a bug bounty programme.

Lab: least privilege and layered defence, measured

Linux setpriv (from util-linux) on the lab machine, run as root so it can drop privileges. The target is a confidential file (secret.txt, mode 640, owner root:root) and binding TCP port 80.

Experiment 1: dropping privilege removes power

Text
as root (no privileges dropped):                 effective uid=0      read secret.txt: YES   bind port 80: YES
as 'nobody', all capabilities cleared:           effective uid=65534  read secret.txt: denied  bind port 80: denied
as 'nobody' + only CAP_NET_BIND_SERVICE:         effective uid=65534  read secret.txt: denied  bind port 80: YES

The commands:

Shell
setpriv --reuid nobody --regid nogroup --clear-groups --inh-caps -all python3 reader.py
setpriv --reuid nobody --regid nogroup --clear-groups \
        --inh-caps +net_bind_service --ambient-caps +net_bind_service python3 reader.py

Two mechanisms are at work. Unix file permissions stopped the read: nobody is neither the file's owner nor in its group, so mode 640 denies it, whatever capabilities it holds (the root-only CAP_DAC_OVERRIDE would bypass that, which is why you never grant it lightly). Capabilities are the fine-grained pieces of root's power: clearing them all took away port 80; granting back only CAP_NET_BIND_SERVICE returned the low-port bind and nothing else. A real service is packaged this way, dropping to a service user and keeping at most the one or two capabilities it genuinely needs, so that a remote-code-execution bug in it can't read /etc/shadow or load kernel modules.

A subtlety worth knowing: an ambient capability must also be in the inheritable set to survive the execve into Python. The first attempt used --inh-caps -all --ambient-caps +net_bind_service and the bind still failed, because clearing the inheritable set dropped the capability before Python started; --inh-caps +net_bind_service fixed it. Capability sets are famously fiddly, which is itself an argument for simpler isolation (containers, systemd's AmbientCapabilities= and User=) over hand-rolled calls.

Experiment 2: why layers multiply (and when they don't)

Treat each control as independently stopping an attack with some probability, and chain them:

Text
layer                        stops attack   chance the attack still succeeds
  input validation               70%             30.000%
  parameterised queries          95%              1.500%
  low-privilege DB user          60%              0.600%
  network policy                 50%              0.300%
  monitoring + alert             40%              0.180%

The product rule, P(through all) = Π (1 − pᵢ), is why no one control has to be perfect: five mediocre, independent layers beat one "99%" layer (1% through). This is the quantitative case for defence in depth. But the independence assumption is where real systems fail: if "input validation" and "parameterised queries" are the same ORM, a bug in it removes both at once; if "network policy" and "monitoring" both trust one service-mesh identity, one stolen token defeats both. When you draw a defence-in-depth diagram, label what each layer assumes; layers that share an assumption are one layer wearing two hats.

A pitfall worth internalising

The numbers above are a model, not a measurement of real effectiveness, and treating made-up percentages as if they were measured is a classic security-theatre mistake. Use the model to reason about structure (independence, how many layers, where the single points of trust are), not to claim "we are 99.8% secure". Real assurance comes from threat modelling (chapter 113), testing, and the track record of each control, not from multiplying guesses.

Try it yourself

  1. Add CAP_DAC_OVERRIDE to the capability set and re-run experiment 1. Which result changes, and why is that capability so dangerous?
  2. Use unshare --user --map-root-user --net to give the reader a network namespace with no interfaces; can it still bind port 80, and what does "bind" even mean there?
  3. Rewrite experiment 2 so two layers share a common dependency that fails with probability 0.1; compute the real "through" probability and compare with the naive product.

Revision sheet: security foundations

Key ideas

  • CIA triad: confidentiality, integrity, availability (+ authenticity, non-repudiation).
  • AAA: authentication (who), authorisation (what you may do), accounting/audit (what happened).
  • Risk = likelihood × impact; treat by reduce / accept / transfer / avoid.
  • Saltzer–Schroeder principles: economy of mechanism, fail-safe defaults, complete mediation, open design (no security by obscurity), least privilege, least common mechanism, psychological acceptability, separation of privilege.
  • Defence in depth: independent layers; blast-radius reduction.
  • Zero trust: no implicit trust from network location; authenticate and authorise every request on identity and device posture.
  • Secure by design: threat model early, eliminate bug classes (memory-safe languages, safe APIs), shift security left.

Numbers to remember

  • Lab: root could read a 640 root file and bind port 80; nobody could do neither; nobody + CAP_NET_BIND_SERVICE could bind only.
  • Five independent layers at 70/95/60/50/40% leave 0.18% through; the product rule needs independence.

Pitfalls

  • Running services as root "to make it work".
  • Security by obscurity instead of open, reviewed design.
  • Defence-in-depth layers that share a dependency, secret or assumption.
  • Treating modelled control percentages as measured assurance.
  • Authenticating but not authorising (or the reverse).

Glossary

  • Capability: a divisible piece of root's power (Linux CAP_*).
  • Trust boundary: where data or control crosses between parties of different privilege.
  • Blast radius: how much a single compromise can reach.
  • Complete mediation: every access is checked, every time.
  • Fail-safe default: deny unless explicitly allowed.