Documentation
¶
Overview ¶
Package dockerhttp serves the registry protocol, the OCI Distribution Specification v1.1 with Docker's extensions, for docker, oci and helmoci repositories (decisions 0003 and 0031). It answers three addressing forms:
- the repository path, /v2/<repo>/<image>/..., the native default, which needs no reverse proxy;
- Artifactory's own prefix, /artifactory/api/docker/<repo>/v2/<image>/...;
- the subdomain, <repo>.<base_url host>/v2/<image>/..., when docker.subdomain_match is on.
The router is hand-written and mounted before the generated servers (decision 0002). It parses each path into a Request and hands it to the endpoint a feature registered for its kind and method; an operation the specification defines that no feature has registered yet answers 405 UNSUPPORTED. Beside the registry, the Docker partial strict server (DockerAPI) answers the JFrog REST operations under a repository's Docker API path: tag delete, promotion and parent manifest lists.
Role ¶
artifacts module, ecosystem layer: the registry protocol of the registry slice, /v2 with registry tokens and subdomain routing, one protocol for the package types docker, oci and helmoci. It is named dockerhttp so that it does not shadow net/http. Outside tests, only its own http subtree, the module's http adapters and app may import it (decision 0044, dependency rule 9).
Inputs ¶
- Driving: the server, which builds the Registry with New and mounts it with Register before the generated servers, runs APIVersion and Challenge as middleware, and asks IsRegistryPath and ChallengesAnonymous while it authenticates, normalises content types and answers unimplemented operations. The router also embeds DockerAPI in the artifactory spec's strict server; its operations (rest.go) check image names with ValidName and find repositories with Lookup.
- Driven: the registry's store (Options.Store, an artifacts/core/registry Store), which resolves repositories and reads items, and over which the registry's writes (artifacts/core/registry) keep upload sessions and store blobs, mounts, manifests and deletes through the item service; Lookup reads only repositories, from any format.Store; the format package (artifacts/ecosystem/docker, imported as layout), which names paths, parses manifests, finds blobs, manifests and referrers, and reads tags lists' and catalogs' pages from the item store's page reader (TagPages, ImagePages; #1402); the access module's API (access/api), whose decider each request carries, whose Tokens sign registry tokens (TokenIssuer) and whose Identity reads a user's email; the registry's remote source service (Options.Sources), through which a remote repository's manifests, blobs, tags and referrers are read; the server's download (Options.ServeBlob, Options.RedirectManifest), which applies the download redirect policy (decision 0029) and counts downloads; and the item kit's BareETag (artifacts/adapters/http/itemkit), which gives a local manifest and a remote blob the bare SHA-1 ETag the download gives a file. DockerAPI runs over the item kit, which resolves the caller's access and writes errors, and over its store (itemkit.Store), in which it finds repositories and over which it builds the registry service its deletes and promotions go through.
Outputs ¶
- Registry: New with Options, Register, the Challenge middleware, and the Endpoint, Request and Kind its features register and serve.
- DockerAPI: the Docker partial strict server, whose three operations (DeleteDockerTag, PromoteDockerImage, FindParentManifestLists) answer in the Artifactory envelope.
- Middleware and predicates for the server: APIVersion, IsRegistryPath, ChallengesAnonymous, GrantsCatalog, ValidName, Serves and Lookup.
- Errors in the specification's envelope: Errorf, Write and WriteAll, with the Code constants; and the headers APIVersionHeader and RegistryHeader.
- Answers: the probe, the token endpoint, and the docker config.json entries at .../v2/auth and the legacy .../v1/auth; for a local repository, blob reads, monolithic and chunked uploads and cross-repository mounts, manifest and index pushes, reads and deletes, tags lists, catalogs and referrers; for a remote repository, reads of manifests, blobs, tags and referrers through its cache.
Invariants ¶
- This package never imports the router (internal/app) that mounts it (decision 0031).
- Every registry response carries Docker-Distribution-API-Version, the 401 included, and every 401 under a registry path carries the Bearer challenge Docker clients follow to the token endpoint (decision 0005); a remote's relayed upstream 401 adds error="invalid_request", which ends containerd's retries (#1277). A request without credentials is challenged on every registry path but the token endpoint, even while anonymous access is on. A request the caller's permissions refuse, an anonymous caller's included, answers 403 UNAUTHORIZED with 7.x's message and no challenge, before a registry token's grant is asked (#1276).
- On a server that authenticates every request (Options.Authenticated), a request whose principal carries no decider is refused, never allowed.
- A remote repository answers reads only, and a virtual one 405 UNSUPPORTED.
- The JFrog operations under the Artifactory prefix (promote, parentManifests and delete) are no registry paths and keep the Artifactory envelope.
- Codes, statuses and messages stay byte-identical: docker, crane, oras, cosign, helm and the JFrog CLI read them.
- A local repository's tags list and a catalog read from the store only the page they answer and the name after it, which decides the Link (#1402), and answer, Link included, byte for byte the page cut from the whole sorted list. A page longer than listBuffer is counted, then read again as it streams, up to the name its Link names, so a write in between adds or drops only the written name; a store failure before the first byte answers 500, and one after it ends the connection with the body unclosed (decision 0043).
- A read the download policy refuses, a local or a remote repository's, answers 404 with the policy's message in Artifactory's envelope, under no registry code, as the Docker client showed 7.x's answer (RTFACT-27234); a missing manifest or blob keeps its registry code. Blackout is checked before the item is looked for, the patterns on the copy a pull serves, and a blob is served from any copy in the image the patterns accept (RTFACT-30134). A blacked-out repository also refuses an image's tags list and referrers, naming the image as a remote's refusal does; the patterns refuse neither. The catalog leaves out an image its repository's patterns reject (RTFACT-26524), and a mount from another repository that would refuse the blob opens a session.
- A blob or manifest pull, local or remote, GET or HEAD, answers If-None-Match and If-Modified-Since with 304, and ignores If-Match, If-Unmodified-Since, Range and If-Range (pullRequest), as 7.x's download does: it never answers 412 or 206 (#1337, #1437). It decides them by that download's rule, one If-None-Match line at a time against the file's SHA-1, so "*" and a list on one line never match (pkgroute.FileNotModified; notModified for a local manifest and a blob the registry streams itself, #1483), before any redirect.
- A remote repository's tags list keeps its upstream's list decoded, sorted and without repeats, by the cached document's SHA-256, within remoteTagsBudget (tagCache); a later page reads none of the document, and every page checks Read only on the tags from last to the one after it, with the answers of the whole list filtered and cut (#1423).
- A remote repository's failure to fetch, its upstream's 401, 403, 429 or 5xx or an upstream that is unreachable, unusable or slow, answers its status and message in Artifactory's envelope, under no registry code, as the Docker client showed 7.x's answer to an upstream that refused its credentials (RTFACT-30467, #1248). That 401's message is 7.x's "Invalid username/password configured for Remote Docker repository: <key>". The caller's own refusal answers as Require's does.
References ¶
- Decision 0031: docs/research/decisions/0031-docker-oci-registry.md (protocol and storage layout), and research 23 (docs/research/23-docker-oci-registry.md).
- Decision 0003: docs/research/decisions/0003-repository-model.md (the addressing forms); decision 0005: docs/research/decisions/0005-authentication-and-tokens.md (the registry token); decision 0002: docs/research/decisions/0002-spec-first-flat-crud-handwritten-item-paths.md; decision 0029: docs/research/decisions/0029-cdn-delivery-and-download-redirect.md; decision 0032: docs/research/decisions/0032-package-format-handlers.md (format hooks).
- Research 17: docs/research/17-undocumented-shapes.md (the token endpoint's values).
- docs/operations/registry-remote.md (Docker, OCI and Helm OCI remote repositories) and docs/testing/nimmodel.md (the Docker remote a NIM repository pairs with).
- The OCI Distribution Specification v1.1.1: https://github.com/opencontainers/distribution-spec/blob/v1.1.1/spec.md.
- JFrog's pages decision 0031 cites: https://docs.jfrog.com/artifactory/docs/docker-repositories and https://docs.jfrog.com/artifactory/docs/additional-docker-information.
- Decision 0044: docs/research/decisions/0044-modular-monolith-migration.md, "Dependency rules".
- Decision 0043: docs/research/decisions/0043-api-reliability.md, "Streaming complete lists" (a listing's store failure after its first byte), and issue 1402 (the paged tags lists and catalogs).
- Target layout: docs/research/architecture-options/5-modular-monolith.md, line 229 (ecosystem/docker; http/ holds /v2), line 404 (the root's docker_rest.go, now rest.go) and line 1022 (the mapping row).
- Plan: docs/implementation/plan.md#p6-dockeroci, #p9-remote-repositories and #p9d-modular-monolith-migration, epics ECO (https://github.com/weaveplatform/artifactweave/issues/943) and WEB (https://github.com/weaveplatform/artifactweave/issues/944).
- https://github.com/weaveplatform/artifactweave/issues/220 (routing), https://github.com/weaveplatform/artifactweave/issues/221 (tokens), https://github.com/weaveplatform/artifactweave/issues/222 (blobs), https://github.com/weaveplatform/artifactweave/issues/223 and https://github.com/weaveplatform/artifactweave/issues/225 (manifests, indexes and referrers), https://github.com/weaveplatform/artifactweave/issues/226 (listings and deletes), https://github.com/weaveplatform/artifactweave/issues/624 (remote reads), https://github.com/weaveplatform/artifactweave/issues/1022, https://github.com/weaveplatform/artifactweave/issues/1086, https://github.com/weaveplatform/artifactweave/issues/1089 and https://github.com/weaveplatform/artifactweave/issues/1090
Status ¶
Implemented P6, with remote retrieval in P9. Moved here in P9d, which also moved the server root's Docker REST operations here (WEB-17).
Testing ¶
- docker_test.go: path parsing, image names, registry paths and anonymous challenges, the version header, routing, subdomains, the JFrog operations under the prefix, the probe, store failures, Require, and the refusal of a request without a decider on an authenticated server.
- blobs_test.go: monolithic and chunked uploads, pulls, mounts, permissions, absolute locations, the ServeBlob hook, streaming layers, and store and index failures.
- manifests_test.go and referrers_test.go: pushes and pulls by tag and digest, refusals, body limits, permissions and store failures; indexes and the referrers API.
- tags_test.go: tags lists and pagination, catalogs, deletes, their permissions and failures, and the catalog grant; list_page_test.go: every page of a listing longer than the buffer, and of the registry-wide catalog's merge, byte for byte as the collected list answered it; the rows a page with n reads from the store; a long page that loses no tag to writes while it streams; and a store failure before and after the first byte.
- token_test.go: the token endpoint, its grants, lifetime and parent binding, the challenge and the auth endpoints, on the access test kit (access/accesstest).
- pull_policy_test.go, reject_test.go and remote_listing_test.go: the download policy's refusals of pulls, of tags lists and of referrers, a blob served from a copy the patterns accept, mounts from a refusing source and catalogs the patterns filter; a format's refusals of writes, which keep their status; and a remote listing's final fence.
- remote_tags_test.go: every page of a remote tags list, for callers refused none, all or some tags, byte for byte as the whole list filtered and cut (paginateHeaders, the reference); a later page that reads none of the document and checks only its own tags and the next; documents that do not decode or carry no SHA-256; the cache's eviction.
- stream_none_match_test.go: a blob the registry streams itself answering If-None-Match and If-Modified-Since by 7.x's rule.
- remote_error_test.go: the envelope and code of each failure a remote read answers, and kernel's shared errors left unchanged.
- refusal_test.go: 7.x's refusal message for each kind and method, the permissions asked before a registry token's grant, and a request without a decider on an authenticated server.
- The guard suites test/server/artifacts/docker and test/server/artifacts/helmoci, and the OCI conformance job, drive the registry through the whole server; the docker suite drives DockerAPI's operations too, which have no tests here, as the root file had none.
Index ¶
- Constants
- func APIVersion(next http.Handler) http.Handler
- func ChallengesAnonymous(path string) bool
- func Errorf(status int, code, format string, args ...any) *apierror.Error
- func GrantsCatalog(r *http.Request) bool
- func IsRegistryPath(path string) bool
- func Lookup(ctx context.Context, st format.Store, key string) (repo.Config, bool, error)
- func Serves(t repo.PackageType) bool
- func ValidName(name string) bool
- func Write(w http.ResponseWriter, err error)
- func WriteAll(w http.ResponseWriter, status int, errs ...*apierror.Error)
- type DockerAPI
- func (s DockerAPI) DeleteDockerTag(ctx context.Context, req artgen.DeleteDockerTagRequestObject) (artgen.DeleteDockerTagResponseObject, error)
- func (s DockerAPI) FindParentManifestLists(ctx context.Context, req artgen.FindParentManifestListsRequestObject) (artgen.FindParentManifestListsResponseObject, error)
- func (s DockerAPI) PromoteDockerImage(ctx context.Context, req artgen.PromoteDockerImageRequestObject) (artgen.PromoteDockerImageResponseObject, error)
- type Endpoint
- type Kind
- type Options
- type Registry
- type Request
- type TokenIssuer
Constants ¶
const ( CodeBlobUnknown = "BLOB_UNKNOWN" CodeBlobUploadInvalid = "BLOB_UPLOAD_INVALID" CodeBlobUploadUnknown = "BLOB_UPLOAD_UNKNOWN" CodeDigestInvalid = "DIGEST_INVALID" CodeManifestBlobUnknown = "MANIFEST_BLOB_UNKNOWN" CodeManifestInvalid = "MANIFEST_INVALID" CodeManifestUnknown = "MANIFEST_UNKNOWN" CodeNameInvalid = "NAME_INVALID" CodeNameUnknown = "NAME_UNKNOWN" CodeSizeInvalid = "SIZE_INVALID" CodeDenied = "DENIED" CodeUnsupported = "UNSUPPORTED" CodeTooManyRequests = "TOOMANYREQUESTS" // CodeTagInvalid is the one code outside the specification's list: a // push to a tag that would collide with the layout's own folders // (decision 0031). CodeTagInvalid = "TAG_INVALID" )
The error codes of the OCI Distribution Specification v1.1 (code-1 to code-14). Docker clients branch on the code, not the message, so every registry error carries one of these.
const (
APIVersionHeader = "Docker-Distribution-API-Version"
)
APIVersionHeader is the header every registry response carries. Docker clients read it from the /v2/ probe, the 401 included, to know that they reached a v2 registry.
const RegistryHeader = "X-Artifactory-Docker-Registry"
RegistryHeader names, on a manifest read, the repository that holds the manifest, by its stored key. jf docker push and pull HEAD the manifest through the registry after the docker client finishes and read the key from here; without it they fail before collecting build-info (jfrog-cli-artifactory ocicontainer/image.go, GetRemoteRepo).
Variables ¶
This section is empty.
Functions ¶
func APIVersion ¶
APIVersion sets the version header on every registry response, before authentication can answer one.
func ChallengesAnonymous ¶
ChallengesAnonymous reports whether a request to path without credentials is challenged even while anonymous access is on: every registry path but the token endpoint, from which an anonymous client fetches the anonymous token it then pulls with (decision 0031).
func Errorf ¶
Errorf builds a registry error: the status, the specification's code and a message for people. Write renders it in the OCI envelope.
func GrantsCatalog ¶
GrantsCatalog reports whether the request's credential may list the catalog: any but a registry token without registry:catalog:*.
func IsRegistryPath ¶
IsRegistryPath reports whether path is under /v2 or a repository's /artifactory/api/docker/<repo>/v2.
func Lookup ¶
Lookup finds the Docker, OCI or Helm OCI repository key names in st, compared without regard to case: keys are unique that way, and Docker clients send references in lower case only (decision 0003). found is false for a missing repository and for one of another package type.
func Serves ¶
func Serves(t repo.PackageType) bool
Serves reports whether the registry serves repositories of package type t: docker, and the oci and helmoci types that share its protocol (research 04).
func Write ¶
func Write(w http.ResponseWriter, err error)
Write renders err in the OCI envelope. An error that is not an *apierror.Error becomes a 500 without its detail, as everywhere else.
Types ¶
type DockerAPI ¶
DockerAPI is the Docker ecosystem's partial strict server: the JFrog REST operations under a repository's Docker API path (tag delete, promotion and parent manifest lists), over the item kit. They are no registry paths, so they answer in the Artifactory envelope, not the registry's.
func (DockerAPI) DeleteDockerTag ¶
func (s DockerAPI) DeleteDockerTag( ctx context.Context, req artgen.DeleteDockerTagRequestObject, ) (artgen.DeleteDockerTagResponseObject, error)
DeleteDockerTag is the multi-architecture tag delete, the JFrog REST operation under a repository's Docker API path (decision 0031): the tag folder goes, with a list's platform manifests nothing else in the image references. It answers in the Artifactory envelope, as the other JFrog operations there do.
func (DockerAPI) FindParentManifestLists ¶
func (s DockerAPI) FindParentManifestLists( ctx context.Context, req artgen.FindParentManifestListsRequestObject, ) (artgen.FindParentManifestListsResponseObject, error)
FindParentManifestLists answers which manifest lists and image indexes of an image name the manifest a tag holds (decision 0031).
func (DockerAPI) PromoteDockerImage ¶
func (s DockerAPI) PromoteDockerImage( ctx context.Context, req artgen.PromoteDockerImageRequestObject, ) (artgen.PromoteDockerImageResponseObject, error)
PromoteDockerImage copies or moves one tag, or every tag, of an image to another local or federated repository of the same package type, under the same or another name and tag (decision 0031). It answers in the Artifactory envelope, with plain text on success as Artifactory does; jf rt docker-promote checks only the status.
type Endpoint ¶
type Endpoint func(w http.ResponseWriter, r *http.Request, q Request)
Endpoint serves one registry operation for a parsed request.
type Kind ¶
type Kind int
Kind is the registry operation a path addresses, before its method picks the endpoint.
const ( // KindBase is the empty path, the version probe clients send first. KindBase Kind = iota + 1 // KindCatalog is _catalog, Docker's listing of image names: of every // repository the caller can read on the repository path, of one // repository under a subdomain, as <repo>/_catalog or under the // Artifactory prefix (decision 0003). KindCatalog // KindToken is token, the registry token endpoint. KindToken // KindAuth is auth under the Artifactory prefix, which answers the // config.json entry. KindAuth // KindBlob is <name>/blobs/<digest>. KindBlob // KindUploads is <name>/blobs/uploads/, which starts an upload. KindUploads // KindUpload is <name>/blobs/uploads/<session>, one upload in progress. KindUpload // KindManifest is <name>/manifests/<tag or digest>. KindManifest // KindTags is <name>/tags/list. KindTags // KindReferrers is <name>/referrers/<digest>. KindReferrers )
The kinds of registry path. Their comments show the path below /v2/, where <name> is the image name and, on the repository-path method, begins with the repository key.
type Options ¶
type Options struct {
Sources *source.Service
// Store resolves repositories. Nil serves no repository, for tests of
// the router alone.
Store registry.Store
// SubdomainMatch turns on the subdomain method. BaseURL must then be
// set: its host is the parent the repository subdomains sit under.
SubdomainMatch bool
BaseURL string
// Fault records an unexpected error for the access log, as the server's
// handlers do; nil drops it.
Fault func(*http.Request, error)
// Blobs is the blob store behind Store. Nil leaves blobs and uploads
// unimplemented, for tests of the router alone.
Blobs blob.Store
// Formats returns a package type's format for the items that uploads,
// manifest pushes and mounts write through the item service; nil means
// the generic handler, which indexes no image or tag.
Formats format.Registry
// ServeBlob answers a GET or HEAD of a blob's item in a repository with
// the server's download, which sends a file's headers, applies the
// download redirect policy to a GET (decision 0029) and counts the
// download. Nil streams it from Blobs.
ServeBlob func(w http.ResponseWriter, r *http.Request, c repo.Config, it model.Item)
// RedirectManifest answers a GET of a manifest's item, whose media type
// is mediaType, with the server's download redirect when the policy says
// so (decision 0029), and reports whether it wrote a response. Nil
// streams every manifest.
RedirectManifest func(
w http.ResponseWriter, r *http.Request, c repo.Config, it model.Item, mediaType string,
) bool
// Now supplies the time to upload sessions; nil means time.Now.
Now func() time.Time
// Tokens signs registry tokens; nil leaves the token endpoint
// unimplemented.
Tokens TokenIssuer
// Identity reads the email of the user a config.json entry names
// (writeAuth); nil leaves the email empty, for tests of the router
// alone. A user it does not know, as an OIDC token may name, has no
// email, and any other error answers 500.
Identity accessapi.Identity
// Authenticated is set when the server authenticates every request
// before the registry sees it and stores each principal with the
// decider that authorised it. A request without a decider is then
// refused rather than allowed (Require), so a principal that reaches
// the registry without its permissions can never act unchecked.
Authenticated bool
}
Options configures a Registry.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry routes registry requests to the endpoints features register.
func (*Registry) Challenge ¶
Challenge gives every 401 from the registry the Bearer challenge Docker clients follow to the token endpoint (decision 0005), whoever wrote it: the authentication middleware, a handler's Require, or a later feature. A 401 written with apierror's default Basic challenge, or none, gets the registry's; one a handler challenged itself (a mount's second scope) keeps its own. It must run after the base-URL middleware.
func (*Registry) Register ¶
Register mounts the registry on r for every method, so that the registry answers 405 itself, in its own envelope. Under the Artifactory prefix chi prefers the generated JFrog operations' literal segments (POST parentManifests, POST promote, DELETE delete) to these catch-alls, so those keep their generated handlers (decision 0003). The JFrog catalog and tags list are the registry's own operations, marked x-handwritten in the specification; they are registered under the patterns the specification gives them as well, so that the server's stubs for unimplemented hand-written operations never claim them.
type Request ¶
type Request struct {
Kind Kind
// RepoKey is the repository the request addressed: the subdomain, or
// the key in /artifactory/api/docker/<key>/v2. It is empty for /v2/,
// /v2/_catalog and /v2/token on the repository path, which address no
// repository, and may be "null", which the token realm uses for that
// (research 17). Only an operation on an image resolves it into Repo.
RepoKey string
// Repo is the resolved repository, set when Kind is an image operation.
Repo repo.Config
// Name is the image name inside the repository.
Name string
// Reference is the digest, tag or upload session the path ends in.
Reference string
// contains filtered or unexported fields
}
Request is a registry request with its operation parsed and, for an operation on an image, its repository resolved and its name validated.
func (Request) Path ¶
Path returns the absolute path of an operation on the request's image in the addressing form the client used, for Location headers: the client may only know the registry by that form. Path("blobs", "uploads", id) is .../<name>/blobs/uploads/<id>.
func (Request) Require ¶
Require answers nil when the caller holds every action in want on path, a path inside the repository, and a registry token it presents grants them for the image as this request names it. A caller the permissions refuse gets 7.x's refusal (refuse). The permissions are asked before the token's grant: the token endpoint leaves out what the caller may not do, so the other way round a docker pull by a user without Read would answer the token's 401 instead of the 403 every 7.x capture of a refused pull shows, and containerd would fetch a token and ask again up to five times. A token without an action the caller does hold gets UNAUTHORIZED with 401, whose challenge (Challenge) names the scope the client then fetches a token for, as Docker's registry answers an insufficient scope. A request without a permission decider reaches the handler on a server built without authentication, which only tests build, and is allowed. On a server that authenticates every request (Options.Authenticated) a principal stored without its decider is refused as one without the right, so that it is never allowed everything, and a request with no principal at all as one without credentials.
type TokenIssuer ¶
type TokenIssuer interface {
IssueRegistry(
ctx context.Context,
r accessapi.RegistryTokenRequest,
) (accessapi.IssuedToken, error)
}
TokenIssuer signs registry tokens. IssueRegistry is accessapi.Tokens', which satisfies it, with that contract's errors, which the token endpoint answers as they come.