feat: WithNoSystemFallback and WithGitKnownHosts#19
Merged
Conversation
Remove reliance on ambient/system state so callers can drive all auth through functional options. WithNoSystemFallback() disables every ambient/system fallback in one switch: - the SSH agent (SSH_AUTH_SOCK) - the system 'git credential' helper (git credential fill) - the archive-fallback environment-variable tokens (GH_TOKEN etc.) - the ~/.ssh/known_hosts default host-key check - the Mercurial (hg) subprocess (hg downloads error out) WithGitKnownHosts([]byte) verifies SSH host keys against known_hosts data in memory (no temp file, no disk read). Unknown hosts are allowed; a host whose recorded key has changed is rejected. Hashed entries are skipped. Host-key resolution precedence: insecure-skip -> configured known_hosts -> system default (~/.ssh/known_hosts, only when system fallback is enabled) -> accept-any-with-warning. The system git credential helper call is indirected through a package variable so its gating is unit-testable. Tests: exhaustive unit coverage of the known_hosts matcher (match, mismatch, unknown host, ports, multi-key, hashed, malformed), the host-key strategy selection, and the credential-helper/env-token/ssh -agent/hg gating; plus an end-to-end SSH integration case proving a known_hosts key mismatch rejects a real clone.
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.
First PR in the stack that makes grabber a side-effect-free replacement for how the parser/runner use go-getter. This one is the lockdown: stop reaching into ambient/system state unless the caller allows it.
What
WithNoSystemFallback()One switch that disables all ambient/system fallbacks:
SSH_AUTH_SOCK)git credentialhelper (git credential fill)GH_TOKEN/GITHUB_TOKEN/GITLAB_TOKEN/GL_TOKEN/BITBUCKET_TOKEN)~/.ssh/known_hostsdefault host-key checkhg) subprocess (hg downloads error out — hg is 100% subprocess-based)Intended for locked-down environments (like the runner) that must not read the ambient user/system configuration.
WithGitKnownHosts([]byte)Verifies SSH host keys against
known_hostsdata in memory — no temp file, no disk read. Unknown hosts are allowed; a host whose recorded key has changed is rejected (the "new host is fine, changed key is a red flag" model). Hashed entries (|1|...) are skipped.Host-key resolution precedence:
InsecureSkipHostKeyVerify→ configuredknown_hosts→ system default (~/.ssh/known_hosts, only when system fallback is on) → accept-any-with-warning.Why
The runner currently feeds git auth through disk + env (writes
id_rsa, setsGIT_SSH_COMMAND, installs a~/.gitconfigcredential helper, exportsGIT_SSL_*). To migrate it onto grabber, grabber must (a) never depend on that ambient state and (b) let the caller turn it all off. This PR delivers (b) and the host-key piece of (a).Testing
known_hostsmatcher: match, changed-key rejection, unknown-host allow, non-standard ports ([host]:port),host,ippatterns, multi-key, hashed-entry skip, malformed input. Host-key strategy selection covered 100%.WithGitKnownHostsis enforced through go-git, not just unit-tested.go build,go vet,golangci-lint(0 issues), andgo test -short -race ./...all clean.Notes
WithNoSystemFallback(), previously-implicit sources (agent, helper, env tokens, disk known_hosts, hg) are off. Default behavior is unchanged when the option isn't set.