Skip to content

Commit b3bd14e

Browse files
authored
Change default value for go telemetry from 'local' to 'off' (#34092)
This will set the default value for go telemetry to 'off' rather than 'local'. Go 1.23 introduced a telemetry feature that collects local audit data about the Go toolchain, storing it by default in $HOME/.config/go/telemetry. While this data is not sent externally by default, the local storage path can trigger security alerts in tools like Falco, as it writes to a sensitive location under /root. The behavior can be disabled with 'go telemetry off', which writes to the config file above, but that means the user needs to do so before calling 'go' in any other manner. Doing so for a container is non-obvious. We could build /root/.config/go/telemetry into a 'go' image, but that would still provide a problem for any user other than uid 0. There is no mechanism to change the behavior "system wide" or an environment variable that can set the value. See golang/go#68960 and golang/go#69113. The second one requests that env GOTELEMETRY=off would disable telemetry. That would be easy for us to utilize but it was rejected upstream. Instead, we just change the default value returned if there is no .config/go/telemetry file present.
1 parent dd744f6 commit b3bd14e

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

go-1.23.yaml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package:
22
name: go-1.23
33
version: 1.23.3
4-
epoch: 0
4+
epoch: 1
55
description: "the Go programming language"
66
copyright:
77
- license: BSD-3-Clause
@@ -38,7 +38,9 @@ pipeline:
3838

3939
- uses: patch
4040
with:
41-
patches: cmd-go-always-emit-ldflags-version-information.patch
41+
patches: |
42+
cmd-go-always-emit-ldflags-version-information.patch
43+
change-default-telemetry-from-local-to-off.patch
4244
4345
- runs: |
4446
cd src
@@ -146,3 +148,41 @@ test:
146148
147149
# Run the Go program with cgo and check the output
148150
go run hello_cgo.go | grep "Hello from cgo!"
151+
- name: Test telemetry settings
152+
runs: |
153+
fail() { echo "FAIL:" "$@" 1>&2; exit 1; }
154+
155+
tmpd=$(mktemp -d)
156+
trap "rm -R '$tmpd'" EXIT
157+
export HOME="$tmpd/home"
158+
mkdir "$HOME"
159+
160+
out=$(go telemetry) || fail "'go telemetry' exited $?"
161+
[ "$out" = "off" ] ||
162+
fail "go telemetry output '$out'. expected 'off'"
163+
164+
cfgdir="$HOME/.config/go/telemetry"
165+
if [ -d "$cfgdir" ]; then
166+
fail "$cfgdir was created by running 'go telemetry'"
167+
fi
168+
169+
go telemetry on ||
170+
fail "'go telemetry on' exited $?"
171+
out=$(go telemetry) || fail "'go telemetry' after 'on' exited $?"
172+
[ "$out" = "on" ] ||
173+
fail "go telemetry after 'on' output '$out'. expected 'on'"
174+
175+
[ -f "$cfgdir/mode" ] ||
176+
fail "ERROR: 'go telemetry on' did not write ~/${cfgdir#$HOME/}"
177+
178+
go telemetry local ||
179+
fail "'go telemetry local' exited $?"
180+
out=$(go telemetry) || fail "'go telemetry' after 'local' exited $?"
181+
[ "$out" = "local" ] ||
182+
fail "go telemetry after 'local' output '$out'. expected 'on'"
183+
184+
go telemetry off ||
185+
fail "explicit 'go telemetry off' exited $?"
186+
out=$(go telemetry) || fail "'go telemetry' after explicit off exited $?"
187+
[ "$out" = "off" ] ||
188+
fail "go telemetry after explicit off output '$out'. expected 'off'"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
From bccdae45d85882dc2fb2fafa80b8b2997f561fe3 Mon Sep 17 00:00:00 2001
2+
From: Scott Moser <[email protected]>
3+
Date: Wed, 13 Nov 2024 14:01:30 -0500
4+
Subject: [PATCH] Change default telemetry setting from 'local' to 'off'
5+
6+
Go 1.23 introduced a telemetry feature that collects local audit data
7+
about the Go toolchain, storing it by default in
8+
$HOME/.config/go/telemetry. While this data is not sent externally by
9+
default, the local storage path can trigger security alerts in tools
10+
like Falco, as it writes to a sensitive location under /root.
11+
12+
The behavior can be disabled with 'go telemetry off', which writes
13+
to the config file above, but that means the user needs to do so
14+
before calling 'go' in any other manner. Doing so for a container
15+
is non-obvious. We could build /root/.config/go/telemetry into
16+
a 'go' image, but that would still provide a problem for any user
17+
other than uid 0.
18+
19+
There is no mechanism to change the behavior "system wide" or an
20+
environment variable that can set the value.
21+
22+
See https://github.com/golang/go/issues/68960 and
23+
https://github.com/golang/go/issues/69113. The second one requests that
24+
env GOTELEMETRY=off would disable telemetry. That would be easy for us
25+
to utilize but it was rejected upstream.
26+
27+
Instead, we just change the default value returned if there is no
28+
.config/go/telemetry/mode file present.
29+
---
30+
src/cmd/vendor/golang.org/x/telemetry/internal/telemetry/dir.go | 2 +-
31+
1 file changed, 1 insertion(+), 1 deletion(-)
32+
33+
diff --git a/src/cmd/vendor/golang.org/x/telemetry/internal/telemetry/dir.go b/src/cmd/vendor/golang.org/x/telemetry/internal/telemetry/dir.go
34+
index dd7a63c816..cc4d08f651 100644
35+
--- a/src/cmd/vendor/golang.org/x/telemetry/internal/telemetry/dir.go
36+
+++ b/src/cmd/vendor/golang.org/x/telemetry/internal/telemetry/dir.go
37+
@@ -127,7 +127,7 @@ func (d Dir) Mode() (string, time.Time) {
38+
}
39+
data, err := os.ReadFile(d.modefile)
40+
if err != nil {
41+
- return "local", time.Time{} // default
42+
+ return "off", time.Time{} // default
43+
}
44+
mode := string(data)
45+
mode = strings.TrimSpace(mode)
46+
--
47+
2.43.0
48+

0 commit comments

Comments
 (0)