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

Change build info date to commit timestamp #3876

Merged
merged 1 commit into from
Aug 17, 2022

Conversation

TripleDogDare
Copy link
Contributor

Which problem is this PR solving?

Binary Reproducibility
See https://reproducible-builds.org for more info on why this is important.

Short description of the changes

This change fixes binary reproducibility of builds. Injecting a
timestamp of the time-of-build produces unique binaries for every build
which is undesirable for security and provenance tracking. If timestamps
for builds are desired, it is recommended to inject the timestamp of the
commit. This gives a timestamp that is consistent for a build based on
that commit and allows checking for binary consistenty across build systems.

This change updates BuildDate to use the commit timestamp from git.
This change also fixes some builds which include the version package but
were not injecting BUILD_INFO.

Manual testing on main

(main) $ make build-all-in-one-linux 
GOOS=linux make build-all-in-one
make[1]: Entering directory '/home/cjb/repos/misc/jaeger'
CGO_ENABLED=0 installsuffix=cgo go build -trimpath  -tags ui -o ./cmd/all-in-one/all-in-one-linux-amd64 -ldflags "-X github.com/jaegertracing/jaeger/pkg/version.commitSHA=711a2b8f0aabca256a8b4e7d61d5395f74e6d848 -X github.com/jaegertracing/jaeger/pkg/version.latestVersion=v1.37.0 -X github.com/jaegertracing/jaeger/pkg/version.date=2022-08-16T22:07:29Z" ./cmd/all-in-one/main.go
make[1]: Leaving directory '/home/cjb/repos/misc/jaeger'
(main) $ sha256sum ./cmd/all-in-one/all-in-one-linux-amd64 
3e8e4038c8dc745b6d1753ef2b3232e8b0e452c9c33326972a4fd3fee2c1aef8  ./cmd/all-in-one/all-in-one-linux-amd64
(main) $ make build-all-in-one-linux 
GOOS=linux make build-all-in-one
make[1]: Entering directory '/home/cjb/repos/misc/jaeger'
CGO_ENABLED=0 installsuffix=cgo go build -trimpath  -tags ui -o ./cmd/all-in-one/all-in-one-linux-amd64 -ldflags "-X github.com/jaegertracing/jaeger/pkg/version.commitSHA=711a2b8f0aabca256a8b4e7d61d5395f74e6d848 -X github.com/jaegertracing/jaeger/pkg/version.latestVersion=v1.37.0 -X github.com/jaegertracing/jaeger/pkg/version.date=2022-08-16T22:07:47Z" ./cmd/all-in-one/main.go
make[1]: Leaving directory '/home/cjb/repos/misc/jaeger'
(main) $ sha256sum ./cmd/all-in-one/all-in-one-linux-amd64 
8444711d8c7deebf0af620086745c2a7f102b63945a03ee82c69caadc6aba931  ./cmd/all-in-one/all-in-one-linux-amd64

Manual testing on branch

(reproducible-date) $ make build-all-in-one-linux 
GOOS=linux make build-all-in-one
make[1]: Entering directory '/home/cjb/repos/misc/jaeger'
CGO_ENABLED=0 installsuffix=cgo go build -trimpath  -tags ui -o ./cmd/all-in-one/all-in-one-linux-amd64 -ldflags "-X github.com/jaegertracing/jaeger/pkg/version.commitSHA=a28c13cac4cf0202e3255ae47d577981f475e8a7 -X github.com/jaegertracing/jaeger/pkg/version.latestVersion=v1.37.0 -X github.com/jaegertracing/jaeger/pkg/version.date=2022-08-16T22:05:45Z" ./cmd/all-in-one/main.go
make[1]: Leaving directory '/home/cjb/repos/misc/jaeger'
(reproducible-date) $ sha256sum ./cmd/all-in-one/all-in-one-linux-amd64 | tee sha256.check
c68b48e2ec5e61e3c7674271c7b3a80cce6833e6a55b9daeedcde85fbcc810e7  ./cmd/all-in-one/all-in-one-linux-amd64
(reproducible-date) $ rm ./cmd/all-in-one/all-in-one-linux-amd64 
(reproducible-date) $ sha256sum -c sha256.check 
sha256sum: ./cmd/all-in-one/all-in-one-linux-amd64: No such file or directory
./cmd/all-in-one/all-in-one-linux-amd64: FAILED open or read
sha256sum: WARNING: 1 listed file could not be read
(reproducible-date) 1 $ make build-all-in-one-linux 
GOOS=linux make build-all-in-one
make[1]: Entering directory '/home/cjb/repos/misc/jaeger'
CGO_ENABLED=0 installsuffix=cgo go build -trimpath  -tags ui -o ./cmd/all-in-one/all-in-one-linux-amd64 -ldflags "-X github.com/jaegertracing/jaeger/pkg/version.commitSHA=a28c13cac4cf0202e3255ae47d577981f475e8a7 -X github.com/jaegertracing/jaeger/pkg/version.latestVersion=v1.37.0 -X github.com/jaegertracing/jaeger/pkg/version.date=2022-08-16T22:05:45Z" ./cmd/all-in-one/main.go
make[1]: Leaving directory '/home/cjb/repos/misc/jaeger'
(reproducible-date) $ sha256sum -c sha256.check 
./cmd/all-in-one/all-in-one-linux-amd64: OK

