Skip to content

Commit 1236f37

Browse files
authored
Improve publish permission error message to show available permissions (#417)
## Summary The permission error now displays what namespaces the user has permission to publish and what namespace they attempted to publish. This helps users debug permission mismatches more easily. Helps mitigate #398 to enable us to figure out what's going on
1 parent 41aacc1 commit 1236f37

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

internal/api/handlers/v0/publish.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
5050

5151
// Verify that the token has permission to publish the server
5252
if !jwtManager.HasPermission(input.Body.Name, auth.PermissionActionPublish, claims.Permissions) {
53-
return nil, huma.Error403Forbidden("You do not have permission to publish this server")
53+
return nil, huma.Error403Forbidden(buildPermissionErrorMessage(input.Body.Name, claims.Permissions))
5454
}
5555

5656
// Publish the server with extensions
@@ -65,3 +65,24 @@ func RegisterPublishEndpoint(api huma.API, registry service.RegistryService, cfg
6565
}, nil
6666
})
6767
}
68+
69+
// buildPermissionErrorMessage creates a detailed error message showing what permissions
70+
// the user has and what they're trying to publish
71+
func buildPermissionErrorMessage(attemptedResource string, permissions []auth.Permission) string {
72+
var permissionStrs []string
73+
for _, perm := range permissions {
74+
if perm.Action == auth.PermissionActionPublish {
75+
permissionStrs = append(permissionStrs, perm.ResourcePattern)
76+
}
77+
}
78+
79+
errorMsg := "You do not have permission to publish this server"
80+
if len(permissionStrs) > 0 {
81+
errorMsg += ". You have permission to publish: " + strings.Join(permissionStrs, ", ")
82+
} else {
83+
errorMsg += ". You do not have any publish permissions"
84+
}
85+
errorMsg += ". Attempting to publish: " + attemptedResource
86+
87+
return errorMsg
88+
}

0 commit comments

Comments
 (0)