Skip to content

feat(auth): keyring standalone password change - #1433

Open
nbmaiti wants to merge 1 commit into
mainfrom
pr/standalone-password-change
Open

nbmaiti wants to merge 1 commit into
mainfrom
pr/standalone-password-change

Conversation

@nbmaiti

@nbmaiti nbmaiti commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds POST /api/v1/authorize/password so an administrator can change their own password when AUTH_SECRET_BACKEND=keyring.

Scope

  • Route: registered only for standalone keyring auth (SecretBackend=keyring, Disabled=false, no OIDC ClientID). It requires an authenticated session.
  • Validation: correct current password, newPassword equal to confirmPassword, and the shared policy pkg/secrets.IsStrongAdminPassword (at least 8 characters with a lowercase letter, an uppercase letter, a digit and a symbol; the CLI uses the same rule). Reusing the current password is rejected.
  • Storage: the new password is saved as a PBKDF2-HMAC-SHA256 hash in the device-management-toolkit keyring service.
  • Session revocation: in keyring mode, login reads the username and hash from the keyring, and each token carries a cred claim (an HMAC of the stored hash, keyed with the JWT key). Every protected request checks it against the hash currently in the keyring. A password change stores a new hash, so every earlier session is rejected, including the one that made the change, across clients and restarts. No extra state or files are stored.
  • API contract: OpenAPI and the Postman collection (console_mps_apis) are updated.

Unchanged

  • Config backend, AUTH_DISABLED, OIDC: the route is not registered, login reads credentials exactly as before, and JWT claims stay {exp} only. TestOtherBackendsKeepOriginalBehavior covers this.
  • JWT signing key: storage and lifecycle are the same as before.

Testing notes

Prerequisites: Console built from this branch, AUTH_SECRET_BACKEND=keyring, and administrator credentials already in the keyring. -k is only needed for the default self-signed certificate. jq is used to build the JSON.

BASE=https://localhost:8181   # change the port if needed
read -r -p 'Admin username: ' U; read -r -s -p 'Current password: ' P; printf '\n'
read -r -s -p 'New password: ' N; printf '\n'

TOKEN=$(printf '%s\n' "$U" "$P" | jq -Rn '[inputs]|{username:.[0],password:.[1]}' |
  curl -sk -X POST "$BASE/api/v1/authorize" -H 'Content-Type: application/json' --data-binary @- | jq -r .token)

