aws-security-hardening
Skill4 starsChanged 5 months agoMITView on GitHub
AWS security hardening patterns including IAM least privilege, GitHub OIDC federation, Secrets Manager, and container security. Use for securing AWS resources, eliminating long-lived credentials, IAM trust policy configuration, or implementing defense in depth.
- Reads credentials
In this repository101 other files it gives its agents.
- ai-video-understandingSkill
- apple-foundation-modelsSkill
- arch-dddSkill
- arch-decision-recordsSkill
- arch-diagramsSkill
- arch-eventsSkill
- arch-mvp-roadmapSkill
- arch-python-modernSkill
- aws-app-runnerSkill
- aws-cicd-patternsSkill
- azure-functions-python-v2Skill
- azure-identity-m2m-authSkill
- azure-service-bus-messagingSkill
- azure-workflow-execution-modelsSkill
- caddy-tls-proxySkill
- compliance-frameworksSkill
- design-system-workflowSkill
- dev-debugging-strategiesSkill
- dev-standardsSkill
- docker-python-poetrySkill
- docker-pythonSkill
- fastapi-patternsSkill
- ffmpeg-laravel-videoSkill
- formik-yup-react-nativeSkill
- frontend-accessibilitySkill
- frontend-angular-aiSkill
- frontend-angularSkill
- frontend-angular-toolingSkill
- frontend-design-systemsSkill
- frontend-material-chatSkill
- frontend-material-design-3Skill
- frontend-svelteSkill
- gcp-cicd-patternsSkill
- gcp-cloud-runSkill
- gcp-cloudsql-infrastructureSkill
- gcp-finopsSkill
- gcp-observabilitySkill
- gcp-security-hardeningSkill
- github-actions-cicdSkill
- healthkit-biofeedbackSkill
- infra-terraformSkill
- ios-app-qualitySkill
- ios-audio-hapticsSkill
- jest-nestjs-testingSkill
- langchain-azure-openai-patternsSkill
- laravel-auth-hardeningSkill
- laravel-ci-mysqlSkill
- laravel-mix-webpackSkill
- laravel-modern-patternsSkill
- laravel-pint-patternsSkill
- laravel-s3-storageSkill
- laravel-sail-dockerSkill
- mobile-app-deploymentSkill
- mobile-e2e-testingSkill
- mobile-offline-syncSkill
- mobile-push-notificationsSkill
- mobile-video-uploadSkill
- mongodb-asyncmongoclient-patternsSkill
- mongodb-atlas-patternsSkill
- nestjs-patternsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 74
When an API key lands in a committed file, prefer rotation over history rewriting.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AWS Security Hardening
Defense-in-depth security patterns for Amazon Web Services. These patterns apply to App Runner, ECS/Fargate, and other container deployment targets.
OIDC security alert: Datadog research found 500+ AWS roles with misconfigured OIDC trust policies (missing
subcondition). As of June 2025, AWS STS auto-blocks trust policies without asubcondition. Scope to specific repo AND branch.
Core Principles
| Principle | Implementation |
| Least Privilege | Scoped IAM policies, resource-level conditions |
| No Long-Lived Keys | OIDC for CI/CD, IAM roles for services |
| Defense in Depth | Multiple security layers (IAM + VPC + encryption) |
| Audit Everything | CloudTrail enabled, S3 access logging |
| Encrypt at Rest | KMS for sensitive data, S3 default encryption |
IAM Best Practices
- Avoid root account for daily operations — dedicated IAM users/roles reduce blast radius
- Scope resource fields to specific ARNs —
Resource: "*"only where AWS mandates it (e.g.,ecr:GetAuthorizationToken) - Use conditions —
aws:RequestedRegion,aws:ResourceTag,aws:PrincipalTagfor additional constraints - IAM Access Analyzer — combines external access detection and unused permission auditing into one tool
- Separate roles per workflow — deploy, terraform, and read-only roles prevent lateral movement
- Policy attachment after
create-role— roles without a subsequentput-role-policyorattach-role-policyare silently useless - GitHub OIDC
subcondition — useStringEqualswith repo + branch scope (not wildcardStringLike) per least-privilege principle
GitHub OIDC Federation
A trust policy omitting a sub-claim restriction lets any workflow in the GitHub org assume the role — a full privilege-escalation path. Restrict to specific repo AND branch. Verify the full chain: OIDC provider exists → trust policy has correct sub → permission policies attached. See examples.md for the full trust policy JSON and reference.md for multi-pattern scoping.
Secrets Manager vs SSM Parameter Store
| Criterion | Secrets Manager | SSM Parameter Store |
| Auto-rotation | Yes (Lambda-based) | No |
| Cross-account | Yes (resource policy) | Limited |
| Cost | $0.40/secret/month | Free (Standard tier) |
| Use for | Credentials, API keys, DB passwords | Config values, feature flags |
Container Security
| Practice | Implementation |
| Non-root user | USER appuser in Dockerfile |
| No secrets in image | Inject via Secrets Manager at runtime |
| Image scanning | ECR basic (free) + enhanced (Inspector, continuous) |
| Minimal base image | python:3.12-slim (not python:3.12) |
| Pin base image digest | FROM python:3.12-slim@sha256:abc... |
See reference.md for ECR scanning mode detail (basic vs enhanced/Inspector, CONTINUOUS_SCAN behavior).
Security Group Replacement Safety
SG names are immutable in AWS — renaming triggers destroy+recreate. Without a create_before_destroy lifecycle block, Terraform deletes the old SG first, causing a traffic gap. Before replacing any SG, verify it isn't attached to other resources (aws ec2 describe-network-interfaces --filters Name=group-id,Values=<SG-ID>); shared SGs (RDS, ALB, Lambda ENI) break on destroy. See reference.md for CIDR validation and scheduling guidance.
OIDC Provider Management
The GitHub OIDC provider (token.actions.githubusercontent.com) is account-scoped — only one can exist per AWS account. Use a data source to reference an existing provider without claiming ownership; a resource block fails if the singleton already exists. Confirm presence with aws iam list-open-id-connect-providers before deciding which to use. See reference.md for the EC2 SSM activation pattern for broken instance profiles.
Secrets Manager Validation
Deploying with placeholder secrets from .env.template risks exposing insecure defaults in production. Deploy-time validation scripts reject known placeholder values (PLACEHOLDER-*, changeme, TODO) before they reach production — add the guardrail early in setup-instance.sh. See examples.md for the validation bash snippet.
Key Rotation vs Git-History Scrub
When an API key lands in a committed file, prefer rotation over history rewriting. Generate a new key, update Secrets Manager, and verify the leaked one returns 403 — rotation makes the leaked value worthless immediately. git filter-repo / BFG requires force-push and disrupts collaborators.
openssl rand -hex 32 # new key
curl -w "HTTP_CODE: %{http_code}\n" -H "Authorization: Bearer <key>" "$URL" # 200 for new, 403 for the rotated-out old keyPrevention: keep secrets out of tracked files; EAS projects use eas env:create --visibility secret --environment production instead of eas.json.
SSM for Live Server Ops
When production is broken, fix the running instance first via aws ssm send-command (no SSH keys required), then codify the fix into setup-instance.sh so future rebuilds pick it up. Chain aws ssm wait command-executed + get-command-invocation for async monitoring. See reference.md for the heredoc pitfall (\n mangling in SSM JSON) and the printf workaround.
Anti-Patterns
| Anti-Pattern | Pattern |
| AWS access keys in GitHub Secrets | GitHub OIDC provider + IAM role |
OIDC trust policy with wildcard sub | Scope to repo:org/repo:ref:refs/heads/main |
AdministratorAccess for CI/CD | Scoped policies per workflow |
| Public RDS/ElastiCache endpoints | Private subnets + VPC connector |
| Secrets in Dockerfiles or env files | Secrets Manager with runtime injection |
| Unencrypted S3 state bucket | KMS + versioning + access logging + public access block |
| DynamoDB for state locking (new projects) | S3-native locking (use_lockfile = true) — preferred since TF 1.11 |
| Single IAM role for all workflows | Separate roles: deploy, terraform, read-only |
| Creating OIDC provider without checking if one exists | data source by default; create only after list-open-id-connect-providers confirms none |
| Deploying with placeholder secrets from templates | Deploy-time validation rejecting PLACEHOLDER-*, changeme, TODO values |
Running services via nohup/screen without systemd | systemd unit or Docker --restart=always for any production service |
See reference.md for Terraform state security, budget alerts, and detailed IAM policy patterns.
See examples.md for IAM JSON policies, ECR scanning config, and budget alert Terraform.
Related
caddy-tls-proxy— SSM deployment patterns and Secrets Manager secret validation at the reverse-proxy layeraws-cicd-patterns— GitHub Actions OIDC pipeline integration and CI/CD role scopingaws-app-runner— container deployment target that consumes the task-role IAM patterns defined heregithub-actions-cicd— platform-neutral GHA workflow syntax that layers on top of the OIDC trust policies above
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

