Skip to content

feat(auth): Authenticated password-change endpoint - #1364

Draft
nbmaiti wants to merge 3 commits into
mainfrom
feat/issue-1356-password-change
Draft

nbmaiti wants to merge 3 commits into
mainfrom
feat/issue-1356-password-change

Conversation

@nbmaiti

@nbmaiti nbmaiti commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add a protected Console API flow for changing standalone administrator credentials, plus the ADR Phase 2 first-run setup service for keyring deployments. The caller must be authenticated and provide the current password before a new one is saved to the configured backend.

Note: this PR contains the full feature. #1433 (password change, keyring-only) and #1434 (first-run setup) are the narrowed, stacked split of the same work; review whichever shape the maintainers prefer.

Changes

  • Add an authenticated password-change endpoint (POST /api/v1/authorize/password).
  • Validate the current password, confirmation, and new-password strength.
  • Persist the new password using the selected backend, hashing it for keyring storage; revoke previously issued sessions.
  • Add first-run setup (GET /api/v1/auth/setup/status, POST /api/v1/auth/setup) on a loopback-only TLS listener with a one-time, file-backed setup token.
  • Add tests for successful changes, invalid requests, and backend-specific behavior.
  • Use the UI route for the password-change page rather than serving a separate embedded Console page.

Testing for reviewers

-k is only for the default self-signed certificate. Replace admin / Current-Pass1 with your values.

Password change (any backend, signed-in session)

BASE=https://localhost:8181

TOKEN=$(curl -sk -X POST "$BASE/api/v1/authorize" -H 'Content-Type: application/json' \
  -d '{"username":"admin","password":"Current-Pass1"}' | jq -r .token)

# 200 {"message":"password changed"}
curl -sk -w '\n%{http_code}\n' -X POST "$BASE/api/v1/authorize/password" \
  -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"currentPassword":"Current-Pass1","newPassword":"New-Pass-2!","confirmPassword":"New-Pass-2!"}'

# Old session token is revoked -> 401; old password -> 401; new password -> 200
curl -sk -o /dev/null -w '%{http_code}\n' "$BASE/api/v1/devices" -H "Authorization: Bearer $TOKEN"
curl -sk -o /dev/null -w '%{http_code}\n' -X POST "$BASE/api/v1/authorize" -H 'Content-Type: application/json' -d '{"username":"admin","password":"Current-Pass1"}'
curl -sk -o /dev/null -w '%{http_code}\n' -X POST "$BASE/api/v1/authorize" -H 'Content-Type: application/json' -d '{"username":"admin","password":"New-Pass-2!"}'

# Weak / mismatched -> 400; wrong current -> 401; no session -> 401
TOKEN=$(curl -sk -X POST "$BASE/api/v1/authorize" -H 'Content-Type: application/json' -d '{"username":"admin","password":"New-Pass-2!"}' | jq -r .token)
curl -sk -o /dev/null -w '%{http_code}\n' -X POST "$BASE/api/v1/authorize/password" -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"currentPassword":"New-Pass-2!","newPassword":"weak","confirmPassword":"weak"}'
curl -sk -o /dev/null -w '%{http_code}\n' -X POST "$BASE/api/v1/authorize/password" -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"currentPassword":"New-Pass-2!","newPassword":"Other-Pass-3!","confirmPassword":"Nope-Pass-3!"}'
curl -sk -o /dev/null -w '%{http_code}\n' -X POST "$BASE/api/v1/authorize/password" -H "Authorization: Bearer $TOKEN" -H 'Content-Type: application/json' \
  -d '{"currentPassword":"wrong","newPassword":"Other-Pass-3!","confirmPassword":"Other-Pass-3!"}'

# AUTH_SECRET_BACKEND=config: config.yml auth.adminPassword is updated.
# AUTH_ADMIN_PASSWORD set in the environment -> 409.

First-run setup (AUTH_SECRET_BACKEND=keyring, no device-management-toolkit keyring entries)

# Start Console. The log prints: "administrator setup required; open https://localhost:<PORT>/setup ..."
# Paste the URL portion of the combined headless startup line.
read -r -p 'Setup URL: ' SETUP_URL
SETUP="${SETUP_URL%%/setup#*}"
SETUP_TOKEN="${SETUP_URL##*#}"
read -r -p 'Console HTTPS port: ' CONSOLE_PORT
BASE="https://localhost:${CONSOLE_PORT}"
curl -sk "$SETUP/api/v1/auth/setup/status" # {"setupRequired":true}
read -r -p 'Admin username: ' SETUP_USERNAME
read -r -s -p 'Admin password: ' SETUP_PASSWORD; printf '\n'
read -r -s -p 'Confirm password: ' SETUP_CONFIRM; printf '\n'
{
  printf '%s\n' "$SETUP_TOKEN" "$SETUP_USERNAME" "$SETUP_PASSWORD" "$SETUP_CONFIRM"
} | jq -Rn '[inputs] | {token: .[0], username: .[1], password: .[2], confirmPassword: .[3]}' |
  curl -sk -w '\n%{http_code}\n' -X POST "$SETUP/api/v1/auth/setup" \
    -H 'Content-Type: application/json' --data-binary @-

