Bài này gộp 3 chủ đề: IAM Nâng cao, KMS và Secrets Manager, ACM và CloudFront Security.
Mục tiêu học tập
- Hiểu Identity Federation (SAML, OIDC, Cognito)
- Nắm Permission Boundaries và STS
- Áp dụng IAM Access Analyzer
- Hiểu ABAC (Attribute-Based Access Control)
- Hiểu KMS: keys, encryption, envelope encryption
- Phân biệt CMK types: AWS-managed, Customer-managed, AWS-owned
- Nắm Secrets Manager vs Parameter Store
- Áp dụng rotation, cross-account sharing
- Hiểu AWS Certificate Manager (ACM) cấp SSL/TLS certs miễn phí
- Nắm CloudFront fundamentals + caching
- Bảo vệ origin với OAC (Origin Access Control)
- Implement signed URLs / signed cookies
Phần 1: IAM Nâng cao
1. STS (Security Token Service)
Định nghĩa
STS = service phát hành temporary security credentials (Access Key + Secret + Session Token).
Use cases
- Assume Role (cross-account access)
- Identity federation (SAML, OIDC)
- Web identity (Cognito)
- MFA-protected operations
Key STS API operations
| API | Use case |
|---|---|
AssumeRole | Assume IAM Role (cross-account, EC2, etc.) |
AssumeRoleWithSAML | SAML-federated (corporate AD) |
AssumeRoleWithWebIdentity | OIDC-federated (Google, Facebook, Cognito) |
GetSessionToken | MFA-protected, temporary credentials |
GetFederationToken | Federate non-AWS users |
GetCallerIdentity | "Whoami" |
Token characteristics
- Lifetime: 15 minutes - 12 hours (default 1 hour)
- Cannot be revoked (until expiry)
- Auto-included AccessKey, SecretKey, SessionToken
2. Cross-Account Access
Pattern: Account A user assumes role in Account B
Setup
- Account B: Create role with trust policy allowing Account A
- Account A: User has permission
sts:AssumeRoleon Account B role ARN - User runs
aws sts assume-role --role-arn arn:aws:iam::B:role/DataReaderRole - Get temp credentials
- Use credentials to access Account B resources
Trust Policy example
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111111111111:root"
},
"Action": "sts:AssumeRole",
"Condition": {
"Bool": { "aws:MultiFactorAuthPresent": "true" }
}
}]
}
→ Account 111... có thể assume role, bắt buộc MFA.
ExternalID (security best practice)
- Khi share role với 3rd party (vendor), add ExternalID trong trust policy
- Vendor must provide ExternalID khi assume role
- Bảo vệ confused deputy problem (vendor bị social engineered)
3. Identity Federation
SAML 2.0
- Enterprise SSO: corporate AD, Okta, Azure AD
- IdP (Identity Provider) → STS → AWS Console/CLI
Flow
1. User → IdP (login với corporate creds)
2. IdP returns SAML assertion
3. App calls sts:AssumeRoleWithSAML
4. STS returns temp credentials
5. User accesses AWS
OIDC (OpenID Connect)
- Web identity providers: Google, Facebook, Apple, GitHub
- Mobile apps, web apps
AWS IAM Identity Center (formerly AWS SSO)
- Recommended modern solution
- SSO across AWS accounts + business apps
- Built-in IdP or integrate with AD, Okta, Azure AD
- Permission sets manage role mapping
Benefits
- Centralized user management
- Multi-account SSO with single login
- Replace per-account IAM users
4. Cognito (User Identity)
2 components
User Pool
- User directory (sign-up, sign-in, password reset)
- Built-in or federated (Google, Facebook, SAML)
- JWT tokens for app authentication
Identity Pool (formerly Federated Identities)
- Exchange identity provider token → AWS temp credentials (STS)
- Direct AWS access from mobile/web app
- 2 roles: authenticated, unauthenticated (guest)
Use case
- Mobile app users → S3 upload personal files
- Web app users → DynamoDB access scoped to user
Architecture
Mobile App → User Pool (sign in) → JWT token
→ Identity Pool (exchange token) → AWS temp credentials
→ DynamoDB / S3 / API Gateway
5. Permission Boundaries
Định nghĩa
Permission Boundary = MAX permissions an IAM entity can have, regardless of attached policies.
Đặc điểm
- Apply to IAM User or Role
- NOT a grant — just a ceiling
- Effective permission = Identity policy ∩ Permission boundary
Example
Identity Policy: allow s3:*, ec2:*, iam:*
Permission Boundary: allow s3:*, ec2:* (NO iam:*)
Effective: s3:* and ec2:* (iam:* blocked by boundary)
Use case
- Developers self-service IAM (tạo role mới for app)
- Boundary prevents tạo role with admin permissions
- Delegated administration
SCP vs Permission Boundary
| SCP (Organizations) | Permission Boundary | |
|---|---|---|
| Scope | OU / Account | Individual IAM User/Role |
| Apply to | Member accounts | Identity |
| Grant | No (limit only) | No (limit only) |
| Set by | Master account | Account admin |
SCP topic chính cho SAP-C02. SAA-C03 hiểu khái niệm cơ bản đủ.
6. AWS Organizations Brief
Định nghĩa
Organizations = multi-account management.
Components
- Management Account (Root): billing, organization-wide
- Organizational Unit (OU): group accounts
- Member Accounts: individual accounts
SCP (Service Control Policy)
- Whitelist hoặc Deny list IAM actions across accounts
- Apply ở OU/Account level
- Không grant permission — chỉ giới hạn max
SAA-C03 thường hỏi SCP basics. Chi tiết deep trong SAP-C02.
7. ABAC (Attribute-Based Access Control)
Định nghĩa
ABAC = grant permissions based on attributes (tags) thay vì specific resource ARNs.
So với RBAC (Role-Based)
- RBAC: separate role per resource set ("admin", "developer-app-A", "developer-app-B")
- ABAC: 1 policy, scale automatic with new resources/users
Example policy
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Action": "ec2:*",
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:ResourceTag/Department": "${aws:PrincipalTag/Department}"
}
}
}]
}
→ User can access EC2 instances only if user's Department tag matches resource's Department tag.
Benefits
- Scale (new resources auto-covered by tags)
- Reduce # of policies/roles
- Easier compliance audit
8. IAM Access Analyzer
Định nghĩa
Tool analyze IAM policies, identify resources shared externally (public, cross-account, federated).
Findings
- S3 bucket accessible to all
- Lambda function exposed to other accounts
- KMS key shared with 3rd party
- IAM role assumable by external account
Features
- External access findings: detect unintended sharing
- Unused access findings: detect unused IAM roles/permissions (cost + security)
- Policy validation: validate IAM policy syntax + best practices
- Policy generation: generate least-privilege policy from CloudTrail events
Use case
- Continuous security audit
- Reduce attack surface
- Compliance (PCI, HIPAA)
9. IAM Roles Anywhere
Định nghĩa
IAM Roles Anywhere = on-prem servers (or other clouds) assume AWS IAM Roles using X.509 certificates (no long-term AWS keys).
Workflow
- Trust anchor: AWS Private CA hoặc external CA
- On-prem server has X.509 cert signed by trust anchor
- Server uses CreateSession API with cert → temp credentials
- Use temp creds to access AWS
Use case
- Hybrid workload (on-prem → AWS)
- CI/CD systems (Jenkins on-prem → AWS deploy)
- Replace stored access keys (security best practice)
10. IAM Best Practices (Top 15)
- Lock root user (MFA, no daily use)
- MFA cho admin users
- Use IAM Roles (not access keys) cho EC2, Lambda, ECS
- Apply least privilege
- Use AWS Identity Center for multi-account SSO
- Rotate access keys every 90 days
- Don't share credentials
- Audit with CloudTrail + Access Analyzer
- Permission boundaries for delegated admin
- Tag resources + use ABAC
- Federated identity instead of IAM users
- Strong password policy
- Enable IAM Roles Anywhere for hybrid
- Use Service Control Policies (Organizations)
- Regular review and cleanup unused users/roles
11. Common Patterns
Pattern 1: Cross-account access cho CI/CD
CI account → Assume role in target account → Deploy resources
Pattern 2: Multi-account SSO via Identity Center
User → Identity Center login → Permission Set chosen → Auto-assume role in chosen account
Pattern 3: Mobile app + Cognito
User signup → User Pool → Identity Pool → AWS temp creds → API Gateway / DynamoDB
Pattern 4: Federated workload (on-prem CI)
Jenkins on-prem → X.509 cert → IAM Roles Anywhere → AWS deploy
Phần 2: KMS và Secrets Manager
1. AWS KMS Overview
AWS KMS (Key Management Service) = managed service tạo và quản lý cryptographic keys.
Đặc điểm
- Multi-tenant AES-256 encryption keys
- Tích hợp với 100+ AWS services
- FIPS 140-3 Level 3 (KMS HSM đạt Level 3 từ 5/2023 — trước đó là 140-2 Level 2)
- Audit logs trong CloudTrail
- Regional (key chỉ dùng được trong region tạo)
Pricing
- $1/key/month (Customer-managed CMK)
- $0.03 per 10,000 API calls
- AWS-managed CMK: free
- Free tier: 20,000 API calls/month
2. KMS Key Types
Customer-Managed Key (CMK)
- Bạn tạo, manage, rotate
- Full control over key policy, alias, deletion
- Pricing: $1/month + API calls
- Best for: granular control, audit, compliance
AWS-Managed Key
- AWS tạo + manage cho service (e.g.,
aws/s3,aws/rds) - Free
- View key trong console (read-only)
- Default cho hầu hết AWS services
- Use case: Default encryption, không cần custom control
AWS-Owned Key
- AWS tạo, không hiển thị trong account
- Used internally by services (DynamoDB encryption by default)
- Free
- Không thể audit, không thể disable
Symmetric vs Asymmetric
| Symmetric (AES-256) | Asymmetric (RSA/ECC) | |
|---|---|---|
| Use case | Encrypt/decrypt data | Sign/verify, encrypt with public key |
| Encryption | Same key for both | Public encrypt, Private decrypt |
| Operations | Encrypt, Decrypt, GenerateDataKey | Sign, Verify, Encrypt, Decrypt |
| Most common | Default cho hầu hết use cases | Code signing, JWT, certificates |
3. Envelope Encryption
Vấn đề
- AES encryption fast cho data nhỏ
- Network call to KMS slow cho data lớn (4 KB limit per Encrypt call)
Giải pháp: Envelope Encryption
- App calls KMS
GenerateDataKey→ returns:- Plaintext data key (for encryption)
- Encrypted data key (wrapped by CMK)
- App encrypts data locally with plaintext data key (fast)
- App stores encrypted data + encrypted data key
- App discards plaintext data key from memory
Decryption
- App reads encrypted data + encrypted data key
- App calls KMS
Decrypton encrypted data key → plaintext data key - App decrypts data locally
Benefit
- Limit KMS API calls (only encrypt/decrypt data key)
- Encrypt large data fast (locally)
- Most AWS services (S3 SSE-KMS, EBS) use envelope encryption
4. KMS Key Rotation
Automatic Rotation (Customer-managed CMK)
- Enable trong KMS console
- Rotation period: 90 ngày → 7 năm, configurable (default 1 năm) — update April 2024
- Old key version kept (decrypt old ciphertext)
- New key version used for new encryption
- Free
- AWS-managed CMK: rotated every 1 year automatically (KHÔNG configurable)
Manual Rotation
- Create new CMK
- Update alias to point to new key
- Old key stays for decrypting old data
5. KMS Multi-Region Keys
Định nghĩa
Multi-Region Keys = create replica of CMK in another Region, same key material.
Use case
- Cross-region applications (decrypt in any region)
- DR (failover to another region)
- Global Tables (DynamoDB), CRR (S3)
vs Single-Region
- Single-region: key bound to 1 region (must re-encrypt to use in another region)
- Multi-region: key works seamlessly across regions
6. KMS Key Policy
Định nghĩa
Key Policy = resource-based policy attached to KMS key (control WHO can use the key).
Default policy
- Allows root user full access
- Allows IAM policies attached to users/roles to grant access
Custom policy
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnableAdminAccess",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111111111111:root" },
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "AllowUseOfKey",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::222222222222:role/AppRole" },
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:GenerateDataKey"
],
"Resource": "*"
}
]
}
7. KMS Key Deletion
Process
- Initiate "Schedule deletion"
- Waiting period: 7-30 days (default 30)
- During waiting period: key disabled (cannot encrypt/decrypt)
- After waiting period: permanently deleted
- Cancel deletion during waiting period possible
Best practice
- Long waiting period (30 days) for safety
- Disable key first, see if anything breaks
- KHÔNG delete key đã encrypt production data (lose access permanently)
8. KMS Grants
Định nghĩa
Grant = temporary permission to use KMS key, programmatically created.
Use case
- AWS services on behalf of user (EBS create snapshot)
- Lambda function temporarily access KMS
- More granular than key policy
Properties
- Created/revoked via API
- Specifies operations, resources, conditions
- Up to 50,000 grants per key
9. AWS Secrets Manager
Định nghĩa
Secrets Manager = managed service store, retrieve, rotate secrets (DB passwords, API keys).
Đặc điểm
- Automatic rotation (built-in for RDS, custom Lambda for others)
- KMS encryption (cần CMK)
- Audit logs in CloudTrail
- Resource-based policy (cross-account access)
- Pricing: $0.40/secret/month + $0.05/10K API calls
Native rotation supported
- RDS: MySQL, PostgreSQL, MariaDB, Oracle, SQL Server
- Aurora
- DocumentDB, Redshift
- Custom Lambda function for other secrets
Rotation flow (RDS example)
- Lambda function rotates DB password
- Lambda updates secret in Secrets Manager
- Lambda updates DB user password
- App fetches new password from Secrets Manager
Use case
- Application secrets (API keys, OAuth tokens)
- Database credentials (with automated rotation)
- 3rd-party service credentials
10. Systems Manager Parameter Store
Định nghĩa
Parameter Store = store configuration data and secrets, integrate với SSM.
Đặc điểm
- Free (Standard tier, < 4 KB value, < 10K parameters)
- Advanced tier: $0.05/parameter/month, > 4 KB values
- Encryption via KMS (SecureString type)
- Hierarchical structure (
/app/dev/db/password) - No built-in rotation (manual or custom)
Types
- String: plain text
- StringList: comma-separated
- SecureString: encrypted với KMS
Use case
- App configuration (non-secret)
- Feature flags
- Database connection strings
- API endpoints
11. Secrets Manager vs Parameter Store
| Secrets Manager | Parameter Store | |
|---|---|---|
| Cost | $0.40/secret/month | Free (Standard), $0.05/param Advanced |
| Rotation | Built-in (RDS automatic) | Manual / custom Lambda |
| Cross-account | Yes (resource policy) | Via shared KMS key |
| Encryption | Always (KMS) | Optional (SecureString) |
| Max size | 64 KB | 4 KB (Standard), 8 KB (Advanced) |
| Versioning | Yes (5 versions kept) | Yes (Advanced) |
| Use case | Secrets needing rotation | Config + simple secrets |
Decision
- Secrets needing rotation: Secrets Manager
- Configuration data: Parameter Store (cheaper)
- Simple secrets, no rotation: Parameter Store SecureString (free)
12. AWS CloudHSM
Định nghĩa
CloudHSM = dedicated Hardware Security Module (HSM) in cloud, single-tenant.
So với KMS
| KMS | CloudHSM | |
|---|---|---|
| Tenancy | Multi-tenant | Single-tenant |
| Compliance | FIPS 140-3 L3 (từ 5/2023) | FIPS 140-3 L3 |
| Control | AWS manages | Customer manages |
| Cost | $1/key/month | |
| Use case | General encryption | Strict compliance, custom crypto |
Use case CloudHSM
- Regulatory requires single-tenant HSM (some financial, government)
- Custom cryptographic algorithms
- BYOK (Bring Your Own Key) into KMS
- SSL/TLS offload for high volume
13. Common Patterns
Pattern 1: S3 with SSE-KMS + Bucket Key
- Encrypt objects with SSE-KMS
- Enable Bucket Key (reduce KMS API calls 99%)
Pattern 2: RDS with Secrets Manager + auto-rotation
- RDS uses Secrets Manager for password
- Rotate every 30 days automatic
- App fetches latest from Secrets Manager
Pattern 3: Application config in Parameter Store
- Lambda reads
/app/prod/api-endpointat cold start - Cache value in memory (avoid repeated calls)
Pattern 4: Cross-account secret sharing
- Resource policy on secret in Account A
- IAM policy in Account B allows GetSecretValue
- Shared via KMS key access
Phần 3: ACM và CloudFront Security
1. AWS Certificate Manager (ACM)
Định nghĩa
ACM = managed SSL/TLS certificate service.
Đặc điểm
- Free cho certs dùng với AWS services (CloudFront, ALB, NLB, API GW)
- Auto-renewal trước khi expire
- Support public certs (DV - Domain Validation) và private certs (qua AWS Private CA)
- Regional: cert ở region nào dùng cho services ở region đó (trừ CloudFront)
CloudFront special case
- CloudFront yêu cầu cert ở us-east-1 (N. Virginia)
- Vì CloudFront là global, dùng us-east-1 làm "home"
Validation methods
- DNS validation (recommended): add CNAME record vào DNS
- Email validation: AWS gửi email đến
admin@domain.com
Workflow public cert
1. Request certificate trong ACM
2. Choose validation: DNS or Email
3. Validate ownership (add CNAME if DNS)
4. Cert issued (few minutes)
5. Deploy to ALB / CloudFront / API GW
6. Auto-renew khi 60 days before expire
Limitations
- Free public certs: không export private key (chỉ dùng trong AWS)
- Cần export private key → dùng AWS Private CA ($)
2. CloudFront Fundamentals
Định nghĩa
CloudFront = global CDN (Content Delivery Network), cache content tại 600+ edge locations.
Đặc điểm
- Low latency: serve content từ edge gần user
- DDoS protection: AWS Shield Standard included free
- Origin types:
- S3 bucket
- ALB / NLB
- EC2 / Custom HTTP origin
- API Gateway
- Lambda Function URL
- MediaStore / MediaPackage
- HTTPS: SSL via ACM
- HTTP/2, HTTP/3 (QUIC) support
Pricing
- Pay per request + data transfer out (edge → user)
- Free tier: 1 TB data transfer out + 10M requests/month (forever free)
- Cheaper than direct S3/ALB data transfer
Cost optimization
- CloudFront data transfer out ($0.085/GB) cheaper than EC2 direct ($0.09/GB)
- Cache hit reduces origin load (origin tính bandwidth riêng)
3. CloudFront Distribution
Components
- Distribution: top-level config (e.g., d1234.cloudfront.net)
- Origins: backends (S3, ALB, ...)
- Behaviors: routing rules per path pattern
- Cache settings: TTL, headers, query strings to forward
- Security: WAF, signed URLs
Architecture
User → CloudFront Edge → Regional Edge Cache → Origin
(600+ locations) (~13 locations) (S3, ALB)
↓
Cache lookup
↓
Cache HIT → Serve from edge (fast)
Cache MISS → Fetch from origin → Cache → Serve
4. Caching Behavior
Cache Key
Combination of fields that uniquely identify a cached object:
- URL path (default)
- Optional: Query strings, headers, cookies
TTL (Time to Live)
- Default TTL: 24 hours
- Min/Max TTL: configurable
- Cache headers from origin:
Cache-Control: max-age=N,Expires: date
Cache invalidation
- Invalidate: remove from cache before TTL expires
- Pattern:
/images/*or specific path - First 1000 invalidations/month free, then $0.005/path
Best practice
- High TTL for static assets (CSS, JS, images): months
- Low TTL for dynamic content: seconds-minutes
- Cache versioning: add hash to filename (
app.v123.js) instead of invalidating
5. Origin Access Control (OAC)
Vấn đề
S3 bucket exposed publicly để CloudFront access → users có thể bypass CloudFront (truy cập S3 trực tiếp, không qua WAF, không cache).
Giải pháp: OAC
- CloudFront có IAM identity, có thể signed request to S3
- S3 bucket policy chỉ allow access từ CloudFront distribution (qua OAC)
- Block direct S3 access
OAC vs OAI (legacy)
- OAI (Origin Access Identity): older, supports only S3 buckets (SSE-S3)
- OAC (Origin Access Control): newer, supports S3 + SSE-KMS + CRR + Object Lambda
- Recommended: OAC for new distributions
Bucket policy example
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": "cloudfront.amazonaws.com" },
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-bucket/*",
"Condition": {
"StringEquals": {
"AWS:SourceArn": "arn:aws:cloudfront::111111111111:distribution/DIST_ID"
}
}
}]
}
6. CloudFront Signed URLs and Cookies
Use case
Restrict access to paid content (videos, downloads) — only authorized users.
Signed URL
- URL với signature
- Access single file
- Generated bằng private key
Signed Cookie
- Cookie với signature
- Access multiple files (entire site or directory)
- Generated bằng private key
Workflow
1. User requests content from app
2. App authenticates user, authorizes
3. App generates signed URL/cookie (using CloudFront key pair)
4. User uses signed URL/cookie to access CloudFront
5. CloudFront validates signature, serves content (or denies)
Trusted Signers vs Trusted Key Groups
| Trusted Signers (legacy) | Trusted Key Groups (modern) | |
|---|---|---|
| Key | Account root user | Public keys group |
| Recommended | No | Yes |
7. Geo Restriction
2 modes
- Whitelist: only allow listed countries
- Blacklist: block listed countries
Use case
- Compliance (copyright, licensing per country)
- Block adversarial regions
- Compliance (GDPR)
8. CloudFront with HTTPS
SSL/TLS termination
- HTTPS at edge: cert via ACM (us-east-1)
- HTTPS to origin: optional (recommended)
Cipher policies
- TLS 1.2 minimum (recommended)
- Modern policies: ECDHE, AES-GCM
9. CloudFront Functions vs Lambda@Edge
CloudFront Functions
- Lightweight JavaScript (~1 KB)
- Sub-millisecond execution
- Run at edge (all 600+ locations)
- Use case: simple header manipulation, URL rewrites, redirects
- Free tier: 2M requests/month
- No external network access
Lambda@Edge
- Full Lambda (Node.js, Python)
- Up to 5 seconds execution
- Run at Regional Edge Cache (~13 locations)
- Use case: complex logic, A/B testing, dynamic content
- Standard Lambda pricing
- Can call external services (DB, APIs)
Comparison
| CloudFront Functions | Lambda@Edge | |
|---|---|---|
| Language | JavaScript only | Node.js, Python |
| Memory | 2 MB | 128 MB - 10 GB |
| Max execution | 1 ms | 5-30 sec |
| Network access | No | Yes |
| Cost | Very cheap | Standard Lambda |
| Use case | Header rewrite, simple | Complex logic |
CloudFront events
- Viewer Request (before cache lookup)
- Origin Request (before forward to origin)
- Origin Response (after origin response)
- Viewer Response (before response to user)
10. CloudFront Patterns
Pattern 1: Static website (S3 + CloudFront)
S3 (private) ← OAC ← CloudFront ← User
SSL via ACM
WAF for security
Pattern 2: Dynamic + Static
Dynamic (api.example.com):
CloudFront → ALB → ECS
Static (cdn.example.com):
CloudFront → S3 (with OAC)
Pattern 3: Paid content
User → App (auth) → Generates signed URL
User → CloudFront (signed URL) → Origin
Pattern 4: A/B testing
User → CloudFront → Lambda@Edge (random pick A/B) → Origin A or B
11. CloudFront vs Global Accelerator
| CloudFront | Global Accelerator | |
|---|---|---|
| Use case | HTTP/HTTPS content caching | Non-HTTP (TCP/UDP), routing |
| Caching | Yes | No |
| Static IPs | No (DNS) | Yes (2 anycast) |
| Protocols | HTTP, HTTPS | TCP, UDP |
| Use case examples | Web content, video streaming | Gaming, IoT, financial |
Câu hỏi ôn tập
-
STS token lifetime range là bao nhiêu?
Xem đáp án
15 phút đến 12 giờ cho AssumeRole (mặc định 1 giờ). Cho AssumeRoleWithWebIdentity và AssumeRoleWithSAML: tối đa 1 giờ. Federated user sessions có thể đến 36 giờ. Role session duration tối đa cấu hình trong role settings (max 12 giờ). Token ngắn hơn = security tốt hơn; token dài hơn = ít calls đến STS hơn.
-
Permission Boundary có grant permission không?
Xem đáp án
Không — Permission Boundary chỉ giới hạn permission tối đa (ceiling), không tự grant permission. Identity vẫn cần identity-based policy riêng để có quyền thực sự. Ví dụ: Boundary cho phép S3+EC2, identity policy cho phép S3+DynamoDB → effective permission chỉ là S3 (intersection). Dùng Boundary để delegate IAM administration: cho phép team tạo roles nhưng không vượt quá scope đã định.
-
Khi share IAM role với 3rd party vendor, dùng tính năng gì để bảo vệ?
Xem đáp án
External ID trong trust policy (Confused Deputy protection). Khi vendor assume role phải cung cấp External ID secret — ngăn attacker lừa vendor access account của bạn bằng cách sử dụng vendor's AWS credentials. External ID là secret chỉ bạn và vendor biết, include trong
sts:ExternalIdcondition. Best practice cho tất cả cross-account third-party integrations. -
ABAC khác RBAC ở điểm gì?
Xem đáp án
RBAC (Role-Based): access dựa trên roles (IAM Roles/Groups) — tạo nhiều roles cho nhiều resource combinations, phức tạp khi scale. ABAC (Attribute-Based): access dựa trên tags của cả identity lẫn resource — một policy có thể cover nhiều resources:
"Condition": {"StringEquals": {"aws:ResourceTag/Project": "${aws:PrincipalTag/Project}"}}. Phù hợp cho large-scale multi-team environments — ít policies hơn, dễ quản lý hơn. -
IAM Access Analyzer giúp phát hiện gì?
Xem đáp án
Access Analyzer phân tích resource-based policies (S3, SQS, KMS, Lambda, IAM roles) để tìm external access — resources được chia sẻ với principals bên ngoài account/Organization. Highlight unintended public access (S3 bucket public, role assume-able từ internet). Cũng có External Access findings cho cross-account access và Unused Access findings (over-permissive policies). Chạy continuously — alert khi phát hiện mới.
-
Envelope Encryption giải quyết vấn đề gì?
Xem đáp án
Giải quyết vấn đề performance và data size limits của KMS. KMS chỉ có thể encrypt dữ liệu đến 4 KB trực tiếp. Envelope Encryption: (1) KMS generate Data Encryption Key (DEK), (2) DEK encrypt actual data (locally, nhanh, không giới hạn size), (3) Encrypt DEK bằng KMS CMK và lưu cùng data. Khi decrypt: gọi KMS decrypt DEK, dùng DEK decrypt data. Chỉ DEK đi qua network đến KMS — data lớn xử lý locally.
-
KMS Key auto-rotation rotate mỗi bao lâu?
Xem đáp án
1 năm (365 ngày) cho AWS-managed keys và customer-managed keys (khi bật auto-rotation). Customer-managed keys có thể cấu hình rotation từ 90 ngày đến 2,560 ngày (7 năm). Auto-rotation chỉ rotate key material — Key ID không đổi, nên không cần update references. Data encrypted với key cũ vẫn decrypt được (KMS giữ old key material).
-
KMS Key deletion có waiting period bao lâu?
Xem đáp án
7 đến 30 ngày (configurable). Không thể xóa key ngay lập tức — waiting period để phát hiện và cancel nếu key vẫn đang được dùng. Trong thời gian này key bị disabled (không thể dùng encrypt/decrypt). Nếu cancel trước khi hết waiting period, key hoạt động lại bình thường. Sau khi xóa, data encrypted với key đó không thể decrypt — mất vĩnh viễn.
-
Khác biệt cốt lõi giữa Secrets Manager và Parameter Store?
Xem đáp án
Secrets Manager: tự động rotation của secrets (RDS, Redshift, DocumentDB, custom), có chi phí ($0.40/secret/month + $0.05/10K API calls). Dùng cho database credentials, API keys cần rotation. Parameter Store: lưu configuration và secrets (SecureString = encrypted), không có auto-rotation tích hợp, rẻ hơn (Standard: free; Advanced: $0.05/10K requests). Dùng cho application config, non-rotating secrets. Lambda/ECS tích hợp tốt với cả hai.
-
Khi nào dùng CloudHSM thay vì KMS?
Xem đáp án
Dùng CloudHSM khi: (1) Cần sole tenancy của hardware HSM (không shared với AWS hay customers khác), (2) Cần quản lý key material hoàn toàn — KMS manages key material, bạn không thể export, (3) Cần custom cryptographic algorithms hoặc SSL/TLS offload, (4) Compliance regulations yêu cầu HSM riêng (PCI DSS, certain government). Lưu ý: từ 5/2023 KMS cũng đạt FIPS 140-3 Level 3 nên FIPS level không còn là lý do chọn CloudHSM (đề thi/tài liệu cũ hay nói "KMS chỉ Level 2"). CloudHSM đắt hơn (~$1.45-1.60/giờ/HSM tùy region) và cần quản lý nhiều hơn.
- CloudFront cert ACM phải ở Region nào?
Xem đáp án
us-east-1 (N. Virginia) — CloudFront là global service nhưng chỉ đọc ACM certificates từ us-east-1. Nếu provision cert ở Region khác sẽ không thấy trong CloudFront. Đây là điểm hay bị sai trong thực tế: team provision cert ở ap-southeast-1 nhưng CloudFront không tìm thấy. Cert cho ALB/API GW có thể provision tại Region của resource đó.
- OAC khác OAI ở điểm gì? Khi nào dùng OAC?
Xem đáp án
OAI (Origin Access Identity): legacy, chỉ S3 standard, không hỗ trợ SSE-KMS encryption. OAC (Origin Access Control): thế hệ mới, hỗ trợ S3 + SSE-KMS encrypted objects, hỗ trợ cross-account, HTTP method signing. AWS khuyến nghị dùng OAC thay OAI cho tất cả deployments mới. Cả hai đều cho phép CloudFront access S3 bucket private mà không cần public access.
- Khác biệt CloudFront Signed URL vs Signed Cookie?
Xem đáp án
Signed URL: restrict access đến 1 file cụ thể — URL chứa signature, expiry, IP restrictions. Phù hợp khi share link download cho 1 file. Signed Cookie: restrict access đến nhiều files trong cùng phiên — browser gửi cookie theo mọi request. Phù hợp cho premium content, video streaming (nhiều segments), khi URL cần giữ sạch (không muốn append signature vào URL).
- CloudFront Functions vs Lambda@Edge: cái nào cho phép external network calls?
Xem đáp án
Chỉ Lambda@Edge — có thể gọi external APIs, DynamoDB, Secrets Manager. CloudFront Functions: không có network access, không có filesystem, execution time < 1ms, rẻ hơn nhiều (~1/6 giá). Phù hợp cho lightweight operations: URL rewrite, header manipulation, simple A/B routing. Lambda@Edge: CPU-intensive, complex logic, cần external data, max 5-30 giây execution.
- Khi nào dùng CloudFront vs Global Accelerator?
Xem đáp án
CloudFront: tối ưu cho HTTP/HTTPS workloads với cacheable content — website, APIs, static assets. CloudFront cache tại Edge Locations. Global Accelerator: tối ưu cho any TCP/UDP traffic (gaming, IoT, VoIP), không cache, cần static IP addresses (NLB-fronting), hoặc cần route non-HTTP traffic. Global Accelerator cũng hỗ trợ HTTP nhưng không cache — phù hợp cho dynamic content, health routing between regions.
Bài tập thực hành
Phần 1: IAM Nâng cao
- Tạo cross-account role: Account A user assume role trong Account B
- Setup IAM Identity Center (free), assign Permission Set
- Tạo Permission Boundary giới hạn user chỉ tạo IAM role với boundary attached
- Test ABAC: user với tag Department=eng access EC2 tag Department=eng
- Enable IAM Access Analyzer, review findings
Phần 2: KMS và Secrets Manager
- Tạo Customer-Managed CMK, enable auto-rotation
- Encrypt S3 bucket với SSE-KMS, observe envelope encryption
- Tạo secret trong Secrets Manager cho RDS password, enable auto-rotation 30 days
- Tạo Parameter Store SecureString cho API key, retrieve via CLI
- Tạo Multi-Region KMS key, replicate sang region khác
Phần 3: ACM và CloudFront Security
- Request ACM cert cho domain ở us-east-1 (DNS validation)
- Setup CloudFront distribution với S3 origin + OAC
- Test direct S3 access bị deny, qua CloudFront thành công
- Tạo signed URL cho 1 object, expire 1 hour
- Setup Geo Restriction blacklist 2 countries
- Tạo CloudFront Function rewrite URL
/api→/v2/api
Tài liệu tham khảo
- IAM User Guide
- STS
- Permission Boundaries
- ABAC
- IAM Access Analyzer
- IAM Identity Center
- KMS Developer Guide
- Envelope Encryption
- Multi-Region Keys
- Secrets Manager
- Parameter Store
- CloudHSM
- AWS Certificate Manager
- CloudFront Developer Guide
- Origin Access Control
- Signed URLs/Cookies
- CloudFront Functions