Skip to content

fix(agent): filter out GOTRACEBACK=none #16924

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

Merged
merged 2 commits into from
Mar 17, 2025

Conversation

mafredri
Copy link
Member

With the switch to Go 1.24.1, our dogfood workspaces started setting
GOTRACEBACK=none in the environment, resulting in missing stacktraces
for users.

This is due to the capability changes we do when
USE_CAP_NET_ADMIN=true.

# If running as root, we do not need to do anything.
if [ "$(id -u)" -eq 0 ]; then
echo "Running as root, skipping setcap"
# Warn the user if root does not have CAP_NET_ADMIN.
if ! capsh --has-p=CAP_NET_ADMIN; then
printnetadminmissing
fi
# If not running as root, make sure we have sudo perms and the "setcap" +
# "capsh" binaries exist.
elif sudo -nl && haslibcap2; then
# Make sure the root user has CAP_NET_ADMIN.
if sudo -n capsh --has-p=CAP_NET_ADMIN; then
sudo -n setcap CAP_NET_ADMIN=+ep ./$BINARY_NAME || true
else
printnetadminmissing
fi

This most likely triggers a change in securitybits which sets
_AT_SECURE for the process.

https://github.com/golang/go/blob/a1ddbdd3ef8b739aab53f20d6ed0a61c3474cf12/src/runtime/os_linux.go#L297-L327

Which in turn triggers secure mode:

https://github.com/golang/go/blob/a1ddbdd3ef8b739aab53f20d6ed0a61c3474cf12/src/runtime/security_unix.go

A better fix may be to read /proc/self/environ to figure out if this
was set by the runtime or manually, but I'm not sure we should care
about that. A template author can still set the environment on the agent
resource.

See https://pkg.go.dev/runtime#hdr-Security

With the switch to Go 1.24.1, our dogfood workspaces started setting
`GOTRACEBACK=none` in the environment, resulting in missing stacktraces
for users.

This is due to the capability changes we do when
`USE_CAP_NET_ADMIN=true`.

https://github.com/coder/coder/blob/564b387262e5b768c503e5317242d9ab576395d6/provisionersdk/scripts/bootstrap_linux.sh#L60-L76

This most likely triggers a change in securitybits which sets
`_AT_SECURE` for the process.

https://github.com/golang/go/blob/a1ddbdd3ef8b739aab53f20d6ed0a61c3474cf12/src/runtime/os_linux.go#L297-L327

Which in turn triggers secure mode:

https://github.com/golang/go/blob/a1ddbdd3ef8b739aab53f20d6ed0a61c3474cf12/src/runtime/security_unix.go

A better fix may be to read `/proc/self/environ` to figure out if this
was set by the runtime or manually, but I'm not sure we should care
about that. A template author can still set the environment on the agent
resource.

See https://pkg.go.dev/runtime#hdr-Security
// Ignore GOTRACEBACK=none, as it disables stack traces, it can
// be set on the agent due to changes in capabilities.
// https://pkg.go.dev/runtime#hdr-Security.
if e == "GOTRACEBACK=none" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there any way for us to override this for ourselves that doesn't also override it for any user of coder? Seems like we're choosing for any user of coder that GOTRACEBACK shouldn't be set.

Copy link
Member Author

Choose a reason for hiding this comment

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

On Linux, we could theoretically read /proc/self/environ to figure out if it was set externally or by the Go runtime. I'm not sure it's worth the lift though.

If someone sets this env in, say, a docker container resource. Yes, it will be filtered out for child-processes (which arguably may be the right thing to do anyway). But if someone sets it on the agent resource (which is the recommended way anyway), they absolutely still can.

@mafredri mafredri merged commit df92df4 into main Mar 17, 2025
30 checks passed
@mafredri mafredri deleted the mafredri/fix-agent-go1241-gotraceback-none branch March 17, 2025 09:10
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants