registries

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT, MIT Imports: 11 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 registries is private registry credentials for the control plane.

── WHY THE HOST BEING LOGGED IN IS NOT ENOUGH ───────────────────────────────────────────────────

An image pull is authenticated by the **client**, not the daemon. `docker pull` reads the client's own `config.json`, finds the entry for that registry, and sends it to the daemon in an `X-Registry-Auth` header with the create-image call. The daemon never consults the client's config — it just uses whatever credential it was handed.

pstack shells out to `docker compose` from **inside the control container**, so the client is the docker CLI in that container, and its `config.json` is the one that matters. A `docker login` run on the host writes `/root/.docker/config.json` on the *host*, which that container cannot see. The result is `pull access denied` for a private image on a host that is demonstrably logged in — and nothing in the error points at the reason.

So the control stack mounts a `DOCKER_CONFIG` directory, and this module manages the file in it.

── ON DEMAND, WITH NO RESTART ───────────────────────────────────────────────────────────────────

The CLI reads `config.json` on **every** invocation, so a credential added now applies to the next pull. Nothing needs recreating, and there is no cache to bust. Two ways in, both landing in the same file:

  • from the host: `docker login --config /var/lib/pstack/control/docker <registry>`
  • from the API: `PUT /api/registries/:host { username, password }`

── `auths` IS NOT ENCRYPTION ────────────────────────────────────────────────────────────────────

A config.json entry is `base64("user:password")` — trivially reversible, which is why this module NEVER returns it. `State()` gives hostnames and usernames only; there is no read path for the secret and no route that exposes one. The file is written 0600, atomically, and the token that can write here already commands a read-write Docker socket, so the boundary that matters is the API's, not this file's.

── CREDENTIAL HELPERS DO NOT TRANSPLANT ─────────────────────────────────────────────────────────

Copying a laptop's `config.json` in is a trap: on macOS and Docker Desktop it usually contains `credsStore: "desktop"` or `"osxkeychain"` and **no** `auths` at all, because the secrets live in the OS keychain. Inside this container that helper binary does not exist, so every pull fails with `error getting credentials`. `State()` reports helpers so the UI can say that rather than let someone debug an empty `auths`.

The file is handled as an ordered document (*omap.Map): everything docker wrote that this module does not understand is preserved, in place.

Index

Constants

View Source
const DockerHubKey = "https://index.docker.io/v1/"

DockerHubKey is Docker Hub's canonical key. `docker login docker.io` writes THIS, not `docker.io` — so a credential stored under the friendly name is silently never used for `nginx:alpine`.

Variables

This section is empty.

Functions

func DecodeUsername

func DecodeUsername(auth string) *string

DecodeUsername is the username half of a stored `auth`, and only that half — nil when there is none to tell.

Exported for testing. A caller wanting the password should not find a helper here that returns it — there is deliberately no such function in this module.

func IsError

func IsError(err error) bool

IsError reports whether err is a *Error.

func NormalizeRegistry

func NormalizeRegistry(input string) (string, error)

NormalizeRegistry is a registry host, as docker's config keys them. Hub's aliases collapse to the canonical key.

Types

type Error

type Error struct{ Msg string }

Error is a refused host, a missing field or an unwritable directory. The API maps it to 400.

func (*Error) Error

func (e *Error) Error() string

type RegistryAuthStore

type RegistryAuthStore struct {
	Dir string
}

RegistryAuthStore manages config.json in a DOCKER_CONFIG directory. Stateless apart from Dir; safe to share. No lock: the write is whole-file and atomic, last one wins.

func New

func New(dir string) *RegistryAuthStore

New returns the store over dir.

func (*RegistryAuthStore) Put

func (s *RegistryAuthStore) Put(registryInput, username, password string) (string, error)

Put stores one credential, preserving everything else in the file. Returns the normalized key.

Written atomically for the same reason Traefik's config is: `docker compose` may read this file at any moment, and a truncated-then-filled config is a parse error that looks like having no credentials at all.

func (*RegistryAuthStore) Remove

func (s *RegistryAuthStore) Remove(registryInput string) (bool, error)

Remove deletes one. Returns false when it was not there, so a caller can answer 404 rather than lie.

func (*RegistryAuthStore) State

func (s *RegistryAuthStore) State() RegistryState

State is the list view: hostnames, usernames, helpers. Never a secret.

func (*RegistryAuthStore) Writable

func (s *RegistryAuthStore) Writable() bool

Writable is true when this process can write the config — probed by writing, so a `:ro` mount is caught.

type RegistryEntry

type RegistryEntry struct {
	Registry string `json:"registry"`
	// Username is decoded from the stored `auth`, because knowing *which account* is the point of a
	// list view. null when it cannot be told.
	Username *string `json:"username"`
	// ViaHelper is true when this entry is served by a credential helper rather than a stored secret.
	ViaHelper bool `json:"viaHelper"`
}

RegistryEntry is what a caller may know about a stored credential. Never the secret.

type RegistryState

type RegistryState struct {
	// Dir is the DOCKER_CONFIG directory, as this process sees it.
	Dir string `json:"dir"`
	// Writable is false on a control stack that predates the mount — the fix is `pstack init`.
	Writable bool            `json:"writable"`
	Entries  []RegistryEntry `json:"entries"`
	// Helpers are the `credsStore` / `credHelpers` found in the file. Present here means "these will
	// not work in this container", which is a different problem from having no credentials at all.
	Helpers []string `json:"helpers"`
}

RegistryState is the GET /api/registries body.

Jump to

Keyboard shortcuts

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