Two related defects in the HARBOR_TOKEN (headless / CI) auth path, found while end-to-end testing #86 against a real server.
1. harbor whoami ignores HARBOR_TOKEN and claims you are logged out
runWhoami (cmd/auth.go:684) reads config.Load() directly instead of going through the credential resolution at cmd/root.go:310 that honours HARBOR_TOKEN. So with a perfectly good token in the environment:
$ HARBOR_TOKEN=<redacted> HARBOR_API_URL=https://<host>/api/v1 harbor whoami
Error: not logged in — run 'harbor login' first
$ HARBOR_TOKEN=<redacted> HARBOR_API_URL=https://<host>/api/v1 harbor profile get
(succeeds — returns the authenticated user)
whoami is the natural command to run first when scripting against the CLI, so this reads as "my token is broken" when nothing is wrong. Every other command works.
Fix: resolve credentials the same way the rest of the tree does, and report the identity the token actually belongs to.
2. harbor crypto setup cannot run under HARBOR_TOKEN at all
$ HARBOR_TOKEN=<redacted> HARBOR_PASSPHRASE=<redacted> harbor crypto setup
Error: The request was invalid.
code: validation_failed
• scope_id: scope_id and device_id are required
HARBOR_TOKEN synthesizes a credential set with an empty DeviceID (cmd/root.go:312), but crypto setup writes the keystore through sync/push (cmd/crypto.go:130), which requires one. The result is that encryption cannot be set up headlessly at all — the documented escape hatch for CI and scripting works for every other command but this one.
Workaround used during testing: hand-write a credentials.json containing a device_id, i.e. reproduce by hand what harbor login writes.
Fix: synthesize a stable device_id for the HARBOR_TOKEN path (the same shape harbor login generates, e.g. cli-<something>), so token-only sessions can push sync records.
Acceptance criteria
Context
Found while verifying #86 (PR #87). Neither affects that fix — flagged separately so they do not evaporate with the PR description.
Two related defects in the
HARBOR_TOKEN(headless / CI) auth path, found while end-to-end testing #86 against a real server.1.
harbor whoamiignoresHARBOR_TOKENand claims you are logged outrunWhoami(cmd/auth.go:684) readsconfig.Load()directly instead of going through the credential resolution atcmd/root.go:310that honoursHARBOR_TOKEN. So with a perfectly good token in the environment:whoamiis the natural command to run first when scripting against the CLI, so this reads as "my token is broken" when nothing is wrong. Every other command works.Fix: resolve credentials the same way the rest of the tree does, and report the identity the token actually belongs to.
2.
harbor crypto setupcannot run underHARBOR_TOKENat allHARBOR_TOKENsynthesizes a credential set with an emptyDeviceID(cmd/root.go:312), butcrypto setupwrites the keystore throughsync/push(cmd/crypto.go:130), which requires one. The result is that encryption cannot be set up headlessly at all — the documented escape hatch for CI and scripting works for every other command but this one.Workaround used during testing: hand-write a
credentials.jsoncontaining adevice_id, i.e. reproduce by hand whatharbor loginwrites.Fix: synthesize a stable
device_idfor theHARBOR_TOKENpath (the same shapeharbor logingenerates, e.g.cli-<something>), so token-only sessions can push sync records.Acceptance criteria
harbor whoamiunderHARBOR_TOKENreports the authenticated identity instead of "not logged in"harbor crypto setupsucceeds underHARBOR_TOKENwith no pre-existingcredentials.jsonharbor crypto statusafterwards reports the keystore present and unlockableHOME)Context
Found while verifying #86 (PR #87). Neither affects that fix — flagged separately so they do not evaporate with the PR description.