session

package
v1.131.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package session supports the job-level Dependency Firewall proxy (`glab dependency-firewall job-proxy`). Unlike the per-command package managers in package pm — each of which starts a proxy for the length of one command — a session runs one inspection proxy for a whole CI job and emits the environment that routes every tool through it and makes every tool trust it, without clobbering a caller's existing proxy or CA configuration.

Index

Constants

View Source
const (
	// AddrFile holds the proxy's listen address. It is written last — after the
	// proxy is listening and its CA is on disk — so its presence signals
	// readiness to `job-proxy start`.
	AddrFile = "addr"
	// PIDFile holds the daemon's process id, for `job-proxy stop`.
	PIDFile = "pid"
	// CACertFile holds the proxy's MITM CA in PEM, for the job to trust.
	CACertFile = "proxy-ca.pem"
)
View Source
const StateDirEnv = "GLAB_DF_JOB_PROXY_STATE_DIR"

StateDirEnv names the directory holding the proxy's runtime state (address, pid, CA). `job-proxy start` exports it so `job-proxy stop` finds the same daemon, and a caller can set it to pin a known location.

Variables

This section is empty.

Functions

func BuildJobEnv

func BuildJobEnv(proxyURL, mergedBundlePath, callerNoProxy string) []string

BuildJobEnv returns the environment, as "KEY=value" strings, that routes a job's tools through the proxy at proxyURL and makes them trust its MITM CA.

Routing points HTTP(S)_PROXY (and the per-manager routing variables) at the proxy, and preserves the caller's NO_PROXY so their internal hosts still go direct, adding only loopback so local traffic is never proxied.

Trust is additive: mergedBundlePath holds the system roots, the caller's existing anchors and the proxy CA, so pointing a tool's CA variable at it never drops a CA the tool trusted before. Installing the proxy CA into the system trust store — done separately by the command — covers everything that reads the system store (git, wget, OpenSSL, apt).

func CallerBundlePaths

func CallerBundlePaths(env []string) []string

CallerBundlePaths returns the non-empty values of callerBundleEnvVars from env ("KEY=value" strings), for seeding WriteMergedBundle.

func InstallSystemTrust

func InstallSystemTrust(stateDir, proxyCAPath string, logf func(string, ...any)) bool

InstallSystemTrust installs the proxy CA at proxyCAPath into the OS trust store, so tools that read it (curl, git, wget, OpenSSL, apt) trust the proxy without any per-tool variable. It is best-effort: on an unsupported image or without privilege it logs and returns, leaving the env-var bundles as the fallback. It reports whether the install succeeded.

func JVMTrustEnv

func JVMTrustEnv(stateDir, proxyURL, proxyCAPath string, warnf func(string, ...any)) ([]string, error)

JVMTrustEnv returns the environment that routes Maven and Gradle through the proxy and makes their JVMs trust its CA, writing the settings.xml and PKCS#12 trust stores they need into stateDir. JVMs ignore the system trust store and (for Maven) the HTTP(S)_PROXY variables that cover the other managers, so they need a generated settings.xml and JVM trust store instead.

Maven and Gradle each write their trust store to "<ca>.p12", so each is given a distinct CA copy under stateDir to avoid clobbering the other's store (the generated store passwords differ). Each trust store also folds in the system roots, so public dependencies the proxy does not intercept still validate.

It returns whatever environment it could build together with an error naming each ecosystem it could not cover, so the caller can report a partial setup rather than leave mvn or gradle silently bypassing the proxy.

func LogBaseDir

func LogBaseDir() (string, error)

LogBaseDir returns the directory the job-level proxy writes its CI log under: CI_PROJECT_DIR in a CI/CD job, otherwise the working directory.

func NewStateDir

func NewStateDir() (string, error)

NewStateDir returns the runtime-state directory for a new proxy: the one named by StateDirEnv, or else a fresh directory only the current user can read. A shared fixed path would let concurrent jobs on one host clobber each other's CA and pid, and let another user plant files the job then trusts.

func RemoveSystemTrust

func RemoveSystemTrust(stateDir string, logf func(string, ...any))

RemoveSystemTrust removes the per-run proxy CA that InstallSystemTrust staged for stateDir from every anchor directory and rebuilds the store, so a job's CA does not linger in the host trust store after stop. It is best-effort and, like InstallSystemTrust, stays silent when there was nothing to remove.

func Serve

func Serve(ctx context.Context, cfg ServeConfig) error

Serve runs the job-level inspection proxy until it is signalled or ctx is cancelled, streaming the firewall's verdicts to the CI log so `glab dependency-firewall ci-summary` can still gate the job even though no single package-manager command owns the proxy. It is the body of the detached `job-proxy serve` daemon.

func ShellExports

func ShellExports(env []string) string

ShellExports renders env ("KEY=value" strings) as POSIX `export` lines that a shell can eval. Values are single-quoted with embedded single quotes escaped, so a value with spaces or shell metacharacters is passed through verbatim.

func WriteMergedBundle

func WriteMergedBundle(stateDir, proxyCAPath string, userBundlePaths []string, logf func(string, ...any)) (string, error)

WriteMergedBundle writes a CA bundle containing the system roots, any caller-supplied CA bundles (userBundlePaths), and the proxy CA at proxyCAPath, to stateDir/ca-bundle.pem, and returns its path. Tools that replace their trust from a single bundle (Python requests, cargo) can be pointed at it without losing the roots they had, which is what makes the proxy's trust additive rather than a replacement. A system or caller bundle that can't be read is reported through logf, because the tools pointed at the merged bundle lose those roots.

Types

type ServeConfig

type ServeConfig struct {
	Client    *gitlab.Client
	ProjectID string
	BaseDir   string // working directory; where .gitlab/df/ci-log.json is written
	StateDir  string // where addr/pid/proxy-ca.pem are written
	// CACertPath is the ca_cert setting for the GitLab host, trusted for
	// upstream registry connections alongside the system roots and the CA
	// bundles named in the environment, as a per-command run does.
	CACertPath string
	// ClientCertPath, ClientKeyPath and ClientCertPassword are glab's client_cert,
	// client_key and client_cert_password for the GitLab host, presented to an
	// https:// outbound proxy that requires a client certificate, as a
	// per-command run does. Registries never receive the certificate.
	ClientCertPath     string
	ClientKeyPath      string
	ClientCertPassword func() (string, error)
	IO                 *iostreams.IOStreams
}

ServeConfig configures the job-level proxy daemon.

Jump to

Keyboard shortcuts

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