unset SETUP_TOKEN SETUP_USERNAME SETUP_PASSWORD SETUP_CONFIRM
# The token file is removed after successful setup.
curl -sk "$SETUP/api/v1/auth/setup/status"           # {"setupRequired":false}  (or connection refused after restart: listener closed)
curl -sk -o /dev/null -w '%{http_code}\n' -X POST "$BASE/api/v1/authorize" -H 'Content-Type: application/json' \
  -d '{"username":"admin","password":"Valid-Setup9"}' # 200

# Wrong token -> 401 INVALID_SETUP_TOKEN; replay after success -> 409 SETUP_ALREADY_COMPLETED;
# request from a non-loopback address -> 403 SETUP_LOCAL_ONLY.

Verify the stored value is a hash, not the password (Linux example):

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

Validation

  • Go tests pass.

Fixes: #1356

@nbmaiti nbmaiti changed the title feat: Authenticated password-change endpoint feat(auth): Authenticated password-change endpoint Oct 29, 2026
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
internal/app/app.go 34.24% 48 Missing ⚠️
internal/authsetup/manager.go 68.70% 46 Missing ⚠️
internal/controller/httpapi/v1/login.go 76.12% 37 Missing ⚠️
internal/authsetup/store.go 75.00% 28 Missing ⚠️
cmd/app/main.go 44.44% 15 Missing ⚠️
config/config.go 8.33% 11 Missing ⚠️
internal/controller/httpapi/ui.go 52.63% 9 Missing ⚠️
cmd/app/secret_store.go 66.66% 3 Missing ⚠️
internal/controller/httpapi/router.go 0.00% 3 Missing ⚠️
internal/controller/openapi/devices.go 84.21% 3 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1364      +/-   ##
==========================================
+ Coverage   64.07%   64.16%   +0.08%     
==========================================
  Files         163      167       +4     
  Lines       13737    14276     +539     
==========================================
+ Hits         8802     9160     +358     
- Misses       4935     5116     +181     

☔ 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 force-pushed the feat/issue-1356-password-change branch from ab4a0f4 to 7ec1430 Compare October 29, 2026 07:10
@nbmaiti
nbmaiti force-pushed the feat/issue-1355-keyring-cli-setup branch from a294d6b to 2fe8b43 Compare October 29, 2026 07:11
@nbmaiti
nbmaiti requested a balanced review from Copilot October 30, 2026 03:04

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

Password updates are unsynchronized with logins and concurrent changes, risking data races and inconsistent credentials, while config-mode verification and environment-managed password persistence also have unresolved defects.

4 open issues
What changed in this PR

Adds an authenticated password-change API for standalone Console administrators, supporting the credential-management workflow in #1356.

Changes:

  • Adds current-password verification, confirmation and strength checks, and backend-specific password storage.
  • Shares password-strength validation with first-run setup and adds authentication and UI-route tests.
  • Documents password changes and forgotten-password recovery by deleting both administrator keyring entries.
File Description
README.md Links to administrator password-management guidance.
pkg/​secrets/​password.go Adds shared, Unicode-aware password-strength validation.
pkg/​secrets/​password_test.go Tests password length and character diversity.
internal/​controller/​httpapi/​v1/​login.go Implements password validation and backend-specific saving.
internal/​controller/​httpapi/​v1/​login_test.go Tests authentication, validation, and backend-specific behavior.
internal/​controller/​httpapi/​ui_test.go Checks that /account/password serves the UI shell.
internal/​controller/​httpapi/​router.go Registers the protected endpoint for standalone authentication.
docs/​standalone-authentication.md Documents password changes and manual keyring recovery.
cmd/​app/​secret_store.go Reuses shared password-strength validation during setup.

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/httpapi/v1/login.go Resolved
Comment thread internal/controller/httpapi/router.go Resolved
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch 2 times, most recently from c4b52b7 to 5320c1f Compare October 30, 2026 04:12
@nbmaiti
nbmaiti force-pushed the feat/issue-1355-keyring-cli-setup branch from 1b0368c to 454763b Compare November 16, 2026 04:58
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch from 5320c1f to a9363b3 Compare November 16, 2026 04:58
@nbmaiti
nbmaiti force-pushed the feat/issue-1355-keyring-cli-setup branch from 454763b to 960a47c Compare November 16, 2026 05:06
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch from a9363b3 to 4907fbe Compare November 16, 2026 05:06
@nbmaiti
nbmaiti force-pushed the feat/issue-1355-keyring-cli-setup branch from 960a47c to f684f77 Compare November 16, 2026 05:15
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch from 4907fbe to 4703293 Compare November 16, 2026 05:15
@nbmaiti
nbmaiti force-pushed the feat/issue-1355-keyring-cli-setup branch from f684f77 to 885e261 Compare November 16, 2026 06:59
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch 2 times, most recently from 1b3cf3c to f7bff0e Compare November 16, 2026 07:16
@nbmaiti
nbmaiti force-pushed the feat/issue-1355-keyring-cli-setup branch from 885e261 to cfe0842 Compare November 16, 2026 07:16
@nbmaiti
nbmaiti requested a balanced review from Copilot November 16, 2026 07:40

