-
Notifications
You must be signed in to change notification settings - Fork 0
Publish release binaries govulncheck can assess #37
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
Open
ai-collaboration-app
wants to merge
5
commits into
main
Choose a base branch
from
cve-assessable-release-binaries
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
854ee07
Keep the symbol table in released binaries
stackstate-ci 71885d9
Gate the release on binaries govulncheck can assess
stackstate-ci 102981f
Bump golang.org/x/crypto to v0.55.0
stackstate-ci 99f8457
Assert the symbol table directly instead of via govulncheck
stackstate-ci 8ff3aef
Merge the x/crypto v0.55.0 bump
stackstate-ci File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Negative control for assert-go-symbols.sh: proves the guard rejects a stripped | ||
| # binary for the absence of symbols alone, on a fixture no advisory matches, so | ||
| # the result cannot come from the vulnerability database. | ||
| # | ||
| # Every target in .goreleaser.yml is covered because the two platform families | ||
| # fail differently: stripping leaves an ELF or PE file with no symbol section at | ||
| # all, while a stripped Mach-O still yields a readable table that `runtime.main` | ||
| # is missing from. A guard that only checked whether `go tool nm` succeeded would | ||
| # pass both darwin artifacts. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| guard="${script_dir}/assert-go-symbols.sh" | ||
| fixture_dir="${script_dir}/testdata/assessable-fixture" | ||
| targets=(darwin/amd64 darwin/arm64 linux/amd64 linux/arm64 windows/amd64) | ||
|
|
||
| work="$(mktemp -d)" | ||
| trap 'rm -rf "${work}"' EXIT | ||
|
|
||
| export CGO_ENABLED=0 | ||
| failures=0 | ||
|
|
||
| for target in "${targets[@]}"; do | ||
| goos="${target%/*}" | ||
| goarch="${target#*/}" | ||
| suffix="" | ||
| [[ "${goos}" == "windows" ]] && suffix=".exe" | ||
|
|
||
| kept="${work}/${goos}-${goarch}-kept${suffix}" | ||
| stripped="${work}/${goos}-${goarch}-stripped${suffix}" | ||
| (cd "${fixture_dir}" && GOOS="${goos}" GOARCH="${goarch}" go build -ldflags '-w' -o "${kept}" main.go) | ||
| (cd "${fixture_dir}" && GOOS="${goos}" GOARCH="${goarch}" go build -ldflags '-s -w' -o "${stripped}" main.go) | ||
|
|
||
| if "${guard}" "${kept}" >/dev/null; then | ||
| echo "PASS ${target}: built with -w only, accepted" | ||
| else | ||
| echo "FAIL ${target}: built with -w only, should have been accepted" >&2 | ||
| failures=1 | ||
| fi | ||
|
|
||
| if "${guard}" "${stripped}" >/dev/null 2>&1; then | ||
| echo "FAIL ${target}: built with -s -w, should have been rejected" >&2 | ||
| failures=1 | ||
| else | ||
| echo "PASS ${target}: built with -s -w, rejected" | ||
| fi | ||
| done | ||
|
|
||
| exit "${failures}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Binary-mode govulncheck can only tell which packages a binary links while its | ||
| # Go symbol table is present; without one it conservatively assumes every package | ||
| # named in an advisory is linked. A stripped binary therefore still exits | ||
| # non-zero today only because an advisory happens to match one of its modules, | ||
| # which is a property of the current vulnerability database rather than of the | ||
| # artifact — so assessability is asserted here instead of inferred from | ||
| # govulncheck's exit status. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| # Linked into every Go binary regardless of platform or build tags, so its | ||
| # absence means the symbol table was stripped rather than that the program | ||
| # differs. | ||
| required_symbol='runtime.main' | ||
|
|
||
| if [[ "$#" -eq 0 ]]; then | ||
| echo "usage: $0 <binary>..." >&2 | ||
| exit 2 | ||
| fi | ||
|
|
||
| status=0 | ||
| for binary in "$@"; do | ||
| if ! symbols="$(go tool nm "${binary}" 2>&1)"; then | ||
| echo "FAIL ${binary}: no readable Go symbol table -- ${symbols%%$'\n'*}" >&2 | ||
| status=1 | ||
| continue | ||
| fi | ||
| if ! grep -q "[[:space:]]${required_symbol}\$" <<<"${symbols}"; then | ||
| echo "FAIL ${binary}: symbol table has no ${required_symbol}" >&2 | ||
| status=1 | ||
| continue | ||
| fi | ||
| echo "OK ${binary}: Go symbol table is usable" | ||
| done | ||
|
|
||
| exit "${status}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| # Binary-mode govulncheck can only judge which packages are linked while the | ||
| # release binaries keep their symbol table, so stripping it again (`-s` in the | ||
| # GoReleaser ldflags) makes this fail instead of publishing artifacts whose | ||
| # reachability nobody can assess. The symbol table is asserted separately rather | ||
| # than inferred from govulncheck's exit status, which would only catch a stripped | ||
| # binary while some advisory still matched one of its modules. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| rootfs_dir="${1:-artifact-scan/rootfs}" | ||
| govulncheck_version="${GOVULNCHECK_VERSION:-v1.6.0}" | ||
| expected_binaries=5 | ||
| binaries=() | ||
|
|
||
| while IFS= read -r binary; do | ||
| binaries+=("${binary}") | ||
| done < <(find "${rootfs_dir}" -type f \( -name sts-backup -o -name sts-backup.exe \) -print | sort) | ||
|
|
||
| if [[ "${#binaries[@]}" -ne "${expected_binaries}" ]]; then | ||
| echo "Expected ${expected_binaries} release binaries under '${rootfs_dir}', found ${#binaries[@]}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| "${script_dir}/assert-go-symbols.sh" "${binaries[@]}" | ||
|
|
||
| status=0 | ||
| for binary in "${binaries[@]}"; do | ||
| echo "== ${binary}" | ||
| if ! go run "golang.org/x/vuln/cmd/govulncheck@${govulncheck_version}" -mode=binary "${binary}"; then | ||
| status=1 | ||
| fi | ||
| done | ||
|
|
||
| exit "${status}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Command assessable-fixture is the smallest Go binary the assessability guard | ||
| // can be tested against, so the test does not pay for a full CLI cross-build. | ||
| package main | ||
|
|
||
| func main() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.