mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
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`.564b387262/provisionersdk/scripts/bootstrap_linux.sh (L60-L76)
This most likely triggers a change in securitybits which sets `_AT_SECURE` for the process.a1ddbdd3ef/src/runtime/os_linux.go (L297-L327)
Which in turn triggers secure mode:a1ddbdd3ef/src/runtime/security_unix.go
This should not affect workspaces as template authors can still set the environment on the agent resource. See https://pkg.go.dev/runtime#hdr-Security
77 lines
2.1 KiB
Go
77 lines
2.1 KiB
Go
package usershell
|
|
|
|
import (
|
|
"os"
|
|
"os/user"
|
|
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
// HomeDir returns the home directory of the current user, giving
|
|
// priority to the $HOME environment variable.
|
|
// Deprecated: use EnvInfoer.HomeDir() instead.
|
|
func HomeDir() (string, error) {
|
|
// First we check the environment.
|
|
homedir, err := os.UserHomeDir()
|
|
if err == nil {
|
|
return homedir, nil
|
|
}
|
|
|
|
// As a fallback, we try the user information.
|
|
u, err := user.Current()
|
|
if err != nil {
|
|
return "", xerrors.Errorf("current user: %w", err)
|
|
}
|
|
return u.HomeDir, nil
|
|
}
|
|
|
|
// EnvInfoer encapsulates external information about the environment.
|
|
type EnvInfoer interface {
|
|
// User returns the current user.
|
|
User() (*user.User, error)
|
|
// Environ returns the environment variables of the current process.
|
|
Environ() []string
|
|
// HomeDir returns the home directory of the current user.
|
|
HomeDir() (string, error)
|
|
// Shell returns the shell of the given user.
|
|
Shell(username string) (string, error)
|
|
// ModifyCommand modifies the command and arguments before execution based on
|
|
// the environment. This is useful for executing a command inside a container.
|
|
// In the default case, the command and arguments are returned unchanged.
|
|
ModifyCommand(name string, args ...string) (string, []string)
|
|
}
|
|
|
|
// SystemEnvInfo encapsulates the information about the environment
|
|
// just using the default Go implementations.
|
|
type SystemEnvInfo struct{}
|
|
|
|
func (SystemEnvInfo) User() (*user.User, error) {
|
|
return user.Current()
|
|
}
|
|
|
|
func (SystemEnvInfo) Environ() []string {
|
|
var env []string
|
|
for _, e := range os.Environ() {
|
|
// 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" {
|
|
continue
|
|
}
|
|
env = append(env, e)
|
|
}
|
|
return env
|
|
}
|
|
|
|
func (SystemEnvInfo) HomeDir() (string, error) {
|
|
return HomeDir()
|
|
}
|
|
|
|
func (SystemEnvInfo) Shell(username string) (string, error) {
|
|
return Get(username)
|
|
}
|
|
|
|
func (SystemEnvInfo) ModifyCommand(name string, args ...string) (string, []string) {
|
|
return name, args
|
|
}
|