Skip to content

Commit d0aba52

Browse files
committed
Add new "govulncheck-with-excludes.sh" wrapper script
This allows us to exclude GO-2023-1840 (aka CVE-2023-29403) from our report since we already refuse to operate when users have enabled the `setuid` bit on the binary. Additionally, this updates our in-code check for `setuid` to also disallow `setgid`, but the impact of that configuration is lesser (so this is considered a best-effort pre-emptive mitigation -- hopefully the block on `setuid` has already discouraged users from using `gosu` in this way).
1 parent 4f8f387 commit d0aba52

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
- run: go install golang.org/x/vuln/cmd/[email protected]
3535
# (update "go-version" above when updating this version; https://github.com/golang/vuln/blob/v0.1.0/go.mod#L3)
3636

37-
- run: for gosu in gosu-*; do govulncheck -mode=binary "$gosu"; done
37+
- run: for gosu in gosu-*; do ./govulncheck-with-excludes.sh -mode=binary "$gosu"; done

Diff for: SECURITY.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
This project does not rebuild/release to "fix" CVEs which do not apply to actual builds of `gosu`. For example, this includes any CVE in Go which applies to interfaces that `gosu` does not ever invoke, such as `net/http`, `archive/tar`, `encoding/xml`, etc.
44

5-
Before reporting that `gosu` is "vulnerable" to a particular CVE, please run [`govulncheck`](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck) to determine whether the latest release is *actually* using the vulnerable functionality. See [this excellent blog post](https://go.dev/blog/vuln) from the Go team for more information about the `govulncheck` tool and the methodology by which it is maintained.
5+
Before reporting that `gosu` is "vulnerable" to a particular CVE, please run our [`./govulncheck-with-excludes.sh`](govulncheck-with-excludes.sh) wrapper around [`govulncheck`](https://pkg.go.dev/golang.org/x/vuln/cmd/govulncheck) to determine whether the latest release is *actually* using the vulnerable functionality. See [this excellent blog post](https://go.dev/blog/vuln) from the Go team for more information about the `govulncheck` tool and the methodology by which it is maintained.
66

77
If you have a tool which is reporting that `gosu` is vulnerable to a particular CVE but `govulncheck` does not agree, **please** report this as a false positive to your CVE scanning vendor so that they can improve their tooling. (If you wish to verify that your reported CVE is part of `govulncheck`'s dataset and thus covered by their tool, you can check [the vulndb repository](https://github.com/golang/vulndb) where they track those.)
88

9+
Our wrapper script ([`govulncheck-with-excludes.sh`](govulncheck-with-excludes.sh)) includes a very small set of vulnerabilities that will be reported by `govulncheck` which do not apply (due to other mitigations or otherwise).
10+
911
# Reporting Vulnerabilities
1012

1113
The surface area of `gosu` itself is really limited -- it only directly contains a small amount of Go code to instrument an interface that is part of [`runc`](https://github.com/opencontainers/runc) (and which itself is a pretty limited interface) for providing the same behavior as Docker's `--user` flag, but from within a running container.

Diff for: govulncheck-with-excludes.sh

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bash
2+
set -Eeuo pipefail
3+
4+
# a wrapper / replacement for "govulncheck" which allows for excluding vulnerabilities
5+
# (https://github.com/golang/go/issues/59507)
6+
7+
excludeVulns="$(jq -nc '[
8+
9+
# https://pkg.go.dev/vuln/GO-2023-1840
10+
# we already mitigate setuid in our code
11+
"GO-2023-1840", "CVE-2023-29403",
12+
# (https://github.com/tianon/gosu/issues/128#issuecomment-1607803883)
13+
14+
empty # trailing comma hack (makes diffs smaller)
15+
]')"
16+
export excludeVulns
17+
18+
if ! command -v govulncheck > /dev/null; then
19+
govulncheck() {
20+
local user; user="$(id -u):$(id -g)"
21+
local args=(
22+
--rm --interactive --init
23+
--user "$user"
24+
--env HOME=/tmp
25+
--env GOPATH=/tmp/go
26+
--volume govulncheck:/tmp
27+
--env CGO_ENABLED=0
28+
--mount "type=bind,src=$PWD,dst=/wd,ro"
29+
--workdir /wd
30+
"${GOLANG_IMAGE:-golang:latest}"
31+
sh -euc '
32+
go install golang.org/x/vuln/cmd/govulncheck@latest > /dev/null
33+
exec "$GOPATH/bin/govulncheck" "$@"
34+
' --
35+
)
36+
docker run "${args[@]}" "$@"
37+
}
38+
fi
39+
40+
if out="$(govulncheck "$@")"; then
41+
printf '%s\n' "$out"
42+
exit 0
43+
fi
44+
45+
json="$(govulncheck -json "$@")"
46+
47+
vulns="$(jq <<<"$json" -cs 'map(select(has("vulnerability")) | .vulnerability.osv)')"
48+
if [ "$(jq <<<"$vulns" -r 'length')" -le 0 ]; then
49+
printf '%s\n' "$out"
50+
exit 1
51+
fi
52+
53+
filtered="$(jq <<<"$vulns" -c '
54+
(env.excludeVulns | fromjson) as $exclude
55+
| map(select(
56+
.id as $id
57+
| $exclude | index($id) | not
58+
))
59+
')"
60+
61+
text="$(jq <<<"$filtered" -r 'map("- \(.id) (aka \(.aliases | join(", ")))\n\n\t\(.details | gsub("\n"; "\n\t"))") | join("\n\n")')"
62+
63+
if [ -z "$text" ]; then
64+
printf 'No vulnerabilities found.\n'
65+
exit 0
66+
else
67+
printf '%s\n' "$text"
68+
exit 1
69+
fi

Diff for: main.go

+3
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ func main() {
5353
} else if fi.Mode()&os.ModeSetuid != 0 {
5454
// ... oh no
5555
log.Fatalf("error: %q appears to be installed with the 'setuid' bit set, which is an *extremely* insecure and completely unsupported configuration! (what you want instead is likely 'sudo' or 'su')", os.Args[0])
56+
} else if fi.Mode()&os.ModeSetgid != 0 {
57+
// ... oh no
58+
log.Fatalf("error: %q appears to be installed with the 'setgid' bit set, which is not quite *as* insecure as 'setuid', but still not great, and definitely a completely unsupported configuration! (what you want instead is likely 'sudo' or 'su')", os.Args[0])
5659
}
5760
}
5861

0 commit comments

Comments
 (0)