Secure User and Group Management Endpoints with Authentication Middleware #4
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?
The user management (
/api/users
) and group management (/api/groups
) API endpoints, along with the token creation endpoint (/api/tokens
), are currently exposed without any authentication or authorization checks. This means any client can create, read, update, or delete users, groups, and API tokens, leading to a critical security vulnerability.Proposed Solution:
Apply the existing
authMiddleware
to all user, group, and token management endpoints defined insetupRoutes
.admin:users:create
,admin:users:read
,admin:users:update
,admin:users:delete
admin:groups:create
,admin:groups:read
,admin:groups:update
,admin:groups:delete
admin:tokens:create
,admin:tokens:read
,admin:tokens:delete
(read/delete for tokens would imply listing/revoking tokens, which might need separate handlers).createUserHandler
,getUserHandler
,updateUserHandler
,deleteUserHandler
,createGroupHandler
,getGroupHandler
,updateGroupHandler
,deleteGroupHandler
, andcreateTokenHandler
, wrap them withs.authMiddleware
and specify the appropriate required scopes. For example,s.authMiddleware([]string{"admin:users:create"}, nil, "")(s.createUserHandler)
.This change will ensure that only authenticated users with explicitly granted administrative privileges can manage users, groups, and API tokens, significantly enhancing the security of the application.
Relevant Code Sections:
setupRoutes
function where handlers are registered.authMiddleware
function.createUserHandler
,getUserHandler
,updateUserHandler
,deleteUserHandler
.createGroupHandler
,getGroupHandler
,updateGroupHandler
,deleteGroupHandler
.createTokenHandler
.JWTClaims
andAPIToken
for scope definitions.This has dependency in the #3.
I was unable to edit the tickets dependency section...