Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-28975] Added support for View permissions at the View level rather than only at global level #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pskumar448
Copy link

@pskumar448 pskumar448 commented Aug 14, 2016

Added possibility to setup permissions at view level rather giving permissions at global level.

This will hide the View from top tab bar, but if the user try to access via direct URL it will be accessible.

New feature PR (jenkinsci/jenkins#2499) to has been submitted to Jenkins Core to handle direct URL authorization of the user on view.

https://issues.jenkins-ci.org/browse/JENKINS-28975

<!--
- The MIT License
-
- Copyright (c) 2013, Oleg Nenashev, Synopsys Inc.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong license header

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho even the slave file needs some rework

@pskumar448
Copy link
Author

OK. I will update the license header and push the changes.

@pskumar448
Copy link
Author

@oleg-nenashev
License headers for the files manage-view-roles.jelly and assign-view-roles.jelly updated and pushed changes.

@pskumar448
Copy link
Author

@oleg-nenashev
Got any chance to look this PR.

@@ -592,6 +599,10 @@ else if (type.equals(SLAVE)) {
groups.remove(PermissionGroup.get(SCM.class));
groups.remove(PermissionGroup.get(Run.class));
}
else if (type.equals(VIEW)) {
groups = new ArrayList<PermissionGroup>();
groups.add(PermissionGroup.get(View.class));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blacklisting of groups above is made for a reason. If somebody adds a permission for view outside this group (e.g. MANAGE_OWNERSHIP.View), it won't appear in the table. For old plugins there is no way to add permissions to existing groups IIRC

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I get all the PermissionGroups then removing other except the View.class but Credentials section is coming in table so to eliminate that section which is not having any importance created a new list with just View PermissionGroup.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oleg-nenashev
Shall I do it like the previous implementation for VIEW too as you said that it has been implemented for a reason.
Or else is this OK to add View.class only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it as is by now

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

@oleg-nenashev
Copy link
Member

Generally looks good to me. Need to perform some testing

@pskumar448
Copy link
Author

@oleg-nenashev
After testing this PR let me know any changes required.

@pskumar448
Copy link
Author

@oleg-nenashev
Any update on this.

@oleg-nenashev
Copy link
Member

I rarely do testing during the working week :(
Hope to spend some time on the weekend

@oleg-nenashev
Copy link
Member

The current permission check approach does not work correctly for Views in Folders Plugin. Seems you may have to emulate a kind of getFullName() method for views. And same for user custom views, for which the current behavior seems to be may be a security risk (needs core code review).

Also, I see the strange layout tabbing in Safari, which didn't use to happen before the patch (needs to be confirmed).

screen shot 2016-08-20 at 23 43 13

@pskumar448
Copy link
Author

@oleg-nenashev
Ok. I will update with view full name for folder level views.

@pskumar448
Copy link
Author

@oleg-nenashev
Emulated view full name to add support for folder level views. Let me know feedback on this after testing.

return getACL(VIEW, getViewFullName(view), RoleType.View, view);
}

String getViewFullName(View view) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will be invoked VERY frequently. It really makes sense to replace recursive call by a loop with StringBuilder

@pskumar448
Copy link
Author

Ok. I will modify the according to your feedback.

return view.getViewName();
}
else {
sb.append("/" + view.getViewName());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The approach is not very safe in the case of slashes in the view name, which were allowed in old Jenkins versions, but it's a corner case we can ignore

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using slash to separate the view name from the parent name.
This functionality I have taken from the Jenkins core, referred some model classes how emulation of full name happening.

@pskumar448
Copy link
Author

Hi @oleg-nenashev
Could you let me know regarding the User private views and any foresee issues with these changes in role-strategy plugin. I am clueless here regarding the User private views.

@oleg-nenashev
Copy link
Member

@pskumar448
The issue is that one user with Jenkins.READ permission may be able to access personal views of another user if the role does not take users into account. E.g. "Foo" pattern may apply to "/Foo" and to "/user/oleg-nenashev/Foo" if you do not somehow resolve users

@pskumar448
Copy link
Author

OK. @oleg-nenashev
Thanks for giving me the scenario, I will try to fix this issue.

@pskumar448
Copy link
Author

@oleg-nenashev
I am working on this to fix the Views related to MyViews.

@remm
Copy link

remm commented Nov 15, 2016

Hi guys, could you help me?
Looks like this bug should be fixed with this pull request.

@oleg-nenashev
Copy link
Member

@remm Responded in the ticket

@oleg-nenashev oleg-nenashev changed the title Added support for View permissions at the View level rather than only at global level [JENKINS-28975] Added support for View permissions at the View level rather than only at global level Jun 12, 2017

String getViewFullName(View view) {
StringBuilder sb = new StringBuilder();
sb.append(view.getOwnerItemGroup().getFullName());
Copy link
Contributor

@mawinter69 mawinter69 Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

View names are ambiguous this way. When you use the nested views plugin There could be 2 views with that name
Assume you have a folder and in this you have 2 views:
view1
view2
view2 is a nested view view, that contains also a view with name view1

folder/view1
      /view2/view1

For both views the above code would just return folder, which makes it unclear which is meant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants