← Learning Hub
Advanced

Security in Depth: KMS, Secrets, Networks

The shared responsibility model

AWS secures the cloud itself: data centres, hardware, the core network. You secure what you put in it: IAM users and roles, your data, your network rules, your app's code and passwords.

Most cloud security incidents come from simple mistakes: a leaked access key, a public S3 bucket, a database open to the internet, missing MFA. AWS gives you strong tools - secrets storage, encryption, network firewalls and audit logs - but you have to use them. This lesson is the checklist every account should follow.

Secrets: never in code

  • Secrets Manager - stores database passwords and API keys, can rotate them automatically, and your app reads them at runtime.
  • Systems Manager Parameter Store - simpler and cheaper for settings and less critical secrets (use SecureString).
Example
import json, boto3
secret = boto3.client("secretsmanager").get_secret_value(SecretId="prod/shop/db")
db = json.loads(secret["SecretString"])     # {"username": "...", "password": "..."}

Encryption with KMS

Key Management Service creates and guards encryption keys. S3, EBS, RDS, DynamoDB and Secrets Manager encrypt data at rest with KMS keys - usually just a setting to turn on. Use HTTPS (TLS) to encrypt data in transit.

Network rules

  • Security groups - a firewall around each server or database. Stateful: if a request is allowed in, the reply is allowed out. Allow only what's needed: the database accepts port 5432 only from the app's security group.
  • Network ACLs - rules for a whole subnet. Stateless: you must allow both directions. Mostly left at the default.
  • Keep databases in private subnets with no route from the internet.

Must-do account checklist

  • Turn on MFA for the root user and every person; don't use root for daily work.
  • Use IAM Identity Center or roles instead of long-lived access keys.
  • Turn on CloudTrail (who did what) and GuardDuty (threat detection).
  • Keep S3 Block Public Access on unless you really need a public bucket.
  • Use AWS WAF in front of public websites and APIs to block common attacks.
If an access key ever leaks (for example pushed to GitHub), deactivate it at once in IAM, create a new one, and check CloudTrail for what it was used for.
Key points
  • Store secrets in Secrets Manager or Parameter Store, never in code.
  • KMS encrypts data at rest; use HTTPS in transit.
  • Security groups and private subnets limit network access.
  • MFA, least privilege and CloudTrail for every account.

📝 Test yourself

1. Who is responsible for your IAM users' permissions?
2. Security groups are...
3. Fill in the service that stores and rotates database passwords:
AWS Manager