Overview
Provides a prioritized hardening checklist and implementation guide for OS, containers, and cloud accounts. Covers unattended upgrades, SSH key-only access + fail2ban, firewall (ufw or security groups), Docker non-root + read-only FS + no privileged, cloud IAM least-privilege + SCPs, secret management, network segmentation, and a severity-based checklist.
When to Use This Skill
- Preparing infrastructure for production or a security review.
- After a penetration test or vulnerability scan highlights infrastructure issues.
- Onboarding a new cloud account or server.
Prerequisites
- Servers or containers you control.
- Cloud account (AWS/GCP/Azure) admin access for IAM work.
- Ability to rebuild or update existing infrastructure.
Steps
OS hardening (Linux):
- Automatic security updates (unattended-upgrades on Debian/Ubuntu, dnf-automatic on RHEL).
- SSH: key-only auth, disable password, disable root login, change port or use fail2ban.
- Firewall: ufw or firewalld — allow only necessary ports from specific sources.
Docker / container hardening:
- Run as non-root user (create user in Dockerfile,
USER instruction).
- Read-only root filesystem + tmpfs for writable dirs.
- Drop all capabilities, add only needed ones.
- No
--privileged, no --network host unless absolutely required.
- Use distroless or minimal base images.
Cloud IAM:
- Least privilege: start with zero and grant only required actions/resources.
- Use IAM roles for EC2 / service accounts instead of long-lived keys.
- Enable MFA for all human users.
- Service control policies (SCPs) / organization policies to prevent dangerous actions at scale.
Secrets:
- Never in env vars or code.
- Use AWS Secrets Manager / Parameter Store / GCP Secret Manager / HashiCorp Vault.
- Rotate regularly.
Network:
- Private subnets for app/DB tiers.
- Security groups / NACLs / firewall rules with least exposure.
- WAF in front of public endpoints.
Output:
- Hardening checklist by severity (Critical / High / Medium).
- Dockerfile snippet showing hardened user + read-only.
- Terraform / cloudformation snippets for IAM roles and security groups.
- Ansible / cloud-init for OS hardening.
- Verification commands (
ss -tuln, docker inspect, aws iam simulate-principal-policy).
Examples
A hardened Dockerfile, ufw + SSH config, least-privilege IAM role for a web app, and a full checklist with commands are included.
Edge Cases & Error Handling
- Legacy apps that require root: Document the risk and isolate them as much as possible.
- Break-glass access: Maintain emergency procedures with additional approvals.
Verification
- Run CIS benchmarks or a scanner (Lynis, Docker Bench, Prowler, ScoutSuite).
- Attempt SSH with password — denied.
- Container runs as non-root and read-only FS (test by trying to write to /).
- IAM policy simulation shows only allowed actions.
- Success: Infrastructure passes automated hardening scanners with minimal or no critical findings, and manual tests confirm reduced attack surface.
References
1---2name: security-hardening3description: Hardens server, container, and cloud infrastructure against common attacks. Use when preparing infrastructure for production or after a security audit.4license: Apache-2.05---67## Overview89Provides a prioritized hardening checklist and implementation guide for OS, containers, and cloud accounts. Covers unattended upgrades, SSH key-only access + fail2ban, firewall (ufw or security groups), Docker non-root + read-only FS + no privileged, cloud IAM least-privilege + SCPs, secret management, network segmentation, and a severity-based checklist.1011## When to Use This Skill1213- Preparing infrastructure for production or a security review.14- After a penetration test or vulnerability scan highlights infrastructure issues.15- Onboarding a new cloud account or server.1617## Prerequisites1819- Servers or containers you control.20- Cloud account (AWS/GCP/Azure) admin access for IAM work.21- Ability to rebuild or update existing infrastructure.2223## Steps24251. **OS hardening (Linux)**:26 - Automatic security updates (unattended-upgrades on Debian/Ubuntu, dnf-automatic on RHEL).27 - SSH: key-only auth, disable password, disable root login, change port or use fail2ban.28 - Firewall: ufw or firewalld — allow only necessary ports from specific sources.29302. **Docker / container hardening**:31 - Run as non-root user (create user in Dockerfile, `USER` instruction).32 - Read-only root filesystem + tmpfs for writable dirs.33 - Drop all capabilities, add only needed ones.34 - No `--privileged`, no `--network host` unless absolutely required.35 - Use distroless or minimal base images.36373. **Cloud IAM**:38 - Least privilege: start with zero and grant only required actions/resources.39 - Use IAM roles for EC2 / service accounts instead of long-lived keys.40 - Enable MFA for all human users.41 - Service control policies (SCPs) / organization policies to prevent dangerous actions at scale.42434. **Secrets**:44 - Never in env vars or code.45 - Use AWS Secrets Manager / Parameter Store / GCP Secret Manager / HashiCorp Vault.46 - Rotate regularly.47485. **Network**:49 - Private subnets for app/DB tiers.50 - Security groups / NACLs / firewall rules with least exposure.51 - WAF in front of public endpoints.52536. **Output**:54 - Hardening checklist by severity (Critical / High / Medium).55 - Dockerfile snippet showing hardened user + read-only.56 - Terraform / cloudformation snippets for IAM roles and security groups.57 - Ansible / cloud-init for OS hardening.58 - Verification commands (`ss -tuln`, `docker inspect`, `aws iam simulate-principal-policy`).5960## Examples6162A hardened Dockerfile, ufw + SSH config, least-privilege IAM role for a web app, and a full checklist with commands are included.6364## Edge Cases & Error Handling6566- **Legacy apps that require root**: Document the risk and isolate them as much as possible.67- **Break-glass access**: Maintain emergency procedures with additional approvals.6869## Verification70711. Run CIS benchmarks or a scanner (Lynis, Docker Bench, Prowler, ScoutSuite).722. Attempt SSH with password — denied.733. Container runs as non-root and read-only FS (test by trying to write to /).744. IAM policy simulation shows only allowed actions.755. Success: Infrastructure passes automated hardening scanners with minimal or no critical findings, and manual tests confirm reduced attack surface.7677## References7879- [CIS Benchmarks](https://www.cisecurity.org/benchmarks/)80- [Docker Security](https://docs.docker.com/engine/security/)81- [AWS Well-Architected Security Pillar](https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/welcome.html)82- [Prowler](https://github.com/prowler-cloud/prowler) (cloud security scanner)