Lab 19: Large-Scale Patch Management

Time: 45 minutes | Level: Architect | Docker: docker run -it --rm --privileged ubuntu:22.04 bash

Overview

Patch management at scale requires automation, staged rollouts, and compliance reporting. In this lab you will configure unattended-upgrades for security-only updates, use apt-mark hold to protect critical packages, simulate patch operations, implement a canary deployment pattern, and build a compliance reporting script. These techniques support maintenance windows and rolling update strategies in enterprise fleets.


Step 1 — Install Patch Management Tools

apt-get update -qq && apt-get install -y -qq \
  unattended-upgrades \
  apt-utils \
  needrestart \
  debsecan 2>/dev/null || \
apt-get install -y -qq unattended-upgrades apt-utils 2>/dev/null

dpkg -l unattended-upgrades | tail -1

📸 Verified Output:

ii  unattended-upgrades  2.8  all  automatic installation of security upgrades

Step 2 — Configure unattended-upgrades for Security-Only Updates

📸 Verified Output:

📸 Verified Output:


Step 3 — Simulate Patch Operations (Dry Run)

📸 Verified Output:

💡 Tip: In CI/CD pipelines, run apt-get upgrade --simulate and parse the output. If non-zero package count, fail the job and notify the team to review.


Step 4 — apt-mark: Hold Critical Packages

📸 Verified Output:


Step 5 — needrestart & Service Restart Analysis

After patching, needrestart identifies services that need restarting (to pick up updated libraries).

📸 Verified Output:


Step 6 — debsecan: CVE Tracking

📸 Verified Output:


Step 7 — Canary Deployment & Rolling Update Strategy

📸 Verified Output:


Step 8 — Capstone: Patch Compliance Reporting

Build a complete patch compliance reporting script that generates a JSON compliance report for fleet management tools:

📸 Verified Output:


Summary

Topic
Tool / File
Purpose

Security-only updates

/etc/apt/apt.conf.d/50unattended-upgrades

Automatic security patching

Enable auto-upgrades

/etc/apt/apt.conf.d/20auto-upgrades

Periodic triggers

Dry-run simulation

apt-get upgrade --simulate

Preview without applying

Package hold

apt-mark hold <pkg>

Prevent auto-upgrade of critical packages

Service restart analysis

needrestart -b

Find services needing restart post-patch

CVE tracking

debsecan --suite jammy

Map CVEs to installed packages

Canary deployment

Staged hostname-based rollout

5% → 20% → 100% fleet

Compliance report

JSON output script

Fleet management integration

Last updated