AWS Security & Identity Deep Dive for Backend Engineers

🔐 AWS Security & Identity Deep Dive for Backend Engineers

IAM | KMS | GuardDuty — Access Control, Encryption & Threat Detection


🚀 Introduction

Security is not a layer you “add later” — it’s built into every AWS decision.
Whether you’re deploying an EC2 service, running an EKS pod, or encrypting S3 data, AWS gives you primitives to control access, encrypt data, and detect anomalies.

This post covers the three pillars every backend engineer must master:

  1. IAM (Identity & Access Management) – Who can do what?

  2. KMS (Key Management Service) – How is data encrypted and controlled?

  3. GuardDuty – How are threats and anomalies detected?


🧱 1. AWS IAM — Identity and Access Management

🔹 What is IAM?

AWS IAM controls who can perform what actions on which resources under what conditions.
Everything in AWS — whether a human, service, or container — operates under an identity governed by IAM.


🧩 IAM Core Building Blocks

ConceptDescriptionCredential Type
UserLong-term identity for a human or external appPassword / Access key
RoleTemporary identity assumed by a trusted service or userSTS token
PolicyJSON document defining allowed or denied actionsn/a
GroupCollection of users sharing common policiesn/a
Trust PolicyDefines who can assume the rolen/a
Permission PolicyDefines what actions the identity can performn/a

🧠 Visual: How IAM Objects Relate

┌───────────────────────────────┐ │ AWS IAM │ └───────────────────────────────┘ │ ▼ ┌──────────────────────────┐ │ Identity (User / Role) │ ← "Who" └───────────┬──────────────┘ │ Attached Policy JSON ← "What they can do" │ ▼ ┌──────────────────────────┐ │ AWS Resource (S3, EC2...)│ ← "On which resource" └──────────────────────────┘

🧍‍♂️ IAM User — Permanent Identity (For People or Long-Lived Systems)

An IAM User is meant for humans or applications that require long-term credentials.
They log in to the AWS console or access APIs via access keys.

Example use case:

  • A developer (Vinod) logs in via the AWS CLI using his access key.

  • A CI/CD system like Jenkins deploys code using an IAM user.

{ "Version": "2012-10-17", "Statement": [{ "Effect": "Allow", "Action": "s3:GetObject", "Resource": "arn:aws:s3:::my-data-bucket/*" }] }

✅ User can download files.
❌ Cannot delete or write unless policy allows.


🎭 IAM Role — Temporary Identity (For AWS Services or Federated Users)

Unlike users, roles don’t have permanent credentials.
They are assumed by trusted entities (AWS services like EC2, Lambda, or EKS pods) through the AWS STS (Security Token Service) which issues short-lived credentials.


🧩 The Role’s Two Parts

TypePurposeExample
Trust PolicyDefines who can assume the roleEC2, Lambda, EKS, or cross-account user
Permission PolicyDefines what actions the role can performs3:GetObject, dynamodb:PutItem

🧠 Role vs User Analogy

ConceptAnalogyCredentialsLifetime
UserEmployee with a permanent badgeYesLong-term
RoleVisitor pass valid for a few hoursNoTemporary

💡 Diagram: User vs Role

┌──────────────────────┐ │ IAM User (Human/App) │ │ - Has password/key │ │ - Long-lived access │ └──────────┬───────────┘ │ ▼ ┌──────────────────────┐ │ IAM Role (Service) │ │ - No credentials │ │ - Temporary access │ └──────────────────────┘

⚙️ Practical IAM Use Cases

🧩 Example 1 — EC2 Instance → S3 Access via Role

When launching an EC2 instance, you can attach an IAM Role called an Instance Profile.
That role tells AWS, “this instance can access S3.”

┌──────────────┐ EC2 Instance └──────┬───────┘ AssumeRole (via metadata) ┌──────────────────────┐ IAM Role: EC2S3Role - Trust: ec2.amazonaws.com - Policy: s3:GetObject └──────────┬───────────┘ ┌─────────────┐ S3 Bucket └─────────────┘

Trust Policy (who can assume):

{ "Effect": "Allow", "Principal": { "Service": "ec2.amazonaws.com" }, "Action": "sts:AssumeRole" }

Permission Policy (what it can do):

{ "Effect": "Allow", "Action": ["s3:GetObject"], "Resource": ["arn:aws:s3:::my-app-config/*"] }

✅ EC2 now fetches configuration files securely — no static keys stored.


🧩 Example 2 — EKS Pod → S3 via IAM Role (IRSA)

EKS pods can assume roles using IAM Roles for Service Accounts (IRSA).

Pod → ServiceAccount → IAM Role → S3

Trust Policy:

