Chapter 26. System Security and Incident Response
Security is not a package you install once; it is the sum of what a system exposes, who can change it, and how quickly you can tell when something has gone wrong. This chapter treats it as an operational discipline on real Debian 13 machines. It starts by mapping what a host exposes and shrinking that surface, then confines individual programs with AppArmor and systemd, manages the credentials that remain, and - the largest single subject - operates a private certificate authority from scratch: an offline root, a restricted issuing intermediate, server and client certificates, then the whole certificate lifecycle of renewal, revocation, rollover, backup, and recovery, each verified from an independent client rather than from the host that produced it. The chapter closes with the two disciplines that make future incidents survivable: audit logging that answers "who changed what", and a rehearsed response sequence for the day the answer is "someone we did not authorize".
The practice machines and their addresses:
| Host | Role | Practice interface | Administration |
|---|---|---|---|
sec1 |
security host: private CA, TLS and mTLS web sites, private container registry, auditd, incident ground | eth1 - 192.168.246.10/24 |
eth0 - management network, 192.168.121.0/24 |
secclient |
independent client: curl, OpenSSL, skopeo, SSH; holds its own trust store and credentials | eth1 - 192.168.246.20/24 |
eth0 - management network |
Figure 26.1. Two Debian 13 guests. Management SSH arrives over eth0 and
stays out of every exercise; the isolated 192.168.246.0/24 link carries
the security work. sec1 produces the certificates, serves the TLS sites, and
runs the audit trail; secclient verifies each claim independently.
The separation is deliberate. A security claim - a certificate validates, a
revocation is enforced, a rebuilt service is reachable - is only worth
something when a second machine confirms it, because the producing host is
exactly the machine an attacker would control. The management network is
kept out of band so that no exercise in this chapter can cost the
administrator access to the hosts; firewall and containment steps always
target the practice network, whose interfaces are configured with the tools
of Chapter 17. Both hosts resolve the
practice names through /etc/hosts; on both hosts, as root, the file
contains:
192.168.246.10 sec1 web.sec1.lab wrong.sec1.lab
192.168.246.20 secclient secclient.lab
The extra wrong.sec1.lab name points at the same address as
web.sec1.lab; Section 26.4.7 uses it to watch a hostname check fail. A
production site would publish these records with DNS as described in
Chapter 22.
Commands entered in john's ordinary shell begin with $ and commands
entered in a root shell begin with #; the prompt marker itself is not
typed. A single elevated step from john's shell is written
$ sudo command, which asks for john's password the first time in a
session (the password is not echoed). CA-signing work and a few
machine-level operations use a root shell on sec1, opened from john's
account with $ sudo -i and left with exit; each such block says so
before it appears. john obtains these rights through the sudo policy of
Chapter 5; the account itself was created
there. Before each block the text names the host and account. Editing files
uses the terminal editor from Chapter 3.
Example files live under a named workspace in john's home. On both hosts, as john:
$ mkdir -p ~/debian-handbook/security
The command prints nothing on success. Unless a step changes directory,
every command on sec1 and secclient runs from
~/debian-handbook/security. After sudo -i, ~ is /root, not john's
home, so elevated steps that need the workspace spell its path out in full.
The exercises on sec1 use these Debian 13 packages, installed with the interactive procedure of Chapter 6:
$ sudo apt install nginx auditd apparmor-utils debsums libcap2-bin cryptsetup-bin gcc hello debsecan docker-registry gnupg lsof
apparmor-utils provides the aa-complain, aa-enforce, and aa-status
tools; libcap2-bin provides setcap and getcap; hello is a small
package used to demonstrate file-integrity verification; docker-registry
serves Section 26.4.6; lsof backs the socket inventory in
Section 26.7.2. On secclient, as john:
$ sudo apt install curl jq skopeo
skopeo copies and inspects container images without running a container;
Chapter 25 covers the wider container tooling. The
Debian 13 versions on the practice hosts are OpenSSL 3.5.x, AppArmor 4.1.x,
systemd 257.x, auditd 4.0.x, and nginx 1.26.x; the commands used here are
stable across those series, but check your own versions before relying on a
particular flag.