Skip to content
Tutorials Center
My learning

Topics

Lesson 4 of 37 ยท Getting Started

Defence in Depth and Core Principles

Learn defence in depth, least privilege, default deny, fail-safe design and attack surface reduction, and simulate layered controls with runnable Python.

A castle did not rely on a single wall. It had a moat, an outer wall, an inner wall, a gatehouse and guards, so that breaking through one barrier still left the attacker facing the next. Network security uses the same idea, called defence in depth (or layered security). No control is perfect: firewalls are misconfigured, software has bugs, people click links. If one failure can hand an attacker everything, the design is fragile.

Alongside defence in depth sit a handful of design principles that appear in every good security architecture. They are simple to state and surprisingly hard to follow consistently. This lesson explains each one, then lets you simulate layered controls to see how much safer the layers make a network.

Defence in depth

The goal is that an attacker must defeat several independent controls, ideally of different kinds, to reach something valuable. A typical layered design for a web application looks like this:

flowchart LR
    I["Internet"] --> E["Edge: DDoS filtering and firewall"]
    E --> W["DMZ: web servers and WAF"]
    W --> A["App tier: internal firewall"]
    A --> D["Database tier: strict allow-list"]
    D --> B["Backups and encryption at rest"]

Traffic crosses several checkpoints. Each tier can only talk to the next one.

The layers fall into groups: perimeter (edge firewall, DDoS protection), network (segmentation, internal firewalls), host (patching, host firewall, endpoint protection), application (input validation, authentication) and data (encryption, backups, access control). People and process are a layer too: training, change control and incident response.

Core principles

Least privilege. Give every user, service and device only the access needed for its job. A web server needs to talk to the database on one port; it does not need to reach the whole internal network. If it is compromised, the attacker inherits only that small slice.

Default deny. Block everything, then allow specific needs. The opposite, "allow everything, block known bad", fails whenever the attacker does something you did not predict. Default deny turns the unknown into blocked.

Minimise attack surface. Every open port, running service and installed package is a potential entry point. Remove what you do not use, and close what you cannot remove to everyone who does not need it.

Fail secure. When a control breaks, it should block rather than allow. A firewall that crashes should stop forwarding, not pass everything. (Some safety systems prefer fail-open, such as a door that unlocks in a fire. Decide on purpose.)

Separation of duties. No single person should be able to complete a sensitive change alone. The person who writes a firewall rule is not the only person who approves it.

Keep it simple. Complexity hides mistakes. A ruleset nobody understands is a ruleset nobody can review.

Assume breach. Design as if an attacker is already inside some part of the network. That mindset drives segmentation, monitoring and the zero trust ideas later in this course.

Do not rely on obscurity. Hiding a service on an unusual port is not protection. The attacker can scan. Secrecy of keys is security; secrecy of design is a bonus at best.

Simulating layers

Suppose an attack succeeds against a single control with some probability. If the controls are independent, the chance the attacker gets through all of them is the product of the individual chances. The program below shows how quickly layering lowers the odds. It also shows the catch: layers that share a weakness (for example, all depending on the same admin password) are not independent and help much less.

Python How layers multiply the odds

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.

The second result is the lesson: three layers that all trust the same credential are barely better than one. Diversity matters. Use different vendors, different technologies and different credentials for different layers where you can.

Default deny versus default allow

A concrete way to see the difference is to run the same traffic through both policies. The unknown service on port 31337 gets through the allow-by-default policy and is stopped by the deny-by-default one.

Python Default allow versus default deny

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.

Default deny does cost effort: someone must understand what the network needs. That effort is the point, because it forces the owner to know what the network does.

Applying the principles in practice

  • Inventory first. You cannot protect devices you do not know about. Keep a list of hosts, services and who owns them.
  • Segment early. Put servers, workstations, guests and IoT devices in separate zones from day one (segmentation comes later in this chapter sequence).
  • Log at every layer. Layered defences also give layered evidence. A blocked packet at the edge, an alert at the WAF and an odd login on a host together tell a story.
  • Review regularly. Rules age. Services that were needed last year may be gone, and their open ports remain.

Defence in depth is not "buy more products". Stacking tools you do not monitor or maintain adds complexity without adding safety. Every layer needs an owner.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does least privilege mean?

    Least privilege limits the damage of a compromised account or service by restricting it to what its job requires.
  2. 2. Why is default deny stronger than a deny-list of known bad ports?

    A deny-list only stops what you predicted. Default deny blocks everything not explicitly allowed, including things nobody thought of.
  3. 3. Three security layers all rely on the same administrator password. What is the main problem?

    Defence in depth works when failures are independent. A shared weakness lets one compromise bypass every layer.
  4. 4. A firewall crashes. Which behaviour is 'fail secure' for a network firewall?

    Fail secure means that a failure results in a safe state. For a firewall, blocking is the safe state.

Summary

  • Defence in depth stacks independent controls so one failure is not fatal.
  • Core principles: least privilege, default deny, small attack surface, fail secure, separation of duties, simplicity, assume breach.
  • Layers multiply the attacker's odds only when they are independent; a shared weakness collapses them.
  • Obscurity is not a control; inventory, segmentation and logging make layering real.
  • Every layer needs an owner and regular review.

Next: Legal and Ethical Ground Rules, and a Safe Lab