fix(df): warn once per registry when a registry request fails

Description

When the glab df inspection proxy can't complete a request to a package registry, the package manager only sees a dropped connection. The real cause (for example Proxy Authentication Required from a corporate proxy, or an untrusted registry certificate) was only printed with GLAB_DEBUG.

This MR adds a warning on stderr the first time a request to each registry authority fails during a run:

warning: dependency firewall request to registry registry.npmjs.org:443 failed: Proxy Authentication Required
  • proxy.WithUpstreamFailureWarning(policy.Logf) is a new proxy option. pm.Run passes opts.IO.LogErrorf, the same sink policy.NewCachingChecker already receives, and uses the same warning: dependency firewall ... wording.
  • Warnings are deduplicated per authority (host:port from the CONNECT) across all tunnels for the life of the proxy, so a large install that fails against one registry prints one line, not one per package.
  • The dedupe map and the call to the sink share one mutex, so concurrent tunnels never write to stderr at the same time.
  • The line contains only the CONNECT authority and the error from http.Transport. Neither one includes proxy credentials. A non-200 CONNECT reply becomes the status text, and dial errors carry addresses only.
  • No warning is printed when the round trip failed because the proxy couldn't read the package manager's own request body (for example, an upload it aborted). The registry wasn't at fault, but the transport reports it as unexpected EOF like any other failure. Cancellation can't cause a false warning: the upstream request isn't tied to the package manager's connection or to proxy shutdown, so neither one makes the round trip fail.
  • The existing GLAB_DEBUG line is unchanged.

Related to #8635 (closed) Related to gitlab-org/gitlab#629431 Related to gitlab-org&24327

Stacks on !4150 (merged) (df-upstream-outbound-proxy).

How has this been tested?

New tests in internal/dependencyfirewall/proxy/outbound_test.go use the in-process corporate CONNECT proxy from !4150 (merged) with wrong credentials:

  • TestProxyWarnsOncePerRegistryWhenUpstreamFails: two failing requests to one registry produce exactly one warning. It contains the registry authority and Proxy Authentication Required, and contains neither the proxy user name nor the password.
  • TestProxyWarnsForEachFailingRegistry: failures against two registries, plus a repeat against the first, produce exactly two warnings, one per registry.
  • TestProxyDoesNotWarnWhenClientAbortsUpload: a client that aborts a PUT partway through the body produces no warning.

TestRunTrustsConfiguredCAsUpstream in internal/dependencyfirewall/pm/pm_test.go now also checks what pm.Run writes to stderr. With no CA configured, stderr has the warning for the registry. When the registry is trusted, stderr has no warning.

I watched each new test fail before implementing. The warning lists were empty and stderr had no warning. The aborted upload produced warning: ... failed: unexpected EOF. After implementing:

  • go test -race -count=3 ./internal/dependencyfirewall/proxy/ ./internal/dependencyfirewall/pm/
  • go test ./internal/dependencyfirewall/... ./internal/commands/df/...
  • golangci-lint run on both packages: 0 issues
  • scripts/comment-overlap: 0 findings
Edited by Arpit Gogia

Merge request reports

Loading
Loading