Skip to content

refactor(auth): harden console credential validation - #1237

Open
nbmaiti wants to merge 1 commit into
mainfrom
pr/CM352
Open

refactor(auth): harden console credential validation#1237
nbmaiti wants to merge 1 commit into
mainfrom
pr/CM352

Conversation

@nbmaiti

@nbmaiti nbmaiti commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace direct credential string comparisons with secure validation
  • hash and verify admin passwords using bcrypt
  • use constant-time comparison for CIRA credential checks

Testing

  • go test ./cmd/app ./internal/controller/httpapi/v1 ./internal/controller/tcp/cira

@nbmaiti
nbmaiti requested a review from a team as a code owner September 2, 2026 06:38
@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.36232% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 51.34%. Comparing base (a9001c9) to head (fd8a2d1).

Files with missing lines Patch % Lines
cmd/app/main.go 68.51% 12 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1237      +/-   ##
==========================================
+ Coverage   50.83%   51.34%   +0.50%     
==========================================
  Files         149      149              
  Lines       13874    13918      +44     
==========================================
+ Hits         7053     7146      +93     
+ Misses       6217     6160      -57     
- Partials      604      612       +8     

☔ View full report in Codecov by Harness.
📢 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.

This comment was marked as outdated.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The current startup path generates an admin password but only persists/logs its bcrypt hash (locking operators out), and the CIRA “constant-time” check still short-circuits on username mismatch, leaking failure type via timing.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details

Suppressed comments (1)

cmd/app/main.go:427

  • On first run (when cfg.AdminPassword is empty), a random admin password is generated, immediately hashed, and only the hash is persisted/logged. That leaves operators with no way to learn the generated password, effectively locking them out unless they already set AUTH_ADMIN_PASSWORD. Either refuse to start and require an explicit password, or print the generated password once (with a strong warning) before hashing.
		password, err := generateRandomPassword(adminPasswordLength)
		if err != nil {
			log.Fatalf("Failed to generate admin password: %v", err)
		}

  • Files reviewed: 8/8 changed files
  • Comments generated: 2
  • Review effort level: Lite

Comment thread internal/controller/tcp/cira/handler.go Outdated
Comment thread internal/usecase/sqldb/device.go
Base automatically changed from pr/jwt_no_default_jwt_key to main September 2, 2026 09:12
@sudhir-intc sudhir-intc changed the title fix(auth): harden console credential validation refactor(auth): harden console credential validation Sep 2, 2026
@nbmaiti
nbmaiti force-pushed the pr/CM352 branch 2 times, most recently from 834a947 to 77e4f1c Compare September 2, 2026 17:08
Comment thread cmd/app/main.go Dismissed
Console compared the admin username and password with plain string
equality, so credentials were matched in cleartext and the comparison
leaked timing information. Verify the admin password as a bcrypt hash
and compare the username in constant time, hashing and persisting any
plaintext value already present in config on startup.

CIRA authentication had the same flaw: the decrypted MPSPassword was
checked with a direct != comparison, which is vulnerable to a timing
side channel. Use subtle.ConstantTimeCompare for both the username and
the password.

Add tests covering the credential rejection paths, including an unset
device ID, a lookup failure, and a missing device.

Signed-off-by: Nabendu Maiti <nabendu.bikash.maiti@intel.com>
@nbmaiti
nbmaiti marked this pull request as ready for review September 3, 2026 02:52
@nbmaiti
nbmaiti requested a review from sudhir-intc September 3, 2026 04:40
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.

3 participants