GitLabgitlab-org

cli

main
ply7 git calls315 ms105 KiB5 cachedprotocol v2
565 lines23 KiBRaw
1// Package pm runs a supported package manager (npm, pip, gem, ...) behind the
2// Dependency Firewall's local MITM proxy. The shared Run flow starts the
3// proxy, routes the manager's HTTPS traffic through it, makes the manager
4// trust the proxy CA, forwards the command's args, records the
5// firewall's per-coordinate verdicts to the CI log, renders a summary, and
6// propagates the child's exit code. Each supported manager is a small
7// implementation of PackageManager describing only what varies by ecosystem.
8package pm
10import (
11 "context"
12 "crypto/x509"
13 "encoding/pem"
14 "errors"
15 "fmt"
16 "io"
17 "os"
18 "os/exec"
19 "os/signal"
20 "strings"
21 "sync"
22 "syscall"
24 gitlab "gitlab.com/gitlab-org/api/client-go/v3"
26 "gitlab.com/gitlab-org/cli/internal/api"
27 "gitlab.com/gitlab-org/cli/internal/dependencyfirewall/cilog"
28 "gitlab.com/gitlab-org/cli/internal/dependencyfirewall/fsx"
29 "gitlab.com/gitlab-org/cli/internal/dependencyfirewall/policy"
30 "gitlab.com/gitlab-org/cli/internal/dependencyfirewall/proxy"
31 "gitlab.com/gitlab-org/cli/internal/dependencyfirewall/summary"
32 "gitlab.com/gitlab-org/cli/internal/dependencyfirewall/verdict"
33 "gitlab.com/gitlab-org/cli/internal/iostreams"
36// PackageManager captures what varies between supported package managers so
37// the shared run flow (proxy + exec + log + summary) is written once. In the
38// upstream-MITM model managers no longer rewrite their own config: they route
39// traffic through the proxy (Environment), trust the proxy CA (CATrustEnviron),
40// and supply the coordinate matcher for their ecosystem (Matcher).
41type PackageManager interface {
42 // Name is the CLI noun and log key: "npm", "pip", "maven".
43 Name() string
44 // Binary is the executable looked up on PATH.
45 Binary() string
46 // Environment returns child-process env vars that route the manager's
47 // HTTPS traffic through proxyURL. The parent env (with proxy vars
48 // sanitized) is supplied by Run via proxyEnviron.
49 Environment(proxyURL string) []string
50 // CATrustEnviron returns the env vars that make the manager trust the
51 // proxy's MITM CA at caPath (NODE_EXTRA_CA_CERTS, SSL_CERT_FILE,
52 // PIP_CERT/REQUESTS_CA_BUNDLE, MAVEN_OPTS truststore, etc.).
53 CATrustEnviron(caPath string) []string
54 // ExistingBundleVars names every environment variable this manager's
55 // CATrustEnviron overwrites that could hold a user's pre-existing CA
56 // bundle (e.g. NODE_EXTRA_CA_CERTS, PIP_CERT and REQUESTS_CA_BUNDLE,
57 // SSL_CERT_FILE and BUNDLE_SSL_CA_CERT), so the engine can prepend those
58 // trust anchors to the proxy CA rather than replacing them. Every variable
59 // CATrustEnviron sets must appear here, or a user who set only the
60 // undeclared one loses their anchors and can no longer verify an internal
61 // index/mirror. An empty slice means the manager has no such variable to
62 // preserve (e.g. Maven, which trusts the proxy through a generated
63 // truststore rather than an env-named bundle).
64 ExistingBundleVars() []string
65 // CleanupCAFiles removes any files this manager derived from the CA
66 // bundle at caPath (for example a JVM truststore or a generated
67 // settings.xml). The engine always removes caPath itself; this covers
68 // ecosystem-specific sidecars the engine would otherwise not know about.
69 CleanupCAFiles(caPath string)
70 // Matcher returns the proxy coordinate matcher for this ecosystem's
71 // upstream URL shape.
72 Matcher() proxy.Matcher
75// setupManager lets a manager prepare the run. Run fails the run without
76// starting the child when Setup errors, and calls stop exactly once, after
77// the child and the MITM proxy stop and before it reads verdicts.
78type setupManager interface {
79 Setup(ctx context.Context, in setupInput) (setupResult, error)
82// argsManager receives the arguments destined for the package manager binary.
83// Run calls SetArgs before it builds the child environment, for managers whose
84// environment depends on what the caller asked for (Maven, whose settings file
85// can be named on the command line).
86type argsManager interface {
87 SetArgs(args []string)
90// argsRewriter takes options out of the arguments before the package manager
91// binary runs with them. Run reads the upstream proxy from the arguments as
92// given, so an option there can still choose it.
93type argsRewriter interface {
94 rewriteArgs(args []string) []string
97type setupInput struct {
98 parent []string // the environment the child would otherwise inherit
99 caPath string
100 bin string // the manager binary's path from LookPath
101 exec Executor
102 checker policy.Checker
103 projectID string
104 io *iostreams.IOStreams
105 upstreamCAs []byte // PEM of the extra registry CAs from upstreamRootCAs; nil means none
108type setupResult struct {
109 env []string
110 stop func()
111 verdicts func() []verdict.Entry
114// upstreamTrustManager lets a manager add the trust anchors its own runtime
115// would use on registry connections, such as a JVM truststore. env is the
116// environment glab was started with, before Run adds any variables for the
117// child; dir and args are the run's working directory and forwarded args. The
118// error is a warning, not a failure: a configured store that contributes
119// nothing, or an option that replaces glab's truststore in the child. It may
120// be an errors.Join of several; Run prints one line per joined error.
121type upstreamTrustManager interface {
122 upstreamTrustAnchors(env []string, dir string, args []string) ([]*x509.Certificate, error)
125// proxyEnviron returns parent with any caller-supplied proxy variables removed
126// and the inspection proxy set for HTTPS traffic only. managerKeys are the
127// env-var names the manager's own Environment sets (e.g. NPM_CONFIG_HTTPS_PROXY
128// for npm); they are stripped from the inherited env here so the engine stays
129// manager-agnostic — it does not hardcode any ecosystem's routing variables.
130func proxyEnviron(parent []string, proxyURL string, managerKeys ...string) []string {
131 proxyKeys := map[string]struct{}{
132 "HTTP_PROXY": {},
133 "HTTPS_PROXY": {},
134 // NO_PROXY must be stripped too: managers (and the Go/Node/curl HTTP
135 // stacks) honor it, so an inherited NO_PROXY=<registry> or NO_PROXY=*
136 // (common in CI images) would route traffic straight past the MITM
137 // proxy — no coordinates matched, no verdicts, a silent fail-open. The
138 // firewall fails closed everywhere else, so it must here too.
139 "NO_PROXY": {},
140 }
141 for _, k := range managerKeys {
142 proxyKeys[strings.ToUpper(k)] = struct{}{}
143 }
144 env := make([]string, 0, len(parent)+2)
145 for _, e := range parent {
146 key, _, _ := strings.Cut(e, "=")
147 if _, skip := proxyKeys[strings.ToUpper(key)]; skip {
148 continue
149 }
150 env = append(env, e)
151 }
152 // Point both HTTP_PROXY and HTTPS_PROXY at the inspection proxy. HTTPS is
153 // the normal path (registries have served over HTTPS for years). HTTP_PROXY
154 // is set — not merely stripped — because the registry URL is
155 // repo-controlled: a committed ".npmrc registry=http://mirror/" (or the
156 // equivalent for any ecosystem) would otherwise fetch over plain HTTP,
157 // consult an absent HTTP_PROXY, and connect directly with zero inspection
158 // on a green job. Through the proxy, a plaintext fetch is checked against
159 // policy like any other.
160 // Manager-specific routing variables are re-added by the manager's
161 // Environment, appended by Run after this call.
162 return append(env, "HTTP_PROXY="+proxyURL, "HTTPS_PROXY="+proxyURL)
165// envKeys returns the KEY names from a "KEY=value" environment slice.
166func envKeys(env []string) []string {
167 keys := make([]string, 0, len(env))
168 for _, e := range env {
169 if k, _, ok := strings.Cut(e, "="); ok {
170 keys = append(keys, k)
171 }
172 }
173 return keys
176// writeCABundle PEM-encodes the proxy CA into a temp file so managers can
177// trust the proxy via CATrustEnviron. For each CA-bundle variable the manager
178// names (ExistingBundleVars) that the parent env sets, those trust anchors are
179// prepended so the user's are preserved. The system roots follow the proxy CA,
180// because most of the variables CATrustEnviron sets replace a tool's default
181// trust instead of extending it. A file already merged (two variables pointing
182// at the same path) is not read twice. Returns the path; the caller removes it.
183func writeCABundle(ios *iostreams.IOStreams, parent []string, bundleVars []string, ca *x509.Certificate, roots []*x509.Certificate) (string, error) {
184 pemBytes := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: ca.Raw})
186 var bundle []byte
187 seen := make(map[string]struct{}, len(bundleVars))
188 for _, bundleVar := range bundleVars {
189 existing := lookupEnv(parent, bundleVar)
190 if bundleVar == "" || existing == "" {
191 continue
192 }
193 if _, dup := seen[existing]; dup {
194 continue
195 }
196 seen[existing] = struct{}{}
197 userPEM, err := os.ReadFile(existing)
198 if err != nil {
199 ios.LogErrorf("warning: could not read existing %s %q: %v\n", bundleVar, existing, err)
200 continue
201 }
202 bundle = append(bundle, userPEM...)
203 if len(bundle) > 0 && bundle[len(bundle)-1] != '\n' {
204 bundle = append(bundle, '\n')
205 }
206 }
207 bundle = append(bundle, pemBytes...)
208 for _, root := range roots {
209 bundle = append(bundle, pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: root.Raw})...)
210 }
212 f, err := os.CreateTemp("", "glab-df-ca-*.pem")
213 if err != nil {
214 return "", err
215 }
216 if _, err := f.Write(bundle); err != nil {
217 return "", errors.Join(err, f.Close(), os.Remove(f.Name()))
218 }
219 if err := f.Close(); err != nil {
220 return "", errors.Join(err, os.Remove(f.Name()))
221 }
222 return f.Name(), nil
225// dedupEnv collapses an environment slice so each key appears once with its
226// last-assigned value, preserving first-seen ordering. This makes the child
227// process's view of each variable deterministic regardless of how its
228// runtime resolves duplicate envp entries.
229func dedupEnv(env []string) []string {
230 index := make(map[string]int, len(env))
231 out := make([]string, 0, len(env))
232 for _, e := range env {
233 key, _, ok := strings.Cut(e, "=")
234 if !ok {
235 out = append(out, e)
236 continue
237 }
238 if i, seen := index[key]; seen {
239 out[i] = e
240 continue
241 }
242 index[key] = len(out)
243 out = append(out, e)
244 }
245 return out
248// lookupEnv returns the value of key in an environment slice ("KEY=value"),
249// or "" if absent. The last occurrence wins.
250func lookupEnv(env []string, key string) string {
251 value := ""
252 for _, e := range env {
253 k, v, ok := strings.Cut(e, "=")
254 if ok && k == key {
255 value = v
256 }
257 }
258 return value
261// Executor runs the package-manager binary. Satisfied by cmdutils.Executor.
262type Executor interface {
263 LookPath(file string) (string, error)
264 ExecWithIO(ctx context.Context, name string, args []string, env []string, stdin io.Reader, stdout, stderr io.Writer) error
267// interruptExitCode is 130 (the SIGINT convention) reported for any interrupt.
268// Run detects interruption from context cancellation and cannot recover the
269// specific signal (the received value is discarded), so it does not compute
270// 128+signal — SIGTERM's 143, for example, is never returned. The sibling df
271// package/ci-summary commands return verdict.BlockedExitCode (3); this code is
272// distinct from that and from the generic-failure 1.
273const interruptExitCode = 130
275// ExitError reports that the package-manager binary exited non-zero, was
276// interrupted, or could not be run, carrying the exit Code the process should
277// return. pm is a library package and must not import internal/cmdutils
278// (command-layer only, enforced by depguard), so the calling command
279// translates this into a *cmdutils.ExitError; see dfcmd.run.
280type ExitError struct {
281 Code int
282 Err error
283 // ChildExited is true only when the package-manager child process
284 // actually ran and exited non-zero (an *exec.ExitError). It is false
285 // when the child never ran (e.g. not found on PATH, fork/exec failure)
286 // or when the run was interrupted. Callers use this to decide whether a
287 // rendered summary already explains the failure: only a real child exit
288 // may be silenced.
289 ChildExited bool
292func (e *ExitError) Error() string { return e.Err.Error() }
293func (e *ExitError) Unwrap() error { return e.Err }
295// RunOptions are the inputs to Run. Registry/token fields are gone: the model
296// no longer talks to a GitLab registry.
297type RunOptions struct {
298 IO *iostreams.IOStreams
299 Executor Executor
300 BaseDir string
301 Client *gitlab.Client // authenticated API client, for the policy checker
302 ProjectID string // project id or full-path slug, for policy scoping
303 Args []string
304 // CACertPath is glab's ca_cert for the GitLab host. Registry connections
305 // trust it in addition to the system roots.
306 CACertPath string
307 // ClientCertPath, ClientKeyPath and ClientCertPassword are glab's client_cert,
308 // client_key and client_cert_password for the GitLab host. The certificate is
309 // presented to an https:// outbound proxy that requires one, never to a registry.
310 ClientCertPath string
311 ClientKeyPath string
312 ClientCertPassword func() (string, error)
314 // notify is a test-only seam. When nil (the production path) Run installs
315 // no signal handler at all — glab's root command owns signals via
316 // fang.WithNotifySignal and cancels ctx on a signal. When non-nil it is
317 // invoked in place of signal.Notify so tests can drive the same
318 // cancellation deterministically without a real OS signal.
319 notify func(c chan<- os.Signal, sig ...os.Signal)
322// UpstreamProxyCertificateOptions returns the option that presents glab's
323// client_cert to an https:// outbound proxy that requires one, loading it the
324// way the API client does. It returns no option when certPath is empty or names
325// no certificate. Run and the job-level proxy both use it, so the two load the
326// certificate the same way.
327func UpstreamProxyCertificateOptions(certPath, keyPath string, password func() (string, error)) ([]proxy.Option, error) {
328 if certPath == "" {
329 return nil, nil
330 }
331 certs, err := api.LoadClientCertificates(certPath, keyPath, password)
332 if err != nil {
333 return nil, fmt.Errorf("failed to load client certificate: %w", err)
334 }
335 if len(certs) == 0 {
336 return nil, nil
337 }
338 return []proxy.Option{proxy.WithUpstreamProxyCertificate(certs[0])}, nil
341// Run executes manager.Binary() with args forwarded verbatim, except the
342// options an argsRewriter takes out, routing HTTPS traffic through a local
343// MITM proxy that policy-checks each artifact/upload coordinate. Blocked
344// packages are recorded and the summary is rendered on exit.
345func Run(ctx context.Context, manager PackageManager, opts RunOptions) error {
346 ctx, cancel := context.WithCancel(ctx)
347 defer cancel()
349 baseChecker, err := policy.New(opts.Client)
350 if err != nil {
351 return err
352 }
353 checker := policy.NewCachingChecker(baseChecker, opts.IO.LogErrorf)
355 // Read the manager's own outbound proxy before its environment is pointed
356 // at the inspection proxy below.
357 proxyOpts, err := upstreamProxyOptions(manager, os.Environ(), opts.BaseDir, opts.Args)
358 if err != nil {
359 return err
360 }
361 proxyOpts = append(proxyOpts, proxy.WithUpstreamFailureWarning(opts.IO.LogErrorf), proxy.WithBlockNotice(opts.IO.LogErrorf))
362 var anchors []*x509.Certificate
363 if m, ok := manager.(upstreamTrustManager); ok {
364 anchors, err = m.upstreamTrustAnchors(os.Environ(), opts.BaseDir, opts.Args)
365 warnings := []error{err}
366 if joined, ok := err.(interface{ Unwrap() []error }); ok {
367 warnings = joined.Unwrap()
368 }
369 for _, w := range warnings {
370 if w != nil {
371 opts.IO.LogErrorf("warning: %v\n", w)
372 }
373 }
374 }
375 roots, upstreamCAs, err := upstreamRootCAs(os.Environ(), opts.CACertPath, anchors)
376 if err != nil {
377 return fmt.Errorf("failed to load registry CA certificates: %w", err)
378 }
379 if roots != nil {
380 proxyOpts = append(proxyOpts, proxy.WithUpstreamRootCAs(roots))
381 }
382 certOpts, err := UpstreamProxyCertificateOptions(opts.ClientCertPath, opts.ClientKeyPath, opts.ClientCertPassword)
383 if err != nil {
384 return err
385 }
386 proxyOpts = append(proxyOpts, certOpts...)
388 p, err := proxy.New(manager.Matcher(), checker, opts.ProjectID, proxyOpts...)
389 if err != nil {
390 return fmt.Errorf("failed to create inspection proxy: %w", err)
391 }
392 if err := p.Start(); err != nil {
393 return fmt.Errorf("failed to start inspection proxy: %w", err)
394 }
395 defer p.Stop() //nolint:contextcheck // proxy shutdown manages its own context internally
397 proxyURL := "http://" + p.Addr()
399 caPath, err := writeCABundle(opts.IO, os.Environ(), manager.ExistingBundleVars(), p.CACertificate(), systemRoots())
400 if err != nil {
401 return fmt.Errorf("failed to write proxy CA bundle: %w", err)
402 }
403 // The engine always removes the CA bundle; the manager removes any
404 // ecosystem-specific sidecars it derived from it (e.g. a JVM truststore).
405 defer func() {
406 _ = os.Remove(caPath)
407 manager.CleanupCAFiles(caPath)
408 }()
410 // Signal handling: glab's root command (main.go) already installs
411 // fang.WithNotifySignal(os.Interrupt, SIGTERM), which cancels ctx on a
412 // signal. We do not install a second signal.Notify; a cancelled context
413 // surfaces as a context.Canceled execErr below, which we map to the
414 // interrupt exit code. The notify hook is retained only so tests can drive
415 // the same cancellation deterministically without a real OS signal.
416 if opts.notify != nil {
417 sigCh := make(chan os.Signal, 1)
418 opts.notify(sigCh, os.Interrupt, syscall.SIGTERM)
419 defer func() {
420 signal.Stop(sigCh)
421 close(sigCh)
422 }()
423 go func() {
424 if _, ok := <-sigCh; !ok {
425 return
426 }
427 cancel()
428 }()
429 }
431 binPath, err := opts.Executor.LookPath(manager.Binary())
432 if err != nil {
433 return fmt.Errorf("%s not found on PATH: %w", manager.Binary(), err)
434 }
436 args := opts.Args
437 if r, ok := manager.(argsRewriter); ok {
438 args = r.rewriteArgs(args)
439 }
440 if a, ok := manager.(argsManager); ok {
441 a.SetArgs(args)
442 }
444 var setup setupResult
445 stopSetup := func() {}
446 if s, ok := manager.(setupManager); ok {
447 setup, err = s.Setup(ctx, setupInput{
448 parent: os.Environ(),
449 caPath: caPath,
450 bin: binPath,
451 exec: opts.Executor,
452 checker: checker,
453 projectID: opts.ProjectID,
454 io: opts.IO,
455 upstreamCAs: upstreamCAs,
456 })
457 if err != nil {
458 return fmt.Errorf("failed to set up %s for the Dependency Firewall: %w", manager.Name(), err)
459 }
460 stopSetup = sync.OnceFunc(setup.stop)
461 defer stopSetup()
462 }
464 managerEnv := append(manager.Environment(proxyURL), setup.env...)
465 // Strip the manager's own routing keys from the inherited env so they
466 // can't leak an old value the manager's Environment doesn't overwrite;
467 // the manager's values are re-appended immediately below.
468 env := proxyEnviron(os.Environ(), proxyURL, envKeys(managerEnv)...)
469 env = append(env, managerEnv...)
470 env = append(env, manager.CATrustEnviron(caPath)...)
471 // Collapse duplicate keys (last wins) so the proxy/CA-trust values we
472 // append override any conflicting entry inherited from the parent
473 // environment, regardless of how the child runtime parses envp.
474 env = dedupEnv(env)
476 execErr := opts.Executor.ExecWithIO(ctx, binPath, args, env, opts.IO.In, opts.IO.StdOut, opts.IO.StdErr)
478 p.Stop() //nolint:contextcheck // proxy shutdown manages its own context internally
479 stopSetup()
480 verdicts := p.Verdicts()
481 if setup.verdicts != nil {
482 verdicts = append(verdicts, setup.verdicts()...)
483 }
484 writeLog(opts.IO, opts.BaseDir, manager.Name(), args, verdicts)
485 if len(verdicts) > 0 {
486 summary.Render(opts.IO, verdicts)
487 }
489 // A cancelled context (from a signal, via fang or the injected notify
490 // hook) means the run was interrupted, regardless of which path fired
491 // first. Report the conventional interrupt code rather than the generic
492 // failure exitError would derive from context.Canceled.
493 if errors.Is(execErr, context.Canceled) || errors.Is(ctx.Err(), context.Canceled) {
494 return &ExitError{Code: interruptExitCode, Err: errors.New("interrupted")}
495 }
496 return exitError(manager.Binary(), execErr)
499// writeLog merges this run's verdicts into the CI log at
500// baseDir/.gitlab/df/ci-log.json. It loads any existing log first and appends
501// (cilog dedupes by Entry.Key) so a job that runs the firewall more than once
502// — npm then pip, or install then publish — accumulates every run's verdicts.
503// Overwriting instead would drop earlier runs, and df ci-summary would then
504// exit 0 even though a package was blocked, silently defeating the job gate.
505//
506// A Load error means a present-but-corrupt log (cilog.Load returns a fresh log
507// with a nil error for a missing file). We must NOT start fresh in that case:
508// overwriting a log we cannot parse would discard an earlier run's Blocked
509// entries and flip ci-summary's fail-closed "unreadable log" exit into a pass.
510// So on a Load error we leave the file untouched and skip the write, keeping
511// the corrupt log in place for ci-summary to fail on.
512//
513// The log is written into the working tree on every run, including local
514// ones, so it will appear as an untracked .gitlab/df/ci-log.json for
515// developers; that is intentional (ci-summary reads it back to gate the job).
516func writeLog(ios *iostreams.IOStreams, baseDir, name string, args []string, entries []verdict.Entry) {
517 command := strings.Join(append([]string{name}, args...), " ")
518 // Hold the sidecar lock across Load -> Append -> Save so two concurrent
519 // "glab df run" invocations in one job serialize instead of racing
520 // last-writer-wins (which would drop the losing run's Blocked entries and
521 // let ci-summary exit 0).
522 err := fsx.WithLock(cilog.LockPath(baseDir), func() error {
523 log, err := cilog.Load(baseDir)
524 if err != nil {
525 // A Load error means a present-but-corrupt log (Load returns a
526 // fresh log with nil error for a missing file). Leave it in place
527 // rather than overwriting: starting fresh would discard an earlier
528 // run's Blocked entries and flip ci-summary's fail-closed
529 // unreadable-log exit into a pass.
530 return fmt.Errorf("existing Dependency Firewall CI log is unreadable; leaving it in place for ci-summary to fail on: %w", err)
531 }
532 // On the normal path Load returns a zero-value log for a missing file,
533 // so its Session (Command/StartedAt) is empty — only cilog.New sets
534 // it. Populate it here for the first run so ci-log.json always records
535 // the session that created it; a later run leaves an already-set
536 // Session alone so the log keeps the originating command.
537 if log.Session.Command == "" {
538 log.Session = cilog.New(command).Session
539 }
540 for _, e := range entries {
541 log.Append(e)
542 }
543 if err := cilog.Save(baseDir, log); err != nil {
544 return fmt.Errorf("failed to write Dependency Firewall CI log: %w", err)
545 }
546 return nil
547 })
548 if err != nil {
549 ios.LogErrorf("warning: %v\n", err)
550 }
553// exitError wraps a package-manager execution error as an *ExitError carrying
554// the child's exit Code. The calling command translates it into the
555// *cmdutils.ExitError that main.go's handler unwraps to set glab's exit
556// status; see dfcmd.run.
557func exitError(binary string, err error) error {
558 if err == nil {
559 return nil
560 }
561 if ee, ok := errors.AsType[*exec.ExitError](err); ok {
562 return &ExitError{Code: ee.ExitCode(), Err: fmt.Errorf("%s exited with a non-zero status: %w", binary, err), ChildExited: true}
563 }
564 return &ExitError{Code: 1, Err: fmt.Errorf("failed to run %s: %w", binary, err)}
Diagnostics7 git calls · 315 ms
CallStatusSizeTime0315 ms
discover200185 B3 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=185
git.server.agent=git/2.56.g1891de4-Linux
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch server-option object-format
git.server.fetch=shallow wait-for-done filter
git.protocol.version=2
git.pkt.frames=9
git.pkt.data=7
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=185
git.pkt.payload.max=35
ls-refs20058 KiB · hit3 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=3
git.response.bytes=59849
git.response.cache=HIT
git.response.duration_ms=3
git.protocol.version=2
git.pkt.frames=731
git.pkt.data=730
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=59849
git.pkt.payload.max=143
git.ls_refs.count=730
git.ls_refs.head=refs/heads/main
fetchtree:0 · deepen 1020032 KiB · hit2 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=2
git.response.bytes=32926
git.response.cache=HIT
git.response.duration_ms=2
git.fetch.filter=tree:0
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=22
git.pkt.data=20
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=32926
git.pkt.payload.max=32046
git.sideband.band1.bytes=32046
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=80
git.pack.bytes=32046
git.pack.ofs_delta=36
git.pack.ref_delta=0
git.pack.chain.max=2
git.pack.trailer=cb0bad5d7ffc514895d8b21c4dd470327f90bc91
git.pack.full=44
Open pack map
fetchcombine:blob:none+tree:2 · deepen 12004.2 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=4273
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=combine:blob:none+tree:2
git.fetch.wants=0dd7574dce9e385c5c30540e6c15657adc6bdce9
git.fetch.haves.count=0
git.fetch.deepen=1
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=7
git.pkt.data=5
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=4273
git.pkt.payload.max=4173
git.sideband.band1.bytes=4173
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=11
git.pack.bytes=4173
git.fetch.wide.objects=11
git.fetch.wide.extra_bytes=3930
git.fetch.wide.blobs=0
fetchtree:0200361 B · hit3 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=361
git.response.cache=HIT
git.response.duration_ms=3
git.fetch.filter=tree:0
git.fetch.wants=506cba622ceda1473ee3cde63969809c144b7247
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=361
git.pkt.payload.max=334
git.sideband.band1.bytes=334
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=334
git.pack.trailer=26d32585a3a474717e00a318584ccd16918c9d32
Open pack map
fetchtree:02001.3 KiB · hit4 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=4
git.response.bytes=1327
git.response.cache=HIT
git.response.duration_ms=4
git.fetch.filter=tree:0
git.fetch.wants=2758711b27b3e124482ce287b5df86092bb20d62
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=1327
git.pkt.payload.max=1300
git.sideband.band1.bytes=1300
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=1
git.pack.bytes=1300
git.pack.trailer=c83fc6004a9a1360845513c0fb16272b5c14a3e4
Open pack map
fetch2008.2 KiB301 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=301
git.response.bytes=8366
git.response.cache=MISS
git.response.duration_ms=301
git.fetch.wants=bfec59de9b3226805f7d87d0e053076e875227e4
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=4
git.pkt.data=3
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=8366
git.pkt.payload.max=8339
git.sideband.band1.bytes=8339
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://gitlab.com/gitlab-org/cli
Ref
refs/heads/main
Commit
0dd7574dce9e385c5c30540e6c15657adc6bdce9
cf-ray
a5e25d8e59b2224d
Request
65467b81…
Protocol
v2 · sha1
Agent
git/2.56.g1891de4-Linux
Filter
advertised
Fetch
shallow wait-for-done filter
Capabilities
agent ls-refs fetch server-option object-format