Sub topic 3
A Safe Hardening Workflow: Baseline, Snapshot, Rollback
Assume you can use the Linux command line, systemd, a text editor, file permissions, basic networking, and sudo. You also need a test server or virtual machine where you can safely change configuration.
Hardening changes a server's security settings to reduce attack paths. A safe workflow makes each change measurable and reversible. Do not apply every recommendation at once. A firewall rule, SSH setting, or mount option can interrupt the service you need to administer the host.
1. Record the baseline
A baseline is a record of the server before changes. Record the operating system version, hostname, IP addresses, listening ports, enabled services, mounted filesystems, installed security tools, and current benchmark results.
Keep the baseline outside the server when possible. If an attacker changes the host, local records may also be changed.
hostnamectl
ip address
ss -tulpen
systemctl list-unit-files --state=enabled
findmnt --list
sudo journalctl --since "24 hours ago" > baseline-journal.txtRun the benchmark scanner that matches the operating system and save its report. Separate failed recommendations into three groups:
- Safe to apply without a service change.
- Requires testing or a maintenance window.
- Conflicts with the server's role and needs an approved exception.
A failed check is not automatically a defect. For example, a database server may need a service or mount option that a general-purpose baseline discourages.
2. Capture a recovery point
Create a tested recovery point before changing configuration. A virtual machine snapshot is useful for a short change window. An LVM snapshot can provide a similar checkpoint for an LVM-backed system. Neither replaces a backup: snapshots can disappear with the storage system or preserve corrupted data.
Back up the configuration files you will edit and export the current firewall rules. Store copies with timestamps and restrict their permissions because some files contain sensitive settings.
stamp=$(date +%Y%m%d-%H%M%S)
sudo tar --xattrs --acls -czf "/root/pre-cis-$stamp.tgz" \
/etc/ssh /etc/sudoers /etc/sudoers.d /etc/sysctl.d /etc/fstab
sudo nft list ruleset | sudo tee "/root/nft-before-$stamp.conf" >/dev/null
sudo chmod 600 "/root/pre-cis-$stamp.tgz" "/root/nft-before-$stamp.conf"Test that the recovery point is usable. A backup that has never been restored is only an assumption.
3. Apply, verify, and record changes
Group related changes into small batches. After each batch, validate syntax, reload the affected service, and test the expected behavior. For example, run sshd -t before reloading SSH, and run nft -c before loading a firewall file.
Record the change, operator, time, test result, and rollback command. This creates an audit trail and makes later troubleshooting faster.
4. Roll back deliberately
When a change fails, stop adding changes. Preserve logs and the failed configuration, restore the last known-good file or snapshot, and test access from a separate session. Then identify whether the problem came from syntax, ordering, a workload dependency, or an incorrect assumption.
After rollback, document the failed recommendation and its business impact. If the setting is necessary, create an exception with an owner, compensating control, review date, and expiration date.
Exercise
Why should you create a baseline before taking a snapshot?
Show answer
The baseline records behavior and configuration, while the snapshot provides a recovery point. You need both to compare the result and restore the system.