Guide: Update the kernel and apply security patches
Patch a VM, ECS host or container image after a vulnerability scan: find your distro, open its folder, run the steps in order.
The vulnerability scan export flags three kinds of things. Each one needs a different fix:
- OS packages and kernels on VMs: patch with the distro’s package manager, then reboot.
- Container images in ECR: patching a running container doesn’t help. Rebuild the image and redeploy it.
- App runtimes the OS doesn’t manage (Chromium bundled with Puppeteer, Node.js, Java, nginx, Splunk Forwarder): upgrade the app or its dependency.
1. Find out which distro the VM runs
Section titled “1. Find out which distro the VM runs”Linux: Check the OS release and running kernel
Look at the ID= line and open that folder. Each folder has every step, in the order you run them:
ID= |
Folder |
|---|---|
ubuntu, debian |
Ubuntu |
amzn + VERSION_ID="2" |
Amazon Linux 2 |
rhel, rocky, ol, almalinux, centos, or amzn + VERSION_ID="2023" |
RHEL / AL2023 |
sles, opensuse-leap |
SUSE |
dnf and yum don’t exist on Ubuntu, and apt doesn’t exist on Amazon Linux or RHEL. A command not found error usually means you’re in the wrong folder.
2. Back up before you patch
Section titled “2. Back up before you patch”Take an AMI of the instance first so you can roll back:
aws ec2 create-image --instance-id <instance-id> --name <name>-before-patch --no-reboot3. Patch, in this order
Section titled “3. Patch, in this order”Each folder follows the same steps:
- List pending updates and pending security updates.
- Apply all updates, or only the security updates, or fix one advisory or CVE.
- Update the kernel.
- Upgrade one package, or install the exact “Fixed In” version.
- Check whether a reboot is needed, then reboot.
- Confirm the new kernel, and remove the old kernels.
- Check the package changelog to confirm a CVE is fixed.
4. Container images
Section titled “4. Container images”Docker: Check the base OS of an image Docker: Patch OS packages in a Debian or Ubuntu Dockerfile Docker: Patch OS packages in an Alpine Dockerfile Linux: Upgrade one package on Alpine Docker: Rebuild an image with the latest base image Trivy: Scan an image for high and critical CVEs AWS: Show ECR scan findings for an image AWS: Rescan an image in ECR
5. ECS hosts and patching many VMs
Section titled “5. ECS hosts and patching many VMs”ECS hosts (kernel, docker, containerd, nvidia toolkit) are patched by moving them to the newest AMI:
AWS: Get the latest ECS-optimized AMI ID
To patch many EC2 instances at once, use SSM Patch Manager:
AWS: Scan instances for missing patches with SSM AWS: Install patches with SSM and reboot if needed AWS: Check the patch state of an instance
6. App runtimes
Section titled “6. App runtimes”Linux: Check versions of common runtimes on a host Linux: Find bundled Chromium binaries on a host Linux: Upgrade nginx and restart it safely
Related
Section titled “Related”- Runbook: Free disk space on a full Linux host (
/bootfull after kernel updates) - Guide: How to write titles
My DevOps Playbook by Angelo John Calleja