LoginSignup
0
0

More than 3 years have passed since last update.

【ダメ。ゼッタイ】脱法ブランチ名やプッシュ乱用を防いでgitを治安維持する

Posted at

運用規則やgitのベストプラクティスを知っててもmaster直修正しちゃいたい誘惑ってありますよね。ギリギリ踏みとどまっても今度はブランチ命名タスクが来て、次にコミット命名です。このgit運用を手抜きしたい誘惑は凄まじく、依存性もあり一度やってしまうと、もう元の生活には戻れず手抜きが横行します。

そこで、CodeCommitならばIAM絞ってとても柔軟にgit運用の統制を設定でき、社内のgit治安が良くなるという話をします。

Git Flow, Github Flowをベースに少し手を加えた以下の制約を導入したいとします。betaはカナリアリリース用の社内独自ブランチです

  • 作成できるブランチ名の制限。master, beta, feature/*, hotfixのみ。自分の名前のブランチ名とかダメ絶対。
  • master, betaは直コミット禁止し、プルリクのみが更新できる。
  • プルリクのマージはマージコミット残し必須。Fast-Fowardは不可

以下のポリシーをHogeCorporationGitFlowPolicyとでも命名して作成し、全開発者に適用するようアタッチします。元々のCodeCommitへの操作権限を有するユーザーを前提にしています。初めてStringNotLikeを使いました。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Deny",
      "Action": [
        "codecommit:*"
      ],
      "Resource": "*",
      "Condition": {
        "StringNotLike": {
          "codecommit:References": [
            "refs/heads/master",
            "refs/heads/beta",
            "refs/heads/feature/*",
            "refs/heads/hotfix"
          ]
        },
        "Null": {
          "codecommit:References": false
        }
      }
    },
    {
      "Effect": "Deny",
      "Action": [
        "codecommit:GitPush",
        "codecommit:DeleteBranch",
        "codecommit:PutFile",
        "codecommit:CreateCommit",
        "codecommit:MergeBranchesByFastForward",
        "codecommit:MergeBranchesBySquash",
        "codecommit:MergeBranchesByThreeWay",
        "codecommit:MergePullRequestByFastForward",
        "codecommit:MergePullRequestBySquash"
      ],
      "Resource": "*",
      "Condition": {
        "StringEqualsIfExists": {
          "codecommit:References": [
            "refs/heads/master",
            "refs/heads/beta"
          ]
        },
        "Null": {
          "codecommit:References": false
        }
      }
    }
  ]
}

もう少し拘って以下も設定したかったのですが、よく分かりませんでした。導入できたら記事更新します。 (教えて優しい人)

  • masterへのプルリクはfeature系から禁止して、betaかhotfixからのみ可
  • commit名にも命名規則としてprefix必須&ホワイトリスト作成
  • セルフマージ禁止(PRと承認の同一人物禁止)

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0