-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathreproducible-builds.slide
108 lines (60 loc) · 1.75 KB
/
reproducible-builds.slide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
Reproducible builds
with Go
12 Sep 2019
Mechiel Lukkien
* What are ...?
- Get the exact same result every time you build.
* Example
$ go build
$ sha256sum helloworld
1bbb17feca46049e90fd70299206e37d876678e49931c7b230ce0e35c2a70f2b helloworld
* Why?
- Verify code with binary.
* Why not in practice?
- Dependencies
- Timestamps
- Deterministic compiler
* In Go
- Possible
- Even easy
- But caveats apply
* Caveats
1. Paths in binary
2. BuildID in binary
3. cgo
* 1. Paths
- Location of build
* 1. Paths - for panic
$ ./helloworld
panic: runtime error: index out of range [1] with length 1
goroutine 1 [running]:
main.main()
/home/mjl/code/helloworld/helloworld.go:9 +0xcf
* 1. Paths - trimpath
$ go build -trimpath
* 1. Paths - trimpath - panic
$ ./howdy
panic: runtime error: index out of range [1] with length 1
goroutine 1 [running]:
main.main()
helloworld@/helloworld.go:9 +0xcf
Go modules must be enabled!
* 2. BuildID
$ go tool buildid helloworld
1Qzp3aRnz2D15nAT1XFy/h1jHto7rUs3hlceGgY2y/AV80yuYo1Qk0IuR_IlMg/A-NJGGhsJxCbXjWv9w-P
* 2. BuildID - clear it
$ z=00000000000000000000
$ go build -ldflags -buildid=$z/$z/$z/$z
* 3. cgo
- Possible
- Host OS toolchain
- Cross compilation
* Conclusion
Give it a try!
$ z=00000000000000000000
$ CGO_ENABLED=0 go build -trimpath -ldflags -buildid=$z/$z/$z/$z
* More
- buildid: https://github.com/golang/go/blob/master/src/cmd/go/internal/work/buildid.go#L23
- reproducible builds: https://reproducible-builds.org/
- adventure with go: https://blog.filippo.io/reproducing-go-binaries-byte-by-byte/
- serve reproducibly built binaries: https://github.com/mjl-/gobuild