change() { jq -Rn '[inputs]|{currentPassword:.[0],newPassword:.[1],confirmPassword:.[2]}' |
  curl -sk -w '\n%{http_code}\n' -X POST "$BASE/api/v1/authorize/password" \
    -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' --data-binary @-; }
# Step Expected
1 printf '%s\n' "$P" weak weak | change 400, policy message
2 printf '%s\n' "$P" "$N" "${N}x" | change 400, confirmation mismatch
3 printf '%s\n' 'Wrong-Pass-1!' "$N" "$N" | change 401
4 printf '%s\n' "$P" "$P" "$P" | change 400, must differ
5 Same request with no Authorization header 401
6 printf '%s\n' "$P" "$N" "$N" | change 200 {"message":"password changed"}
7 curl -sk -o /dev/null -w '%{http_code}\n' "$BASE/api/v1/devices" -H "Authorization: Bearer $TOKEN" 401 (old session revoked)
8 Log in with the old password / the new password 401 / 200
9 Restart Console, repeat steps 7 and 8 still 401 for the old token; new password works

Afterwards: unset P N TOKEN.

Check that the keyring holds a hash, not the password (Linux):

secret-tool lookup service device-management-toolkit username admin-password-hash   # starts with $pbkdf2-sha256$

Check that other modes are unchanged: restart with AUTH_SECRET_BACKEND=config.

  • POST /api/v1/authorize/password returns 404.
  • The login JWT payload (cut -d. -f2 <<<"$TOKEN" | base64 -d) contains only exp.

Unit tests:

go test -race -count=1 ./internal/controller/httpapi/... ./internal/controller/openapi ./pkg/secrets ./cmd/app

Validation

  • gofumpt -extra, go vet ./..., go test -race -count=1 ./... and golangci-lint with the CI config all pass.
  • E2E against a real gnome-keyring passed: change 200, wrong current 401, old token rejected immediately and after restart, only the new password logs in. Config mode was unchanged.

Related: #1356

@nbmaiti
nbmaiti requested a review from a team as a code owner November 25, 2026 04:18
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.90805% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.16%. Comparing base (5748beb) to head (e149975).

Files with missing lines Patch % Lines
internal/controller/httpapi/v1/login.go 84.74% 9 Missing ⚠️
internal/controller/openapi/devices.go 84.21% 3 Missing ⚠️
internal/controller/httpapi/router.go 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1433      +/-   ##
==========================================
+ Coverage   64.07%   64.16%   +0.09%     
==========================================
  Files         163      164       +1     
  Lines       13737    13812      +75     
==========================================
+ Hits         8802     8863      +61     
- Misses       4935     4949      +14     

☔ 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.

@nbmaiti
nbmaiti marked this pull request as draft November 25, 2026 04:25
@nbmaiti
nbmaiti force-pushed the pr/standalone-password-change branch from e0c4b08 to d003178 Compare November 25, 2026 04:49
@nbmaiti nbmaiti changed the title feat(auth): standalone password change and auth state feat(auth): keyring-only standalone password change Nov 25, 2026
@nbmaiti
nbmaiti force-pushed the pr/standalone-password-change branch 3 times, most recently from 6696226 to 5a0df73 Compare November 25, 2026 07:12
@nbmaiti
nbmaiti requested a balanced review from Copilot November 25, 2026 12:32

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 tests fail to compile, and password changes lack required authentication-mode checks and introduce data races with concurrent login requests.

5 open issues
What changed in this PR

Adds a keyring-only administrator password-change endpoint to Console’s standalone authentication flow, providing backend support for the workflow in #1356. Config-backed password changes remain out of scope.

Changes:

  • Adds password-change request/response types and a route with current-password, confirmation, and strength checks.
  • Shares administrator password-policy validation between startup and password changes.
  • Adds handler, password-policy, and OpenAPI contract tests.
File Description
pkg/​secrets/​password.go Extracts shared administrator password validation.
pkg/​secrets/​password_test.go Tests password-policy rules and boundaries.
internal/​entity/​dto/​v1/​creds.go Adds password-change request and response types.
internal/​controller/​openapi/​devices.go Declares the password-change API contract.
internal/​controller/​openapi/​devices_test.go Adds contract and setup-route exclusion assertions.
internal/​controller/​httpapi/​v1/​login.go Implements keyring password verification and updates.
internal/​controller/​httpapi/​v1/​login_test.go Adds success and unsupported-backend tests.
internal/​controller/​httpapi/​router.go Registers the password-change route.
cmd/​app/​secret_store.go Uses shared validation during credential setup.
cmd/​app/​main.go Replaces local password-policy logic with the shared helper.
cmd/​app/​main_test.go Updates generator checks and relocates policy tests.

Review effort: Balanced

Comment thread internal/controller/httpapi/v1/login.go Resolved
Comment thread internal/controller/httpapi/v1/login.go Resolved
Comment thread internal/controller/openapi/devices.go Resolved
Comment thread internal/controller/openapi/devices.go Resolved

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 HTTP API test package cannot compile because config.Config literals incorrectly use fields from the embedded config.Auth as direct keys.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Test password-change rejection paths and in-memory credential updates

internal/​controller/​httpapi/​v1/​login.go:119

The endpoint tests cover deployment guards and a successful keyring write, but not missing fields, weak passwords, confirmation mismatches, wrong current passwords, password reuse, or failed keyring writes. Add rejection tests that check the status and verify both stored and in-memory credentials remain unchanged. Extend the success test to verify that login rejects the old password and accepts the new one; the hash-only assertion misses a broken in-memory update.

Medium severity Report keyring read failures as storage errors, not invalid credentials

internal/​controller/​httpapi/​v1/​login.go:146

If the OS keyring is locked or unavailable, both credential-read paths return 401 and report incorrect credentials even when the current password is correct. Handle username and password-hash read errors as storage failures (500) with availability/unlock guidance, and reserve 401 for a successfully read hash that fails verification.

4 resolved since last review

Review effort: Balanced

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

Keyring mode rejects package-issued RPC tokens missing the required credential claim, while redirection tokens remain usable after password changes, bypassing session revocation.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread internal/controller/httpapi/v1/login.go Resolved
Comment thread internal/controller/httpapi/v1/login.go Resolved
@nbmaiti
nbmaiti force-pushed the pr/standalone-password-change branch 4 times, most recently from 30689a7 to c03b687 Compare November 27, 2026 09:17
@nbmaiti nbmaiti changed the title feat(auth): keyring-only standalone password change feat(auth): keyring standalone password change Nov 27, 2026
@nbmaiti
nbmaiti force-pushed the pr/standalone-password-change branch from c03b687 to 0dcbdc4 Compare November 27, 2026 10:04
Add POST /api/v1/authorize/password for AUTH_SECRET_BACKEND=keyring:

- Registered only for standalone keyring auth. The config backend,
  AUTH_DISABLED and OIDC keep their existing routes, login, and token
  claims.
- Verifies the current password and confirmation, applies the shared
  admin password policy (pkg/secrets.IsStrongAdminPassword, also used
  by the CLI), rejects reuse, and stores a PBKDF2 hash in the keyring.
- Keyring mode reads credentials from the keyring on login, and tokens
  carry an HMAC tag of the stored hash that is checked on each
  protected request. A password change replaces the hash, so every
  earlier session is revoked, including across restarts, without any
  extra state.
- OpenAPI and Postman updated.

Related: #1356

Signed-off-by: Nabendu Maiti <nabendu.bikash.maiti@intel.com>
@nbmaiti
nbmaiti force-pushed the pr/standalone-password-change branch from 0dcbdc4 to e149975 Compare November 27, 2026 11:44
@nbmaiti
nbmaiti marked this pull request as ready for review November 27, 2026 11:47
@nbmaiti
nbmaiti requested a review from sudhir-intc November 27, 2026 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants