Documentation
¶
Overview ¶
Package gitcred is the run pipeline's in-memory git credential helper (run-pipeline.md §Steps 2): git asks `factory-agent fx git-credential get` for a credential, and the helper asks the worker over a Unix socket that only the worker's user can open. The worker answers from memory, so the token is never written to disk, to .git/config or to a command line.
The socket lives in its own directory, created 0700 for the run and removed when the Server closes. The worker answers only for the repos its Entries list (the task repo with the task token, each private read repo with its own read-only token), matched on the protocol, the host and the repo path (git sends the path because the pipeline sets credential.useHttpPath): any other repo gets no credential, so public repos are cloned anonymously. The entries are read at each request, so refreshed tokens apply at once.
Index ¶
- Constants
- func ConfigEnv(pairs [][2]string) []string
- func Helper(ctx context.Context, args []string, stdin io.Reader, stdout io.Writer, ...) error
- func HelperConfig(helper []string) [][2]string
- func ParseRequest(b []byte) map[string]string
- func ShellQuote(s string) string
- type Entries
- type Entry
- type Server
Constants ¶
const EnvSocket = "FACTORY_GIT_CREDENTIAL_SOCKET"
EnvSocket names the environment variable that carries the socket path to the helper.
Variables ¶
This section is empty.
Functions ¶
func ConfigEnv ¶
ConfigEnv turns git config pairs into GIT_CONFIG_COUNT/KEY_n/VALUE_n environment entries: process-scoped config that is never written to a file.
func Helper ¶
func Helper(ctx context.Context, args []string, stdin io.Reader, stdout io.Writer, socket string) error
Helper is the git credential helper (`factory-agent fx git-credential <op>`): for get it forwards git's request to the socket and prints the answer; store and erase are ignored (nothing is ever stored). Without a socket it answers nothing, and git goes on without a credential.
func HelperConfig ¶
HelperConfig is the git config that makes git use only this helper: an empty credential.helper first resets any helper from the system or global config (osxkeychain would store the token on disk), then the helper command, run through the shell as git does for "!" helpers, and credential.useHttpPath so requests carry the repo path.
func ParseRequest ¶
ParseRequest parses git's credential protocol attributes (key=value lines, ending at a blank line or EOF). Repeated and array keys keep their last value.
Types ¶
type Entries ¶
type Entries func() []Entry
Entries returns the current entries; the Server calls it for every request.
type Entry ¶
type Entry struct {
// Protocol is the URL scheme git uses (https; http only for loopback test servers).
Protocol string
// Host is host[:port], as in the clone URL.
Host string
// Repo is owner/name.
Repo string
Username string
Password string
}
Entry is one repo the helper answers for, with its credential.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server answers credential requests from memory. Close it when the run ends.
func Listen ¶
Listen starts a Server on a socket in a new 0700 directory under parent (os.TempDir() when ""). Unix socket paths are short (104 bytes on macOS), so parent should be short too.