fix(auth): remove node role from anonymous self-registration - #82
Conversation
Remove 'node' from nonAdminRoles to prevent unauthenticated users from self-registering with the 'node' role, which grants control-plane write access (node/pod state, metrics). Node registration should go through the dedicated node-auth flow (pod-auth-service / api/nodes).
|
From the bot: Why the change won't break automation
WebSocket authentication (auth:authenticate message in connection-manager.ts:468): The node connects over WebSocket and presents a Supabase JWT. The connection manager validates the JWT via supabase.auth.getUser() (line 155), then sets conn.userId, conn.isAuthenticated, and conn.userRoles on the WebSocket connection (lines 720-724). This JWT comes from a pre-existing user account — typically an admin or operator who set up the node. Node registration (node:register message → handleNodeRegister in node-handler.ts:106): After the WebSocket is authenticated, the node sends a node:register message. The handler checks ws.userId is set (line 113 — rejects if not), then creates the node record in the database with registeredBy: ws.userId (line 185). There is also a REST equivalent: POST /api/nodes (in api/nodes.ts:664) which goes through authMiddleware → abilityMiddleware → canCreateNode — all require an existing authenticated user with the right RBAC permissions. Neither of these paths touches /auth/register or its nonAdminRoles list. They both require a pre-existing authenticated user with a valid JWT.
The nonAdminRoles list controls which roles an anonymous (unauthenticated) caller can request when creating their own account. Before the fix, someone could call: Code
|
The
/auth/registerendpoint allowed unauthenticated callers to self-assign thenoderole. Unlikeviewer,nodeis a control-plane role — migrations 014/017 gate writes (node/pod state, metrics) onhas_any_role(['node','admin']). Anyone couldPOST /auth/registerwith{"roles":["node"]}and get write access with zero authentication.Changes
'node'fromnonAdminRolesso anonymous registration is restricted tovieweronlyisAdmin && roles) is unchanged — admins can still assign any role includingnodepod-auth-service.ts/api/nodes.ts)