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 ¶
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.
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).
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 ¶
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.