我希望所有用户to cryptographically sign their contributions都能访问git存储库。提交,标记,合并,一切。
假设此过程存在缺陷,并且某人意外或故意设法将更改隐藏到尚未签名的存储库中。我怎样才能发现这种情况?
(另外,我如何正确指定"一切都必须签名"?我很惊讶地知道合并可以与提交分开签名。还有什么?)
答案 0 :(得分:1)
此人wrote a script将在存储库中找到未签名的提交。
#!/bin/sh
#
# Validate signatures on each and every commit within the given range
##
# if a ref is provided, append range spec to include all children
chkafter="${1+$1..}"
# note: bash users may instead use $'\t'; the echo statement below is a more
# portable option
t=$( echo '\t' )
# Check every commit after chkafter (or all commits if chkafter was not
# provided) for a trusted signature, listing invalid commits. %G? will output
# "G" if the signature is trusted.
git log --pretty="format:%H$t%aN$t%s$t%G?" "${chkafter:-HEAD}" \
| grep -v "${t}G$"
# grep will exit with a non-zero status if no matches are found, which we
# consider a success, so invert it
[ $? -gt 0 ]
答案 1 :(得分:0)
基于spraff's answer并基于对git log
格式选项的一些实验,我提出了以下用于查找无符号提交的脚本。在PATH
上将其作为名为git-unsigned
的文件安装,您可以将其作为git unsigned
或git-unsigned
调用:
#!/bin/bash
set -e
function main() {
if [ "$1" == "-h" -o "$1" == "--help" ]; then
echo "usage: git-unsigned [-h|--help] [options]" >&2
echo "Show long refs for all unsigned/unverified git commits in the current tree." >&2
echo " -h, --help Display this usage guide." >&2
echo " options Options to be passed to the invocation of git log." >&2
return 1
fi
git log --pretty='format:%H|%aN|%s|%G?' $@ | awk -F '|' '{ if($4 != "G"){print $1;} }'
}
if [[ ${BASH_SOURCE[0]} == $0 ]]; then
main $@
fi
在我的情况下,我发现一个提交,我不谨慎,并没有签署我的提交:
575274a81b63d231f20e524b65030d96682fc646
不幸的是,对此的解决方案基本上是修改提交并签名,这将重写Git历史记录,这很糟糕。
最好的办法是使用此工具作为审核工具,在这些提交中查看,并在检查提交时,git show 575274a81b63d231f20e524b65030d96682fc646
中找不到任何可疑内容。
我相信,虽然我不确定,如果有人要重写这个提交并强行推送它,那么其他提交的签名将被剥离或呈现无效,所以我认为我们仍然处于绿色环保之中,但我想找时间进行测试。