This comment was marked as outdated.

@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch from fe6b466 to 9b8d014 Compare November 20, 2026 13:55
@nbmaiti
nbmaiti force-pushed the feat/issue-1355-keyring-cli-setup branch from 9f38364 to 613e8f1 Compare November 20, 2026 15:12
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch from 7ef62f6 to 6a8f035 Compare November 23, 2026 03:13
@nbmaiti
nbmaiti force-pushed the feat/issue-1355-keyring-cli-setup branch from 613e8f1 to 7332423 Compare November 23, 2026 03:13
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch 2 times, most recently from 0ad946f to 229e90a Compare November 23, 2026 03:29
@nbmaiti
nbmaiti force-pushed the feat/issue-1355-keyring-cli-setup branch 2 times, most recently from 7feec1e to 375e499 Compare November 23, 2026 04:09
Base automatically changed from feat/issue-1355-keyring-cli-setup to main November 23, 2026 04:14
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch 2 times, most recently from e52a966 to b5cf24b Compare November 24, 2026 09:27
@nbmaiti
nbmaiti requested a balanced review from Copilot November 24, 2026 17:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Comment thread cmd/app/browser_test.go Resolved
Comment thread internal/authsetup/handler.go Resolved
Comment thread internal/controller/httpapi/ui.go Resolved
Comment thread internal/authsetup/manager.go Resolved
Comment thread internal/authsetup/manager.go Resolved
Comment thread docs/standalone-authentication.md Resolved
Comment thread docs/standalone-authentication.md Resolved
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch 2 times, most recently from 3c594ca to 38cfd35 Compare November 25, 2026 04:09
@nbmaiti nbmaiti changed the title feat(auth): Authenticated password-change endpoint feat(auth): add standalone password change and auth state Nov 25, 2026
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch from 38cfd35 to 7887ddf Compare November 25, 2026 04:16
@nbmaiti nbmaiti changed the title feat(auth): add standalone password change and auth state feat(auth): Authenticated password-change endpoint Nov 25, 2026
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch from 7887ddf to 3c594ca Compare November 26, 2026 04:16
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch from 0aaa23a to 254a224 Compare November 26, 2026 07:18
@nbmaiti
nbmaiti force-pushed the feat/issue-1356-password-change branch from f354e97 to e996a11 Compare November 26, 2026 08:07
nbmaiti added a commit that referenced this pull request Nov 27, 2026
Add POST /api/v1/authorize/password for AUTH_SECRET_BACKEND=keyring
with the #1364 password-change behaviour:

- Registered only for standalone keyring auth. The config backend,
  AUTH_DISABLED and OIDC keep their existing routes, login, and token
  claims, and create no auth-state file.
- Verifies the current password, confirmation, and the shared admin
  password policy (pkg/secrets.IsStrongAdminPassword, also used by the
  CLI); rejects reuse of the current password; stores a PBKDF2 hash.
- Revokes every earlier session: keyring-mode tokens carry a durable
  auth_version (SQLite auth-state DB next to config.yml) and an HMAC tag
  of the stored credential, both checked on each protected request. A
  failed revocation rolls the credential back.
- Login and password change share one credential lock; credentials are
  read live from the keyring, so the handler no longer rewrites the
  shared config (which raced with concurrent logins).
- OpenAPI, Postman, and docs updated.

Related: #1356
Signed-off-by: Nabendu Maiti <nabendu.bikash.maiti@intel.com>
nbmaiti added a commit that referenced this pull request Nov 27, 2026
Replace the terminal keyring prompt with the #1364 first-run flow:

- With AUTH_SECRET_BACKEND=keyring and no keyring entries, Console
  issues a one-time setup token (10-minute lifetime) and serves
  GET /api/v1/auth/setup/status and POST /api/v1/auth/setup on a
  separate HTTPS listener bound to 127.0.0.1; non-loopback peers or
  origins get 403 SETUP_LOCAL_ONLY. Setup writes the username and a
  PBKDF2 hash, verifies the write, and rolls back on failure.
- The token lives only in process memory and is never written to any
  file: not to a token file, the auth-state DB, or a log file.
  cmd/app and app.Run share one authsetup.Manager.
- The browser and the tray "Open" action open the token-free
  /setup/redirect URL; that loopback-only endpoint redirects to
  /setup#<token>, so the token never appears in process arguments or
  the tray lock file.
- Headless (no embedded UI) startup on a terminal prints the setup URL
  with the token for copy/paste, as in #1364. When output is redirected
  it prints a token-free curl hint for /setup/redirect instead. Tray
  mode stays in the foreground while setup is pending.
- Config backend, AUTH_DISABLED, and OIDC are unchanged: no setup
  listener and no auth-state file.
- Partial keyring state still fails closed. golang.org/x/term removed.

Related: #1356
Signed-off-by: Nabendu Maiti <nabendu.bikash.maiti@intel.com>
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.

Add Credential Recovery and Authenticated Password Change

2 participants