Implement Autogenerated Root Account for Initial Setup #3
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When the KVS server starts for the first time with an empty database and no seed nodes configured, there is currently no mechanism to create an initial administrative user. This makes it impossible to interact with authentication-protected endpoints, like /kv.
Currently the api endpoints to create users and groups are not under the authentication midware. This is bad security practice.
Proposed Solution:
Introduce logic in the server initialization (
NewServer
function) to detect if the database is empty and if theseed_nodes
configuration is empty. If both conditions are met, the server should:User
entry with a server-generated UUID, a hashed nickname (e.g., "root"), and assign it to a default "admin" group (which should also be created if it doesn't exist).APIToken
for this root user with a set of predefined administrative scopes (e.g., "admin", "read", "write", "create", "delete").User
andAPIToken
objects in BadgerDB.This ensures that a new, uninitialized instance of the KVS server can be brought up with a functional administrative account, allowing immediate secure interaction with the API.
Relevant Code Sections:
NewServer
function for initialization logic.User
,Group
,APIToken
structs.hashUserNickname
,hashGroupName
,hashToken
functions.userStorageKey
,groupStorageKey
,tokenStorageKey
functions.generateJWT
,storeAPIToken
functions.