實戰:雲端安全架構
Vibe Prompt
「幫我設計一個安全的 AWS 多層架構:WAF → ALB → ECS (Fargate) → RDS,全部在私有子網中。」
安全架構
Internet
│
▼
Cloudflare (DDoS + WAF)
│
▼
AWS WAF (SQLi / XSS 過濾)
│
▼
ALB (Application Load Balancer)
│ (公有子網)
▼
ECS Fargate (容器)
│ (私有子網)
├──→ RDS (資料庫,私有子網)
└──→ ElastiCache Redis (私有子網)
安全措施清單
| 層級 | 措施 | |------|------| | 網路 | VPC 內不開 Public IP、SG 最小規則、NACL | | 運算 | ECS Fargate 執行在私有子網、IMDSv2 強制 | | 資料 | RDS 加密、自動備份、刪除保護 | | 存取 | IAM Role 代替 Access Key、MFA 強制 | | 監控 | GuardDuty + Security Hub + Config |
CDK 範例
const vpc = new ec2.Vpc(this, 'SecureVpc', {
maxAzs: 2,
natGateways: 1,
subnetConfiguration: [
{ name: 'Public', subnetType: ec2.SubnetType.PUBLIC, cidrMask: 28 },
{ name: 'Private', subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS, cidrMask: 24 },
{ name: 'Isolated', subnetType: ec2.SubnetType.PRIVATE_ISOLATED, cidrMask: 24 },
],
});
const albSg = new ec2.SecurityGroup(this, 'AlbSg', { vpc });
albSg.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(443));
albSg.addIngressRule(ec2.Peer.anyIpv4(), ec2.Port.tcp(80));
const ecsSg = new ec2.SecurityGroup(this, 'EcsSg', { vpc });
ecsSg.addIngressRule(albSg, ec2.Port.tcp(3000));
const rdsSg = new ec2.SecurityGroup(this, 'RdsSg', { vpc });
rdsSg.addIngressRule(ecsSg, ec2.Port.tcp(5432));
課程總結
雲端安全課程完成!
- ✅ 共享責任模型
- ✅ IAM Policy 實戰
- ✅ CSPM 自動檢查
- ✅ 容器安全
- ✅ 安全雲端架構