ရိုးရိုးလေး ရှင်းပြမယ်
အိမ်မပြောင်းခင် ဘေးကင်းရေး အရင်တပ်ဆင်ပါ
ရုံးခန်းအသစ်တစ်ခုကို ဝန်ထမ်းတွေ မပြောင်းလာခင် CCTV တပ်ထားမယ်၊ မီးခိုး alarm တပ်မယ်၊ လစဉ် အသုံးစရိတ် ကန့်သတ်ချက် သတ်မှတ်မယ်၊ အတွင်းပိုင်း စင်္ကြံတွေကို သော့ခတ်ထားမယ်၊ ပြီးတော့ ဝန်ထမ်းအသစ်တွေ ဘယ်တံခါးသော့တွေ ကိုယ်တိုင် ပွားလို့ရလဲဆိုတဲ့ စည်းမျဉ်း ချထားမယ်ဆိုပါစို့။ Account baseline ဆိုတာ အဲဒီ ဘေးကင်းရေး kit ပါပဲ။
AWS မှာ CCTV က CloudTrail၊ alarm က GuardDuty၊ အသုံးစရိတ် ကန့်သတ်ချက်က AWS Budgets၊ သော့ခတ်ထားတဲ့ စင်္ကြံက private subnet တွေနဲ့ VPC endpoint တွေ၊ သော့ပွားခွင့် စည်းမျဉ်းက permission boundary ဖြစ်ပါတယ်။ ဒါတွေကို code (CDK) နဲ့ ရေးထားတော့ account အသစ်တိုင်းက တစ်ပုံစံတည်း kit ကို မိနစ်ပိုင်းအတွင်း ရပါတယ်။
Problem → Why → Solution
Account ကို 'ပထမဆုံး workload' နဲ့ စလိုက်ရင်
Team အများစုဟာ account အသစ်ရတာနဲ့ app ကို ချက်ချင်း deploy လုပ်ကြပါတယ်။ Security နဲ့ cost control တွေကို 'နောက်မှ ထည့်မယ်' လို့ ထားလိုက်ပြီး၊ အဲဒီ 'နောက်မှ' က ပြဿနာတစ်ခု ဖြစ်တော့မှ ရောက်လာတတ်ပါတယ်။ အောက်က command တွေက AWS Fundamentals မှာ သင်ခဲ့တဲ့ CLI နဲ့ပဲ၊ deploy လုပ်ပြီး သုံးလကြာတဲ့ account တစ်ခုကို စစ်ကြည့်တာပါ။
Trail မရှိတော့ 'ဒီ table ကို ဘယ်သူဖျက်လဲ' ဆိုတာ ဖြေလို့မရပါဘူး။ GuardDuty မရှိတော့ leak ဖြစ်သွားတဲ့ access key နဲ့ crypto-mining instance တွေ run နေတာ ဘယ်သူမှ မသိပါဘူး။ Budget မရှိတော့ ပထမဆုံး cost signal က လကုန် invoice ပဲ ဖြစ်နေပါတယ်။ S3 traffic အားလုံး NAT Gateway ကနေ GB နှုန်းနဲ့ ပေးပြီး ထွက်နေပါတယ်။
# A "fresh" workload account, three months after the first deploy.
aws cloudtrail describe-trails --query 'trailList[].Name'
# [] <- nobody can answer "who deleted that table?"
aws guardduty list-detectors
# {"DetectorIds": []} <- crypto-mining on a leaked key goes unnoticed
aws budgets describe-budgets --account-id 111122223333
# {} <- the first cost signal is the invoice
aws ec2 describe-nat-gateways --query 'NatGateways[].State'
# ["available", "available", "available"] <- S3 traffic billed per GBဘာကြောင့် ဒီလို ထပ်ခါထပ်ခါ ဖြစ်တာလဲ
Baseline က ဘယ် feature ticket ထဲမှာမှ မပါတဲ့အတွက် ဘယ်သူ့တာဝန်မှ မဖြစ်ဘဲ ကျန်ခဲ့တတ်ပါတယ်။ Console ကနေ လက်နဲ့ setup လုပ်ရင်လည်း account သုံးခုလောက်ကျော်တာနဲ့ account တစ်ခုချင်း မတူတော့ပါဘူး (drift)။ အဖြေကတော့ baseline ကို code အဖြစ်ရေးပြီး workload မတင်ခင် deploy လုပ်တာပါပဲ။
Baseline တစ်ခုက ဖြေပေးရမယ့် မေးခွန်း ငါးခု
Baseline ဆိုတာ workload account တိုင်းမှာ တစ်ပုံစံတည်း deploy လုပ်ထားတဲ့ control အနည်းငယ်ပါ။ သူက မေးခွန်း ငါးခုကို ဖြေပေးရပါတယ် - ဘယ်သူ ဘာလုပ်ခဲ့လဲ (audit)၊ အခု ဆိုးတာတစ်ခုခု ဖြစ်နေလား (detection)၊ မျှော်လင့်ထားတဲ့အတိုင်း သုံးနေလား (cost)၊ network အမှားတစ်ခုက အပြင်ကို ပေါက်ထွက်နိုင်လား (containment)၊ ပြီးတော့ developer တစ်ယောက် ဖန်တီးတဲ့ role က သူ့ကိုယ်ပိုင် permission ထက် ကျော်လွန်နိုင်လား (guardrail) ဆိုတာပါ။
ဒီ project မှာ အဲဒါတွေကို CDK stack သုံးခု ခွဲထားပါတယ်။ ခွဲရတဲ့ အကြောင်းရင်းက lifecycle နဲ့ blast radius မတူလို့ပါ။ Audit stack ထဲက bucket နဲ့ key က နှစ်နဲ့ချီ ရှိနေရမှာမို့ RETAIN ထားပါတယ်။ Network က ခဏခဏ မပြောင်းပါဘူး။ Guardrail ကတော့ team လိုအပ်ချက်အလိုက် မကြာခဏ ပြင်ရပါတယ်။ Stack ခွဲထားရင် 'cdk deploy Baseline-Guardrails' run လိုက်တိုင်း trail bucket ကို မတော်တဆ replace လုပ်မိမယ့် အန္တရာယ် မရှိတော့ပါဘူး။
BASELINE: THREE STACKS, ONE WORKLOAD ACCOUNT
--------------------------------------------
+-------------------- Baseline-Audit (RETAIN) ---------------------+
| CloudTrail (all regions) --> S3 bucket: versioned, BPA, TLS-only |
| | encrypted with |
| v |
| KMS key (rotation on) |
| GuardDuty detector Budget: 80% actual / 100% forecast email |
+-------------------------------------------------------------------+
+---------------- Baseline-Network --------------------------------+
| VPC 10.20.0.0/16 public /24 x2 private-isolated /20 x2 |
| no NAT gateway S3 + DynamoDB gateway endpoints (free) |
| flow logs: REJECTed traffic |
+------------------------------------------------------------------+
+---------------- Baseline-Guardrails -----------------------------+
| managed policy 'workload-developer-boundary' |
| allow app services | deny audit tampering | deny boundary escape |
+------------------------------------------------------------------+- Permission boundary
- IAM role (သို့) user တစ်ခုရဲ့ identity policy တွေက ဘယ်လောက်ပဲ ကျယ်ကျယ်၊ ဒီ managed policy က ခွင့်ပြုထားတာထက် ပိုမလုပ်နိုင်အောင် ချထားတဲ့ ceiling ပါ။ Effective permission = identity policy နဲ့ boundary နှစ်ခုစလုံး ခွင့်ပြုတဲ့ အပိုင်း (intersection) ပါ။ Boundary ကိုယ်တိုင်က ဘာ permission မှ မပေးပါဘူး။
| Control | ဆုံးဖြတ်ချက် | ဘာကြောင့် |
|---|---|---|
| Trail bucket | SSE-KMS + versioning + BPA + TLS-only | Key policy က ဒုတိယ သော့ပါ - bucket read ရရုံနဲ့ log ကို decrypt လုပ်လို့ မရပါ |
| Trail | Multi-region + file validation | အသုံးမပြုတဲ့ region မှာ attacker လုပ်တာကိုလည်း မြင်ရပြီး log ပြင်ထားရင် သိနိုင်ပါတယ် |
| Budget | ACTUAL 80% + FORECASTED 100% | Forecast alert က လကုန်မရောက်ခင် ရက်တွေစောပြီး သတိပေးပါတယ် |
| VPC | NAT မရှိ, isolated subnet + gateway endpoint | S3/DynamoDB traffic က အခမဲ့ endpoint ကနေသွားပြီး internet egress ကို ရည်ရွယ်ချက်ရှိရှိမှ ထည့်ရပါတယ် |
ဒီ baseline က account တစ်ခုအတွက်ပါ။ Organization အဆင့်မှာ AWS Control Tower နဲ့ SCP တွေက account အားလုံးကို ကာကွယ်ပေးနိုင်ပါတယ်၊ အဲဒါကို deeper section မှာ ဆက်ပြောပါမယ်။ ဒီ project ရဲ့ ရည်ရွယ်ချက်က building block တစ်ခုချင်းစီကို ကိုယ်တိုင် နားလည်ဖို့ပါ - managed service တွေက ဘာကို automate လုပ်ပေးနေလဲ မြင်ရအောင်ပါ။
Baseline က ရည်ရွယ်ချက်ရှိရှိ ချန်ထားခဲ့တာတွေကိုလည်း သတိထားကြည့်ပါ - NAT Gateway မပါ၊ internet-facing load balancer မပါ၊ application role တွေ မပါပါဘူး။ အဲဒါတွေ တစ်ခုချင်းစီက workload team က လုံခြုံပြီးသား အောက်ခြေ (floor) တစ်ခုပေါ်မှာ သိသိကြီး ဆုံးဖြတ်ပြီး ထည့်ရမယ့် အရာတွေ ဖြစ်ပါတယ်။
- Record: CloudTrail -> KMS S3
- Detect: GuardDuty findings
- Budget: alert before invoice
- Contain: private VPC + endpoints
- Limit: boundary on new roles
ပထမ သုံးခုက 'ဘာဖြစ်ခဲ့လဲ' ကို သိစေပြီး နောက်ဆုံး နှစ်ခုက 'ဘာမှ မဖြစ်အောင်' တားပေးပါတယ်။ Baseline ကောင်းတစ်ခုမှာ နှစ်မျိုးလုံး လိုပါတယ်။
Multi-stack CDK app ကို deploy လုပ်တဲ့ ပုံစံ
# once per account + region: the roles and bucket CDK deploys with
cdk bootstrap aws://111122223333/us-east-1
cdk synth # templates only, nothing touches AWS
cdk diff --all # what would change, stack by stack
cdk deploy --all --require-approval broadeningBootstrap ကို account/region တစ်ခုမှာ တစ်ကြိမ်ပဲ လုပ်ရပါတယ်။ 'cdk diff --all' က stack တစ်ခုချင်း ဘာပြောင်းမလဲ ပြပေးပြီး '--require-approval broadening' က IAM permission ကျယ်လာတဲ့ change တွေမှာ ရပ်ပြီး အတည်ပြုခိုင်းပါတယ်။ Baseline လို security stack မှာ ဒီ setting က အရေးကြီးပါတယ်။
Baseline CDK app အပြည့်အစုံ
အောက်က app ကို file တစ်ခုတည်းမှာ ရေးထားပေမယ့် stack သုံးခု ထုတ်ပေးပါတယ်။ AWS Fundamentals မှာ console ကနေ တစ်ခုချင်း ဖန်တီးခဲ့တဲ့ S3 bucket, VPC, IAM policy တွေကို ဒီမှာတော့ ဆုံးဖြတ်ချက်တွေနဲ့အတူ code အဖြစ် ရေးထားပါတယ်။ Comment တွေက 'ဘာကြောင့်' ကို ရှင်းပြထားပါတယ်။
import { App, Duration, RemovalPolicy, Stack, StackProps, Tags } from "aws-cdk-lib";
import * as budgets from "aws-cdk-lib/aws-budgets";
import * as cloudtrail from "aws-cdk-lib/aws-cloudtrail";
import * as ec2 from "aws-cdk-lib/aws-ec2";
import * as guardduty from "aws-cdk-lib/aws-guardduty";
import * as iam from "aws-cdk-lib/aws-iam";
import * as kms from "aws-cdk-lib/aws-kms";
import * as s3 from "aws-cdk-lib/aws-s3";
import { Construct } from "constructs";
// 1) Audit: who did what, stored where nobody can quietly change it.
class AuditStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const key = new kms.Key(this, "AuditKey", {
alias: "alias/audit-logs",
enableKeyRotation: true,
removalPolicy: RemovalPolicy.RETAIN,
});
// CloudTrail must be allowed to encrypt with this key, or delivery fails.
const trailArns = `arn:${this.partition}:cloudtrail:*:${this.account}:trail/*`;
key.addToResourcePolicy(
new iam.PolicyStatement({
principals: [new iam.ServicePrincipal("cloudtrail.amazonaws.com")],
actions: ["kms:GenerateDataKey*", "kms:DescribeKey"],
resources: ["*"],
conditions: {
StringLike: { "kms:EncryptionContext:aws:cloudtrail:arn": trailArns },
},
}),
);
const bucket = new s3.Bucket(this, "TrailBucket", {
encryption: s3.BucketEncryption.KMS,
encryptionKey: key,
bucketKeyEnabled: true,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
enforceSSL: true,
versioned: true,
objectOwnership: s3.ObjectOwnership.BUCKET_OWNER_ENFORCED,
lifecycleRules: [
{
transitions: [
{ storageClass: s3.StorageClass.GLACIER, transitionAfter: Duration.days(90) },
],
noncurrentVersionExpiration: Duration.days(365),
},
],
removalPolicy: RemovalPolicy.RETAIN,
});
new cloudtrail.Trail(this, "Trail", {
bucket,
encryptionKey: key,
isMultiRegionTrail: true,
includeGlobalServiceEvents: true,
enableFileValidation: true,
sendToCloudWatchLogs: false,
});
new guardduty.CfnDetector(this, "GuardDuty", {
enable: true,
findingPublishingFrequency: "FIFTEEN_MINUTES",
});
new budgets.CfnBudget(this, "MonthlyBudget", {
budget: {
budgetName: "workload-monthly",
budgetType: "COST",
timeUnit: "MONTHLY",
budgetLimit: { amount: 200, unit: "USD" },
},
notificationsWithSubscribers: [
{
notification: {
notificationType: "ACTUAL",
comparisonOperator: "GREATER_THAN",
threshold: 80,
thresholdType: "PERCENTAGE",
},
subscribers: [{ subscriptionType: "EMAIL", address: "cloud-team@example.com" }],
},
{
notification: {
notificationType: "FORECASTED",
comparisonOperator: "GREATER_THAN",
threshold: 100,
thresholdType: "PERCENTAGE",
},
subscribers: [{ subscriptionType: "EMAIL", address: "cloud-team@example.com" }],
},
],
});
}
}
// 2) Network: private by default, S3/DynamoDB traffic never touches NAT.
class NetworkStack extends Stack {
readonly vpc: ec2.Vpc;
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
this.vpc = new ec2.Vpc(this, "Vpc", {
ipAddresses: ec2.IpAddresses.cidr("10.20.0.0/16"),
maxAzs: 2,
natGateways: 0,
subnetConfiguration: [
{ name: "public", subnetType: ec2.SubnetType.PUBLIC, cidrMask: 24 },
{ name: "app", subnetType: ec2.SubnetType.PRIVATE_ISOLATED, cidrMask: 20 },
],
gatewayEndpoints: {
S3: { service: ec2.GatewayVpcEndpointAwsService.S3 },
DynamoDB: { service: ec2.GatewayVpcEndpointAwsService.DYNAMODB },
},
});
this.vpc.addFlowLog("FlowLogs", {
trafficType: ec2.FlowLogTrafficType.REJECT,
});
}
}
// 3) Guardrails: the ceiling every role created by app teams must live under.
class GuardrailStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new iam.ManagedPolicy(this, "DeveloperBoundary", {
managedPolicyName: "workload-developer-boundary",
statements: [
new iam.PolicyStatement({
sid: "AllowAppServices",
actions: ["s3:*", "dynamodb:*", "sqs:*", "lambda:*", "logs:*", "cloudwatch:*"],
resources: ["*"],
}),
new iam.PolicyStatement({
sid: "DenyAuditTampering",
effect: iam.Effect.DENY,
actions: [
"cloudtrail:StopLogging",
"cloudtrail:DeleteTrail",
"guardduty:DeleteDetector",
"kms:ScheduleKeyDeletion",
],
resources: ["*"],
}),
new iam.PolicyStatement({
sid: "DenyBoundaryEscape",
effect: iam.Effect.DENY,
actions: [
"iam:DeleteRolePermissionsBoundary",
"iam:CreatePolicyVersion",
"iam:DeletePolicy",
"iam:SetDefaultPolicyVersion",
],
resources: ["*"],
}),
],
});
}
}
const app = new App();
const env = { account: process.env.CDK_DEFAULT_ACCOUNT, region: "us-east-1" };
new AuditStack(app, "Baseline-Audit", { env });
new NetworkStack(app, "Baseline-Network", { env });
new GuardrailStack(app, "Baseline-Guardrails", { env });
Tags.of(app).add("baseline", "v1");
app.synth();Browser ထဲမှာ run လို့ မရပါ
ဒီ code ဟာ AWS account အစစ်ပေါ်မှာ run ရမယ့် code ဖြစ်လို့ browser playground ထဲမှာ run လို့ မရပါ။ ကိုယ့် terminal (သို့) AWS CloudShell ထဲမှာ စမ်းပါ။
Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်
- KMS key + key policy
key.addToResourcePolicy(...cloudtrail.amazonaws.com...)Key rotation ဖွင့်ထားပြီး RETAIN ထားပါတယ်။ CloudTrail service ကို ဒီ key နဲ့ encrypt လုပ်ခွင့် ပေးတဲ့ statement က မဖြစ်မနေ လိုပါတယ် - မပါရင် trail ကို ဖန်တီးတဲ့အခါ (သို့) log ပို့တဲ့အခါ fail ဖြစ်ပါတယ်။ Condition က ဒီ account ရဲ့ trail တွေအတွက်ပဲ ကန့်သတ်ထားပါတယ်။
- Trail bucket
blockPublicAccess: BLOCK_ALL, enforceSSL: true, versioned: truePublic access လုံးဝ ပိတ်၊ TLS မဟုတ်တဲ့ request တွေကို bucket policy နဲ့ deny၊ versioning နဲ့ overwrite/delete ကို ပြန်ယူနိုင်အောင် လုပ်ထားပါတယ်။ BUCKET_OWNER_ENFORCED က ACL တွေကို ပိတ်ပါတယ်။ Lifecycle rule က ရက် ၉၀ ကျော်တဲ့ log ကို Glacier ကို ရွှေ့ပြီး cost လျှော့ပါတယ်။
- Trail
isMultiRegionTrail: true, enableFileValidation: trueRegion အားလုံးက management event တွေကို ဖမ်းပြီး digest file တွေနဲ့ log ကို တစ်ယောက်ယောက် ပြင်ထားရင် သိနိုင်ပါတယ်။ CDK က bucket policy ထဲကို CloudTrail ရေးခွင့် statement တွေ အလိုအလျောက် ထည့်ပေးပါတယ်။
- GuardDuty + Budget
new guardduty.CfnDetector(...); new budgets.CfnBudget(...)L2 construct မရှိသေးလို့ L1 (Cfn) construct တွေကို သုံးထားပါတယ်။ Budget မှာ notification နှစ်ခုပါ - တကယ်သုံးပြီးတာ 80% ရောက်ရင်၊ ခန့်မှန်းချက်က 100% ကျော်မယ်ဆိုရင် email ပို့ပါတယ်။
- NetworkStack
natGateways: 0, PRIVATE_ISOLATED, gatewayEndpoints: { S3, DynamoDB }Private subnet တွေမှာ internet route မရှိပါဘူး။ S3 နဲ့ DynamoDB ကို gateway endpoint (အခမဲ့) ကနေ ရောက်ပါတယ်။ Flow log က REJECT ဖြစ်တဲ့ traffic ကိုပဲ မှတ်ထားလို့ log cost နည်းပြီး security group ပြဿနာ debug လုပ်ဖို့ လုံလောက်ပါတယ်။
- GuardrailStack
sid: "DenyAuditTampering" / "DenyBoundaryEscape"Boundary က app service တွေကို ခွင့်ပြုပြီး trail ရပ်တာ၊ detector ဖျက်တာ၊ key ဖျက်ဖို့ schedule လုပ်တာနဲ့ boundary ကို ဖြုတ်တာ/ပြင်တာကို explicit deny လုပ်ပါတယ်။ Explicit deny က ဘယ် allow ကိုမဆို အနိုင်ယူပါတယ်။
Sample output (ID တွေ ကွဲပြားပါမယ်):
✅ Baseline-Audit
✅ Baseline-Network
✅ Baseline-Guardrails
'cdk synth' က template သုံးခုထုတ်ပေးပြီး 'cdk deploy --all' က stack တစ်ခုချင်း ✅ ပြပါတယ်။ Budget email subscriber ဆီကို confirmation email မပို့ပါဘူး - alert ကို တိုက်ရိုက်ပို့ပါတယ်။- Role calls ec2:RunInstances
- Boundary + policies evaluated
- CloudTrail records the call
- Log encrypted (KMS) into S3
- GuardDuty analyses the events
ပုံမှန် activity
Logged, no finding
ထူးခြားတဲ့ pattern
GuardDuty finding -> alert
Role ဖန်တီးခွင့်ကို ထိန်းချုပ်မှု မဆုံးရှုံးဘဲ ခွဲပေးခြင်း
Boundary ကို ဖန်တီးထားရုံနဲ့ မလုံလောက်ပါဘူး - developer တွေ role အသစ် ဖန်တီးတိုင်း အဲဒီ boundary ကို တွဲထည့်ဖို့ အတင်းအကျပ် လိုအပ်ပါတယ်။ ဒါကို iam:PermissionsBoundary condition key နဲ့ လုပ်ပါတယ်။ အောက်က policy ကို developer role ပေါ်မှာ တွဲထားရင် 'app-' နဲ့ စတဲ့ role တွေကိုပဲ၊ boundary ပါမှသာ ဖန်တီးနိုင်ပါတယ်။
ဒီ pattern မရှိရင် iam:CreateRole ရထားတဲ့ developer တစ်ယောက်က AdministratorAccess ပါတဲ့ role အသစ်တစ်ခု ဖန်တီးပြီး သူ့ကိုယ်သူ admin ဖြစ်အောင် လုပ်လို့ရပါတယ် (privilege escalation)။
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CreateRolesOnlyWithTheBoundary",
"Effect": "Allow",
"Action": ["iam:CreateRole", "iam:PutRolePolicy", "iam:AttachRolePolicy"],
"Resource": "arn:aws:iam::111122223333:role/app-*",
"Condition": {
"StringEquals": {
"iam:PermissionsBoundary":
"arn:aws:iam::111122223333:policy/workload-developer-boundary"
}
}
},
{
"Sid": "PassOnlyAppRoles",
"Effect": "Allow",
"Action": "iam:PassRole",
"Resource": "arn:aws:iam::111122223333:role/app-*"
}
]
}CDK ထဲမှာ boundary ကို အလိုအလျောက် ထည့်ခြင်း
App team တွေရဲ့ CDK app တွေမှာ 'iam.PermissionsBoundary.of(stack).apply(policy)' လို့ ရေးလိုက်ရင် အဲဒီ stack ထဲက role အားလုံးမှာ boundary အလိုအလျောက် တွဲပါတယ်။ CDK bootstrap template ကိုလည်း customize လုပ်ပြီး CloudFormation execution role ပေါ်မှာ boundary ထည့်နိုင်ပါတယ်။
Baseline အလုပ်လုပ်နေကြောင်း verify လုပ်ခြင်း
'Deploy အောင်မြင်တယ်' ဆိုတာ 'အလုပ်လုပ်နေတယ်' လို့ မဆိုလိုပါဘူး။ Key policy မှားရင် trail က ရှိနေပေမယ့် log ပို့လို့ မရတာမျိုး ဖြစ်နိုင်ပါတယ်။ ဒါကြောင့် control တစ်ခုချင်းကို စစ်ပါ။
Trail delivery
IsLogging က true ဖြစ်ပြီး LatestDeliveryError က null ဖြစ်ရပါမယ်။ Error ရှိရင် KMS key policy နဲ့ bucket policy ကို အရင်စစ်ပါ။
Bucket လုံခြုံရေး
Public access block flag လေးခုလုံး true၊ versioning Enabled၊ encryption က aws:kms ဖြစ်ရပါမယ်။
GuardDuty alert လမ်းကြောင်း
Sample finding တွေ generate လုပ်ပြီး ကိုယ့် alert (EventBridge rule, Slack, email) ဆီ တကယ်ရောက်လား စစ်ပါ။ Detector ရှိရုံနဲ့ ဘယ်သူမှ finding ကို မမြင်ရင် အသုံးမဝင်ပါဘူး။
Endpoint နဲ့ budget
Gateway endpoint နှစ်ခု (s3, dynamodb) ရှိရပြီး budget name ကို list ထဲမှာ တွေ့ရပါမယ်။
# 1. CloudTrail is logging and its last delivery succeeded
TRAIL=$(aws cloudtrail describe-trails --query 'trailList[0].TrailARN' --output text)
aws cloudtrail get-trail-status --name "$TRAIL" \
--query '{logging:IsLogging,lastError:LatestDeliveryError}'
# 2. The log bucket is private, versioned and KMS-encrypted
BUCKET=$(aws cloudtrail describe-trails --query 'trailList[0].S3BucketName' \
--output text)
aws s3api get-public-access-block --bucket "$BUCKET"
aws s3api get-bucket-versioning --bucket "$BUCKET"
aws s3api get-bucket-encryption --bucket "$BUCKET"
# 3. GuardDuty is on; generate sample findings to test your alert path
DETECTOR=$(aws guardduty list-detectors --query 'DetectorIds[0]' --output text)
aws guardduty create-sample-findings --detector-id "$DETECTOR"
# 4. Gateway endpoints exist for S3 and DynamoDB
aws ec2 describe-vpc-endpoints \
--filters Name=vpc-endpoint-type,Values=Gateway \
--query 'VpcEndpoints[].ServiceName'
# 5. Budget exists
aws budgets describe-budgets --account-id 111122223333 \
--query 'Budgets[].BudgetName'Account တစ်ခုကနေ Organization တစ်ခုလုံးဆီ
Account နှစ်ဆယ် ရှိလာတဲ့အခါ ဒီ app ကို account တစ်ခုချင်း deploy လုပ်တာထက် org အဆင့် feature တွေက ပိုကောင်းပါတယ်။ အောက်က table က ဒီ project ထဲက အစိတ်အပိုင်း တစ်ခုချင်းကို Organizations / Control Tower မှာ ဘယ်လို လုပ်လေ့ရှိလဲ ပြထားပါတယ်။
| ဒီ project | Org အဆင့်မှာ |
|---|---|
| Account တစ်ခုချင်းရဲ့ trail | Management account (သို့) Control Tower က ဖန်တီးတဲ့ organization trail၊ log တွေက သီးသန့် Log Archive account ထဲ သွားပါတယ် |
| Account တစ်ခုချင်းရဲ့ GuardDuty detector | Delegated administrator account က member account အသစ်တွေမှာ GuardDuty ကို auto-enable လုပ်ပါတယ် |
| Permission boundary (role တစ်ခုချင်းရဲ့ ceiling) | SCP (account တစ်ခုလုံးရဲ့ ceiling၊ root user ပါ အကျုံးဝင်) |
| Account တစ်ခုချင်းရဲ့ VPC | Network account ထဲက shared VPC ကို AWS RAM နဲ့ share (သို့) Transit Gateway |
| Account budget | Consolidated billing + team အလိုက် budget + Cost Anomaly Detection |
Org control နဲ့ မထပ်အောင် သတိထားပါ
Organization trail ရှိပြီးသား account မှာ ဒီ trail ကို ထပ်ထည့်ရင် management event ရဲ့ ဒုတိယ copy အတွက် ပိုက်ဆံပေးရပါတယ် (ပထမ copy ပဲ အခမဲ့ပါ)။ GuardDuty ကို delegated admin က enable လုပ်ထားပြီးသားဆိုရင် CfnDetector က 'detector already exists' နဲ့ fail ဖြစ်ပါတယ်။ Org မှာ ဘာရှိပြီးသားလဲ အရင်စစ်ပြီးမှ ဒီ stack တွေကို ရွေးချယ်ပြီး deploy လုပ်ပါ။
Production မှာ
Production team တွေ ဘယ်လို လုပ်ကြလဲ
Production မှာ baseline ကို 'account vending' ရဲ့ အစိတ်အပိုင်းအဖြစ် run ပါတယ်။ Account အသစ်ကို Control Tower Account Factory (သို့) Organizations API နဲ့ ဖန်တီးပြီးတာနဲ့ pipeline က baseline stack တွေကို CDK pipeline (သို့) CloudFormation StackSets နဲ့ အလိုအလျောက် deploy လုပ်ပါတယ်။ App team ကို account ပေးချိန်မှာ baseline က ရှိပြီးသား ဖြစ်နေပါပြီ။
Baseline မှာ version tag (ဥပမာ baseline=v1) ထည့်ထားတဲ့အတွက် 'ဘယ် account တွေ v1 မှာ ကျန်နေသေးလဲ' ဆိုတာ Tag Editor (သို့) Config နဲ့ ရှာနိုင်ပါတယ်။ GuardDuty finding တွေကို EventBridge rule နဲ့ Security Hub, Slack (သို့) on-call tool ဆီ route လုပ်ပါတယ်။ Log Archive bucket တွေမှာ S3 Object Lock ကို ထပ်ဖွင့်ပြီး admin ကိုယ်တိုင်တောင် retention ကာလအတွင်း ဖျက်လို့ မရအောင် လုပ်လေ့ရှိပါတယ်။
Budget ကို account တစ်ခုလုံးအတွက်တင်မဟုတ်ဘဲ cost allocation tag (team, service) အလိုက်လည်း ခွဲထားပါတယ်။ ဒါမှ alert ရောက်လာတဲ့အခါ ဘယ် team ကို ခေါ်ရမလဲ ချက်ချင်းသိပါတယ်။
အမှားများ
အဖြစ်များတဲ့ အမှားများ
KMS key policy မှာ CloudTrail ကို မေ့ခြင်း
Bucket ကို KMS နဲ့ encrypt လုပ်ပြီး trail ကို အဲဒီ key သုံးခိုင်းထားပေမယ့် key policy မှာ cloudtrail.amazonaws.com ကို kms:GenerateDataKey* မပေးထားရင် trail ဖန်တီးတာ (သို့) log ပို့တာ fail ဖြစ်ပါတယ်။ ပိုဆိုးတာက error ကို ဘယ်သူမှ မကြည့်ရင် 'trail ရှိတယ်' လို့ ယုံကြည်ထားပြီး log တစ်ခုမှ မရှိတာ ဖြစ်တတ်ပါတယ်။ Verify step ထဲက get-trail-status ကို pipeline ထဲမှာ ထည့် run ပါ။
Audit resource တွေမှာ RemovalPolicy.DESTROY သုံးခြင်း
Lab တွေမှာ cleanup လွယ်အောင် DESTROY သုံးတဲ့ အကျင့်ကို baseline ထဲ ယူလာရင် 'cdk destroy' တစ်ခါ (သို့) stack rename တစ်ခါနဲ့ audit log နှစ်နှစ်စာ ပျောက်သွားနိုင်ပါတယ်။ Audit bucket နဲ့ key ကို RETAIN ထားပြီး ဖျက်ချင်ရင် လက်နဲ့ ရည်ရွယ်ချက်ရှိရှိ ဖျက်ပါ။
Boundary က သူ့ကိုယ်သူ မကာကွယ်ခြင်း
Boundary ထဲမှာ iam:DeleteRolePermissionsBoundary နဲ့ policy version အသစ်ဖန်တီးခြင်းကို deny မထားရင် boundary အောက်က role တစ်ခုက boundary ကို ဖြုတ်ပစ် (သို့) ပြင်ပစ်ပြီး လွတ်မြောက်သွားနိုင်ပါတယ်။ Ceiling တစ်ခုဟာ ceiling ကိုယ်တိုင်ကို ပြောင်းခွင့် မပေးရပါဘူး။
Best Practices
Best practices
- Baseline ကို workload မတင်ခင် deploy လုပ်ပြီး app stack တွေနဲ့ သီးခြား pipeline မှာ ထားပါ
- Audit, network, guardrail ကို lifecycle အလိုက် stack ခွဲပါ
- Deploy ပြီးတိုင်း verify script ကို အလိုအလျောက် run ပါ
- Org အဆင့်မှာ ရှိပြီးသား control (org trail, GuardDuty delegated admin) နဲ့ မထပ်ပါစေနဲ့
💰 Cost & Cleanup
CloudTrail ရဲ့ management event ပထမ copy က အခမဲ့ပါ၊ ဒါပေမယ့် log သိမ်းတဲ့ S3 storage နဲ့ KMS request တွေအတွက် ပေးရပါတယ်။ Customer managed KMS key တစ်ခုချင်းကို လစဉ် ကြေးရှိပါတယ်။ GuardDuty မှာ region တစ်ခုချင်း ရက် ၃၀ free trial ရှိပြီး နောက်ပိုင်း analyse လုပ်တဲ့ event/data ပမာဏအလိုက် ပေးရပါတယ်။ ဒီ VPC မှာ NAT Gateway မရှိလို့ နာရီကြေး မရှိပါဘူး၊ gateway endpoint တွေက အခမဲ့ပါ၊ flow log ကတော့ CloudWatch Logs ingestion ကြေးရှိပါတယ်။ AWS Budgets ဈေးနှုန်းကိုတော့ pricing page မှာ စစ်ပါ။ Lab ပြီးရင် အောက်က command တွေနဲ့ ဖျက်ပါ - RETAIN ထားတဲ့ bucket နဲ့ key ကို လက်နဲ့ ဖျက်ရပါမယ်။
စမ်းပြီးရင် ဖျက်ဖို့ command
# Note the retained bucket's name BEFORE the trail disappears
BUCKET=$(aws cloudtrail describe-trails --query 'trailList[0].S3BucketName' \
--output text)
cdk destroy --all
# RETAIN resources survive the destroy on purpose. In a lab, remove them.
# A versioned bucket: delete every object version and delete marker first
# (repeat while there are more than 1,000, or use the console "Empty").
aws s3api delete-objects --bucket "$BUCKET" --delete "$(aws s3api \
list-object-versions --bucket "$BUCKET" --output json \
--query '{Objects: Versions[].{Key: Key, VersionId: VersionId}}')"
aws s3api delete-objects --bucket "$BUCKET" --delete "$(aws s3api \
list-object-versions --bucket "$BUCKET" --output json \
--query '{Objects: DeleteMarkers[].{Key: Key, VersionId: VersionId}}')"
aws s3api delete-bucket --bucket "$BUCKET"
KEY_ID=$(aws kms describe-key --key-id alias/audit-logs \
--query 'KeyMetadata.KeyId' --output text)
aws kms delete-alias --alias-name alias/audit-logs
aws kms schedule-key-deletion --key-id "$KEY_ID" --pending-window-in-days 7Mini challenge
Root account သုံးတာနဲ့ alert ထွက်အောင် လုပ်ပါ
Root user ကို ပုံမှန်အားဖြင့် ဘယ်တော့မှ မသုံးသင့်ပါဘူး။ Baseline ထဲကို root user အသုံးပြုတာနဲ့ security team ဆီ email ရောက်အောင် stack တစ်ခု ထပ်ထည့်ပါ။
- Trail က CloudWatch Logs log group ဆီကိုလည်း ပို့ရမယ်
- userIdentity.type = Root ဖြစ်တဲ့ event တွေကို metric filter နဲ့ ရေတွက်ရမယ်
- Metric 1 နဲ့အထက် ရောက်ရင် alarm က SNS topic ကနေ email ပို့ရမယ်
ရလဒ်: Root user နဲ့ console ကို login ဝင်ပြီး မိနစ်အနည်းငယ်အတွင်း alarm က ALARM state ရောက်ပြီး security@example.com ဆီ email ရောက်ပါမယ် (SNS subscription ကို အရင် confirm လုပ်ထားရပါမယ်)။
အရိပ်အမြွက် ကြည့်ရန်
cloudtrail.Trail မှာ sendToCloudWatchLogs နဲ့ cloudWatchLogGroup ကိုသုံးပါ။ Filter pattern က JSON pattern ဖြစ်ပြီး AWS service ကိုယ်တိုင်လုပ်တဲ့ event (AwsServiceEvent) တွေကို ဖယ်ထုတ်ပါ။
အဖြေ ကြည့်ရန်
import { App, Duration, Stack, StackProps } from "aws-cdk-lib";
import * as cloudtrail from "aws-cdk-lib/aws-cloudtrail";
import * as cloudwatch from "aws-cdk-lib/aws-cloudwatch";
import * as actions from "aws-cdk-lib/aws-cloudwatch-actions";
import * as logs from "aws-cdk-lib/aws-logs";
import * as sns from "aws-cdk-lib/aws-sns";
import * as subs from "aws-cdk-lib/aws-sns-subscriptions";
import { Construct } from "constructs";
class RootUsageAlarmStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
const group = new logs.LogGroup(this, "TrailLogs", {
retention: logs.RetentionDays.ONE_YEAR,
});
// The trail also streams to CloudWatch Logs so we can alarm on events.
new cloudtrail.Trail(this, "Trail", {
sendToCloudWatchLogs: true,
cloudWatchLogGroup: group,
isMultiRegionTrail: true,
});
const filter = new logs.MetricFilter(this, "RootUse", {
logGroup: group,
metricNamespace: "Baseline",
metricName: "RootAccountUsage",
filterPattern: logs.FilterPattern.literal(
'{ $.userIdentity.type = "Root" && $.eventType != "AwsServiceEvent" }',
),
metricValue: "1",
});
const topic = new sns.Topic(this, "SecurityAlerts");
topic.addSubscription(new subs.EmailSubscription("security@example.com"));
const alarm = new cloudwatch.Alarm(this, "RootUsageAlarm", {
metric: filter.metric({ period: Duration.minutes(5), statistic: "Sum" }),
threshold: 1,
evaluationPeriods: 1,
comparisonOperator:
cloudwatch.ComparisonOperator.GREATER_THAN_OR_EQUAL_TO_THRESHOLD,
treatMissingData: cloudwatch.TreatMissingData.NOT_BREACHING,
});
alarm.addAlarmAction(new actions.SnsAction(topic));
}
}
const app = new App();
new RootUsageAlarmStack(app, "Baseline-RootAlarm");
app.synth();Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
မှတ်ထားရမယ့် အချက်များ
- Baseline က audit, detection, cost, containment, guardrail ငါးမျိုးကို account တိုင်းမှာ တစ်ပုံစံတည်း ပေးပါတယ်
- Stack တွေကို lifecycle အလိုက်ခွဲပြီး audit resource တွေကို RETAIN ထားပါ
- KMS key policy က CloudTrail ကို ခွင့်ပြုရပြီး deploy ပြီးတိုင်း delivery ကို verify လုပ်ပါ
- Permission boundary ကို iam:PermissionsBoundary condition နဲ့ အတင်းအကျပ်တွဲမှ guardrail ဖြစ်ပါတယ်
- Org trail, delegated admin, SCP တွေရှိရင် account-level control တွေနဲ့ မထပ်ပါစေနဲ့
AWS CloudTrail User Guide — AWS Documentation
IAM: Permissions boundaries for IAM entities — AWS Documentation
What is AWS Control Tower? — AWS Documentation