回溯签署git提交记录

6

最近的git版本(>=1.7.9)支持使用GPG为每个提交进行签名。

是否可以对树内的所有提交进行追加签名?


1
这回答解决了你的问题吗?有没有一种方式可以gpg签署所有以前的提交? - Michael Freidgeim
3个回答

4
git commit命令中--gpg-sign选项(也称为-S)生成的签名是用于生成标识提交的sha1哈希值的数据的一部分。因此,要对提交进行后期签名,需要更改已完成签名的每个提交的ID。
如果您真的想这样做,可能可以使用git filter-branch命令,但最好只是对新提交进行签名。由于所有祖先的提交ID都会影响任何新提交将要签名的数据,因此通过新签名的提交仍然可以使用gpg验证旧提交。

谢谢。所以:可能,但是具有破坏性。而签名标签已经提供了大部分优势。 - more tension

4
在一棵树中对所有提交进行追溯签名吗?
是的:添加一个标签,你会签名
实际上,这是在签署提交方面首选选项:通过标签签署所有设置,而不是单独签署每个提交。
请参见“如何在post-receive钩子中获取推送者信息?”。
请注意(2017年5月更新),只有Git 2.13.x/2.14(2017年第三季度)才能完全修复签名过程,因为“git cherry-pick”和其他使用序列机制的操作会处理一个尾随块,其最后一行是不完整的。
已经进行了修复,以便在完成现有不完整行之后添加其他的签名等内容。

参见提交44dc738(2017年4月26日),由Jonathan Tan(jhowtan进行修改。
(由Junio C Hamano -- gitster --提交6ebfa10中合并,2017年5月16日)

sequencer: 在添加页脚之前添加换行符

当遇到不以换行符结尾的提交信息时,顺序器在确定是否添加空白行之前不会完成该行。
这会导致"(cherry picked..."和签名行有时出现在提交消息的最后一行上
这种行为是由commit 967dfd4("sequencer:使用trailer的布局",2016-11-29)引入的。但是,撤消该提交不会完全解决此问题:在该提交之前,如果没有终止换行符,则has_conforming_footer()认为符合规范的页脚不符合规范,从而导致符合规范和不符合规范的页脚被视为相同,而它们不应该是。
通过在检查页脚是否符合规范之前始终向提交消息中添加换行符,以解决符合规范和不符合规范的页脚问题,并且在do_pick_commit()append_signoff()中都要这样做

在Git 2.29(2020年第四季度)中,这将更加可靠。

查看提交842385b, 提交9dad073, 提交26e28fe, 提交75d3bee, 提交20f4b04, 提交5b9427e, 提交8d2aa8d, 提交424e28f, 提交e885a84, 提交185e865(2020年9月30日)由Jeff King (peff)
(由Junio C Hamano -- gitster --合并于提交19dd352, 2020年10月5日)

序列生成器:在解析预告片时处理忽略页脚

签名:Jeff King

The append_signoff() function takes an "ignore_footer" argument, which specifies a number of bytes at the end of the message buffer which should not be considered (they cannot contain trailers, and the trailer is spliced in before them).

But to find the existing trailers, it calls into has_conforming_trailer(). That function takes an ignore_footer parameter, but since 967dfd4d56 ("sequencer: use trailer's trailer layout", 2016-11-02, Git v2.12.0-rc0 -- merge listed in batch #2) the parameter is completely ignored.

The trailer interface we're using takes a single string, with no option to tell it to use part of the string. However, since we have a mutable strbuf, we can work around this by simply overwriting (and later restoring) the boundary with a NUL.

I'm not sure if this can actually trigger a bug in practice. It's easy to get a non-zero ignore_footer by doing something like this:

git commit -F - --cleanup=verbatim <<-EOF
subject  

body  

Signed-off-by: me  

# this looks like a comment, but is actually in the
# message! That makes the earlier s-o-b fake.
EOF  

git commit --amend -s  

There git-commit calls ignore_non_trailer() to count up the "#" cruft, which becomes the ignore_footer header. But it works even without this patch! That's because the trailer code also calls ignore_non_trailer() and skips the cruft, too. So it happens to work because the only callers with a non-zero ignore_footer are using the exact same function that the trailer parser uses internally.

And that seems true for all of the current callers, but there's nothing guaranteeing it. We're better off only feeding the correct buffer to the trailer code in the first place.


谢谢。我已经使用签名标签有一段时间了。来自Linus的讨论帮助我将其放入上下文中。 - more tension
3
仅签署标签并不能保证其之前的所有提交的有效性。有些东西会被忽略掉。不要从Linus Torvalds那里获取安全提示。这个家伙绝对是个天才,别误会我的意思,但他在历史上一直是安全专家的头疼人物。 :) - DanielM
@DanielM - 对我来说,提交签名解决了什么问题还不清楚。我认为这是在寻找问题的解决方案。我相当确定这是对众所周知的***身份验证不是授权问题的诠释。但在Git的情况下,这个诠释是身份验证不是代码完整性***。 - jww
1
使用https解决了什么问题?这是一个几乎不费力的步骤(当您像我一样没有搞砸它的时候),它保证了作者就是作者,就像https证明服务器就是它自己所说的那个服务器一样。我曾经有过一个同事将提交标记为我编写。他出于最好的意图这样做,并在我面前进行了操作,而且我所有的实际提交都已签名,但这突显出人们可能会出于非善意目的而这样做。对于我正在设置的一个新项目,出于这个原因,我将让CI拒绝未签名的提交或未被识别的签名。 - DanielM

2

您可以尝试从想要开始签署提交的位置创建一个新分支。最近我就为一个在没有访问我的私钥的机器上创建的分支做了这个操作:

# git checkout -b new-branch <last-signed-commit>
# git cherry-pick <first-unsigned-commit>
# git checkout unsigned-branch
# git rebase new-branch

这需要您的Git配置自动签署您的提交,并且显然不应该有太多的合并提交,否则rebase会看起来很奇怪。如果有疑问,请挑选您的提交;每个挑选的提交都将被签署。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接