You run production servers. A critical CVE drops at 3 AM. You need a repeatable process that catches it, tests it, deploys it safely, and rolls back if something breaks. Not a vague policy document—a workflow you can actually execute.
I've seen teams lose half a day scrambling because they had no tested process. The steps below assume a Linux environment (Debian/Ubuntu or RHEL/CentOS family), but the structure translates to any stack. You'll walk away with monitoring feeds wired up, a staging lane for patches, deployment scripts that don't touch every server at once, and a rollback plan you've already rehearsed.
Step 1: Wire Up CVE Monitoring and Alerting
You can't patch what you don't know about. Set up automated monitoring so critical CVEs hit your inbox or Slack channel within minutes of disclosure.
Subscribe to Distribution Security Feeds
Every major distribution publishes a security mailing list:
- Debian: debian-security-announce
- Ubuntu: ubuntu-security-announce
- RHEL/CentOS/Rocky/Alma: redhat-watch-list or the vendor's equivalent
Subscribe with a dedicated email address (like [email protected]) and route it to your ticketing system or a monitoring channel. These lists announce CVEs affecting packages in the official repos, often with severity scores and patch availability.
Install and Configure a CVE Scanner
For real-time checks against your installed packages, run a local scanner on each server. Two solid options:
Option A: Trivy (works across distros, supports container images too)
# Install trivy
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo "deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/trivy.list
sudo apt update && sudo apt install trivy
# Scan the OS for CVEs
trivy rootfs --severity CRITICAL,HIGH /
Option B: Lynis (security auditing with CVE checks)
sudo apt install lynis
sudo lynis audit system --quick
Schedule these scans via cron (daily at minimum) and parse the output for CRITICAL findings. Pipe results to a log aggregator or send a summary email if any high-severity CVE appears.
Centralize Alerts
If you manage multiple servers, centralize alerts in one place. A simple approach:
#!/bin/bash
# /usr/local/bin/cve-check.sh
trivy rootfs --severity CRITICAL --format json / > /tmp/cve-report.json
CRIT_COUNT=$(jq '[.Results[].Vulnerabilities[] | select(.Severity=="CRITICAL")] | length' /tmp/cve-report.json)
if [ "$CRIT_COUNT" -gt 0 ]; then
curl -X POST https://your-slack-webhook-url \
-H 'Content-Type: application/json' \
-d "{\"text\":\"⚠️ $HOSTNAME: $CRIT_COUNT critical CVEs detected\"}"
fi
Add this to root's crontab on each server, or run it from a central management node via SSH in a loop.
With feeds and scanners running, you'll know about a critical CVE before your users do.
Step 2: Build a Staging Environment for Patch Testing
Never apply a security patch directly to production, even if the CVE is rated critical. Packages can introduce regressions, break application dependencies, or require configuration changes. You need a staging server that mirrors production.
Clone Your Production Configuration
The staging server should run the same OS version, kernel, installed packages, and application stack as production. If you manage infrastructure as code (Ansible, Puppet, Chef), provision staging from the same playbooks. If not, snapshot a production instance and spin up a staging clone (just make sure it doesn't serve real traffic or touch production databases).
Create a Snapshot or Backup Before Patching
Always take a snapshot before testing patches. On a VM:
# Example with QEMU/KVM
virsh snapshot-create-as staging-vm pre-patch-snapshot
On a cloud instance (AWS, DigitalOcean, Linode), use the provider's snapshot feature. On bare metal, use LVM snapshots if your root filesystem is on LVM:
lvcreate -L 5G -s -n root_snapshot /dev/vg0/root
This snapshot becomes your instant rollback if the patch breaks something.
Apply the Patch and Run a Test Suite
Update the affected package:
# Debian/Ubuntu
sudo apt update
sudo apt install --only-upgrade <package-name>
# RHEL/CentOS/Rocky
sudo dnf upgrade <package-name>
After the upgrade, run your application's test suite (unit tests, integration tests, smoke tests). At minimum, verify:
- The service restarts without errors:
systemctl status <service> - Critical endpoints respond correctly (curl a health-check URL, run a DB query, etc.)
- Logs show no new errors after restart
If staging passes for 24-48 hours with normal-ish load (or a load test if you have one), the patch is ready for production.
Step 3: Automate Phased Deployment to Production
Rolling out a patch to all production servers at once is how you turn a security fix into an outage. Deploy in phases: one canary server, then a small batch, then the rest.
Define Your Deployment Groups
Segment your production fleet:
- Canary: 1-2 servers (or 5-10% of your fleet if large)
- Batch 1: 25-30% of remaining servers
- Batch 2: The rest
Tag these groups in your inventory (Ansible hosts file, a spreadsheet, or your CMDB). Example Ansible inventory snippet:
[production]
web01.example.com deployment_group=canary
web02.example.com deployment_group=batch1
web03.example.com deployment_group=batch1
web04.example.com deployment_group=batch2
web05.example.com deployment_group=batch2
Write a Deployment Playbook
Here's a minimal Ansible playbook for patching:
---
- name: Apply critical CVE patch
hosts: "{{ target_group }}"
serial: 1
become: yes
tasks:
- name: Take LVM snapshot if available
shell: lvcreate -L 2G -s -n pre_patch_$(date +%s) /dev/vg0/root
ignore_errors: yes
- name: Upgrade affected package
apt:
name: "{{ package_name }}"
state: latest
update_cache: yes
when: ansible_os_family == "Debian"
- name: Restart service
systemd:
name: "{{ service_name }}"
state: restarted
- name: Wait for service health check
uri:
url: "http://localhost:{{ health_check_port }}/health"
status_code: 200
retries: 5
delay: 3
Run it in stages:
ansible-playbook patch.yml -e "target_group=canary package_name=openssl service_name=nginx"
# Wait 30 minutes, monitor logs and metrics
ansible-playbook patch.yml -e "target_group=batch1 ..."
# Wait another 30 minutes
ansible-playbook patch.yml -e "target_group=batch2 ..."
The serial: 1 directive patches one host at a time within each group. If a host fails the health check, Ansible stops the playbook and you can investigate before touching the rest.
Monitor During Deployment
Watch error rates, response times, CPU, and memory during each phase. If the canary shows elevated errors or crashes, halt and roll back (covered next). A simple check:
# Check service status on canary
ansible canary -m shell -a "systemctl is-active nginx"
# Tail logs for errors
ansible canary -m shell -a "journalctl -u nginx --since '5 minutes ago' | grep -i error"
If the canary is clean for 30-60 minutes and metrics look normal, move to the next batch.
Step 4: Prepare and Test Your Rollback Procedure
Patches fail. A rollback procedure you've never tested is not a rollback procedure—it's a hope. Rehearse it at least once in staging so you know it works under pressure.
Rollback via Package Downgrade
Most package managers support downgrading to the previous version:
Debian/Ubuntu (if the old .deb is still cached):
sudo apt install <package-name>=<old-version>
# Example: sudo apt install openssl=1.1.1f-1ubuntu2
If the old package isn't cached, you'll need to fetch it from a snapshot repo like snapshot.debian.org or keep a local mirror of previous package versions.
RHEL/CentOS/Rocky:
sudo dnf downgrade <package-name>
After downgrade, restart the service and verify health.
Rollback via LVM Snapshot
If you took an LVM snapshot before patching (Step 2), you can merge it back:
# Unmount the filesystem (requires downtime or a reboot)
umount /
lvconvert --merge /dev/vg0/root_snapshot
reboot
The server boots from the pre-patch state. This is faster and cleaner than package-level rollback if multiple packages were updated or if config files changed.
Rollback via VM Snapshot
For virtualized or cloud instances, revert to the snapshot taken before patching:
# KVM example
virsh snapshot-revert staging-vm pre-patch-snapshot
# AWS CLI example
aws ec2 create-image --instance-id i-1234567890abcdef0 --name "pre-patch-backup"
# Then terminate and launch from the snapshot AMI if needed
Cloud snapshots introduce more steps (stop instance, revert, restart), so they're better suited for severe failures than quick rollbacks.
Document and Drill the Rollback
Write a one-page runbook with exact commands for each rollback method. Store it in your wiki or a ROLLBACK.md in your repo. Once a quarter, pick a non-critical patch and rehearse the rollback in staging. Time how long it takes and fix any missing steps.
The first time you need to roll back a production patch at 2 AM, you'll be glad you practiced.
What to Check First When a Patch Fails
If a patch causes errors, start here: check the service logs (journalctl -u <service> or /var/log/<service>/), verify the config file syntax if the package updated a config, and confirm all dependencies upgraded together (some CVE fixes span multiple packages). Roll back, fix the issue in staging, then try again.
A patching workflow isn't glamorous, but it's the difference between a controlled fix and a midnight scramble. Build it once, test it twice, and you'll handle the next critical CVE with a checklist instead of chaos.
![How to Set Up Critical CVE Patching Workflow [Solved in 4 Steps]](/images/blog/how-to-set-up-critical-cve-patching-workflow-solved-in-4-steps.jpg)