
From CVE to patch: automatic remediation with Amazon Inspector and Systems Manager
How to automatically detect and remediate CVE-2026-98432 on EC2 with Amazon Inspector, EventBridge, SSM Automation and Patch Manager.
🎥 Watch the talk where I walk through this lab (in Spanish, AWS UG AI Perú Meetup):  https://youtu.be/NN94pxOGufY?t=1671Â
🇪🇸 Versión en español:  https://builder.aws.com/content/3LcpIgD2tHzjPaOkyCPXkPO0qS1/del-cve-al-parche-remediacion-automatica-con-amazon-inspector-y-ssmÂ
Level: 300 · Category: Security · Reading time: 12 min
The problem: a kernel CVE and an unpatched fleet
On October 15, 2026, Â CVE-2026-98432Â was published: a use-after-free in the Linux kernel's IPv4 TCP connection handling. It is triggered by a SYN carrying IPv4 options sent to a listening port, before the application authenticates anything. It affects kernels since 4.4, and the maintained branches already have fixes.
The kernel CVE team scored it 9.8 (critical). Amazon Linux scored it 8.1 (Important), because it rates the attack complexity as high. That difference matters, as we will see in step 6.
The real risk is not the CVE itself: it is the time between the fix being released and your server having it installed. With 5 instances you can check by hand; with 50 across several accounts, one gets left behind.
In this article we build a flow that closes that gap with no human intervention:
- Amazon Inspector detects the vulnerability on your EC2 instances.
- Amazon EventBridge reacts if the finding is severe, matches the chosen CVE and has a fix available.
- AWS Systems Manager Automation checks that the instance opted in to automatic patching.
- Patch Manager installs the update and reboots if needed.
- The runbook verifies the running kernel and any pending packages.
- Amazon SNS sends you that result.
Prerequisites
- An AWS account with administrator permissions (a lab, not production).
- Terraform 1.5 or later and the AWS CLI configured. AWS CloudShell works.
- EC2 instances with the SSM Agent and the Â
AmazonSSMManagedInstanceCoreÂrole (Amazon Linux 2023 ships with the agent).
Architecture
EC2 → Inspector → EventBridge → SSM Automation → Patch Manager → SNS
Inspector scans each EC2 instance through the SSM Agent and publishes one event per finding. An EventBridge rule keeps only active, HIGH or CRITICAL findings on EC2, with a fix available and for the CVEs you choose, and starts an SSM Automation runbook with the instance ID.
The runbook has four steps:
- Check: confirms the instance has the Â
AutoPatch=trueÂtag. If not, it stops and touches nothing.
- Patch: runs Â
AWS-RunPatchBaselineÂwith ÂOperation=InstallÂand ÂRebootOption=RebootIfNeededÂ.
- Verify: shows the running kernel and any packages still pending for the CVE.
- Notify: publishes the instance, the CVE and what it checked to SNS.
Why the tag? Because rebooting a production database at 3 p.m. is an incident too. The tag lets you decide which instances patch themselves and which wait for a maintenance window.
Implementation with Terraform
Step 0: provider and variables
terraform { required_version = ">= 1.5" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } }}
provider "aws" { region = var.region}
variable "region" { type = string default = "us-east-1"}
variable "alert_email" { type = string}
variable "cve_ids" { description = "CVEs that trigger patching." type = list(string) default = ["CVE-2026-98432"]}
data "aws_caller_identity" "current" {}data "aws_region" "current" {}
locals { account = data.aws_caller_identity.current.account_id region = data.aws_region.current.name}Step 1: enable Amazon Inspector for EC2
resource "aws_inspector2_enabler" "this" { account_ids = [local.account] resource_types = ["EC2"]}Step 2: SNS topic for notifications
resource "aws_sns_topic" "patching" { name = "cve-auto-patching"}
resource "aws_sns_topic_subscription" "email" { topic_arn = aws_sns_topic.patching.arn protocol = "email" endpoint = var.alert_email}Step 3: a patch baseline with no delay
The predefined Amazon Linux 2023 baseline approves patches seven days after release. With it, the runbook finishes successfully and does not install a brand-new patch. This baseline approves Critical and Important security patches with no delay, only for instances tagged Â
PatchGroup=cve-auto :resource "aws_ssm_patch_baseline" "al2023_immediate" { name = "al2023-security-immediate" operating_system = "AMAZON_LINUX_2023"
approval_rule { approve_after_days = 0 compliance_level = "CRITICAL"
patch_filter { key = "CLASSIFICATION" values = ["Security"] } patch_filter { key = "SEVERITY" values = ["Critical", "Important"] } }}
resource "aws_ssm_patch_group" "auto" { baseline_id = aws_ssm_patch_baseline.al2023_immediate.id patch_group = "cve-auto"}Step 4: least-privilege automation role
This is the key security detail: the role can only run commands on instances tagged Â
AutoPatch=true . Even if someone edits the runbook, IAM blocks the rest. Whoever can set that tag decides what gets rebooted, so restrict that permission too.data "aws_iam_policy_document" "automation_trust" { statement { actions = ["sts:AssumeRole"] principals { type = "Service" identifiers = ["ssm.amazonaws.com"] } }}
resource "aws_iam_role" "automation" { name = "cve-patch-automation" assume_role_policy = data.aws_iam_policy_document.automation_trust.json}
data "aws_iam_policy_document" "automation" { statement { actions = ["ec2:DescribeTags"] resources = ["*"] } statement { actions = ["ssm:SendCommand"] resources = [ "arn:aws:ssm:${local.region}::document/AWS-RunPatchBaseline", "arn:aws:ssm:${local.region}::document/AWS-RunShellScript", ] } statement { actions = ["ssm:SendCommand"] resources = ["arn:aws:ec2:${local.region}:${local.account}:instance/*"] condition { test = "StringEquals" variable = "ssm:resourceTag/AutoPatch" values = ["true"] } } statement { actions = [ "ssm:ListCommands", "ssm:ListCommandInvocations", "ssm:DescribeInstanceInformation", ] resources = ["*"] } statement { actions = ["sns:Publish"] resources = [aws_sns_topic.patching.arn] }}
resource "aws_iam_role_policy" "automation" { role = aws_iam_role.automation.id policy = data.aws_iam_policy_document.automation.json}Step 5: the SSM Automation runbook
The Â
VerifyPatch step keeps the email from claiming something that was not checked: it reports the running kernel and any packages still pending for the CVE.resource "aws_ssm_document" "patch_on_cve" { name = "PatchInstanceOnCVE" document_type = "Automation" document_format = "YAML"
content = <<-DOC schemaVersion: '0.3' description: Patches an EC2 instance tagged AutoPatch=true and reports what it checked. assumeRole: '{{ AutomationAssumeRole }}' parameters: InstanceId: type: String allowedPattern: '^i-[0-9a-f]{8,17}$' CveId: type: String allowedPattern: '^CVE-[0-9]{4}-[0-9]{4,}$' AutomationAssumeRole: type: String default: '${aws_iam_role.automation.arn}' TopicArn: type: String default: '${aws_sns_topic.patching.arn}' mainSteps: - name: CheckAutoPatchTag action: aws:assertAwsResourceProperty onFailure: Abort inputs: Service: ec2 Api: DescribeTags Filters: - Name: resource-id Values: ['{{ InstanceId }}'] - Name: key Values: ['AutoPatch'] PropertySelector: '$.Tags[0].Value' DesiredValues: ['true'] - name: InstallPatches action: aws:runCommand timeoutSeconds: 3600 onFailure: Abort inputs: DocumentName: AWS-RunPatchBaseline InstanceIds: ['{{ InstanceId }}'] Parameters: Operation: Install RebootOption: RebootIfNeeded - name: VerifyPatch action: aws:runCommand timeoutSeconds: 600 onFailure: Abort inputs: DocumentName: AWS-RunShellScript InstanceIds: ['{{ InstanceId }}'] Parameters: commands: - 'echo "running kernel: $(uname -r)"' - 'echo "pending for {{ CveId }}:"' - 'dnf -q updateinfo list --releasever=latest --cve={{ CveId }}' - name: Notify action: aws:executeAwsApi inputs: Service: sns Api: Publish TopicArn: '{{ TopicArn }}' Subject: 'Patching result: {{ CveId }}' Message: | Instance {{ InstanceId }} CVE {{ CveId }} If no package is listed under "pending", the advisory is fully applied. {{ VerifyPatch.Output }} DOC}Step 6: the EventBridge rule that triggers everything
The filter keeps noise out: only active findings on EC2, with a fix available and for the CVEs in the list. It accepts HIGH as well as CRITICAL because Amazon Linux rates this CVE as Important, and a rule that only matches CRITICAL might never fire. Scoping by CVE also keeps an old AMI with dozens of findings from starting dozens of executions on the same instance.
resource "aws_cloudwatch_event_rule" "cve" { name = "inspector-cve-with-fix" event_pattern = jsonencode({ source = ["aws.inspector2"] "detail-type" = ["Inspector2 Finding"] detail = { severity = ["CRITICAL", "HIGH"] status = ["ACTIVE"] fixAvailable = ["YES"] resources = { type = ["AWS_EC2_INSTANCE"] } packageVulnerabilityDetails = { vulnerabilityId = var.cve_ids } } })}
data "aws_iam_policy_document" "events_trust" { statement { actions = ["sts:AssumeRole"] principals { type = "Service" identifiers = ["events.amazonaws.com"] } }}
resource "aws_iam_role" "events" { name = "cve-patch-eventbridge" assume_role_policy = data.aws_iam_policy_document.events_trust.json}
data "aws_iam_policy_document" "events" { statement { actions = ["ssm:StartAutomationExecution"] resources = ["arn:aws:ssm:${local.region}:${local.account}:automation-definition/${aws_ssm_document.patch_on_cve.name}:*"] } statement { actions = ["iam:PassRole"] resources = [aws_iam_role.automation.arn] }}
resource "aws_iam_role_policy" "events" { role = aws_iam_role.events.id policy = data.aws_iam_policy_document.events.json}
resource "aws_cloudwatch_event_target" "start_automation" { rule = aws_cloudwatch_event_rule.cve.name arn = "arn:aws:ssm:${local.region}:${local.account}:automation-definition/${aws_ssm_document.patch_on_cve.name}:$DEFAULT" role_arn = aws_iam_role.events.arn
input_transformer { input_paths = { instance = "$.detail.resources[0].id" cve = "$.detail.packageVulnerabilityDetails.vulnerabilityId" } input_template = <<-EOF {"InstanceId": ["<instance>"], "CveId": ["<cve>"]} EOF }}The repository also includes two test instances from an AMI published before the fix: one tagged Â
AutoPatch=true and  PatchGroup=cve-auto , and one with no tags.Testing
- Deploy with Â
terraform initÂand Âterraform apply -var="alert_email=you@example.com" -var="lab_ami_id=ami-XXXX"Â, then confirm the SNS subscription email.
- Wait for Inspector to scan and query the finding:
aws inspector2 list-findings \ --filter-criteria '{"vulnerabilityId":[{"comparison":"EQUALS","value":"CVE-2026-98432"}]}' \ --query 'findings[].[resources[0].id,severity,inspectorScore,status,fixAvailable]' --output table- The tagged instance should patch itself. Check Systems Manager > Automation and your email.
- To skip the wait, run the runbook directly. EventBridge rejects test events with an Â
aws.*Âsource, so this is the way to validate it:
aws ssm start-automation-execution \ --document-name PatchInstanceOnCVE \ --parameters InstanceId=i-0123456789abcdef0,CveId=CVE-2026-98432- Repeat with the untagged instance: the runbook must abort at Â
CheckAutoPatchTagÂand the finding must stay active.
- Compare the installed package with the  Amazon Linux advisory .
Best practices before production
- Start with non-critical environments. Tag only dev and staging; for production, combine this flow with Systems Manager maintenance windows.
- Avoid reboots with Kernel Live Patching. Amazon Linux 2023 supports it and reduces the need for Â
RebootIfNeededÂ.
- Handle concurrency. One kernel update fixes several CVEs, so several findings for the same instance can arrive together. Before patching, check whether an execution is already running for that instance, or queue and batch the findings.
- Scale to multi-account. Use Inspector with a delegated administrator in AWS Organizations and centralize events on a cross-account EventBridge bus.
- Keep audit evidence. Send Run Command output to S3 or CloudWatch Logs, along with the previous kernel and the execution ID.
- Watch the cost. Inspector has a free trial and then charges per scanned instance; run Â
terraform destroyÂwhen the lab is done.
Conclusion
With Terraform you went from "I found out about the CVE on social media" to "my instances patch themselves and tell me what changed". The key is not the automation itself but the guardrails around it: a filter that understands how your distribution scores vulnerabilities, a baseline that does not wait a week, the opt-in tag, the condition-scoped IAM policy and a verification before the alert.
If this helped, leave a comment: how long does your team take today to patch a critical CVE?
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article