Agent Wranglers

INF-46Required

Install security updates by themselves

Let every long-lived server install security updates by itself every day, and reboot in a set window when the kernel needs it. Servers you replace instead of patching get a rebuilt image within 24 hours of each security update.

How to do it

Use the system's own tool, such as unattended-upgrades on Debian and Ubuntu or dnf-automatic on Red Hat family systems. Set a reboot time when traffic is low. On a fleet of immutable servers, patch the image instead of the running servers. A daily job rebuilds the image when a security update is out, and the rollout replaces the servers. Alert when a server has waited more than 7 days for a reboot. The deadlines for patches are in keep software current.

Examples

Shell example

# Debian and Ubuntu: prints security updates still waiting. Expect nothing.
apt list --upgradable 2>/dev/null | grep -- '-security'
# Prints the age of a pending reboot in days, if one is pending
[ -f /var/run/reboot-required ] && echo $(( ($(date +%s) - $(stat -c %Y /var/run/reboot-required)) / 86400 ))

INI example

# /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";

# /etc/apt/apt.conf.d/52unattended-upgrades-local
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:00";

INI example 2

# /etc/dnf/automatic.conf, then: systemctl enable --now dnf-automatic.timer
[commands]
upgrade_type = security
apply_updates = yes
reboot = when-needed

How to check

apt list --upgradable lists no package from a security pocket, or dnf updateinfo list --security lists none, outside the 24 hours after a release. On a fleet, run the same query on one server per running image. It lists no security update older than 24 hours. No server has had /var/run/reboot-required for more than 7 days.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/infrastructure/servers/automatic-security-updates">Agent Wranglers infrastructure and environments playbook</a>. In code you write, add a comment next to it with the same link.