{ "Effect": "Allow", "Principal": { "Federated": "arn:aws:iam::<acct>:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/XXXX" }, "Action": "sts:AssumeRoleWithWebIdentity", "Condition": { "StringEquals": { "oidc.eks.us-east-1.amazonaws.com/id/XXXX:sub": "system:serviceaccount:default:s3-reader" } } }

✅ The pod automatically assumes its role and retrieves temporary credentials — no access keys required.


🧩 Example 3 — IAM User → S3

Human user (Vinod) accessing S3 via AWS CLI using an access key.

1. User authenticates → IAM 2. IAM reads attached policy 3. If policy allows s3:GetObject → Access granted

Policy:

{ "Effect": "Allow", "Action": ["s3:GetObject"], "Resource": "arn:aws:s3:::my-analytics-data/*" }

🧩 Example 4 — Cross-Account Role

Account A’s EC2 instance can access a Role in Account B if trust policy allows:

Account A EC2 → AssumeRole → Role in Account B → S3

🧩 IAM Summary Table

Identity TypeUsed ByCredentialsDurationExample Access
UserHuman / appAccess key / passwordLong-termDeveloper CLI
Role (EC2)AWS ServiceSTS TokenTemporaryEC2 → S3
Role (IRSA)EKS PodOIDC Token → STSTemporaryPod → S3
Cross-Account RoleExternal AWS accountSTS TokenTemporaryBackup jobs

🔐 IAM – Complete Flow Overview

┌──────────────┐ │ Identity │ (User / Role / Pod / EC2) └──────┬───────┘ │ Signed Request ▼ ┌──────────────┐ │ AWS STS │ Issues temp credentials └──────┬───────┘ ▼ ┌──────────────┐ │ IAM Policies │ Evaluate allow/deny └──────┬───────┘ ▼ ┌──────────────┐ │ AWS Service │ (e.g., S3) └──────────────┘

🧠 Quick IAM Takeaways

  • IAM User → permanent human or app identity

  • IAM Role → temporary AWS identity for services or federated users

  • IAM Policy → rules describing what actions are allowed

  • Trust Policy → defines who can assume a role

  • Permission Policy → defines what a role can do

  • Default = Deny; explicit Deny always wins


🔑 2. AWS KMS — Key Management Service

KMS handles all encryption keys used across AWS.
It provides centralized control for key generation, rotation, access, and audit.


🧩 Envelope Encryption

┌──────────────┐ │ Your App │ └──────┬───────┘ │ Request Data Key ▼ ┌──────────────┐ │ AWS KMS CMK │ └──────┬───────┘ │ Generates Data Key ▼ ┌──────────────────────────┐ │ Data encrypted with Key │ │ Key encrypted by CMK │ └──────────────────────────┘

🧠 KMS Interview Essentials

QuestionAnswer
CMK vs Data Key?CMK = master key in KMS; Data Key = temporary key used by app
Key rotation?Auto every 365 days
Share across accounts?Add principal in key policy
Integrated services?S3, EBS, RDS, DynamoDB, Lambda
Logs?All actions logged in CloudTrail

🛡️ 3. Amazon GuardDuty — Threat Detection

GuardDuty continuously analyzes logs (CloudTrail, VPC Flow Logs, DNS, EKS Audit Logs) to identify malicious activity or compromised resources.


🧠 GuardDuty Essentials

FeatureDescription
No agentsWorks by analyzing logs
FindingsReconnaissance, credential theft, exfiltration
IntegrationSecurity Hub, EventBridge, Lambda
ResponseAutomate isolation or alerting

🧩 GuardDuty Flow

┌──────────────┐ │ Logs: VPC, CT│ └──────┬───────┘ ▼ ┌──────────────┐ │ GuardDuty │ (ML + Threat Intel) └──────┬───────┘ ▼ Findings → EventBridge → Lambda / SNS

🧭 End-to-End Security Architecture

 



🧠 Interview Cheat Sheet

AreaKey Points
IAMUser = human, Role = temporary identity, Policy = rules
KMSCMK for key mgmt, Data Key for encryption
GuardDutyML-driven threat detection
STSGenerates short-lived tokens for roles
Best PracticeUse roles over users, least privilege, encryption everywhere
AuditCloudTrail + Security Hub integration

✅ Key Takeaways

  • IAM: Who can do what

  • KMS: How data is encrypted

  • GuardDuty: Who’s doing something suspicious

Together they form the security triad of AWS:
Access → Encryption → Detection — protecting your cloud end-to-end.

 

No comments:

Post a Comment

Model Context Protocol (MCP) — Complete Guide for Backend Engineers

  Model Context Protocol (MCP) — Complete Guide for Backend Engineers Build Tools, Resources, and AI-Driven Services Using LangChain Moder...

Featured Posts