test(rbac): cover review gaps from PR 2 self-review
- Add TestRequireRole_CrossTenantSuperuserBypass: pin the CanAccessAllTenants -> Owner-gate bypass behaviour for RequireRole, matching the existing coverage on RequireOwnershipOrRole. Catches reorderings of the fast paths that would re-lock org-level superusers out of foreign-tenant Owner-only routes. - Add TestAgentCreatorLookup_CrossTenantIsHiddenAsNotFound: lock down the defence-in-depth tenant re-check inside AgentCreatorLookup so a future refactor that loosens the service-layer scope (or wires a cross-tenant variant by mistake) cannot leak access via the ownership shortcut. - Reword RequireOwnershipOrRole step 7-8 doc comment so "role check already failed" is unambiguous (it refers to step 1 above). - Annotate the synthetic-system-user construction in middleware/auth.go with a back-pointer to types.IsSyntheticUserID so anyone changing the prefix or numeric suffix knows to update the helper too.
This commit is contained in:
@@ -116,8 +116,9 @@ func RequireRole(min types.TenantRole, cfg *config.Config) gin.HandlerFunc {
|
||||
// 5. lookup returns other error -> 503 (transient/unexpected fault).
|
||||
// Preserves observability instead of disguising server errors as 403.
|
||||
// 6. lookup returns the caller's user ID -> allow (ownership match).
|
||||
// 7. lookup returns "" -> tenant-owned, role check already failed: 403.
|
||||
// 8. lookup returns a different non-empty user ID -> 403.
|
||||
// 7. lookup returns "" (tenant-owned, no human creator) -> 403 (we
|
||||
// already know role < min from step 1).
|
||||
// 8. lookup returns a non-empty creator that is not the caller -> 403.
|
||||
func RequireOwnershipOrRole(min types.TenantRole, lookup CreatorLookup, cfg *config.Config) gin.HandlerFunc {
|
||||
warnOnNilConfig(cfg)
|
||||
return func(c *gin.Context) {
|
||||
|
||||
Reference in New Issue
Block a user