Run gateway sessions with HOME at the per-host home - #20
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withHOME=/root, so nothing they wrote was found — agit cloneof a private repo died withcould not read Username for https://github.com, because the credential helper in/home/<host>/.gitconfigwas 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 exportsHOMEbefore it runs. A command then finds$HOME, detached children (nohup,setsid) inherit it, and SFTP relative paths (realpathof.) resolve against it.The setup happens once, where the sbx session shell is built (
SbxExecProcess), so all three session kinds get it through the singleopen()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.HOME; the SFTP backing shell resolves relative paths under it; the home is made before the first command./home/<host>/.gitconfigover SFTP, then read it back through an exec session withsh -c 'cat $HOME/.gitconfig'.