Documentation
¶
Overview ¶
Package registry issues tokens for the private Docker registry (§5.9) using the Docker registry token protocol: clients get a short-lived ES256 JWT from the controller, and the registry verifies it against the issuer certificate.
Index ¶
- Constants
- Variables
- func CompressLayout(dir, ref string) error
- func IsSystemRepo(repo string) bool
- func Parse(body []byte) ([]store.RegistryEvent, error)
- func ParseRef(image string, hosts []string) (repo, tag, digest string, ok bool)
- func ValidateRules(rules []Rule) error
- func Verify(ctx context.Context, b *Browser, want []Repository) error
- func VerifyCopy(ctx context.Context, src, dst *Browser) error
- type Access
- type Browser
- func (b *Browser) DeleteTag(ctx context.Context, repo, tag string) error
- func (b *Browser) Digest(ctx context.Context, repo, ref string) (string, error)
- func (b *Browser) HasImage(ctx context.Context, repo, ref string) (bool, error)
- func (b *Browser) Images(ctx context.Context, repo string) ([]Image, error)
- func (b *Browser) PushLayout(ctx context.Context, repo, tag, dir string) error
- func (b *Browser) Repositories(ctx context.Context) ([]Repository, error)
- type CopyProgress
- type Decision
- type Descriptor
- type Events
- type Image
- type Issuer
- type Repository
- type Rule
Constants ¶
const ( // Service is the registry's token "service" name (aud claim). Service = "syncloud-registry" // IssuerName is the iss claim the registry expects. IssuerName = "syncloud" // TokenTTL keeps tokens short-lived; Docker fetches new ones as needed. TokenTTL = 5 * time.Minute CertFile = "registry-token.crt" )
const BrowserSubject = "syncloud-controller"
BrowserSubject is the token subject the controller reads the registry as.
const EventsRetention = 30 * 24 * time.Hour
EventsRetention is how long individual registry events are kept.
const SystemProject = "syncloud-system"
SystemProject holds the platform's own images in the built-in registry (the release's PostgreSQL images). No project may take the name, and its images are neither expired nor deleted by hand.
Variables ¶
var ErrManifestNotFound = errors.New("not found")
ErrManifestNotFound means the registry has no such repository, tag or blob.
ErrUnavailable means the registry could not be reached.
Functions ¶
func CompressLayout ¶
CompressLayout rewrites a layout from `docker save` so its layers are gzip-compressed (registries and nodes then move a third of the bytes), and names the image ref. The config, and so the image ID, is unchanged.
func IsSystemRepo ¶
IsSystemRepo reports a repository of the platform's own images.
func Parse ¶
func Parse(body []byte) ([]store.RegistryEvent, error)
Parse turns a notification envelope into the events worth keeping.
func ParseRef ¶
ParseRef splits a private-registry image reference into repository, tag and digest. Other images return ok=false.
func ValidateRules ¶
ValidateRules checks rules and sorts them by priority.
func Verify ¶ added in v0.1.9
func Verify(ctx context.Context, b *Browser, want []Repository) error
Verify checks that b lists every repository of want with at least as many tags.
func VerifyCopy ¶ added in v0.1.9
VerifyCopy checks that dst lists every repository of src with at least as many tags. dst's catalog is read the way the registry walks its storage, so an S3 provider that lists objects wrongly is caught here, before the registry switches to it.
Types ¶
type Access ¶
type Access struct {
Type string `json:"type"`
Name string `json:"name"`
Actions []string `json:"actions"`
}
Access is one granted scope, e.g. {repository, shop/api, [pull push]}.
func ParseScope ¶
ParseScope parses "repository:shop/api:pull,push" (names may contain ':' in the middle only for registry:catalog:*).
type Browser ¶
type Browser struct {
URL string // e.g. http://127.0.0.1:5000
Issuer *Issuer
HTTP *http.Client
}
Browser reads the registry's contents for the dashboard (§5.10), with tokens the controller issues to itself.
func (*Browser) DeleteTag ¶
DeleteTag removes a tag's manifest. Other tags pointing at the same digest go with it; disk space is reclaimed by registry garbage collection.
func (*Browser) Digest ¶ added in v0.1.7
Digest is the manifest digest repo's ref (a tag) points to now.
func (*Browser) PushLayout ¶
PushLayout uploads a layout's image to repo:tag. Blobs the registry has already are skipped, so pushing again is cheap.
func (*Browser) Repositories ¶
func (b *Browser) Repositories(ctx context.Context) ([]Repository, error)
Repositories lists repositories with their tag counts.
type CopyProgress ¶ added in v0.1.9
type CopyProgress struct {
Repositories int `json:"repositories"`
RepositoriesDone int `json:"repositoriesDone"`
Images int `json:"images"`
ImagesDone int `json:"imagesDone"`
Blobs int `json:"blobs"` // blobs uploaded or mounted
Skipped int `json:"skipped"` // blobs the target had already
Bytes int64 `json:"bytes"` // bytes uploaded
Current string `json:"current,omitempty"`
}
CopyProgress describes a copy between two registries (Phase 19).
func Copy ¶ added in v0.1.9
func Copy(ctx context.Context, src, dst *Browser, progress func(CopyProgress)) (CopyProgress, error)
Copy copies every tagged image of src into dst: manifests byte for byte (digests stay the same), index children before their index, blobs streamed. Blobs dst has are skipped and blobs already copied to another repository are cross-mounted, so a failed copy resumes when retried. Untagged manifests are not copied. progress is called after each image.
type Decision ¶
type Decision struct {
Image
Expire bool `json:"expire"`
// InUse images are never expired (a service runs or can roll back to them).
InUse bool `json:"inUse"`
Rule int `json:"rule"` // priority of the deciding rule; 0 = no rule matched
Reason string `json:"reason"`
}
Decision says what a policy does with one image.
func Evaluate ¶
func Evaluate(images []Image, rules []Rule, inUse func(digest string) bool, now time.Time) []Decision
Evaluate applies rules (validated) to a repository's images. inUse reports digests that must be kept. Deleting a manifest removes every tag pointing at it, so an image is only expired when all its tags expire.
type Descriptor ¶
type Descriptor struct {
MediaType string `json:"mediaType"`
Digest string `json:"digest"`
Size int64 `json:"size"`
Annotations map[string]string `json:"annotations,omitempty"`
Platform map[string]any `json:"platform,omitempty"`
URLs []string `json:"urls,omitempty"`
}
Descriptor points at a blob of a layout.
type Events ¶
type Events struct {
Store *store.Store
Token string
TokenHeader string
Log *slog.Logger
// OnEvent is called after new events were stored (dashboard refresh).
OnEvent func(repos []string)
}
Events receives the registry's notification webhooks (§5.9) and records manifest pushes, pulls and deletes, which distribution does not track itself: they give last-pulled times, pull counts and an activity feed.
type Image ¶
type Image struct {
Tag string `json:"tag"`
Digest string `json:"digest"`
MediaType string `json:"mediaType"`
SizeBytes int64 `json:"sizeBytes"` // compressed layers + config of the first platform
Platforms []string `json:"platforms"`
Created *time.Time `json:"created"`
}
Image is one tag with its manifest details.
type Issuer ¶
type Issuer struct {
// CertPath is the issuer certificate mounted into the registry container.
CertPath string
// contains filtered or unexported fields
}
func LoadOrCreateIssuer ¶
LoadOrCreateIssuer loads the token signing key from dir, creating it once.
type Repository ¶
Repository is one image repository.
type Rule ¶
type Rule struct {
Priority int `json:"priority"`
Description string `json:"description,omitempty"`
// TagPrefix selects tags starting with it ("" = every tag).
TagPrefix string `json:"tagPrefix"`
// Exactly one of the two:
KeepLast int `json:"keepLast,omitempty"` // keep the newest N, expire the rest
OlderThanDays int `json:"olderThanDays,omitempty"` // expire images created more than N days ago
}
Rule is one lifecycle rule (§5.10). Rules are applied in priority order (lowest first); an image belongs to the first rule whose tag prefix matches it, so a lower-priority rule never expires an image that a higher-priority rule kept. Untagged manifests are always removed by garbage collection.