一致的构建/从二进制文件中删除个人信息

huangapple go评论86阅读模式
英文:

Consistent builds / remove personal information from binaries

问题

我现在意识到,Go语言在二进制文件中保存源代码的绝对路径,以便打印堆栈跟踪等信息。我不想完全删除这些信息,但这也意味着每个构建相同程序的开发者将生成具有不同校验和的可执行文件。在尝试使用chroot或类似方法重新实现构建之前,有没有办法告诉Go不要使用绝对路径来实现这个目的呢?

英文:

I've now realized that Go saves absolute paths to source code in binaries for the purpose of printing stack-traces and the likes. I don't want to completely remove this information, however, this also means that every developer building the same program will produce an executable with a different checksum. Before I try to reimplement the build using chroot or something like that: isn't there any way to tell Go not to use absolute paths for this purpose?

答案1

得分: 1

我知道这并不直接回答你的问题,但是@JimB的建议确实指出了一类解决你所遇到问题的方法。

其中一个比较简单的方法(我认为)是让你的开发人员安装Docker并创建一个别名,这样go命令就可以运行了:

docker run --rm --tty --volume $GOPATH:/go golang:1.7.1(-$YOUR_PLATFORM) go

然后,每次构建(以及测试和运行)都会认为它正在使用/go作为GOPATH,这样你的开发人员的校验和就不会因此而产生冲突。

更多信息请参见这里

英文:

I know it doesn't directly address what you asked, but @JimB's suggestion does indicate a class of solutions to the problem you seem to be having.

One of the easier ones (I think) would be to have your developers install Docker and create an alias so that the go command runs:

docker run --rm --tty --volume $GOPATH:/go golang:1.7.1(-$YOUR_PLATFORM) go

Then, every build (and test and run) thinks it's using a GOPATH of /go and your developers' checksums won't disagree based on that.

See here for more info.

答案2

得分: 0

现在有一种方法可以告诉Go不要为此目的使用绝对路径:-trimpath

https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies 解释了如下内容:

-trimpath

从生成的可执行文件中删除所有文件系统路径。
记录的文件名将以模块路径@版本(使用模块时)或纯粹的导入路径(使用标准库或GOPATH时)开头,而不是绝对文件系统路径。

英文:

> isn't there any way to tell Go not to use absolute paths for this purpose?

Nowadays there is: -trimpath.

https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies explains:

> -trimpath

> remove all file system paths from the resulting executable.
Instead of absolute file system paths, the recorded file names
will begin either a module path@version (when using modules),
or a plain import path (when using the standard library, or GOPATH).

huangapple
  • 本文由 发表于 2016年9月25日 20:37:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/39686900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定