proxy

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 61 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package proxy serves proxy repositories: files are fetched from the repository's upstream on first request, cached content-addressed in the blob store, recorded in proxy_cache_entries (which also backs the repository's package listing) and served from the cache until their TTL expires. When an expired entry cannot be revalidated because the upstream is down, it is served stale for up to the repository's max_stale_seconds.

Index

Constants

View Source
const (
	// DefaultMaxBody caps any single file fetched from an upstream.
	DefaultMaxBody int64 = 4 << 30 // 4 GiB

	// DefaultMaxMetadata caps an index or metadata file fetched from an
	// upstream (Packages, repodata, packuments, simple pages, maven-metadata,
	// helm and cargo indexes, Go version lists). The largest real ones are
	// tens of MiB; a hostile upstream must not make the proxy spool and store
	// gigabytes under a metadata name.
	DefaultMaxMetadata int64 = 256 << 20

	// DefaultUpstreamStallTimeout is how long an upstream response body may
	// deliver no data before the fetch fails, so a dead connection releases
	// its flight (and the requests waiting on it) in a minute rather than
	// holding it until fetchTimeout.
	DefaultUpstreamStallTimeout = 60 * time.Second
)
View Source
const DefaultMaxCondaIndex int64 = 2 << 30

DefaultMaxCondaIndex caps one repodata file fetched from a conda upstream, both as downloaded and decompressed. The conda-forge linux-64 repodata.json is about 460 MB (59 MB as .zst) and keeps growing, far beyond what any other format's index reaches, so it has a limit of its own.

Variables

View Source
var ErrBlocked = errors.New("proxy: repository is blocked")

ErrBlocked is returned by Open for a blocked proxy repository.

View Source
var ErrNotFound = errors.New("proxy: not found upstream")

ErrNotFound is returned by Open for a file the upstream does not have.

Functions

func CleanPath added in v0.4.0

func CleanPath(p string) (string, bool)

CleanPath validates a client-supplied repository-relative path and returns it without the leading slash. Empty paths, directory paths (trailing slash), empty/dot/dot-dot segments, backslashes and control characters are refused: the path is appended to the upstream URL and must not be able to escape it.

func Immutable added in v0.4.0

func Immutable(format, key string) bool

Immutable reports whether the file at key never changes once published, so a cached copy never needs revalidation. Formats whose bodies are verified against a published digest (see fetchOpts) pin by name alone; the ones that have no such check here (Maven, deb, rpm, pacman) pin only under layouts whose file names are never reused, and everything else is cached for the repository TTL so a wrong copy is replaced on revalidation:

  • maven: released artifacts, not maven-metadata*.xml, archetype-catalog.xml (both are regenerated in place) or -SNAPSHOT files; a checksum or signature file (.md5 .sha1 .sha256 .sha512 .asc) is as immutable as the file it belongs to.
  • ivy, sbt: released files, not checksum or signature files, maven-metadata*.xml or -SNAPSHOT files; a file is pinned only when its body matched the checksum the upstream publishes (ivy.go), otherwise the repository TTL applies.
  • pacman: nothing. A mirror may republish a package file name, so package files use the repository TTL.
  • apk: `.apk` files of a `<branch>/<repo>/<arch>/<file>` key; they are only cached once their checksum matched the upstream index (apk.go).
  • deb: .deb/.udeb below a pool/ directory (the Debian archive layout, where a file name is never reused); the same names in a flat repository, where a publisher may overwrite a package, use the repository TTL.
  • rpm: .rpm below a Packages/ directory (the layout of Fedora, CentOS, RHEL and most vendor repositories, whose NEVRA-named files are not rebuilt in place); flat or other layouts use the repository TTL. No cheap integrity signal (the repodata checksums are not checked by this proxy) exists to pin the rest.

Types

type Service added in v0.4.0

type Service struct {
	// contains filtered or unexported fields
}

Service fetches and caches upstream files for proxy repositories.

func NewService added in v0.4.0

func NewService(log *logger.Logger, db database.Database, blobStore storage.BlobStore) *Service

NewService creates the proxy service. Upstream requests use an SSRF-safe client: blocked destination addresses are refused at dial time and on every redirect hop.

func (*Service) Open added in v0.8.0

func (s *Service) Open(ctx context.Context, repo *models.Repository, relPath string) (io.ReadCloser, error)

Open returns the body of relPath of a path-mirrored proxy repository (deb, rpm, maven, raw), fetching and caching it exactly as Serve would. It is for server-side consumers of upstream metadata (deb/rpm groups merging a proxy member's indexes), which read it once and must see what a client of the proxy would. An expired entry is revalidated, and served stale when the upstream is down within the repository's max-stale window. ErrNotFound is returned for an upstream 404; any other error means the file could not be obtained. The caller closes the reader.

func (*Service) Serve added in v0.4.0

func (s *Service) Serve(w http.ResponseWriter, r *http.Request, repo *models.Repository, relPath string)

Serve answers a GET/HEAD for relPath (the path below the repository root) of proxy repo.

func (*Service) ServeOCI added in v0.6.0

func (s *Service) ServeOCI(w http.ResponseWriter, r *http.Request, repo *models.Repository, req ocipath.Request)

ServeOCI answers a request under /v2/ for the docker proxy repository repo: manifests and blobs are pulled through (and cached), tag and referrer listings are passed through, anything that would write is refused. req is the parsed /v2/<repo>/<image>/... path.

func (*Service) ServeTerraformDownload added in v0.13.0

func (s *Service) ServeTerraformDownload(w http.ResponseWriter, r *http.Request, repo *models.Repository, d terraform.Download)

ServeTerraformDownload serves the file a ticket of proxy repo names, fetching it from its upstream host first when it is not cached (terraform.ProxyServer). The ticket's coordinates were validated by the caller; the requested file name must be the one the documents served by this proxy carry.

func (*Service) SetBaseURL added in v0.6.0

func (s *Service) SetBaseURL(baseURL string)

SetBaseURL sets the server base URL that rewritten tarball URLs point at (the value hosted npm repositories use). Call it before serving requests.

func (*Service) WithDockerDigestTTL added in v0.8.0

func (s *Service) WithDockerDigestTTL(ttl time.Duration) *Service

WithDockerDigestTTL sets how long a docker manifest or blob addressed by digest stays cached without being used. Such an entry never changes, so until now it never expired; with a positive ttl the cache worker evicts it (and its blob, once no other entry references it) after ttl without a pull, and every pull that finds it past half its lifetime renews it. 0 keeps the old behavior. It must be called before the service serves requests.

func (*Service) WithTerraformTicketKey added in v0.13.0

func (s *Service) WithTerraformTicketKey(secret []byte) *Service

WithTerraformTicketKey sets the server HMAC secret the download tickets of Terraform proxy repositories are signed with (the secret the hosted registry verifies them with). Without it such repositories answer downloads with 503. Call it before serving requests.

func (*Service) WithUpstreamStallTimeout added in v0.13.0

func (s *Service) WithUpstreamStallTimeout(d time.Duration) *Service

WithUpstreamStallTimeout sets how long an upstream response body may deliver no data before the fetch fails (DefaultUpstreamStallTimeout by default); 0 disables the check. It must be called before the service serves requests.

Jump to

Keyboard shortcuts

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