# OS Hardening

OS hardening is the process of reducing an operating system’s attack surface and enforcing secure configurations to limit compromise and its impact.

Cloud concept. Updated 2026-10-29. Page: https://blowstack.com/tools/cloud-concepts-hub/os-hardening

> OS hardening turns a general-purpose operating system into a controlled baseline suited to a specific workload. It combines minimal software, restricted privileges, secure configuration, patching, and monitoring so that compute instances and container workloads expose fewer opportunities for attack.

Practice exams covering OS Hardening: [SCS-C03 AWS Certified Security - Specialty](https://blowstack.com/practice-exams/aws-certified-security-specialty).

## 6 key aspects of OS Hardening

Effective OS hardening combines minimal software, secure configuration, least privilege, reproducible images, and continuous verification throughout the workload lifecycle.

1. **Attack-surface reduction**: Install only required packages and disable unnecessary services, accounts, and listeners. Validate that removing components does not break application dependencies or required management access.
2. **Secure configuration baselines**: Define version-controlled settings for authentication, permissions, auditing, host firewalls, and operating-system security mechanisms. Adapt recognized benchmarks to the workload and record justified exceptions.
3. **Least-privilege execution**: Separate application identities from administrative identities and limit elevation to specific operational needs. Run container processes as non-root where feasible and enforce additional capability restrictions at runtime.
4. **Reproducible image pipelines**: Build versioned VM and container images from trusted inputs using automated configuration and tests. Include required security agents without embedding credentials or other reusable secrets.
5. **Continuous maintenance and drift control**: Patch supported operating systems, rebuild images, and explicitly deploy updated workloads. Detect and remediate deviations from the baseline rather than assuming the initial image remains secure indefinitely.
6. **Verification and operational safety**: Combine vulnerability assessment with configuration checks and application tests. Use staged rollouts, health checks, and rollback procedures to avoid turning a security change into an availability incident.

## Cloud services for OS Hardening

EC2 Image Builder creates tested, versioned AMIs and container images containing approved configurations and required agents. AWS Systems Manager manages deployed hosts, applies patching policies, and helps maintain configuration state. Amazon ECR stores container artifacts, while Amazon Inspector supplies vulnerability findings for supported EC2 workloads and ECR images. Teams use those findings to update image recipes, rebuild artifacts, and roll out replacements. These services support the hardening lifecycle, but engineers must still define baselines, test application compatibility, enforce runtime controls, and verify remediation.

- **[EC2 Image Builder](https://blowstack.com/tools/cloud-services-hub/ec2-image-builder)**: Automates pipelines for building, testing, and distributing AMIs and container images. Build components can apply patches and hardening settings, while test components verify the resulting image before distribution.
- **[AWS Systems Manager](https://blowstack.com/tools/cloud-services-hub/aws-systems-manager)**: Supports ongoing host management through capabilities such as State Manager, Run Command, Patch Manager, and Session Manager. Managed nodes need the required agent, permissions, and connectivity; Session Manager can reduce reliance on inbound administrative ports when appropriately configured.
- **[Amazon Inspector](https://blowstack.com/tools/cloud-services-hub/amazon-inspector)**: Assesses supported EC2 instances and container images in Amazon ECR for software vulnerabilities, with EC2 scanning also identifying supported network exposure findings. Its findings inform remediation priorities but do not establish complete compliance with an OS configuration benchmark.

## OS Hardening exam questions

Real practice exam questions on OS Hardening, with the correct answer and its explanation.

### Question 1 (SCS-C03)

**Question:**

A company builds a Linux container image for a compiled application. The build downloads private dependencies by using a repository token. The Dockerfile copies the token into the image, compiles the application, and deletes the token and compiler in a later instruction. A security review recovers the token from the published image and finds that the image still includes substantial build-tool content.

The company requires published images to contain neither the build credential nor the build toolchain. The application must also start without root privileges. The application needs only its compiled executable and a documented set of runtime libraries; it does not need the repository token at runtime.

Which build design meets these requirements?

**Correct answer:** Use a multi-stage build. Supply the token to the dependency-download instruction through a BuildKit secret mount without writing it into build outputs. Copy only the executable and required runtime libraries into a minimal final stage, and configure that stage to run as a non-root user.

**Explanation:** The secret mount makes the token available during the required build instruction without incorporating it into an image layer. A separate final stage that receives only explicitly selected runtime artifacts excludes the build toolchain and builder filesystem. Configuring a non-root user in the final stage establishes the required default execution identity.

## Practice OS Hardening in a full exam

Questions on OS Hardening in each practice exam, with every answer option and an explanation for each:

- [SCS-C03](https://blowstack.com/practice-exams/aws-certified-security-specialty): 6 questions

## What is OS Hardening

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.

## Learn OS Hardening in lessons

2 short lessons on OS Hardening in 1 certification course.

- SCS-C03: OS Hardening: EC2 guest OS baselines (Premium), https://app.blowstack.com/lessons/os-hardening-ec2-guest-os-baselines-scs-c03
- SCS-C03: OS Hardening: Container image baselines (Premium), https://app.blowstack.com/lessons/os-hardening-container-image-baselines-scs-c03
