Description
The harbor login command currently allows both --password (-p) and --password-stdin to be used together, resulting in ambiguous behavior where one input silently overrides the other without any user-facing error.
This behavior may lead to confusion in CI/CD pipelines where unintended input sources are used.
When both flags are provided, --password-stdin takes precedence and discards the value passed via --password, leaving the user with no indication that their -p input was ignored. This can lead to confusing and unexpected authentication behavior.
Additionally, --context-name is the only login flag that lacks a short alias (-n), which is inconsistent with other flags such as -u and -p.
Steps to Reproduce
- Run command:
harbor login demo.goharbor.io -u admin -p MyPassword123 --password-stdin
- With arguments/config: any valid server and username
- Observe: the command does not return an error — it silently ignores
-p and waits for stdin input instead
Expected Behavior
The CLI should immediately return a clear error when both --password and --password-stdin are provided together:
Error: if any flags in the group [password password-stdin] are set none of the others can be; [password password-stdin] were all set
This is consistent with the behavior of docker login and other standard CLI tools.
Actual Behavior
No error is returned. The --password-stdin path takes precedence silently, discarding the value passed via --password, leading to confusing and unpredictable behavior.
Environment
- OS: Linux / macOS / Windows (reproducible on all platforms)
- Tool version: latest (
main branch)
- Other relevant details: Cobra v1.9+ supports
MarkFlagsMutuallyExclusive natively
Additional Context
Proposed fix:
Use Cobra's built-in MarkFlagsMutuallyExclusive after flag definitions in LoginCommand():
cmd.MarkFlagsMutuallyExclusive("password", "password-stdin")
This enforces the constraint at the framework level with zero additional logic, and also updates the --help output automatically to communicate the restriction to users.
Also propose adding -n as a short alias for --context-name to maintain flag consistency across the login command.
Files affected:
cmd/harbor/root/login.go
cmd/harbor/root/login_test.go (new test case)
Description
The
harbor logincommand currently allows both--password(-p) and--password-stdinto be used together, resulting in ambiguous behavior where one input silently overrides the other without any user-facing error.This behavior may lead to confusion in CI/CD pipelines where unintended input sources are used.
When both flags are provided,
--password-stdintakes precedence and discards the value passed via--password, leaving the user with no indication that their-pinput was ignored. This can lead to confusing and unexpected authentication behavior.Additionally,
--context-nameis the only login flag that lacks a short alias (-n), which is inconsistent with other flags such as-uand-p.Steps to Reproduce
-pand waits for stdin input insteadExpected Behavior
The CLI should immediately return a clear error when both
--passwordand--password-stdinare provided together:This is consistent with the behavior of
docker loginand other standard CLI tools.Actual Behavior
No error is returned. The
--password-stdinpath takes precedence silently, discarding the value passed via--password, leading to confusing and unpredictable behavior.Environment
mainbranch)MarkFlagsMutuallyExclusivenativelyAdditional Context
Proposed fix:
Use Cobra's built-in
MarkFlagsMutuallyExclusiveafter flag definitions inLoginCommand():This enforces the constraint at the framework level with zero additional logic, and also updates the
--helpoutput automatically to communicate the restriction to users.Also propose adding
-nas a short alias for--context-nameto maintain flag consistency across the login command.Files affected:
cmd/harbor/root/login.gocmd/harbor/root/login_test.go(new test case)