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.05compatibility: Claude Code, Codex, Gemini CLI6metadata:7 author: ai-skills8 version: "1.0"9 category: devops10 tags: security, hardening, docker, ssh, iam, firewall, least-privilege11---1213## Overview1415Provides 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.1617## When to Use This Skill1819- Preparing infrastructure for production or a security review.20- After a penetration test or vulnerability scan highlights infrastructure issues.21- Onboarding a new cloud account or server.2223## Prerequisites2425- Servers or containers you control.26- Cloud account (AWS/GCP/Azure) admin access for IAM work.27- Ability to rebuild or update existing infrastructure.2829## Steps30311. **OS hardening (Linux)**:32 - Automatic security updates (unattended-upgrades on Debian/Ubuntu, dnf-automatic on RHEL).33 - SSH: key-only auth, disable password, disable root login, change port or use fail2ban.34 - Firewall: ufw or firewalld — allow only necessary ports from specific sources.35362. **Docker / container hardening**:37 - Run as non-root user (create user in Dockerfile, `USER` instruction).38 - Read-only root filesystem + tmpfs for writable dirs.39 - Drop all capabilities, add only needed ones.40 - No `--privileged`, no `--network host` unless absolutely required.41 - Use distroless or minimal base images.42433. **Cloud IAM**:44 - Least privilege: start with zero and grant only required actions/resources.45 - Use IAM roles for EC2 / service accounts instead of long-lived keys.46 - Enable MFA for all human users.47 - Service control policies (SCPs) / organization policies to prevent dangerous actions at scale.48494. **Secrets**:50 - Never in env vars or code.51 - Use AWS Secrets Manager / Parameter Store / GCP Secret Manager / HashiCorp Vault.52 - Rotate regularly.53545. **Network**:55 - Private subnets for app/DB tiers.56 - Security groups / NACLs / firewall rules with least exposure.57 - WAF in front of public endpoints.58596. **Output**:60 - Hardening checklist by severity (Critical / High / Medium).61 - Dockerfile snippet showing hardened user + read-only.62 - Terraform / cloudformation snippets for IAM roles and security groups.63 - Ansible / cloud-init for OS hardening.64 - Verification commands (`ss -tuln`, `docker inspect`, `aws iam simulate-principal-policy`).6566## Examples6768A hardened Dockerfile, ufw + SSH config, least-privilege IAM role for a web app, and a full checklist with commands are included.6970## Edge Cases & Error Handling7172- **Legacy apps that require root**: Document the risk and isolate them as much as possible.73- **Break-glass access**: Maintain emergency procedures with additional approvals.7475## Verification76771. Run CIS benchmarks or a scanner (Lynis, Docker Bench, Prowler, ScoutSuite).782. Attempt SSH with password — denied.793. Container runs as non-root and read-only FS (test by trying to write to /).804. IAM policy simulation shows only allowed actions.815. Success: Infrastructure passes automated hardening scanners with minimal or no critical findings, and manual tests confirm reduced attack surface.8283## References8485- [CIS Benchmarks](https://www.cisecurity.org/benchmarks/)86- [Docker Security](https://docs.docker.com/engine/security/)87- [AWS Well-Architected Security Pillar](https://docs.aws.amazon.com/wellarchitected/latest/security-pillar/welcome.html)88- [Prowler](https://github.com/prowler-cloud/prowler) (cloud security scanner)