Skip to content

Commit

Permalink
Merge pull request #29 from terrastruct/fix-signature-check-with-ssh
Browse files Browse the repository at this point in the history
setup empty allowed signers to check ssh signature status
  • Loading branch information
gavin-ts authored Oct 12, 2023
2 parents 782b3f6 + 7a2914b commit 8a1fb2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.changed-files
.emptyAllowedSigners
14 changes: 13 additions & 1 deletion lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ ensure_signed() {
return
fi

# look for signature status N: no signature
setup_allowed_signers
# look for signature status N: no signature (verification done by github)
if [ ! "$(git log --format="%G?" ${GIT_BASE:+"$GIT_BASE..HEAD"} | grep "N")" ]; then
return
fi
Expand All @@ -344,6 +345,17 @@ ensure_signed() {
return 1
}

setup_allowed_signers() {
# we only care if a signature is present (github will verify) so we don't need any entries,
# but "gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verification"
if git config --get gpg.ssh.allowedSignersFile >/dev/null; then
return
fi
allowed_signers=".emptyAllowedSigners"
touch $allowed_signers
git config --local gpg.ssh.allowedSignersFile "$allowed_signers"
}

git_commit_count() {
# macOS sh is buggy and requires the subshell here.
(git rev-list HEAD --count 2>/dev/null) || echo 0
Expand Down
14 changes: 13 additions & 1 deletion lib/git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ ensure_signed() {
return
fi

# look for signature status N: no signature
setup_allowed_signers
# look for signature status N: no signature (verification done by github)
if [ ! "$(git log --format="%G?" ${GIT_BASE:+"$GIT_BASE..HEAD"} | grep "N")" ]; then
return
fi
Expand All @@ -186,6 +187,17 @@ ensure_signed() {
return 1
}

setup_allowed_signers() {
# we only care if a signature is present (github will verify) so we don't need any entries,
# but "gpg.ssh.allowedSignersFile needs to be configured and exist for ssh signature verification"
if git config --get gpg.ssh.allowedSignersFile >/dev/null; then
return
fi
allowed_signers=".emptyAllowedSigners"
touch $allowed_signers
git config --local gpg.ssh.allowedSignersFile "$allowed_signers"
}

git_commit_count() {
# macOS sh is buggy and requires the subshell here.
(git rev-list HEAD --count 2>/dev/null) || echo 0
Expand Down

0 comments on commit 8a1fb2d

Please sign in to comment.