Add auth auto-login, env-based auth toggle, and logout support#106
Open
youbuwei wants to merge 1 commit intoevildecay:masterfrom
Open
Add auth auto-login, env-based auth toggle, and logout support#106youbuwei wants to merge 1 commit intoevildecay:masterfrom
youbuwei wants to merge 1 commit intoevildecay:masterfrom
Conversation
- Add "Remember password and auto login" option in Authentication dialog - Persist username/password in localStorage (etcdkeeper_auth) when login succeeds - Auto-connect on page load and reuse saved credentials if available - Keep etcd endpoint / version / tree-mode / editor-mode stored in cookies - Introduce ETCD_KEEPER_AUTH env var to control backend auth instead of hard-coded -auth flag - Add Logout button in the top right to clear saved auth, reset UI, and reconnect unauthenticated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR improves the auth experience in etcdkeeper by:
All existing behavior remains compatible, with environment configuration taking precedence where applicable.
Background / Motivation
Previously:
-authCLI flag.In typical usage (local development or internal tools), it is convenient to:
This PR implements that behavior while trying to keep the implementation simple and opt-in.
Changes
Backend (Go)
Add an environment-variable-based override for the
-authflag:ETCD_KEEPER_AUTHstrconv.ParseBoolcan parse, e.g.:1,t,T,true,TRUE,True0,f,F,false,FALSE,FalseETCD_KEEPER_AUTHis set and parses successfully, it overrides the-authflag.ETCD_KEEPER_AUTHis set but invalid, the flag value is used and a log line is printed:invalid ETCD_KEEPER_AUTH value "<value>", expected true/false; fallback to -auth=<flagValue>No behavior change if
ETCD_KEEPER_AUTHis not set:-authcontinues to work exactly as before.Frontend (assets/etcdkeeper/index.html)
Authentication dialog
Add a checkbox:
The submit button still calls
userOK(), which closes the dialog and callsconnect()as before.Auth persistence (localStorage)
Introduce two helper functions:
saveAuthstores the following JSON object inlocalStorageunder the keyetcdkeeper_auth:{ "username": "<username>", "password": "<password>", "remember": true }loadSavedAuthreturns this object ornullif not found/invalid.Auto-connect on page load
At the end of
$(document).ready(...),connect()is called automatically:Auto-fill and auto-login in
connect()connect()now:#unameand#passwd.etcdkeeper_authvialoadSavedAuth().remember === true:#unameand#passwdwith the saved values.#rememberAuthcheckbox./v3/connectrequest with these credentials.On successful connect (
data.status === 'ok'):connect()inspects the state of#rememberAuth:saveAuth(uname, passwd, true)persists the credentials.reload()is called to refresh the tree.On
status === 'login'orstatus === 'root':status === 'root', a warning message is shown as before.User button behavior
Clicking the user icon (
#userButton) now:loadSavedAuth()if any credentials are stored.#rememberAuthcheckbox.Logout button in the top right
Add a Logout button to the header area:
Bind click handler in jQuery init:
Implement
logout():This effectively:
Configuration / Migration
New environment variable
ETCD_KEEPER_AUTH(bool string)-authflag.-authflag behavior is unchanged.No changes required to existing cookies
etcd-endpoint,etcd-version,tree-mode,ace-modecontinue to work as before.New localStorage entry
etcdkeeper_authSecurity Considerations
localStorageonly on the client side and only when the user opts in.Testing
Tested manually with:
Auth-enabled etcd
ETCD_KEEPER_AUTH=true./etcdkeeperin the browser:Non-auth etcd
ETCD_KEEPER_AUTH=false./etcdkeeper:Notes
/v2/*and/v3/*) and overall UX remain backward compatible.