gitcred

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

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

View Source
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

func ConfigEnv(pairs [][2]string) []string

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

func HelperConfig(helper []string) [][2]string

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

func ParseRequest(b []byte) map[string]string

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.

func ShellQuote

func ShellQuote(s string) string

ShellQuote quotes s for sh.

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

func Listen(parent string, entries Entries) (*Server, error)

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.

func (*Server) Answered

func (s *Server) Answered() int

Answered is how many requests got a credential.

func (*Server) Close

func (s *Server) Close() error

Close stops answering, waits for open exchanges, drops the entries and removes the socket directory.

func (*Server) Path

func (s *Server) Path() string

Path is the socket's path (the helper's EnvSocket).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL