fix(agent): unify working directory resolution (#26102)

agentssh's CommandEnv, sftpHandler, and agentproc each resolved the
session working directory on their own and had drifted: sftpHandler used
the configured directory without checking it exists and bypassed the
injected EnvInfoer, while the others stat-checked and fell back to home.
Home and shell lookups could also skip the EnvInfoer seam through the
exported usershell.HomeDir and Get.

Resolve through a single usershell.ResolveWorkingDirectory and confine
host home and shell lookups to usershell, so SSH sessions, the process
API, and tests can no longer diverge and the injected environment is
always honored. This also fixes SFTP landing in a configured directory
that no longer exists.

Refs coder/coder#26099
This commit is contained in:
Mathias Fredriksson
2026-06-08 14:24:32 +03:00
committed by GitHub
parent 1e5dd83a95
commit 3955df796e
11 changed files with 231 additions and 116 deletions
+4 -3
View File
@@ -9,9 +9,10 @@ import (
"golang.org/x/xerrors"
)
// Get returns the $SHELL environment variable.
// Deprecated: use SystemEnvInfo.UserShell instead.
func Get(username string) (string, error) {
// get resolves the user's shell via dscl, falling back to $SHELL. It
// backs SystemEnvInfo.Shell. Callers resolve the shell through an
// EnvInfoer.
func get(username string) (string, error) {
// This command will output "UserShell: /bin/zsh" if successful, we
// can ignore the error since we have fallback behavior.
if !filepath.IsLocal(username) {