Skip to content

[deckhouse-cli] d8 cr login and --username/--password flags#377

Merged
ldmonster merged 3 commits into
mainfrom
feat/cr-login
Jun 2, 2026
Merged

[deckhouse-cli] d8 cr login and --username/--password flags#377
ldmonster merged 3 commits into
mainfrom
feat/cr-login

Conversation

@ldmonster
Copy link
Copy Markdown
Collaborator

What

Adds d8 cr login — a new subcommand that authenticates against a container
registry and persists the credentials to the Docker config
(~/.docker/config.json, honouring $DOCKER_CONFIG and any configured
credential helper/store), exactly like docker login.

Also adds persistent -u/--username and -p/--password flags to the
d8 cr root so one-off credentials can be passed to any command without a
prior login.

Why

  • packagecmd already calls d8 delivery-kit cr login <registry> --username … --password …; this PR provides the backing command.
  • CI pipelines need a way to authenticate without storing secrets in
    ~/.docker/config.json on the host (--username/--password).
  • The existing long-help text pointed users at d8 login (Kubernetes OIDC),
    which is unrelated to registry auth.

Changes

File Change
internal/cr/cmd/basic/login.go New d8 cr login cobra command. Verifies credentials via the registry auth handshake, then writes them through docker/cli's credential store. Interactive prompts when flags are omitted; password is read without echo on a TTY.
internal/cr/internal/registry/login.go New registry.Login domain function. Performs a registry ping + token exchange to validate credentials before persisting. Normalises Docker Hub to its canonical https://index.docker.io/v1/ key.
internal/cr/internal/registry/options.go Adds Transport field to Options (so --insecure is honoured during login), and NewStaticKeychain for inline credentials.
internal/cr/cmd/rootflags.go Adds persistent -u/--username and -p/--password flags; builds a static keychain when --username is set so credentials override the Docker config for the current invocation.
internal/cr/cmd/rootflagnames/names.go Adds Username and Password constants.
internal/cr/cmd/cr.go Registers login subcommand; fixes help text to reference d8 cr login and --username/--password instead of the unrelated d8 login.
internal/cr/README.md Documents login, new global flags, and a login examples cheat-sheet.

Usage

# Interactive
d8 cr login registry.example.com

# Non-interactive (CI)
d8 cr login registry.example.com -u robot -p "$TOKEN"

# One-off without persisting (any command)
d8 cr pull registry.example.com/app:v1 ./app.tar -u robot -p "$TOKEN"

Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
@ldmonster ldmonster added the enhancement New feature or request label Jun 2, 2026
ldmonster and others added 2 commits June 2, 2026 13:27
Signed-off-by: Pavel Okhlopkov <pavel.okhlopkov@flant.com>
- `cr login` now sends an authenticated `GET /v2/`, so a wrong password on a basic-auth (htpasswd) registry fails instead of landing in the Docker config.
- `transport.NewWithContext` only validates bearer-token registries; the explicit `/v2/` probe covers the basic-auth case it skips.
- A lone `--username` or `--password` on non-login commands now errors `must be used together` instead of being silently dropped into a confusing 401.
- `login_test.go` covers basic and bearer registries, each with correct and wrong credentials.

Signed-off-by: Roman Berezkin <roman.berezkin@flant.com>
@ldmonster ldmonster merged commit 4c1c1c0 into main Jun 2, 2026
5 checks passed
@ldmonster ldmonster deleted the feat/cr-login branch June 2, 2026 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants