Add support for git commit verification#3905
Conversation
zhming0
left a comment
There was a problem hiding this comment.
I see the value in this change, but I left some questions re overall directions and the cost / gain asymmetry. Also I recommend relocating some codes to another file.
|
Another thing we raised in the Agent Office hour is the big feature branch approach. We recommend targeting the main branch: 1. to derisk the big bang deployment. 2. V4 is happening in parallel, we worry that you would hit non-trivial conflicts if we hold a long running feature branch. Oz and Ben might be able to share a bit more context, they were on the meeting. What do you think? |
|
@zhming0 yeah I'm catching up on our internal thread about that topic. I was just following the example we were already using for this work, but since it sounds like folks would rather have us merge to main in discrete chunks, I'm fine with that. |
Description
Adds commit-on-branch verification to the checkout phase.
As part of our agent checkout improvement work, we are adding support for git commit verification. This addresses a potential security issue: if an attacker adds a malicious commit to the repo, and is then able to trigger a build which specifies
commit: 3v1l5ha123branch: mainwe would build that commit as if it were on themainbranch, without verifying that this is the case, which could potentially lead to a production deployment of malicious code.This change introduces a
BUILDKITE_GIT_COMMIT_VERIFICATIONenvironment variable, which defaults tofalse. If set totrue, when we are given a commit and branch, before checkout and build, we do the following:git merge-base --is-ancestorto check if the commit really belongs to the specified branch.unshallowand check again.In terms of alternatives, the only change I considered was just going straight to
unshallowbefore verifying any commit. But I didn't want users to have to completely give up shallow commits to get verification, so I went with the "deepen first, then unshallow if necessary" approach.Context
See SUP-6535.
Changes
Adds a
BUILDKITE_GIT_COMMIT_VERIFICATIONenv var to enable to functionality. When set, we perform various git operations in between fetch and checkout, to make sure the provided commit is valid on the provided branch.Testing
go test ./...). Buildkite employees may check this if the pipeline has run automatically.go tool gofumpt -extra -w .)Disclosures / Credits
I used Claude to help me plan the feature and teach me some Go fundamentals. I coded the core functionality myself, and let Claude write the tests.