ã©ãããã¯ãããããã¾ãã
æè¿æ¬§å·No.1ãµãã«ã¼ã¯ã©ãã決ãããã¼ãã¡ã³ã âãã£ã³ããªã³ãºãªã¼ã°ï¼ç¥ã㦠CL ï¼â ã®äºé¸ãå§ã¾ããå¯ããªãæ¥ã
ãç¶ãã¦ããæ°åã®ã¾ã¤ãã¨ã§ãã
ã
åªä»ã絶è³ã客æ§ããã®ãåãåãã対å¿ã§ä¿®è¡ä¸ã®èº«ã§ãããããæ¥ã
ã IAM ããªã·ã¼ã§ããªã¼ã¸ã§ã³ã¨ãªã½ã¼ã¹ã¸ã®ã¢ã¯ã»ã¹å¶éãããããããã¾ããããªãï¼ãã¨ãããåãåãããããã ãã¾ããã
ã
ããã§æ¬ããã°ã§ã¯ãã客æ§ãã¢ã¯ã»ã¹å¶éã§ããªãã£ãåå ã調ã¹ãã客æ§ã® IAM ããªã·ã¼ãå ã«ããªã¼ã¸ã§ã³ã¨ãªã½ã¼ã¹ã¸ã®ã¢ã¯ã»ã¹å¶éãã§ãã IAM ããªã·ã¼ã®ä½æããã¦ããã¾ãã ã
- ä½æããã IAM ããªã·ã¼ã®è¦ä»¶ã«ã¤ãã¦
- ã客æ§ãä½æãã IAM ããªã·ã¼ã§ã¢ã¯ã»ã¹å¶éã®ç¢ºèª
- ãªã½ã¼ã¹ã®ã¢ã¯ã»ã¹å¶éããã¾ããããªãåå ã¯ï¼
- IAM ããªã·ã¼ãä¿®æ£ãã¦ã¿ã
- ã¾ã¨ã
â»ã客æ§ããé ãã IAM ããªã·ã¼ã®è¦ä»¶ã¨ IAM ããªã·ã¼ï¼JSONï¼ã¯ä¸é¨æ¹å¤ãã¦ãã¾ãã
ä½æããã IAM ããªã·ã¼ã®è¦ä»¶ã«ã¤ãã¦
ä½æããã IAM ããªã·ã¼ã®è¦ä»¶ã¯ä»¥ä¸ã®4ç¹ã§ãã
ã
ã
- 大éªãªã¼ã¸ã§ã³ã«ã¢ã¯ã»ã¹ä¸å¯
- æ±äº¬ãªã¼ã¸ã§ã³ã® EC2 ã®ã¿æä½å¯è½
- ã§ããæä½ã¯ EC2 ã®éå§ã¨åæ¢ã®ã¿
- EC2 ã® CloudWatch ã¡ããªã¯ã¹ã表示
ã客æ§ãä½æãã IAM ããªã·ã¼ã§ã¢ã¯ã»ã¹å¶éã®ç¢ºèª
IAM ããªã·ã¼( JSON ) ã®è¦æ¹ã«é¢ãã¦ã¯ãå½ç¤¾ã®ãã¡ãã®ããã°ã§ç°¡åã«ã¾ã¨ãã¦ãã¾ãã®ã§ãæ¯éã覧ãã ããã
ã
ããã§ã¯ãã客æ§ãä½æãã IAM ããªã·ã¼( JSON )ã確èªãã¦ã¿ã¾ãã
{ ã"Version": "2012-10-17", ã"Statement": [ ãã{ ããã"Effect": "Deny", ããã"Action": "*", ããã"Resource": "*", ããã"Condition": { ãããã"StringEquals": { ããããã"aws:RequestedRegion": "ap-northeast-3" ãããã} ããã} ãã}, ~~~ããã¾ã§ããªã¼ã¸ã§ã³ã®å¶éã«é¢ããå 容~~~ ãã{ ããã"Effect": "Allow", ããã"Action": [ ãããã"cloudwatch:DescribeAlarms", ãããã"cloudwatch:GetMetricStatistics" ããã], ããã"Resource": "arn:aws:ec2:ap-northeast-1: 123456789101 :instance/*" ãã}, ~~~ããã¾ã§ã EC2 ã® CloudWatch ã¡ããªã¯ã¹ã®è¡¨ç¤ºã«é¢ããå 容~~~ ãã{ ããã"Effect": "Allow", ããã"Action": [ ãããã"ec2:Describe*", ãããã"ec2:StartInstances", ãããã"ec2:StopInstances" ããã], ããã"Resource": "arn:aws:ec2:ap-northeast-1: 123456789101 :instance/i-0780b15213d764866" ãã} ã] } ~~~ããã¾ã§ã EC2 ã®æä½ã«é¢ããå 容~~~
ã
ãã® IAM ããªã·ã¼ãã¢ã¿ãããã IAM ã¦ã¼ã¶ã¼ãä½æãã¦ãè¦ä»¶ç¢ºèªãè¡ãã¾ãã
以ä¸ã®éãã"大éªãªã¼ã¸ã§ã³ã«ã¢ã¯ã»ã¹ä¸å¯" ã¯æºããã¦ãã¾ããã
ã
次ã«æ±äº¬ãªã¼ã¸ã§ã³ã«ã¢ã¯ã»ã¹ãè¡ãã¨ãæ±äº¬ãªã¼ã¸ã§ã³ã¸ã®ã¢ã¯ã»ã¹ã¯â Deny âãã¦ããªãã®ã§ãããã¢ã¯ã»ã¹ãããã¨ãã§ãã¾ããã§ããã
ãªã½ã¼ã¹ã®ã¢ã¯ã»ã¹å¶éããã¾ããããªãåå ã¯ï¼
IAM ããªã·ã¼ã®ãã¸ã¥ã¢ã«ã¨ãã£ã¿ãè¦ãã¨ãããã¤ãã®ã¢ã¯ã·ã§ã³ã«ã¨ã©ã¼ãåºã¦ãã¾ããã
ã
çµè«ã¨ãã¦ã¯ãã¢ã¯ã·ã§ã³ã«ãã£ã¦ãªã½ã¼ã¹ã®å¶éã®ä»æ§ãç°ãªãããã§ãã
ã
ä»å使ç¨ãã¦ããã¢ã¯ã·ã§ã³ã¯ä»¥ä¸ã®ï¼ã¤ã«ãªãã¾ãã
- "cloudwatch:DescribeAlarms"
- "cloudwatch:GetMetricStatistics"
- "ec2:Describe*"
- "ec2:StartInstances"
- "ec2:StopInstances"
ã
ããããã®ã¢ã¯ã·ã§ã³ã«ã¤ã㦠AWS ããã¥ã¡ã³ãã§ç¢ºèªãã¦ããã¾ãã
ã
- "cloudwatch:DescribeAlarms"
ãã®ã¢ã¯ã·ã§ã³ã¯ããªã½ã¼ã¹ã®å¶éããããã¨ãã§ãã¾ãã
ãã ããªã½ã¼ã¹ã® ARN ã®æ¸ãæ¹ã決ã¾ã£ã¦ããã以ä¸ã®ããã«ãªã£ã¦ãã¾ãã
arn:${Partition}:cloudwatch:${Region}:${Account}:alarm:${AlarmName}
ã
ã
- "cloudwatch:GetMetricStatistics"
ãã®ã¢ã¯ã·ã§ã³ã¯ããªã½ã¼ã¹ã®å¶éããããã¨ãã§ãã¾ããã
ãã®ããã"Resource": ã®å¾ã¯ã"*" ï¼ãã¹ã¦ã®ãªã½ã¼ã¹ã¨ããæå³ï¼ã§ãªããã°ãªãã¾ããã
ã
ã
- "ec2:StartInstances"
- "ec2:StopInstances"
ãã®2ã¤ã®ã¢ã¯ã·ã§ã³ã¯ããªã½ã¼ã¹ã®å¶éããããã¨ãå¯è½ã§ãã
ãã ããªã½ã¼ã¹ã® ARN ã®æ¸ãæ¹ã決ã¾ã£ã¦ããã以ä¸ã®ããã«ãªã£ã¦ãã¾ãã
arn:${Partition}:ec2:${Region}:${Account}:instance/${InstanceId}
ã
ã
- "ec2:Describe*"
ç¶ãã¦ãã¢ã¯ã»ã¹å¶éããã¾ããããªãã£ãåå ã§ãããã®ã¢ã¯ã·ã§ã³ã«ã¤ãã¦ã§ãã
Describe ã®å¾ãã« â*â ããããã¨ã§ãâDescribe ããå§ã¾ããã¹ã¦ã®ã¢ã¯ã·ã§ã³âãæå³ãã¾ããDescribe ããå§ã¾ãã¢ã¯ã·ã§ã³ã¯ã¨ã¦ãå¤ããããããã§ãªã½ã¼ã¹ã® ARN ã®æ¸ãæ¹ãç°ãªãã¾ãã
ãã®ããããªã½ã¼ã¹ã® ARN ã®æ¸ãæ¹ãä¸æã«å®ãããã¨ãã§ããããªã½ã¼ã¹ã®å¶éããããã¨ãã§ãã¾ããã
ã
ã
以ä¸ã®ãã¨ãã IAM ããªã·ã¼( JSON )ã§ã¯ããªã½ã¼ã¹ã®å¶éã§ããã¢ã¯ã·ã§ã³ãã©ããã§ãè¨è¿°ãåãããªã©ã®å¯¾å¿ãããå¿ è¦ãããã¾ãã
IAM ããªã·ã¼ãä¿®æ£ãã¦ã¿ã
ä¸è¨ãè¸ã¾ãã¦ãIAM ããªã·ã¼ãæ¸ãæãã¦ã¿ã¾ãã
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Deny", "Action": "*", "Resource": "*", "Condition": { "StringEquals": { "aws:RequestedRegion": "ap-northeast-3" } } }, { "Effect": "Allow", "Action": [ "cloudwatch:DescribeAlarms", "cloudwatch:GetMetricStatistics", "ec2:Describe*" ], "Resource": "*" <-å¶å¾¡ã§ããªãã¢ã¯ã·ã§ã³ãã¾ã¨ãã¦ãResourse ã "*" ã«å¤æ´ }, { "Effect": "Allow", "Action": [ "ec2:StartInstances", "ec2:StopInstances" ], "Resource": "arn:aws:ec2:ap-northeast-1: 123456789101 :instance/i-0780b15213d764866" } ] }
ã
"cloudwatch:DescribeAlarms" ã¯ãªã½ã¼ã¹ã®å¶éãã§ããã¢ã¯ã·ã§ã³ã§ãããä»åã¯å¶éãã¦ãã¾ãããã¾ãã対象ãªã½ã¼ã¹ã EC2 ã§ã¯ãªããä½è£½ããã¢ã©ã¼ã ã§ãã®ã§ãæ£ç¢ºã«ã¯ãã¡ãã®ã¢ã¯ã·ã§ã³ã "ec2:Describe*" ãªã©ã¨åãã¦è¨è¿°ããæ¹ãããã®ããããã¾ããã
ã
ããä¸åº¦æ±äº¬ãªã¼ã¸ã§ã³ã«ã¢ã¯ã»ã¹ããã¨ãç¡äº EC2 ãªã½ã¼ã¹ã®è¡¨ç¤ºã«æåãã¾ããã
ã¾ããæå®ã® EC2 ã®ã¤ã³ã¹ã¿ã³ã¹ã®åæ¢ããã以å¤ã® EC2 ã®æä½ãä¸å¯ã§ãããã¨ã CloudWatch ã¡ããªã¯ã¹ã®è¡¨ç¤ºã確èªã§ãã¾ããããã³ã¶ã¼ã¤ã
ã¾ã¨ã
æ¬ããã°ã§ã¯ãIAM ããªã·ã¼ï¼ JSON ï¼ã§ã"ãªã½ã¼ã¹" 㨠"ãªã¼ã¸ã§ã³" ã¸ã®ã¢ã¯ã»ã¹å¶éããã¦ã¿ã¾ãããå AWS ãµã¼ãã¹ã®ã¢ã¯ã·ã§ã³ãã¨ã«ãªã½ã¼ã¹ã®å¶éæ¹æ³ãç°ãªãã®ã§ãå°ã大å¤ã§ãããAWS ããã¥ã¡ã³ãããã£ãã確èªãã¦ããã¾ãããï¼ ã
ãã¾ã IAM ããªã·ã¼ã® AWS ããã¥ã¡ã³ããçºããæ©ä¼ããªãã£ããããããåå¼·ã«ãªãã¾ããã
AWS ããã¥ã¡ã³ãä¸æ³ï¼ï¼
ã
ã»åèã«ããããã°
ã¾ã¤ãã¨ã¨ããã(å·çè¨äºã®ä¸è¦§)
ã¢ããªã±ã¼ã·ã§ã³ãµã¼ãã¹é¨ã©ã¼ãã³ã°ã¨ã¯ã¹ããªã¨ã³ã¹èª² 2022å¹´æ°åå ¥ç¤¾ãå¾åãçãæ²»ãããï¼åå®ï¼