feat: multi-user authentication with role-based access control#797
Open
Schattenwelt wants to merge 17 commits into
Open
feat: multi-user authentication with role-based access control#797Schattenwelt wants to merge 17 commits into
Schattenwelt wants to merge 17 commits into
Conversation
35403f3 to
c14b21c
Compare
- Update-Channel in service.go now points to Schattenwelt/NanoKVM Releases - Fix dangling reference: hid.go re-adds HIDLoopbackHTTPAllowedPaths that router.go was already calling (broken build on fresh clone) - Add cgo build tag + kvm_vision_stub.go for non-CGO builds - network.go: re-add RequireRole(Admin, Operator) on Wake-on-LAN endpoint - http.ts: re-add PUT method used by user-management UI - Various source-formatting alignments to match the released binary
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.
Multi-User Authentication with Role-Based Access Control
Summary
This PR adds support for multiple users with three distinct roles, replacing the current single-user authentication system.
Motivation
Many users (myself included) want to give different people different levels of access to the NanoKVM:
Currently only one shared admin account exists, which is a security and usability limitation.
Roles
adminoperatorviewerChanges
Backend (Go)
server/service/auth/account.go– New multi-user storage in/etc/kvm/accounts.json(bcrypt hashed)server/service/auth/login.go– Role embedded in JWT claimsserver/service/auth/password.go– Permission-aware password changesserver/service/auth/users.go– NEW – CRUD endpoints for user managementserver/middleware/jwt.go– NewRequireRole()middleware for fine-grained access controlserver/proto/auth.go– New request/response typesserver/router/auth.go– New user management endpointsserver/router/hid.go– Role-based access (operator+ for inputs)server/router/vm.go– Role-based access per endpointFrontend (React)
web/src/hooks/useRole.ts– NEW – Hook to retrieve current user roleweb/src/pages/desktop/menu/settings/users/index.tsx– NEW – User management UIweb/src/pages/desktop/menu/settings/index.tsx– Tabs filtered by roleweb/src/pages/desktop/menu/index.tsx– Menu items hidden based on roleweb/src/api/auth.ts– New API functions for user managementweb/src/i18n/locales/{all}.ts– TranslationsBackwards compatibility
The legacy
/etc/kvm/pwdfile is automatically migrated to/etc/kvm/accounts.jsonon first start. The migrated user receives theadminrole.New API Endpoints
All require
adminrole except/api/auth/users/:username/password(admins can change anyone's password, others only their own).Testing
Tested on NanoKVM-PCIe with NanoKVM v2.4.1:
Screenshot
(add a screenshot of the user management page here)
