Documentation
¶
Overview ¶
Package upstream is the outbound HTTP of remote repositories: the client and its pool, credential, cookie, client certificate and proxy resolution, destination and TLS security, and the Docker registry client with its challenge and token exchange. It sends what core remote decides to fetch and never decides whether to fetch or what to cache.
Role ¶
artifacts module, adapter layer: outbound HTTP to remote origins. It implements core remote's ports, remote.Upstream (Pool) and remote.Registries (RegistryClients), which the application binds; core remote and Smart Remote reach origins only through those ports and never import this package (decision 0044, dependency rule 8).
Inputs ¶
- Driving: the shared remote policy, Smart Remote and the format slices' upstream rules, through remote.Upstream and remote.Connection (Fetch, Do, and for Smart's own requests Guarded, CheckURL, Prepare and Send); the Docker rules through remote.Registries; and the application, which builds the pools and the resolver.
- The repository configuration, the resolved remote.Options and each remote.Request, and the request-scoped remote.Outbound hooks, which Do applies to the first request and its redirects.
- Driven: the resolver's store, ResolverStore (repository configurations and their sealed credentials, headers and cookies, and the proxy configuration documents), the keyring that unseals them and derives the credential revision, and the access API's Keys, which hold the client certificates a remote names.
Outputs ¶
- Pool, the remote.Upstream of ordinary remotes, with Client and NewClient; Resolver, NewResolver and ResolverOptions, which turn a repository into its remote.Options and credential revision, ResolverStore, the store a Resolver reads, and StoreFault, the store's error behind options it failed to read.
- RegistryPool, Registry, NewRegistry and RegistryOptions, the Docker registry clients, and RegistryClients, the remote.Registries over them; ErrRegistryChallenge.
Invariants ¶
- DNS answers are validated together and pinned: the transport dials the addresses it checked, so a second lookup cannot swap a public address for a private one.
- Private networks are reachable only for authorities the operator configured, and known cloud metadata endpoints are always denied.
- Credentials go to another origin only with allowAnyHostAuth and HTTPS; a caller's own Authorization, API keys and cookies are never forwarded.
- The caller owns every response body that a successful Fetch, Do or Send returns, and closes it.
- Registry tokens are isolated by source identity, credential revision, image, service and scope, and never follow a redirect to a CDN or to another image.
- The remote: sentinel texts, ErrRegistryChallenge's text and the redirect, proxy and destination behaviour stay byte-identical.
References ¶
- Decision 0007: docs/research/decisions/0007-remote-repositories.md (transport #617, source security #618, registry authentication #623: https://github.com/weaveplatform/artifactweave/issues/617, https://github.com/weaveplatform/artifactweave/issues/618 and https://github.com/weaveplatform/artifactweave/issues/623).
- docs/implementation/remote-http-transport.md and docs/implementation/remote-registry-authentication.md.
- Decision 0017: docs/research/decisions/0017-sealed-columns-and-master-key.md (sealed remote passwords, headers and proxy passwords).
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md, "Remote is split fully" (the ports live in core remote; url.go and destination.go are split; the registry client is here).
- JFrog remote repository and proxy documentation: https://docs.jfrog.com/artifactory/docs/remote-repositories and https://docs.jfrog.com/administration/docs/manage-proxy-servers.
- Target layout: docs/research/architecture-options/5-modular-monolith.md, lines 254 to 256 (adapters/upstream), lines 647 to 652 (its file list) and line 1013 (the mapping row).
- Plan: docs/implementation/plan.md#p9-remote-repositories and #p9d-modular-monolith-migration, epic RMT (https://github.com/weaveplatform/artifactweave/issues/942).
- https://github.com/weaveplatform/artifactweave/issues/1026 and https://github.com/weaveplatform/artifactweave/issues/1091
Status ¶
Implemented P9. Moved here in P9d, which narrowed the resolver's store to ResolverStore (https://github.com/weaveplatform/artifactweave/issues/1091).
Testing ¶
- client_test.go and client_guard_test.go: fetches and validators, HEAD fallback, URL preservation, proxies, TLS and binding, redirects, cancellation and deadlines, the pool, the Connection contract and the request destination guard.
- credentials_test.go: the resolver's sealed credentials and rotation, redirect credentials, cookies, client certificates, proxies and DNS pinning, over the in-memory and SQLite stores.
- destination_test.go: the destination policy, mixed DNS answers, rebinding and the security transport's pools.
- outbound_test.go: the outbound hooks on requests and redirects.
- p2_child_auth_test.go: P2 child repositories and credentials.
- store_fault_test.go: a statement the store fails to run as the resolver reads a repository, its proxy or its client certificate fails the options with remote.ErrConfiguration and keeps the store's error for StoreFault.
- registry_test.go and registry_challenge_test.go: the registry exchange, its coalescing, denial, redirects and token faults, and the challenge grammar.
- registry_feature_test.go: the godog scenarios of testdata/registry_auth.feature.
- Core remote and Smart Remote tests build a pool and a resolver through upstreamtest.
Index ¶
- Variables
- func StoreFault(err error) error
- type Client
- func (c *Client) CheckURL(ctx context.Context, u *url.URL) error
- func (c *Client) Close()
- func (c *Client) Do(ctx context.Context, r remote.Request) (*http.Response, error)
- func (c *Client) Fetch(ctx context.Context, r remote.Request) (*http.Response, error)
- func (c *Client) Guarded() bool
- func (c *Client) Prepare(req *http.Request) error
- func (c *Client) Send(req *http.Request) (*http.Response, error)
- type Pool
- type Registry
- type RegistryClients
- type RegistryOptions
- type RegistryPool
- type Resolver
- type ResolverOptions
- type ResolverStore
Constants ¶
This section is empty.
Variables ¶
var ErrRegistryChallenge = errors.New("remote: invalid upstream registry authentication challenge")
ErrRegistryChallenge reports an upstream registry's authentication challenge that the registry client cannot answer: a malformed WWW-Authenticate header, or a Bearer challenge to a repository without token authentication. Its text keeps the remote: prefix of the transport's other sentinels.
Functions ¶
func StoreFault ¶
StoreFault is the store's error behind err, an error of Resolver.Options, when the options failed because a statement the store ran failed (kernel.ErrStore), and nil otherwise.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is immutable and safe for concurrent use. Every successful Do or Fetch transfers response-body ownership to the caller, including non-2xx responses.
func NewClient ¶
NewClient builds the client of repository c under its resolved options, as a Pool does for each configuration and credential revision. It copies c's pointer-valued settings, so a later change to c never reaches the client. An invalid repository URL is refused with remote.ErrURL; a negative timeout, a local address that is no IP address or a proxy that is neither HTTP nor HTTPS with remote.ErrConfiguration.
func (*Client) CheckURL ¶
CheckURL applies remote.Options.CheckURL to u, and returns remote.ErrSecurity when c has none, so that an unguarded client never vouches for a destination.
func (*Client) Close ¶
func (c *Client) Close()
Close releases the client's idle connections; requests in flight finish on their own connections.
func (*Client) Do ¶
Do sends r, a GET or HEAD relative to the repository URL, or to r.ExternalURL when the client has a CheckURL, and returns the response whatever its status; the caller owns and closes its body. The only POSTs it admits are a closed set of protocol exchanges (the VS Code gallery query, the Git LFS batch call and a CocoaPods Git upload-pack), each with its exact path, size and Accept header. It applies the request's and the options' checks, the credential preparation, the metadata deadline to a metadata request, and the WithOutbound hooks. A refused request answers remote.ErrRequest or remote.ErrSecurity; a transport failure comes back classified, without the URL or headers it carried.
func (*Client) Fetch ¶
Fetch probes with HEAD unless bypassed. An unsupported HEAD falls back to GET; a definitive error or conditional 304 is returned directly. GET is authoritative when the resource changes between requests: no HEAD length/checksum is reused.
func (*Client) Guarded ¶
Guarded reports whether c was built with remote.Options.CheckURL, the check that every absolute destination taken from metadata must pass.
func (*Client) Prepare ¶
Prepare applies remote.Options.Prepare to req, a request its caller built rather than Do; without one it does nothing and returns nil.
func (*Client) Send ¶
Send sends req over c's transport, proxy, TLS settings and cookie jar included, and refuses every redirect with remote.ErrRedirect, because a request built outside Do has none of the redirect checks Do installs. It applies neither Do's checks nor the WithOutbound hooks; its caller checks and prepares req first. The error is the HTTP client's own, unwrapped and not classified, and a successful call transfers response-body ownership.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool reuses a repository's connections until its configuration or resolved credential revision changes. Remove closes a deleted repository's idle clients; Close drains all idle clients during application shutdown. Active requests are owned by their caller contexts and may finish against the previous revision.
func (*Pool) Client ¶
Client returns the pooled client of repository c, or builds one with NewClient when c's configuration or opts.Revision changed since the last, closing the client it replaces. It answers remote.ErrClosed after Close, and NewClient's errors. Safe for concurrent use.
func (*Pool) Close ¶
func (p *Pool) Close()
Close closes every pooled client, for application shutdown; every later Client answers remote.ErrClosed.
func (*Pool) Connection ¶
Connection returns Client(c, opts) as the Upstream port's Connection, with Client's errors, remote.ErrClosed after Close among them. On error it returns a literal nil, never a nil *Client inside the interface, which would compare unequal to nil.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry authenticates read-only Distribution v2 requests. It is bound to one resolved repository revision; RegistryPool also fences its source incarnation. Native adapters own authorization, cache publication and digest validation.
func NewRegistry ¶
func NewRegistry(c repo.Config, opts RegistryOptions) (*Registry, error)
NewRegistry builds the registry client of remote Docker, OCI or Helm OCI repository c under opts, which Resolver.RegistryOptions returns: a Distribution v2 client whose own Prepare replaces any Authorization with the scoped Basic or Bearer exchange, and which keeps no cookies. A repository of another class or type, options without Prepare, CheckURL or a revision, an unsupported Docker API version or an invalid project ID is refused with remote.ErrConfiguration.
func (*Registry) Base ¶
Base returns a copy of the registry's base URL, so that no caller can change where the client sends its requests.
func (*Registry) Close ¶
func (r *Registry) Close()
Close releases the registry client's idle connections.
func (*Registry) Do ¶
Do addresses a registry resource relative to an image, for example Do(ctx, "team/image", Request{Method: "GET", Path: "manifests/latest"}). A request retries authentication at most once. All returned bodies are owned by the caller, including terminal non-authentication error statuses.
type RegistryClients ¶
type RegistryClients struct {
Pool *RegistryPool
Options func(context.Context, repo.Config) (RegistryOptions, error)
}
RegistryClients implements Registries over the application's RegistryPool and the resolver's registry options (Resolver.RegistryOptions).
func (*RegistryClients) Foreign ¶
func (r *RegistryClients) Foreign( ctx context.Context, c repo.Config, opts remote.Options, q remote.Request, ) (*http.Response, error)
Foreign sends q once through a client built from opts for c, and closes it, for a foreign layer a manifest names (decision 0031). It is unpooled on purpose: the pool's fingerprint covers the repository, the source identity and the credential revision but not opts.Prepare and opts.CheckRedirect, which the caller sets to strip registry credentials and custom headers from a foreign layer's request, so a pooled client could send them (decision 0007).
func (*RegistryClients) Open ¶
func (r *RegistryClients) Open( ctx context.Context, c repo.Config, id model.SourceIdentity, revision string, ) (remote.RegistryClient, error)
Open resolves c's registry options, refuses with source.ErrSuperseded when their credential revision is not revision, the one the read was admitted under, and returns the pool's client for c and id. On every error it returns a literal nil, never a nil *Registry inside a non-nil RegistryClient, which a caller that checks the client for nil would go on to use.
type RegistryOptions ¶
type RegistryOptions struct {
Transport remote.Options
Now func() time.Time
// contains filtered or unexported fields
}
RegistryOptions comes from Resolver.RegistryOptions, never downstream headers. Now is an optional clock for deterministic expiry tests.
type RegistryPool ¶
type RegistryPool struct {
// contains filtered or unexported fields
}
RegistryPool owns token and connection lifetimes. A changed repository incarnation, source generation or credential revision starts an empty cache.
func (*RegistryPool) Client ¶
func (p *RegistryPool) Client( c repo.Config, identity model.SourceIdentity, opts RegistryOptions, ) (*Registry, error)
Client returns the pooled registry client of repository c for the source identity, or builds one with NewRegistry when c, the identity or the credential revision changed, closing the one it replaces, so its tokens and challenges start empty. An identity that is not a complete external HTTP source answers remote.ErrConfiguration, a closed pool remote.ErrClosed.
func (*RegistryPool) Close ¶
func (p *RegistryPool) Close()
Close closes every pooled registry client, for application shutdown; every later Client answers remote.ErrClosed.
func (*RegistryPool) Remove ¶
func (p *RegistryPool) Remove(key string)
Remove closes and forgets the registry client of the repository named key, with its tokens.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver turns a stored repository configuration into the transport's remote.Options: its sealed credentials, headers, cookies, client certificate and proxy, the destination policy, and the credential revision that fences the remote cache against credential changes. It is safe for concurrent use.
func NewResolver ¶
func NewResolver( st ResolverStore, keyring *crypt.Keyring, opts ResolverOptions, ) (*Resolver, error)
NewResolver returns the resolver over st. The credential revision key is derived from keyring when there is one, else it is opts.RevisionKey, which must then be at least 32 bytes and not all zero; otherwise, without a store, or with an AllowedPrivateOrigins entry that is no checked URL, it answers remote.ErrConfiguration. Root certificates that cannot be loaded answer remote.ErrSecurity.
func (*Resolver) Options ¶
Options reloads sealed secrets through the store, rather than treating an API's masked view as usable credentials. A stale non-secret configuration fails closed. Revision is a stable HMAC of source-affecting settings, not cache/access policy.
func (*Resolver) RegistryOptions ¶
RegistryOptions preserves the shared destination, proxy and TLS policy while keeping registry Basic credentials separate from ordinary HTTP Bearer mode.
type ResolverOptions ¶
type ResolverOptions struct {
// RevisionKey is trusted, stable application key material for installations
// without a master key. It never comes from a repository or HTTP request.
RevisionKey []byte
RootCAsPEM []byte
AllowedPrivateOrigins []string
LookupIP func(context.Context, string) ([]net.IPAddr, error)
// Certificates reads the client TLS certificate, private key unsealed,
// that a remote names in clientTlsCertificate. The resolver reads it only
// for such a remote, so it must be set wherever a remote can name one.
// Any error it returns fails that remote's options with ErrConfiguration,
// except an ended context, which fails them as a request error.
Certificates accessapi.Keys
}
ResolverOptions is trusted application configuration, never upstream metadata. RootCAsPEM augments system trust. AllowedPrivateOrigins grants exact additional authorities private-network access without authorizing credential forwarding. LookupIP is injectable for deterministic DNS/rebinding tests; nil uses net.Resolver.
type ResolverStore ¶
type ResolverStore interface {
Repos() port.RepoStore
Configs() configdoc.ConfigStore
}
ResolverStore is what Resolver reads: the stored repository (its sealed credentials, headers and security settings, which the store unseals on read) and the proxy configuration documents. Each composite store in app is a ResolverStore.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fakeupstream provides deterministic, loopback-only HTTP fixtures for remote repository tests: chi fakes of upstream registries with fault modes, request recording, a clock, barriers, TLS and a restricted forward proxy.
|
Package fakeupstream provides deterministic, loopback-only HTTP fixtures for remote repository tests: chi fakes of upstream registries with fault modes, request recording, a clock, barriers, TLS and a restricted forward proxy. |
|
Package upstreamtest gives tests the upstream transport's pool and credential resolver without importing the transport: core remote's and Smart Remote's tests may not import their own module's adapters (decision 0044, dependency rule 8), but test files may import any test support package (rule 1).
|
Package upstreamtest gives tests the upstream transport's pool and credential resolver without importing the transport: core remote's and Smart Remote's tests may not import their own module's adapters (decision 0044, dependency rule 8), but test files may import any test support package (rule 1). |