Skip to content

Run gateway sessions with HOME at the per-host home - #20

Merged
czpython merged 2 commits into
mainfrom
gateway-home
Aug 26, 2026
Merged

Run gateway sessions with HOME at the per-host home#20
czpython merged 2 commits into
mainfrom
gateway-home

Conversation

@czpython

Copy link
Copy Markdown
Owner

Gateway callers treat the host name as a unix user: they mkdir /home/<host>, write a .gitconfig, credential helpers, and CLI credential files under it, then run commands that resolve config by $HOME. But a session ran as root with HOME=/root, so nothing they wrote was found — a git clone of a private repo died with could not read Username for https://github.com, because the credential helper in /home/<host>/.gitconfig was never read.

Change

Every session the gateway opens now runs with HOME=/home/<host-name>: an exec, an interactive shell, and the persistent shell behind SFTP. Each session makes that home, moves into it, and exports HOME before it runs. A command then finds $HOME, detached children (nohup, setsid) inherit it, and SFTP relative paths (realpath of .) resolve against it.

The setup happens once, where the sbx session shell is built (SbxExecProcess), so all three session kinds get it through the single open() path. The host name is server-generated, thus the home path is a safe shell token.

Verification

  • uv run ruff check / ruff format --check / pyright: clean; uv run pytest: 461 pass.
  • Unit tests over the fakes: a session command runs with the exported HOME; the SFTP backing shell resolves relative paths under it; the home is made before the first command.
  • Caller pattern end to end: write /home/<host>/.gitconfig over SFTP, then read it back through an exec session with sh -c 'cat $HOME/.gitconfig'.

A caller treats the host name as a unix user and writes a .gitconfig and
credential files under /home/<name>, but a session ran as root with
HOME=/root, so a command did not find them — a private git clone failed
because the configured credential helper was never read.

Every session the gateway opens — an exec, an interactive shell, and the
persistent shell behind SFTP — now makes /home/<name>, moves into it, and
exports HOME before it runs. A command finds $HOME, SFTP relative paths
resolve there, and detached children inherit it.
@czpython
czpython merged commit 4637f2e into main Aug 26, 2026
6 checks passed
@czpython
czpython deleted the gateway-home branch August 26, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant