Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zero out the build id for reproducible builds #89136

Merged

Conversation

dims
Copy link
Member

@dims dims commented Mar 16, 2020

We have been having issues with making builds reproducible, especially
with the .note.go.buildid ELF section. One tip from a golang issue was
to set -ldflags=-buildid= which seems to work well. You can confirm
that the buildid is set to empty by inspecting the binaries with the go
command example go tool buildid _output/local/go/bin/kubectl

Signed-off-by: Davanum Srinivas davanum@gmail.com

What type of PR is this?
/kind bug

What this PR does / why we need it:
Tip is from here : golang/go#34186 (comment)
Struggles with reproducible builds are documented here : #70131
Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

NONE

We have been having issues with making builds reproducible, especially
with the `.note.go.buildid` ELF section. One tip from a golang issue was
to set `-ldflags=-buildid=` which seems to work well. You can confirm
that the buildid is set to empty by inspecting the binaries with the go
command example `go tool buildid _output/local/go/bin/kubectl`

Signed-off-by: Davanum Srinivas <davanum@gmail.com>
@k8s-ci-robot k8s-ci-robot added kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 16, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dims

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 16, 2020
@dims
Copy link
Member Author

dims commented Mar 16, 2020

/priority important-soon
/sig release

cc @bmwiedemann Bernhard, can you please try this?

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. sig/release Categorizes an issue or PR as relevant to SIG Release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Mar 16, 2020
@dims
Copy link
Member Author

dims commented Mar 16, 2020

/assign @cblecker @BenTheElder

@cblecker
Copy link
Member

Seems reasonable to me.

/cc @justaugustus

@BenTheElder
Copy link
Member

is it reproducible after this?
is there a pointer to how this value is normally used?

@BenTheElder
Copy link
Member

starting points:

The Build ID is a hash of the filenames of the compiled files, plus the version of the compiler (and other things in zversion.go, like the default GOROOT). See pkg.go.

Here we can see more about how it is used, in short it appears to be part of how go identifies if a binary is up to date for caching purposes.
https://github.com/golang/go/blob/26154f31ad6c801d8bad5ef58df1e9263c6beec7/src/cmd/go/internal/work/buildid.go#L41

It seems like we may only want to set this to zero when we produce release binaries, otherwise we may be unnecessarily defeating the cache. Some of the binaries we build probably don't need to be reproducible anyhow (code generators? linters?).

@dims
Copy link
Member Author

dims commented Mar 16, 2020

@BenTheElder if you see the issue, we are chipping away at the reproducibility bit by bit. please see latest runs from @bmwiedemann here:
https://rb.zq1.de/compare.factory-20200303/kubernetes-compare.out

There's a few more things to take care of after that:

$ rg 'differs in' kubernetes-compare.out | grep -v buildid
/usr/bin/kube-apiserver differs in ELF section .typelink
/usr/bin/kube-controller-manager differs in ELF section .typelink
/usr/src/kubernetes/hack/../platforms/linux/amd64/e2e.test differs in ELF section .gopclntab
/usr/src/kubernetes/platforms/linux/amd64/e2e.test differs in ELF section .gopclntab
/usr/bin/kube-apiserver differs in ELF section .typelink
/usr/bin/kube-controller-manager differs in ELF section .typelink

Also note that -s -w strips out debugging information which we added a few releases ago!

@dims
Copy link
Member Author

dims commented Mar 16, 2020

/retest

@BenTheElder
Copy link
Member

cc @Katharine FYI WRT caching
I'm OK to do this, but I suspect stripping the cache key may bite us later.

I would suggest that reproducible builds be performed in a container (e.g. like our official releases...) which should ensure fixed paths. KIND has had reproducible release artifacts for some time by simply doing this...

@dims
Copy link
Member Author

dims commented Mar 18, 2020

@Katharine will you have some time to dig into this? i'd like to get this in early to see if this breaks something ..

@BenTheElder
Copy link
Member

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Mar 19, 2020
@k8s-ci-robot k8s-ci-robot merged commit 80d5622 into kubernetes:master Mar 19, 2020
@k8s-ci-robot k8s-ci-robot added this to the v1.19 milestone Mar 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note-none Denotes a PR that doesn't merit a release note. sig/release Categorizes an issue or PR as relevant to SIG Release. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants