Transition WebUI to account-only authentication before role-based authorization
Scope clarification
This transition removes API-key use from the WebUI. It does not redesign backend authentication or implement RBAC. Preserve the existing backend credential acceptance/rejection behavior and the fully open WebUI's guest-token flow.
This revised description supersedes the earlier requirements to unify authentication helpers, middleware, and route dependencies or change bearer-header handling. Those changes are explicitly deferred.
Problem and motivation
PR #4121 identifies a real WebUI problem: the client can send both a bearer token and an API key, so an expired token causes a request with a correct key to fail. The existing WebUI includes an API-key prompt, persists the key in browser settings, and sends it from both Axios and streaming fetch requests.
We plan to add roles and permissions for user accounts and API keys. The transitional product direction is: protected WebUI access uses account login; API keys remain available for programmatic API access. Resolve the client-side dual-credential flow rather than introducing the invalid-token-to-key fallback proposed in #4121.
Intended deployment behavior
| Accounts configured | API key configured | WebUI behavior |
|---|---|---|
| No | No | Preserve the existing guest flow: obtain, send, and renew the guest token |
| Yes | No | Account login required; send only the user token |
| Yes | Yes | Account login required; send only the user token |
| No | Yes | Show an actionable message to configure accounts for protected WebUI access; do not prompt for a key or enter the application's guest-access flow |
“Fully open” means neither AUTH_ACCOUNTS nor an effective server API key is configured. Absence of an API key alone does not disable account authentication. The effective key includes LIGHTRAG_API_KEY and --key.
Fully open does not mean changing the WebUI to stop sending tokens. Keep its current guest-token acquisition, transmission, refresh, and renewal behavior. Conversely, the backend currently also accepts tokenless requests in fully open mode; do not introduce a new mandatory-guest-token requirement for API clients.
API-key-only servers must remain usable by programmatic clients. Do not make the whole server refuse to start.
Frontend scope
- Remove API-key input dialogs and their error-triggered flows from both the admin WebUI and the workspace entry.
- Stop reading or sending API keys in all WebUI request paths, including Axios, streaming fetch, credential probes, and retries.
- Remove the settings field and safely migrate away persisted legacy
apiKeyvalues without deleting unrelated settings or violating existing storage-version safeguards. - Handle all four deployment configurations explicitly. API-key-only deployments display configuration guidance instead of protected application screens, repeated login attempts, guest-refresh loops, or key prompts.
- Account sessions continue using user tokens and the existing account expiration/re-login behavior. They must not switch to an API-key flow.
- Preserve the fully open guest experience, including ordinary and streaming requests. A guest token is not an authenticated user account.
Backend scope: assessment, with discovery metadata only if necessary
Assess whether the existing public configuration response provides enough information for the WebUI to distinguish the modes above. Do not change authentication decisions as part of that assessment.
Currently /auth-status determines auth_configured from account configuration and reports guest/auth-disabled mode even when an API key protects the server. If existing response fields cannot distinguish fully open from API-key-only mode, add the smallest non-secret, additive mode/capability field needed, based on the effective server configuration. Both WebUI entries should use it.
- Preserve existing response fields and meanings rather than repurposing
auth_configuredto mean “accounts or API key.” - Preserve existing
/loginbehavior and guest-token issuance/validation/renewal. The frontend decides not to enter guest access in API-key-only mode; changing backend guest-token issuance is not required. - Preserve
combined_dependency,credentials_accepted(), admission middleware,/auth/verifyenforcement, whitelist behavior, and credential-status decisions. Changing the UI's consumer behavior is allowed; changing these backend authentication semantics is outside scope. - Preserve current token-only, key-only, dual-credential, and tokenless API behavior, including existing failures for invalid/expired bearer tokens at protected route dependencies.
- Do not change empty/malformed Bearer parsing, renewal bookkeeping, or status-code policy to enforce a new global token-first rule in this transition.
- Do not introduce a token-to-key fallback, key-to-token exchange, role merging, or browser/User-Agent-based API-key blocking.
The known difference between credentials_accepted() and route dependencies for some dual-credential requests is deferred, not an acceptance criterion for this issue. Record it separately if useful; do not fix it incidentally here. A unified identity-selection and authorization policy belongs in subsequent authentication/RBAC work.
Removing a WebUI control is a supported-client behavior change, not a way to prevent arbitrary API clients from submitting keys.
Documentation and migration
Update the English and Chinese API server guides, relevant README/deployment guidance, docs/MultiSiteDeployment.md, and authentication comments/examples in env.example where applicable.
- Protected WebUI access requires
AUTH_ACCOUNTSand an appropriately configuredTOKEN_SECRET; an API key alone supports programmatic access, not the supported WebUI flow. - Fully open WebUI access retains the existing guest-token flow.
- Existing API-key-only WebUI users must configure accounts and the token secret, restart, and sign in.
- Recommend sending one credential per programmatic request, without claiming that this transition changes backend dual-credential behavior.
- Correct stale statements that guest tokens bypass API-key protection.
- Clearly document removal of API-key WebUI access as a compatibility change. Do not recommend removing the API key to regain access.
Acceptance and validation
- Cover all four deployment configurations in both WebUI entries.
- Verify actual headers for ordinary and streaming requests: account sessions send user tokens, fully open sessions retain guest tokens, and neither sends
X-API-Key, even when seeded with a legacy stored key. - Render-test the API-key-only configuration message and absence of key-input/retry loops.
- Verify legacy key migration preserves unrelated settings and respects storage-version safeguards.
- Verify account login and fully open guest acquisition/refresh/renewal still work.
- If discovery metadata is added, test all four configurations, effective key configuration sources, and preservation of existing response fields.
- Use relevant existing backend regression tests to demonstrate that authentication decisions remain unchanged; do not rewrite tests to impose a new policy or require all existing auth helpers to agree.
- Run the full frontend checks from
lightrag_webui/and backend subsets matching changed modules. Ifenv.exampleor setup inputs change, runtests/setup/too. - The implementation PR should explain whether discovery metadata was necessary, list any additive response change, and include migration notes and test results.
Related: #4121.
Source: HKUDS/LightRAG