A review of the recent fixes found three gaps, and an e2e cascade.
- hostgit: protocol.allow=never is only the default for protocols with no
key of their own, so a repo's protocol.ext.allow=always and a url
insteadOf for the VM's URL made a --clone VM's seed push and rm's fetch
run a command the repo named on the host. Host git now runs with
GIT_ALLOW_PROTOCOL=ssh, which git takes over every protocol setting.
TestCommandSSHOnly (failed on the old code).
- git-protect: checkGit set a mode saved while the VM ran before it
checked .git, so a .git the VM replaced meanwhile became the baseline
without git_replaced. It checks under the mode the VM ran with first,
then sets the new one. git_protect.txtar's replaced-.git step (failed
on the old code).
- retention: its lock was a folder taken over after 10 minutes, so a
long retention run could be joined by a second devvm and a crash left
it held. It's platform.TryLockFile on retention.lock now, and
retainLockAge is gone. TestRetainDueAndLock checks an hour-old held
lock isn't taken over.
- e2e: when the group join's helper server didn't start, gp_refused ran
devvm network on for a VM outside the group, which turned its policy
on, so six later group and link checks failed too. gp_refused now
checks the VM is a member first, and lk_start says which server didn't
start.
Docs: internals/git-protection (GIT_ALLOW_PROTOCOL, the check's order),
using/space (retention.lock).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
devvm ran git on the host bare: --clone's git status could run a repo's
core.fsmonitor or filters, its push, fetch, update-ref and remote remove
the repo's hooks, and git could ask on devvm's terminal or follow
GIT_DIR from devvm's environment. internal/hostgit is now the one runner
(Command, Output, Status), with its settings as GIT_CONFIG_COUNT pairs:
core.fsmonitor=false, core.hooksPath=/dev/null,
core.alternateRefsCommand=true, hook.EVENT.enabled=false for every
githooks(5) event, protocol.allow=never with protocol.ssh.allow=always;
and, for a command with -C DIR, hook.NAME.enabled=false and
filter.NAME's clean/smudge/process emptied with required=false for
each hook and filter driver DIR's config names. It drops every GIT_*
variable and relative PATH folders, and sets GIT_TERMINAL_PROMPT=0,
GIT_NO_LAZY_FETCH=1 (a repo that says it's a partial clone fetches
nothing, with its core.sshCommand or ssh), GIT_SSH_COMMAND=false (no ssh
but gitSSH's) and GIT_SSH_VARIANT=ssh; maintenance.auto=false and
gc.auto=0. Status adds --no-optional-locks and --ignore-submodules=all.
Callers: gitprotect (git, ignoreSubmodules), project.SSHRemote, vm/sync's
gitConfig, vm/clone (hostGit, gitSSH, saveFetched, the uncommitted-changes
status). gitSSH takes the VM: ssh with BatchMode, StrictHostKeyChecking,
devvm's known hosts only, HostKeyAlias=VM, ForwardAgent=no and
ClearAllForwardings=yes, so a url.*.insteadOf reaches only the VM with
its pinned key. The seed push adds --no-verify, --no-recurse-submodules
and --no-signed; rm's fetch --no-recurse-submodules.
Not neutralized: an include.path can make gitConfig read
user.name/email from another git-config file (sent to the VM as its
identity), and a FIFO as a config file hangs git until Ctrl+C; neither
runs code. A VM swapping the repo's config between repoOff's listing and the command
could hide a filter from it, and a --clone VM's root (its host key)
working with another VM that writes the repo could send the push to a
server of theirs; both documented in internals/git-protection.
Tests, each with plain git first running what the hardened one doesn't:
hostgit's TestCommandNoFsmonitor, TestCommandNoHooks (reference-
transaction, pre-push, from .git/hooks and a core.hooksPath; path,
file:// and ext:: pushes refused), TestCommandNoConfigHooks (hook.NAME.*),
TestCommandIgnoresGitEnv (GIT_DIR, GIT_WORK_TREE; environ),
TestCommandNoLazyFetch (a partial clone's core.sshCommand),
TestStatusNoFilters (clean, process, required, names with dots, = and
capitals), TestStatusNoSubmodules; vm's TestHostGitNoFsmonitor and
TestCloneRunsNoHooks (seed push and rm's fetch, update-ref and remote
remove); clone.txtar's push ssh options.
Docs: safety/attack-vectors (devvm's own git commands),
internals/git-protection.
Co-Authored-By: Claude Opus 5.5 <[email protected]>