â ã¯ããã«
Github Workflow 㧠Self-Hosted runner (EC2) ä¸ã§ä½æãããã¡ã¤ã«ã ãã® Self-Hosted runner ã¨ã¯ãå¥ã®AWS ã¢ã«ã¦ã³ãã«ãã¡ã¤ã«ãç½®ãããã ããã§ãå¥AWSã¢ã«ã¦ã³ãã®S3ã«ãã¡ã¤ã«ãã¢ãããã¼ããããã¨ã 調ã¹ã¦ã¿ãã
ç®æ¬¡
ãï¼ãããããã㨠ãï¼ãèãããã¤ã³ã ãï¼ï¼IAMãã¼ã«ããã³ããªã·ã¼ ãï¼ï¼S3ãã±ããããªã·ã¼ ãï¼ï¼ï¼Optionï¼KMS使ç¨æï¼KMSãã¼ ãï¼ãæé ãï¼ï¼ã¢ã«ã¦ã³ããBãã®S3 ãã±ããä½æ ãï¼ï¼ã¢ã«ã¦ã³ããAãã®IAM Policyä½æ ãï¼ï¼ã¢ã«ã¦ã³ããAãã§ä½¿ç¨ããRoleã«Policyãã¢ã¿ãããã ãï¼ï¼ã¢ã«ã¦ã³ããBãã®S3 ãã±ããPolicyä½æ ãï¼ï¼ï¼Optionï¼KMS使ç¨æï¼ã¢ã«ã¦ã³ããBãã§KMSãã¼ããªã·ã¼ã«ã¢ã«ã¦ã³ããAãã¸ã®ä½¿ç¨è¨±å¯ ãï¼ï¼ï¼Optionï¼KMS使ç¨æï¼ã¢ã«ã¦ã³ããAãã§KMSãã¼ã®ä½¿ç¨è¨±å¯ ãï¼ï¼åä½ç¢ºèª
ãï¼ããããããã¨
AWSã¢ã«ã¦ã³ããAãããã å¥ã¢ã«ã¦ã³ããBãï¼ã¯ãã¹ã¢ã«ã¦ã³ãï¼ã«ãã S3ãã±ããã«ãã¡ã¤ã«ãã¢ãããã¼ãããã
ãï¼ãèãããã¤ã³ã
* 以ä¸ã®é¢é£è¨äºã§ã触ãã¦ããããèãããã¤ã³ãã¯ã以ä¸ã®3ç¹ã
ã¯ãã¹ã¢ã«ã¦ã³ãã§ã®S3ã¢ã¯ã»ã¹ã«é¢ãããã©ãã«
https://dk521123.hatenablog.com/entry/2022/06/30/193834
ï¼ï¼IAMãã¼ã«ããã³ããªã·ã¼
* AWSã¢ã«ã¦ã³ããAãå´ã®IAMãã¼ã«ããã³ããªã·ã¼ä»ä¸ãå¿ è¦
ï¼ï¼S3ãã±ããããªã·ã¼
* AWSã¢ã«ã¦ã³ããBãå´ã§ã ãAWSã¢ã«ã¦ã³ããAãå´ã®IAMãã¼ã«ã«å¯¾ãã¦ã ãS3ãã±ããã許å¯ï¼Allowï¼ããå¿ è¦ããã
ï¼ï¼ï¼Optionï¼KMS使ç¨æï¼KMSãã¼
* AWSã¢ã«ã¦ã³ããBãå´ã®S3ãã±ããã§KMSãã¼ãæå·åãã¦ããå ´å㯠ããã®KMSãã¼ã®ä½¿ç¨è¨±å¯ï¼Allowï¼ãAWSã¢ã«ã¦ã³ããAããBã両æ¹ã§ ãè¡ãå¿ è¦ããã
ãï¼ãæé
ï¼ï¼ã¢ã«ã¦ã³ããBãã®S3 ãã±ããä½æ
åãå ¥ãå ã®ã¢ã«ã¦ã³ããBãã®S3 ãã±ããä½æãã => ãã§ã«ããã°ãSkip
ï¼ï¼ã¢ã«ã¦ã³ããAãã®IAM Policyä½æ
* ã¢ã«ã¦ã³ããAãã§ãã¢ã«ã¦ã³ããBãã® ãS3 ãã±ããã«ãã¡ã¤ã«ãã¢ãããã¼ãå¯è½ãª ãIAM Policyãä½æãã => KMS使ç¨ãã¦ããå ´åã¯ãå®éã§ã¯ ããï¼ï¼ï¼Optionï¼KMS使ç¨æï¼ã¢ã«ã¦ã³ããAãã§KMSãã¼ã®ä½¿ç¨è¨±å¯ã ãã¨åæã«ãã£ã¦ãã¾ã£ã¦ãã => åé¤ãå¿ è¦ãªå ´åã¯ã"s3:DeleteObject",ãã追å ããã°ãã
ã¤ã¡ã¼ã¸ï¼S3ãã±ãã使ç¨è¨±å¯Policy
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:GetObject", "s3:ListBucket", "s3:PutObject" ], "Resource": [ "arn:aws:s3:::ï¼S3ãã±ããåï¼", "arn:aws:s3:::ï¼S3ãã±ããåï¼/*" ] } ] }
ã¤ã¡ã¼ã¸ï¼å
¨ä½S3ãã±ããåç
§è¨±å¯Policyï¼è¦ããªãããï¼
https://docs.aws.amazon.com/ja_jp/AmazonS3/latest/userguide/using-with-s3-actions.html#using-with-s3-actions-related-to-buckets
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "s3:ListAllMyBuckets", "s3:GetBucketLocation" ], "Resource": "arn:aws:s3:::*" } ] }
ï¼ï¼ã¢ã«ã¦ã³ããAãã§ä½¿ç¨ããRoleã«Policyãã¢ã¿ãããã
ï¼ï¼ã§ä½æããIAM Policyãã¢ã¯ã»ã¹ãããIAM Roleã«å¯¾ã㦠ï¼ä¾ãã°ãEC2 ã§ã¢ã¯ã»ã¹ããå ´åã¯ãEC2 ã® IAM Roleï¼ ã¢ã¿ãããã
ï¼ï¼ã¢ã«ã¦ã³ããBãã®S3 ãã±ããPolicyä½æ
ã¢ã«ã¦ã³ããBãã«ä½æ¥ãæ»ã£ã¦ã S3ãã±ããã®ãã±ããPolicyã« ã¢ã«ã¦ã³ããAãã® IAM Policy ã許å¯ï¼Allowï¼ããããã«ãã => åé¤ãå¿ è¦ãªå ´åã¯ã"s3:DeleteObject",ãã追å ããã°ãã => ã"AWS" : "arn:aws:iam::<AWSã¢ã«ã¦ã³ããAãID>:role/<IAM Role>"ãããã¢
ã¤ã¡ã¼ã¸
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::<AWSã¢ã«ã¦ã³ããAãID>:role/<IAM Role>" }, "Action": [ "s3:GetObject", "s3:ListBucket", "s3:PutObject" ], "Resource": [ "arn:aws:s3:::ï¼S3ãã±ããåï¼", "arn:aws:s3:::ï¼S3ãã±ããåï¼/*" ] } ] }
ï¼ï¼ï¼Optionï¼KMS使ç¨æï¼ã¢ã«ã¦ã³ããBãã§KMSãã¼ããªã·ã¼ã«ã¢ã«ã¦ã³ããAãã¸ã®ä½¿ç¨è¨±å¯
* KMS使ç¨ããå ´åãã¢ã«ã¦ã³ããBãã§KMSãã¼ããªã·ã¼ã«å¯¾ã㦠ãã¢ã«ã¦ã³ããAãã¸ã®ä½¿ç¨è¨±å¯ãè¡ãå¿ è¦ããã => ã"AWS" : "arn:aws:iam::<AWSã¢ã«ã¦ã³ããAãID>:role/<IAM Role>"ãããã¢
ã¤ã¡ã¼ã¸
{ "Version" : "2012-10-17", "Id" : "demo-key-policy-for-cross-accounts", "Statement" : [ { "Sid" : "Enable IAM User Permissions for Cross accounts", "Effect" : "Allow", "Principal" : { "AWS" : "arn:aws:iam::<AWSã¢ã«ã¦ã³ããAãID>:role/<IAM Role>" }, "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:DescribeKey" ], "Resource" : "*" } ] }
ï¼ï¼ï¼Optionï¼KMS使ç¨æï¼ã¢ã«ã¦ã³ããAãã§KMSãã¼ã®ä½¿ç¨è¨±å¯
* KMS使ç¨ããå ´åãã¢ã«ã¦ã³ããAãã§KMSãã¼ã®ä½¿ç¨è¨±å¯ãè¡ãããã« ãIAMããªã·ã¼ã追å ããï¼ï¼ã§è¡ã£ãããã«IAMãã¼ã«ã«ã¢ã¿ãããã => å®éã¯ãï¼ï¼ã¢ã«ã¦ã³ããAãã®IAM Policyä½æãã¨åæããã¨ããããã => ã¡ãªã¿ã«ãkms:GenerateDataKeyãã¯çµ¶å¯¾å¿ è¦ï¼ããããã¨ã©ã¼ãã§ãã®ã§ï¼
ã¤ã¡ã¼ã¸
{ "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Action": [ "kms:Encrypt", "kms:Decrypt", "kms:ReEncrypt*", "kms:GenerateDataKey*", "kms:DescribeKey" ], "Resource": [ "arn:aws:kms:ï¼AWS Regionï¼:ï¼AWSã¢ã«ã¦ã³ããBãIDï¼":key:*" ] } ] }
ï¼ï¼åä½ç¢ºèª
* ã¢ã«ã¦ã³ããAãå´ã§åä½ç¢ºèªãã¦ã¿ã
確èªä¾ï¼ãã¡ã¤ã«ã®Put
echo "Hello world!!" > hello.txt aws s3 cp hello.txt s3://ï¼ã¢ã«ã¦ã³ããBãã®S3ãã±ããåï¼/tests/hello.txt
åèæç®
https://repost.aws/ja/knowledge-center/s3-cross-account-upload-access
https://docs.aws.amazon.com/ja_jp/mediaconvert/latest/ug/write-your-outputs-to-another-accounts-amazon-s3-bucket.html
https://cloud5.jp/cross-account-upload-to-s3/
https://www.capybara-engineer.com/entry/2021/05/20/120604
é¢é£è¨äº
IAM ï½ å
¥éç·¨ ï½
https://dk521123.hatenablog.com/entry/2017/02/26/231046
IAM ï½ åºæ¬ç·¨ ï½
https://dk521123.hatenablog.com/entry/2022/07/03/000000
IAM ï½ IAM Policy ï½
https://dk521123.hatenablog.com/entry/2020/09/30/133123
IAM ï½ ã¯ãã¹ã¢ã«ã¦ã³ã ï½
https://dk521123.hatenablog.com/entry/2022/05/23/000000
AWS CLI ï½ aws sts ï½
https://dk521123.hatenablog.com/entry/2023/04/13/000000
IAM ï½ Service-Linked Roles ï½
https://dk521123.hatenablog.com/entry/2023/01/22/000000
ã¯ãã¹ã¢ã«ã¦ã³ãã§ã®S3ã¢ã¯ã»ã¹ã«é¢ãããã©ãã«
https://dk521123.hatenablog.com/entry/2022/06/30/193834