Security on AWS
Securing AWS workloads end to end — a multi-account security baseline, KMS keys and envelope encryption, Secrets Manager vs Parameter Store, ACM certificates, network protection with WAF and Shield, threat detection with GuardDuty, Security Hub, Inspector and Macie, data perimeters, incident response, and the most common AWS breach patterns.
Under the shared responsibility model, AWS secures the infrastructure and you secure everything you configure. Most real-world AWS breaches don't involve exotic exploits — they're leaked credentials, over-permissive IAM, public data and missing detection. This lesson is a practical map of the services and practices that prevent them. Identity is covered in depth in IAM.
A security baseline
- Accounts: multi-account structure with Organizations; workloads isolated from the management and security accounts (AWS fundamentals).
- Identity: root locked with MFA; people via IAM Identity Center with MFA; workloads via roles; CI via OIDC — no long-lived access keys.
- Guardrails: SCPs that deny leaving CloudTrail, disabling GuardDuty, using unapproved regions, or creating public S3 access.
- Logging: an organisation CloudTrail to a locked log-archive account; Config recording everywhere (CloudWatch and observability).
- Detection: GuardDuty, Security Hub and Inspector enabled organisation-wide, delegated to the security account.
- Data: encryption by default (EBS, S3, RDS), Block Public Access at the account level, backups with AWS Backup vault lock.
- Network: private subnets, security-group chaining, VPC endpoints, WAF on public endpoints (VPC).
- Response: runbooks and automation for the common findings; practise them.
Encryption with KMS
AWS Key Management Service creates and controls encryption keys stored in FIPS-validated hardware security modules. The keys never leave KMS unencrypted — you ask KMS to encrypt, decrypt or generate data keys, and every use is authorised by IAM and logged in CloudTrail (Symmetric encryption).
Envelope encryption
KMS itself only encrypts up to 4 KB directly. For real data, services use envelope encryption:
Bulk data is encrypted locally and fast; only the small data key travels to KMS. Revoking access to the KMS key makes all the data unreadable — a powerful control.
| Key type | Managed by | Use |
|---|---|---|
| AWS owned | AWS, invisible to you | Default encryption in many services |
AWS managed (aws/s3, aws/ebs) | AWS, visible in your account | Easy encryption with CloudTrail visibility; can't change the policy |
| Customer managed | You: key policy, rotation, deletion | Control who can decrypt, cross-account sharing, separation of duties |
- The key policy is the primary access control for a KMS key; IAM policies apply only if the key policy allows the account to delegate.
- Enable automatic rotation; old key material is retained so existing data still decrypts.
- Key deletion has a 7–30 day waiting period — deleting a key destroys every piece of data encrypted under it.
- CloudHSM gives you dedicated HSMs when regulations require single-tenant control.
Secrets
Never put passwords, API keys or tokens in code, AMIs, container images or plain environment variables committed to Git.
| Secrets Manager | SSM Parameter Store | |
|---|---|---|
| Purpose | Secrets | Configuration and secrets (SecureString) |
| Rotation | Built-in automatic rotation (RDS, Redshift, DocumentDB, or custom Lambda) | Manual |
| Cross-account, replication to other regions | Yes | Limited |
| Cost | Per secret per month + API calls | Standard parameters free |
| Choose for | Database credentials, third-party API keys | Feature flags, endpoints, non-rotating config |
Fetch secrets at startup and cache them (the Lambda extension and ECS secrets injection help), and refresh on authentication failure so rotation doesn't break you. Run secret scanning in CI and pre-commit hooks — and if a key leaks, revoke it first, then investigate.
Certificates
AWS Certificate Manager (ACM) issues free public TLS certificates for ALB, CloudFront and API Gateway and renews them automatically (with DNS validation via Route 53). AWS Private CA issues internal certificates for mTLS between services (PKI and certificates).
Edge and network protection
- AWS WAF: managed rule groups (OWASP core, known bad inputs, SQL injection, IP reputation, bot control), rate-based rules, geo rules and custom rules on CloudFront, ALB, API Gateway, AppSync and Cognito (Web security).
- Shield Standard (free, automatic) and Shield Advanced against DDoS.
- Network Firewall for stateful inspection and domain filtering of VPC egress; Route 53 Resolver DNS Firewall blocks lookups of malicious domains — a strong control against data exfiltration and malware call-backs.
- Firewall Manager applies these policies across all accounts.
Detection and posture
| Service | What it does |
|---|---|
| GuardDuty | Threat detection from CloudTrail, VPC Flow Logs, DNS logs, plus S3, EKS, RDS, Lambda and runtime monitoring — finds credential exfiltration, crypto-mining, unusual API calls, access from Tor |
| Security Hub | Aggregates findings from all of these and checks against standards (AWS Foundational Security Best Practices, CIS) with a score |
| Inspector | Continuously scans EC2, ECR images and Lambda for software vulnerabilities and network exposure |
| Macie | Discovers sensitive data (PII, credentials) in S3 |
| IAM Access Analyzer | Finds resources shared externally and unused access; validates policies |
| Detective | Investigation graphs linking findings, principals and resources |
| Config | Configuration history and compliance rules |
Route high-severity findings through EventBridge to the on-call channel and to automated remediation (quarantine an instance's security group, disable a leaked access key).
Data perimeters
A data perimeter ensures that only trusted identities access trusted resources from expected networks. It's built from conditions in SCPs, resource policies and VPC endpoint policies, such as:
aws:PrincipalOrgID— resource policies only allow principals from your organisation.aws:ResourceOrgID— endpoint policies only allow reaching buckets owned by your organisation (blocks copying data to an attacker's bucket).aws:SourceVpc/aws:SourceVpce— sensitive data only accessible through your network.
Common breach patterns
| Pattern | Prevention |
|---|---|
| Access keys leaked in Git, CI logs or a laptop | No long-lived keys; OIDC for CI; secret scanning; GuardDuty alerts on use from unusual places |
| Public S3 bucket or snapshot | Account-level Block Public Access, SCPs, Config rules, Macie |
| SSRF reaching the instance metadata service | Enforce IMDSv2, least-privilege instance roles (EC2) |
| Over-permissive roles enabling escalation | Scoped policies, permission boundaries, Access Analyzer, restricted iam:PassRole |
| SSH/RDP or databases open to 0.0.0.0/0 | Session Manager, private subnets, Config rules on security groups |
| Unpatched software | Inspector, golden AMI pipelines, managed services |
| Compromised account used for crypto-mining | Budgets and anomaly alerts, GuardDuty, SCPs limiting regions and instance types |
Incident response
- Prepare: runbooks, a break-glass role, logs centralised, contacts known, exercises run.
- Detect and analyse: GuardDuty/Security Hub finding → scope with CloudTrail (what did this principal do?), Detective, VPC Flow Logs.
- Contain: deactivate keys, revoke role sessions (an IAM policy denying tokens issued before now), isolate instances with a quarantine security group, snapshot disks for forensics — don't terminate evidence.
- Eradicate and recover: rotate credentials, rebuild from known-good images and IaC, restore data from immutable backups.
- Learn: blameless post-incident review, new guardrails and detections.
QExplain envelope encryption and why AWS uses it.medium
Data is encrypted locally with a unique symmetric data key; that data key is itself encrypted under a KMS key that never leaves the HSMs, and the encrypted data key is stored alongside the ciphertext. To decrypt, the service asks KMS to decrypt the data key — authorised by IAM and the key policy and logged in CloudTrail — then decrypts the data locally. This avoids sending large data to KMS, keeps encryption fast, limits the exposure of any single key, and lets you revoke access to all data by controlling one KMS key.
QAn access key was accidentally pushed to a public GitHub repo. What do you do?medium
Immediately deactivate (then delete) the key — revocation comes before investigation, because automated scanners exploit leaked keys within minutes. Check CloudTrail for every action taken with that key since the commit, looking for new users, roles, keys, instances (crypto-mining), changed policies or data access, and remove anything the attacker created. Review GuardDuty findings and the bill, rotate any other secrets that might be exposed, purge the key from Git history, and fix the root cause by moving that workload to roles or OIDC so no long-lived keys exist.
QSecrets Manager or Parameter Store?easy
Use Secrets Manager for secrets that need rotation, cross-account sharing or replication — database credentials and third-party API keys — since it rotates automatically. Use Parameter Store for configuration values and simple secrets that don't rotate, where its free standard tier and hierarchy of parameters are convenient. Both encrypt with KMS and integrate with Lambda, ECS and CloudFormation.
- Most AWS breaches come from leaked credentials, over-permissive IAM, public data and missing detection.
- Build a baseline: multi-account, no long-lived keys, SCP guardrails, organisation CloudTrail and Config, detection services everywhere.
- KMS uses envelope encryption; customer-managed keys give control through key policies; deleting a key destroys its data.
- Store secrets in Secrets Manager (with rotation) or Parameter Store; never in code or images.
- Protect the edge with WAF and Shield, egress with Network Firewall and DNS Firewall, and data with perimeter conditions.
- Detect with GuardDuty, Security Hub, Inspector and Macie; contain incidents by revoking credentials first and preserving evidence.