23.7. Practical Lab: Publishing an Internal HTTPS Application

This lab assembles the whole chapter into one deliverable: an application published at https://app.handbook.test/, reachable and verifiable from a client host, with automated certificate renewal and a rehearsed backend-failure recovery. Everything has already been built once, section by section; the lab's work is to see it as one system and to practice the checks that keep it standing.

23.7.1. Providing Client Addresses, DNS Records, and a Private Trust Root

A client needs three things before it can use the service, and all three are already in place on the practice network - this subsection is the checklist, plus the one client-side operation that has not been exercised yet: withdrawing trust.

Client need Provided by Where
an address on the practice LAN static interface configuration Chapter 17; the intro table's addresses
name resolution for *.handbook.test dnsmasq on web1 Section 23.1.3, verified there with getent
trust for the lab's root CA the system trust store Section 23.3.1's update-ca-certificates run

Trust is the one that deserves a rehearsal, because retiring a compromised or retired root is an operation you want to have done once before you need it. The certificate file added in Section 23.3.1 is /usr/local/share/ca-certificates/handbook-lab-root.crt. Removing it withdraws trust for every lab name at once: until it is restored, HTTPS checks against the practice servers will fail certificate validation. Remove it, on client1, as john - the removal itself prints nothing; the next command reports the effect:

$ sudo rm /usr/local/share/ca-certificates/handbook-lab-root.crt
$ sudo update-ca-certificates
Updating certificates in /etc/ssl/certs...
rehash: warning: skipping ca-certificates.crt, it does not contain exactly one certificate or CRL
0 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

The count exposes a subtlety worth knowing before it surprises you: plain update-ca-certificates processes additions - it does not remove the bundle entry for a file that is gone. The bundle still contains the lab root. The documented way to rebuild the bundle from what is actually present is --fresh, on client1, as john:

$ sudo update-ca-certificates --fresh
Clearing symlinks in /etc/ssl/certs...
done.
Updating certificates in /etc/ssl/certs...
rehash: warning: skipping ca-certificates.crt, it does not contain exactly one certificate or CRL
148 added, 0 removed; done.
Running hooks in /etc/ca-certificates/update.d...
done.

Every symlink was cleared and the 148 roots still installed were relinked - the lab's root is not among them, so it is now fully withdrawn. Reinstalling it repeats Section 23.3.1's add exactly (install -m 0644 of root.crt into /usr/local/share/ca-certificates/, then update-ca-certificates, which reports 1 added, 0 removed) and restores the clients. Do that now before moving on; the rest of the lab depends on it.

23.7.2. Deploying the Application, Reverse Proxy, and TLS Configuration

From a bare set of four hosts, the deployment is the chapter's procedures in this order - each step cites the section with its complete commands and file contents:

  1. web1 - names and certificates. Configure the internal resolver (Section 23.1.3), install Apache and its modules (Section 23.2.1), build the practice hierarchy with make-ca.sh (Section 23.3.1), and install the certificate material for the Apache names (Section 23.4.1).
  2. web1 - Apache sites. Create the document roots and site files, enable www and shop, validate, reload (Sections 23.2.2 through 23.2.4), then enable the TLS vhosts (Section 23.4.1).
  3. web2 - the edge. Install Nginx (Section 23.3.1), copy the wildcard material over and install it (Section 23.3.1), deploy the log format and the static site, validate, restart (Section 23.3.1).
  4. app1 - the application. Create the service account, the two release trees, the environment file, and the units; enable and start them (Section 23.5.1). Load the backend filter (Section 23.5.2) and, for the PHP side, the pool and its script (Section 23.5.4).
  5. web2 - proxying. Deploy app.conf for the application and php.conf for the PHP site, validate, reload (Sections 23.5.3 and 23.5.4).
  6. client1 - trust. Install the root into the trust store (Section 23.3.1; the withdrawal rehearsal above assumes it is back in place).

The file destinations follow the roles: everything under /etc/apache2 belongs to web1, everything under /etc/nginx to web2, and everything under /etc/systemd/system, /etc/handbook, /etc/php, and /etc/nftables-ch23.nft to app1. The shared fixtures/ tree in john's workspace is identical on every host except for the certificate files, which exist in full only on web1 (keys never leave the host that uses them); web2 and client1 hold copies of exactly the files they consume.

23.7.3. Checking Client Requests, Certificate Renewal, and Backend Failure Recovery

Acceptance is checked from the client, in this order:

  1. Name and trust. getent hosts app.handbook.test resolves to 192.168.234.11 (Section 23.1.3's check), and curl -sS https://app.handbook.test/ returns the application page with client= set to the client's own address and scheme=https - the two fields that prove DNS, TLS trust, the proxy hop, and the forwarded headers all work (Section 23.5.3's captures show both responses).
  2. Headers. curl -sSI https://app.handbook.test/ shows HTTP/2, an x-request-id, and the strict-transport-security header, as captured in Section 23.5.3.
  3. The real path. The WebSocket exercise of Section 23.5.3 - python3 fixtures/ws/ws-client.py wss://app.handbook.test/ws returning the echo line - is the one end-to-end check that exercises the upgraded-connection path, not just plain request and response.
  4. Health. curl -sS https://app.handbook.test/healthz reports status ok, the release currently selected, and the database reachable (Section 23.6.2's capture).
  5. Renewal. Confirm the automated renewal is real, not assumed: systemctl list-timers certbot.timer shows the next run (Section 23.4.3's capture); a forced renewal against the test server, or a --dry-run against a public staging environment, completes the challenge-to-reload pipeline; and the served certificate's serial and dates change afterwards (Section 23.4.3's verification procedure).
  6. Failure recovery. Rehearse the drill of Section 23.6.4: stop handbook-app on app1, watch the client's request return 502, read the connect() failed line in web2's app.error.log, start the service again, and see 200 return through the edge. Doing this once on purpose converts the production incident from a mystery into a procedure.

When the practice network's purpose is served, the cleanup boundary is the workspace: upload.bin is already gone (Section 23.3.3), the CA material under ~/debian-handbook/web-services/ca/ can be archived or deleted with rm -r, and the fixtures/ tree was disposable from the start. The system configuration - sites, units, pools, the trust root on clients - is the running service; remove it only by uninstalling deliberately, or by rebuilding the practice hosts. On any real host, the equivalent teardown is a decision about the service, not the files: disable the sites, stop the units, withdraw the trust - each the reverse of the procedure that installed it.