fix: When having read permission for the application, the application settings page can be viewed#4337
Conversation
… settings page can be viewed
|
Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
| if (to.path.includes('resource-management')) { return PermissionConst.RESOURCE_APPLICATION_READ } | ||
| }, | ||
| ] | ||
| }, |
There was a problem hiding this comment.
The provided code has several potential issues:
-
Function
get_next_routeUsage:- The function
get_next_route()is not defined in the given snippet. Without its implementation, the logic for determining permissions will not be functional.
- The function
-
String Matching in Conditional Logic:
- In both cases where
to.params.from == 'resource-management', nothing significant is done in either return statement. This could cause unexpected behavior if you intend to conditionally apply different policies within these routes.
- In both cases where
-
Permissions Return Values:
- While it appears that
PermissionConst.APPLICATION_READshould work similarly toPermissionConst.APPLICATION_EDIT, usingPermissionConst.RESOURCE_APPLICATION_READinstead ofPermissionConst.APPLICATION_READwhen handling resource management routes might inadvertently allow more access than intended due to differences between application read and resource edit permissions.
- While it appears that
-
Path Handling:
- When checking paths with
if (to.path.includes('resource-management')), this approach directly checks against partial strings (includes). It’s generally better to compare full URLs or specific path segments to ensure accuracy and prevent false positives.
- When checking paths with
Suggestions:
- Ensure that
get_next_route()returns an object containing necessary route information if the dependency is needed elsewhere in your application. - Evaluate whether conditional logic based on
fromparams is actually required. If all resources fall under "application," perhaps simplifying the check would suffice:if (!to.path.startsWith('/resource-management')). This reduces complexity without changing permissions unnecessarily. - Double-check the definitions/assignments of
PermissionConstconstants to maintain consistency across your project.
To address some of these concerns, here's a revised version of one of the affected sections assuming proper dependencies and correct usage contexts:
const ApplicationDetailRouter = {
[RouteType.Application]: [
{
method: RouteMethod.Get,
controllerName: 'ApplicationController',
methodName: 'GetApplicationById',
authorizationRuleFn: (
_authInfo: AuthResultInterface | null,
context: ControllerContext<Request<any>, Response>
) => {
const to: any = context.req.url // Assuming req.url provides enough info
if (to && to.includes("resource-management")) {
return PermissionConst.RESOURCE_APPLICATION_READ;
}
return PermissionConst.APPLICATION_READ; // Default permission for everything else
}
},
// Repeat similar pattern for other methods/routes as applicable...
],
}Make sure that this revision aligns correctly with your actual architecture and data flow, including how request objects are structured.
fix: When having read permission for the application, the application settings page can be viewed