Skip to content

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.

Index
  • #linux
  • #patching
  • #kernel
  • #vulnerabilities
Created Updated

Also:kernel update · patch vm · security updates · update single package · vulnerability remediation · fix cve · dnf check-update · check-update

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.

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.

Take an AMI of the instance first so you can roll back:

Terminal window
aws ec2 create-image --instance-id <instance-id> --name <name>-before-patch --no-reboot

Each folder follows the same steps:

  1. List pending updates and pending security updates.
  2. Apply all updates, or only the security updates, or fix one advisory or CVE.
  3. Update the kernel.
  4. Upgrade one package, or install the exact “Fixed In” version.
  5. Check whether a reboot is needed, then reboot.
  6. Confirm the new kernel, and remove the old kernels.
  7. Check the package changelog to confirm a CVE is fixed.

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

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

Linux: Check versions of common runtimes on a host Linux: Find bundled Chromium binaries on a host Linux: Upgrade nginx and restart it safely

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…