This change fixes binary reproducibility of builds. Injecting a
timestamp of the time-of-build produces unique binaries for every build
which is undesirable for security and provenance tracking. If timestamps
for builds are desired, it is recommended to inject the timestamp of the
commit. This gives a timestamp that is consistent for a build based on
that commit and allows checking for binary consistenty across build systems.

This change updates BuildDate to use the commit timestamp from git.
This change also fixes some builds which include the version package but
were not injecting BUILD_INFO.

Signed-off-by: Calvin Behling <[email protected]>
@TripleDogDare TripleDogDare requested a review from a team as a code owner August 16, 2022 22:21
Copy link
Member

@yurishkuro yurishkuro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a particular objection to this change, but it's worth noting that the binary output also depends on the version of Go compiler, which is not controlled by our setup, e.g. we define the compiler version as 1.18.x in GH actions.

And a related question. I see you verified the checksum. Should we be publishing it along with the binaries? I remember it came up before.

@@ -170,15 +170,15 @@ build-tracegen:

.PHONY: build-anonymizer
build-anonymizer:
$(GOBUILD) -o ./cmd/anonymizer/anonymizer-$(GOOS)-$(GOARCH) ./cmd/anonymizer/main.go
$(GOBUILD) -o ./cmd/anonymizer/anonymizer-$(GOOS)-$(GOARCH) $(BUILD_INFO) ./cmd/anonymizer/main.go
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe it's better to define GOBUILD to contain BUILD_INFO, to avoid this repetition

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've limited the scope to those that include `github.com/jaegertracing/jaeger/pkg/version. Including it in GOBUILD does seem like a reasonable improvement for consistency across the binaries but would force changes to the actual go code for some number of binaries.

@yurishkuro
Copy link
Member

Another possible issue is the UI assets are always generated with some unique number. Your test did not rebuild UI assets.

@yurishkuro yurishkuro enabled auto-merge (squash) August 16, 2022 23:26
@codecov
Copy link

codecov bot commented Aug 16, 2022

Codecov Report

Base: 97.64% // Head: 97.62% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (a28c13c) compared to base (711a2b8).
Patch has no changes to coverable lines.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3876      +/-   ##
==========================================
- Coverage   97.64%   97.62%   -0.02%     
==========================================
  Files         293      293              
  Lines       17064    17064              
==========================================
- Hits        16662    16659       -3     
- Misses        317      319       +2     
- Partials       85       86       +1     
Impacted Files Coverage Δ
cmd/query/app/static_handler.go 96.38% <0.00%> (-1.81%) ⬇️

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@TripleDogDare
Copy link
Contributor Author

Another possible issue is the UI assets are always generated with some unique number. Your test did not rebuild UI assets.

This is true and reproducibility should be fixed with regard to the UI builds as well. Testing the gzipped files in ./cmd/query/app/ui/actual does reveal that the resulting gzipped files are not reproducible. I made the assumption that these files were included via Docker and were not injected into the go binaries themselves but that may be incorrect. I think that might be out-of-scope for this PR and would be worth opening as separate issues. Ultimately need to verify that both the UI files and the file injection is reproducible.

@yurishkuro yurishkuro merged commit 20ff31e into jaegertracing:main Aug 17, 2022
@@ -42,7 +42,7 @@ IMPORT_LOG=.import.log

GIT_SHA=$(shell git rev-parse HEAD)
GIT_CLOSEST_TAG=$(shell git describe --abbrev=0 --tags)
DATE=$(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
DATE=$(shell date -u -d @$(shell git show -s --format=%ct) +'%Y-%m-%dT%H:%M:%SZ')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

date -d does not work on Mac. We can do this directly with git:

$ TZ=UTC0 git show --quiet --date='format-local:%Y-%m-%dT%H:%M:%SZ' --format="%cd" | cat
2022-10-28T15:18:09Z

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0f87027

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants