{"id":2143,"date":"2021-11-22T06:39:33","date_gmt":"2021-11-21T21:39:33","guid":{"rendered":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/?p=2143"},"modified":"2021-11-22T06:39:33","modified_gmt":"2021-11-21T21:39:33","slug":"assume_role_github_actions_circleci","status":"publish","type":"post","link":"https:\/\/p-corporate-blog-cms.mmmcorp.co.jp\/blog\/2021\/11\/22\/assume_role_github_actions_circleci\/","title":{"rendered":"GitHub Actions\u3068CircleCI\u3067Assume Role\u3059\u308b\u8a2d\u5b9a"},"content":{"rendered":"
\u4eca\u56de\u306f\u3001\u4ee5\u524d\u5f0a\u793e\u306e\u897f\u85e4\u304c\u3084\u3063\u3066\u3044\u305f Terraform\u7528\u306eAWS\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306e\u6a29\u9650\u7ba1\u7406\u3092\u3001\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u5f62\u5f0f\u3067\u6700\u9069\u5316\u3059\u308b\u65b9\u6cd5<\/a> \u3092\u3001CI\/CD(Continuous Integration: \u7d99\u7d9a\u7684\u30a4\u30f3\u30c6\u30b0\u30ec\u30fc\u30b7\u30e7\u30f3\/Continuous Delivery: \u7d99\u7d9a\u7684\u30c7\u30ea\u30d0\u30ea\u30fc)\u3067\u3088\u304f\u4f7f\u308f\u308c\u308b GitHub Actions<\/a> \u3068 CircleCI<\/a> \u3067\u3084\u3063\u3066\u307f\u305f\u306e\u3067\u3001\u305d\u306e\u307e\u3068\u3081\u3067\u3059\u3002<\/p>\n IAM\u30e6\u30fc\u30b6\u30fc\u306e\u4f5c\u6210\u3084\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u306e\u4f5c\u6210\u65b9\u6cd5\u306b\u3064\u3044\u3066\u306f\u524d\u8ff0\u306e\u897f\u85e4\u306e\u30d6\u30ed\u30b0\u8a18\u4e8b\u306b\u8a73\u7d30\u304c\u3042\u308a\u307e\u3059\u306e\u3067\u3001\u4eca\u56de\u306f\u5272\u611b\u3057\u307e\u3059\u3002<\/p>\n \u4eca\u56de\u306f\u3001<\/p>\n \u3068\u3057\u3066\u4f5c\u6210\u3057\u307e\u3057\u305f\u3002<\/p>\n \u307e\u305a\u306f\u3001GitHub\u3078AWS\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306e\u8a2d\u5b9a\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n GitHub\u306e\u30ea\u30dd\u30b8\u30c8\u30ea\u306e <\/a><\/p>\n \u4eca\u56de\u4f7f\u3046IAM\u30e6\u30fc\u30b6\u30fc\u306eAWS\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306a\u3069\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n <\/a><\/p>\n \u8a2d\u5b9a\u3057\u305f\u306e\u306f\u4e0b\u8a183\u3064\u3067\u3059\u3002<\/p>\n GitHub Marketplace<\/a> \u3067 <\/a><\/p>\n \u691c\u7d22\u7d50\u679c\u306e\u4e2d\u304b\u3089\u753b\u50cf\u306e<\/p>\n \u3092\u4f7f\u3063\u3066\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n \u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u914d\u4e0b\u306b\u3001 \u30ed\u30fc\u30eb\u3092\u30b9\u30a4\u30c3\u30c1\u3059\u308b\u524d\u5f8c\u3067\u308f\u304b\u308a\u3084\u3059\u3044\u3088\u3046\u306b\u3001 \u5b9f\u884c\u3057\u305f\u7d50\u679c\u306e\u753b\u50cf\u3067\u3059\u3002<\/p>\n <\/a><\/p>\n \u30b9\u30a4\u30c3\u30c1\u3059\u308b\u524d\u306f\u3001 <\/a><\/p>\n \u8a2d\u5b9a\u3057\u305f\u306e\u306f\u4e0b\u8a184\u3064\u3067\u3059\u3002<\/p>\n\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb\u3092\u884c\u3046\u30e1\u30ea\u30c3\u30c8<\/h3>\n
GitHub Actions<\/code> \u3084
CircleCI<\/code> \u306b\u8a2d\u5b9a\u3059\u308bAWS\u306e\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306b\u306f\u3001\u30b9\u30a4\u30c3\u30c1\u30ed\u30fc\u30eb(Assume Role)\u3059\u308b\u305f\u3081\u3060\u3051\u306e\u6700\u4f4e\u9650\u306e\u6a29\u9650\u306e\u307f\u3068\u3059\u308b\u3053\u3068\u3067\u3001\u4e07\u304c\u4e00\u4f55\u3089\u304b\u306e\u7406\u7531\u3067\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u304c\u6f0f\u6d29\u3057\u3066\u3057\u307e\u3063\u3066\u3082\u3001\u5f71\u97ff\u7bc4\u56f2\u3092\u6700\u4f4e\u9650\u306b\u3067\u304d\u308b\u3053\u3068\u304c\u30e1\u30ea\u30c3\u30c8\u3068\u3057\u3066\u8003\u3048\u3089\u308c\u307e\u3059\u3002<\/p>\n
\u4e8b\u524d\u6e96\u5099(IAM\u30e6\u30fc\u30b6\u30fc\u3001\u30ed\u30fc\u30eb\u4f5c\u6210)<\/h3>\n
\n
gene-test-user<\/code> <\/li>\n
gene-test-role<\/code><\/li>\n<\/ul>\n
GitHub Actions<\/h3>\n
Secrets \u8a2d\u5b9a<\/h4>\n
Settings<\/code> ->
Secrets<\/code> ->
New repository secret<\/code> \u306e\u9806\u306b\u753b\u9762\u9077\u79fb\u3057\u3001<\/p>\n
\n
AWS_ROLE_TO_ASSUME<\/code> \u306b\u306f\u30b9\u30a4\u30c3\u30c1\u3059\u308b\u30ed\u30fc\u30eb\u306eARN\u3092\u5165\u529b\u3057\u307e\u3059\u3002
\narn:aws:iam::111111111111:role\/gene-test-role<\/code> \u306e\u3088\u3046\u306a\u5f62\u3067\u3059\u3002<\/p>\n
yml\u30d5\u30a1\u30a4\u30eb\u306e\u8a2d\u5b9a<\/h4>\n
Actions<\/code> \u3092\u691c\u7d22\u3067\u304d\u308b\u306e\u3067\u3001\u305d\u3053\u3067
aws<\/code> \u3068\u5165\u529b\u3057\u307e\u3059\u3002<\/p>\n
\n
.github\/workflows\/<\/code> \u3068\u3044\u3046\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3066\u3001\u305d\u3053\u306b
switch-role-test.yml<\/code> \u3068\u3044\u3046yml\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n
switch-role-test.yml<\/code> \u306e\u8a2d\u5b9a\u5185\u5bb9\u306f\u4e0b\u8a18\u306e\u3068\u304a\u308a\u3067\u3059\u3002<\/p>\n
name: CI\n\non:\n push:\n branches: [ main ]\n pull_request:\n branches: [ main ]\n\n workflow_dispatch:\n\njobs:\n build:\n runs-on: ubuntu-latest\n\n steps:\n - uses: actions\/checkout@v2\n\n - name: Configure AWS Credentials\n uses: aws-actions\/configure-aws-credentials@v1\n with:\n aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}\n aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}\n aws-region: ap-northeast-1\n - run: aws sts get-caller-identity\n\n - name: Set AWS_ROLE_TO_ASSUME\n uses: aws-actions\/configure-aws-credentials@v1\n with:\n role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }}\n role-duration-seconds: 900\n role-skip-session-tagging: true\n aws-region: ap-northeast-1\n - run: aws sts get-caller-identity<\/code><\/pre>\n
${{ secrets.AWS_ACCESS_KEY_ID }}<\/code> \u306e\u3088\u3046\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u3001\u5148\u7a0b\u8a2d\u5b9a\u3057\u305fSecrets\u3092\u5229\u7528\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n
aws sts get-caller-identity<\/code> \u30b3\u30de\u30f3\u30c9\u3067\u3001\u73fe\u5728\u4f7f\u3063\u3066\u3044\u308b\u8a8d\u8a3c\u60c5\u5831\u3092\u8868\u793a\u3057\u3066\u307f\u307e\u3057\u305f\u3002<\/p>\n
\u5b9f\u884c\u7d50\u679c<\/h4>\n
aws sts get-caller-identity<\/code> \u306e\u7d50\u679c\u304c\u3001
gene-test-user<\/code> \u3068\u306a\u3063\u3066\u3044\u3066\u3001\u30b9\u30a4\u30c3\u30c1\u5f8c\u306b\u306f\u3001\u30b9\u30a4\u30c3\u30c1\u3057\u305f\u30ed\u30fc\u30eb
gene-test-role<\/code> \u304c\u78ba\u8a8d\u3067\u304d\u308b\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n
CircleCI<\/h3>\n
\u74b0\u5883\u5909\u6570\u8a2d\u5b9a<\/h4>\n
CircleCI<\/code> \u306e\u65b9\u3082\u74b0\u5883\u5909\u6570\u3068\u3057\u3066AWS\u30a2\u30af\u30bb\u30b9\u30ad\u30fc\u306a\u3069\u3092\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n
Project Settings<\/code> ->
Environment Variables<\/code> ->
Add Environment Variable<\/code> \u3067\u8a2d\u5b9a\u3067\u304d\u307e\u3059\u3002<\/p>\n