Root cause of missing security updates in Cloud‑Init
Cloud‑Init runs during the first boot of an EC2 instance, executing the cloud‑init modules defined in /etc/cloud/cloud.cfg. If the package_update or package_upgrade modules are disabled, or if the instance uses a cached AMI that was built without the latest repositories, security patches will not be installed. Network restrictions, IAM policies that block access to the package repository, and custom cloud.cfg that sets disable_root: true can also prevent update commands from executing.
- Root cause of missing security updates in Cloud‑Init
- Common configuration pitfalls
- How to enable security updates in Cloud‑Init
- Modify /etc/cloud/cloud.cfg
- Use user‑data to enforce updates
- Validate network access
- Automating ongoing security patches
- Table: Cloud‑Init update settings by distribution
- Testing the fix
More from this site
Keep reading the latest coverage
Common configuration pitfalls
Several settings in the default Cloud‑Init configuration lead to skipped updates:
- apt_update: false (Ubuntu/Debian) or yum_update: false (RHEL/CentOS) disables the repository refresh.
- The package_upgrade: false flag stops the actual upgrade step.
- Using cloud_final_modules that omit package_update or package_upgrade.
- Network ACLs or security groups that block outbound HTTP/HTTPS traffic to the distro's mirrors.
How to enable security updates in Cloud‑Init
Adjust the Cloud‑Init configuration on the base AMI or in user data:
Modify /etc/cloud/cloud.cfg
Set the following keys to true:
- apt_update: true or yum_update: true
- package_upgrade: true
Ensure the module list includes package_update and package_upgrade in cloud_init_modules or cloud_final_modules as appropriate.
Use user‑data to enforce updates
Insert a cloud‑init script that runs after networking is ready:
#cloud-config package_update: true package_upgrade: true runcmd:- [ yum, -y, update ] # for Amazon Linux / RHEL
- [ apt-get, -y, upgrade ] # for Ubuntu/Debian
Validate network access
Confirm the instance can reach the appropriate repository URLs. A quick curl -I https://repo.amazonaws.com test from the instance helps spot blocked egress.
Automating ongoing security patches
Cloud‑Init only runs at boot, so recurring updates require additional mechanisms. Common approaches include:
- Amazon SSM Patch Manager – schedule patch baselines that run yum update or apt-get upgrade on a defined cadence.
- Launch templates that reference a hardened AMI built nightly with the latest security patches.
- Cron jobs or systemd timers that invoke the package manager daily.
Table: Cloud‑Init update settings by distribution
| Distribution | Cloud‑Init flag | Default value |
|---|---|---|
| Ubuntu/Debian | apt_update | false |
| Ubuntu/Debian | package_upgrade | false |
| Amazon Linux/RHEL/CentOS | yum_update | false |
| Amazon Linux/RHEL/CentOS | package_upgrade | false |
Testing the fix
After editing cloud.cfg or adding user data, launch a new instance and inspect the Cloud‑Init log (/var/log/cloud‑init.log). Look for entries like "Running module package_update" and verify that the latest security packages appear in the package manager's history.