registryauth

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 9 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 registryauth adds the credential of a private registry or mirror (PRD F16) to every request of a source's HTTP client, so the sources themselves stay credential-free.

The credential is a stored secret resolved by name on every request (ADR 0024: values are not cached, and a reference needs a host binding) or a token read from the environment at startup. Each hop of a redirect is a request of its own, so it is checked too: a stored secret is sent only to the hosts it is bound to, an environment token only to the host of the source's base URL, and nothing that carries a credential goes in clear text through a proxy. A refusal is an error naming the secret and the host, never the value.

Index

Constants

This section is empty.

Variables

View Source
var ErrClearProxy = errors.New("registryauth: credential refused over plain http through a proxy")

ErrClearProxy is wrapped when a credential would reach a proxy as plain http, or when the proxy cannot be chosen.

View Source
var ErrClearText = errors.New("registryauth: credential refused over plain http to a host outside http.allow_http_hosts")

ErrClearText is wrapped when a credential would be sent over plain http to a host that is not in http.allow_http_hosts (decision D12, as for webhooks).

View Source
var ErrUnbound = errors.New("registryauth: secret has no host binding")

ErrUnbound is wrapped when a secret referenced by a source has no hosts: a source credential must be bound (ADR 0024 §2).

Functions

func CheckRefs

func CheckRefs(refs []Ref, hosts map[string][]string) []error

CheckRefs checks, from metadata only (nothing is decrypted), that each referenced secret exists and that its hosts include its registry's host and port. hosts maps a secret name to its hosts. It returns one error per problem, in the order of refs.

func Wrap

func Wrap(hc *http.Client, c Config) *http.Client

Wrap returns a client like hc whose requests carry the credential. hc is not changed. With no credential configured it returns hc.

Types

type Config

type Config struct {
	// TokenRef names the stored secret sent as "Authorization: Bearer"
	// (type bearer and npm_auth_token, whose header is the same).
	TokenRef string
	// PasswordRef names the stored secret sent with Username as HTTP basic
	// authentication. At most one of TokenRef and PasswordRef is set.
	PasswordRef string
	// Username is the basic-auth user name.
	Username string
	// Token is a token already read from the environment (token_env). It
	// is sent only to the host of BaseURL.
	Token secrets.Value
	// Resolver resolves the *Ref names; nil makes every request that
	// needs one fail.
	Resolver Resolver
	// BaseURL is the source's base URL, whose host an environment Token is
	// bound to.
	BaseURL *url.URL
	// Proxy chooses the proxy of a request, as http.Transport.Proxy does. It
	// must be the function the transport under the client uses (the
	// process passes one function to netguard and to this package), or the
	// rule below checks a route the request does not take. An error from it
	// refuses the request. Default http.ProxyFromEnvironment.
	Proxy func(*http.Request) (*url.URL, error)
	// AllowHTTPHosts are the lower-case host names (http.allow_http_hosts)
	// to which a credential may be sent over plain http://. Any other
	// http:// request that needs a credential is refused.
	AllowHTTPHosts []string
}

Config is the credential of one source.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether c carries a credential.

type Ref

type Ref struct {
	// Key is the configuration key, such as "sources.npm.auth.token_ref".
	Key  string
	Name string
	URL  *url.URL
}

Ref is one stored secret a source configuration names, and the registry URL it is sent to.

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, name string, dest *url.URL) (secrets.Bound, error)
}

Resolver turns a secret name into its value for a destination; *secrets.Resolver implements it.

Jump to

Keyboard shortcuts

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