Skip to content

fix(login): support --password-stdin for piped input#944

Open
rambhardwajj wants to merge 1 commit into
goharbor:mainfrom
rambhardwajj:fix/password-stdin-login
Open

fix(login): support --password-stdin for piped input#944
rambhardwajj wants to merge 1 commit into
goharbor:mainfrom
rambhardwajj:fix/password-stdin-login

Conversation

@rambhardwajj
Copy link
Copy Markdown

Description

Fixes an issue with harbor login --password-stdin when password is provided via piped input
Previously, the login flow relied on term.ReadPassword(...), which expects an interactive terminal (TTY). This caused failures or incorrect behavior when stdin was non-interactive (e.g., piped input).

This change ensures correct handling of both interactive and piped stdin, and also fixes unintended password modification caused by trimming whitespace.

Type of Change

Please select the relevant type.

  • Bug fix
  • New feature
  • Refactor
  • Documentation update
  • Chore / maintenance

Changes

  • Use GetSecretStdin(...) to handle both interactive and piped stdin input
  • Detect non-TTY stdin and read password directly from input stream
  • Preserve leading/trailing whitespace in passwords (avoid TrimSpace)
  • Trim only newline characters (\r, \n)
  • Add unit tests for piped input and whitespace preservation

Signed-off-by: Ram Bhardwaj <rambhardwaj101000@gmail.com>
@qcserestipy
Copy link
Copy Markdown
Collaborator

Can you please add screenshots or screen recordings that document the current and expected behavior.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 25, 2026

Codecov Report

❌ Patch coverage is 30.76923% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 8.54%. Comparing base (60ad0bd) to head (ef9c4c5).
⚠️ Report is 163 commits behind head on main.

Files with missing lines Patch % Lines
pkg/utils/utils.go 36.36% 6 Missing and 1 partial ⚠️
cmd/harbor/root/login.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             main    #944      +/-   ##
=========================================
- Coverage   10.99%   8.54%   -2.45%     
=========================================
  Files         173     288     +115     
  Lines        8671   14448    +5777     
=========================================
+ Hits          953    1235     +282     
- Misses       7612   13094    +5482     
- Partials      106     119      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug]: support --password-stdin for piped input and preserve whitespace

2 participants