OS hardening starts with deciding what a workload actually needs and disabling or removing everything else. A general-purpose image may contain unnecessary services, administrative tools, default accounts, or permissive settings. Hardening replaces those defaults with a documented, testable security baseline. Recognized benchmarks, such as CIS Benchmarks, provide starting points, but settings must match the operating system, workload, and operational requirements rather than being applied blindly.
For cloud virtual machines, the customer generally controls the guest operating system while the provider secures the underlying infrastructure. A hardened baseline might disable password-based remote login, restrict administrative privileges, configure host firewalls, enforce file permissions, enable security auditing, and retain mandatory access controls such as SELinux where supported. Network security groups and identity permissions complement these controls; they do not configure or patch the guest operating system.
A practical implementation uses an automated image pipeline. Start with a trusted, supported base image, install approved packages and updates, apply configuration rules, and embed required management and security agents. Test both the controls and application functionality before publishing a versioned image. On AWS, EC2 Image Builder can automate building and testing Amazon Machine Images and container images. For example, a Linux web-server AMI could include the Systems Manager Agent and configured audit logging while disabling unused daemons and direct root login.
Never bake credentials, private keys, or reusable application secrets into an image. Remove build-time artifacts and unwanted access material before publication, restrict who can modify or distribute images, and retrieve runtime secrets through an authorized mechanism. An installed management agent is not automatically operational: it also needs suitable permissions, connectivity, and configuration. When instances fail to appear in Systems Manager, check these prerequisites before weakening the host baseline.
Container hardening applies the same principles to the image’s user-space components. Use a trusted minimal base, remove unnecessary build tools, update dependencies, and configure a non-root application user where feasible. Containers normally share the host kernel, so a hardened container image does not replace host hardening. Controls such as dropping Linux capabilities, avoiding privileged mode, and using a read-only root filesystem must also be enforced through runtime or orchestration configuration; they are not guaranteed by the image alone.
Hardening continues after deployment. Detect configuration drift, assess vulnerabilities, collect security logs, and rebuild images when patches or baseline changes are required. Updating an AMI does not update instances already launched from it, and rebuilding a container image does not replace running containers. Roll out replacement workloads or use controlled in-place remediation, with health checks and rollback procedures.
The main trade-off is reduced flexibility: removing shells can complicate debugging, restrictive permissions can break applications, and kernel updates may require restarts. Test changes on representative workloads and document exceptions with owners and review dates. Vulnerability scanning is not equivalent to hardening, and a clean scan does not prove that authentication, auditing, or permissions are secure. The goal is a reproducible, maintained baseline with evidence that both security controls and operational functions work.