Upgrade to Pro — share decks privately, control downloads, hide ads and more …

ニフティ開発インターンで使うAWS環境をできるだけ楽に構築した話 (LT) - NIFTY Tech Day 2023

ニフティ開発インターンで使うAWS環境をできるだけ楽に構築した話 (LT) - NIFTY Tech Day 2023

ニフティ株式会社

November 29, 2023
Tweet

Video


Resources

NIFTY Tech Day 2023

https://techday.nifty.co.jp/2023/

More Decks by ニフティ株式会社

Other Decks in Programming

Transcript

  1. コンソールログイン用のパスワード払い出し aws_iam_user_login_profile resource "aws_iam_user" "example" { name = "example" path

    = "/" for ce_destroy = true } resource "aws_iam_user_login_profile" "example" { user = aws_iam_user.example.name pgp_key = "keybase:some_person_that_exists" } IAMユーザー作成 コンソールログイン 用のパスワード払い 出し
  2. .encrypted_passwordで 生成したパスワードを参照可能 aws_iam_user_login_profile resource "aws_iam_user_login_profile" "example" { user = aws_iam_user.example.name

    pgp_key = "keybase:some_person_that_exists" } パスワード払い出し (暗号化キーも指定) output "password" { value = aws_iam_user_login_profile.example.encrypted_password } 暗号化されたパスワード を参照可能
  3. Gitクライアント用の認証情報の払い出し aws_iam_service_specific_credential resource "aws_iam_service_specific_credenBal" "example" { service_name = "codecommit.amazonaws.com" user_name

    = aws_iam_user.example.name } output "codecommit_user_name" { value = aws_iam_service_specific_credential.example.service_user_name } output "codecommit_password" { value = aws_iam_service_specific_credential.example.service_user_password } Git用認証情報 Git認証用の ID/パスワード
  4. IAMユーザーのアクセス可能時間制御 • IAMポリシーにConditionがあ る • Conditionに時間制限をかけら れる { "Version": "2012-10-17",

    "Statement": [ { "Sid": "VisualEditor0", "Effect": "Allow", "Action": [ "*" ], "Resource": "*", "Condition": { "DateGreaterThan": { "aws:CurrentTime": "${start}" }, "DateLessThan": { "aws:CurrentTime": "${end}" } } } ] }
  5. IAMユーザーのアクセス可能時間制御 { "Version": "2012-10-17", "Statement": [ { "Sid": "VisualEditor0", "Effect":

    "Allow", "AcKon": [ "codecommit:GitPush" ], "Resource": "arn:aws:codecommit:us-east-2:111111111111:MyDemoRepo", "CondiKon": { "DateGreaterThan": { "aws:CurrentTime": "2024-09-21T09:00:00+09:00" }, "DateLessThan": { "aws:CurrentTime": "2024-09-21T17:00:00+09:00" } } } ] } 学生が使うIAMユーザーは 9/21の9:00-17:00で MyDemoRepoに pushのみ 可能
  6. AWS CodeCommitのmasterに直push禁止 masterに対してpush禁止を 示すIAMポリシーを作成 →ユーザーにアサインすれば、 そのユーザーはpushできない { "Version": "2012-10-17", "Statement":

    [ { "Effect": "Deny", "AcKon": ["codecommit:GitPush"], "Resource": "*", "CondiKon": { "StringEqualsIfExists": { "codecommit:References": ["refs/heads/master"] }, "Null": { "codecommit:References": false } } } ] } https://docs.aws.amazon.com/ja_jp/service-authorization/latest/reference/list_awscodecommit.html
  7. Terraformで承認ルールテンプレートを作る時 ハマりポイント resource "aws_codecommit_approval_rule_template" "approval_rule" { name = "approval-rule" description

    = "承認テンプレート" content = <<EOF { "Version": "2018-11-08", "DestinationReferences": ["refs/heads/master", "refs/heads/main"], "Statements": [{ "Type": "Approvers", "NumberOfApprovalsNeeded": 1, "ApprovalPoolMembers": ["CodeCommitApprovers:Administrator/*"] }] } EOF } CodeCommitApprovers:がprefixに必要 × Administrator/*
  8. 紹介したこと • 学生に払い出すIAMユーザーの認証情報をぽちぽちせずに払い出し たい • 指定時間以外は学生がAWS CodeCommitにアクセスできないように したい • AWS

    CodeCommitのmasterブランチに直pushできないようにしたい • AWS CodeCommitでPRは必ず社員の承認を得てからマージできるよ うにしたい