Skip to content

Add configurable minimum permissions for triggers - #60

Merged
bluesliverx merged 1 commit into
jenkinsci:masterfrom
pascal-hofmann:configurable-minimum-permissions
Apr 17, 2023
Merged

bluesliverx merged 1 commit into
jenkinsci:masterfrom
pascal-hofmann:configurable-minimum-permissions

Conversation

@pascal-hofmann

@pascal-hofmann pascal-hofmann commented Mar 3, 2023 •

Copy link
Copy Markdown
Contributor

For private repositories people with Read role (aka pull permission) are seen as collaborators
by the GitHub API. This means, they were able trigger builds with older versions of the plugin.

This change fixes this, and also adds the option to limit triggering of builds to repository admins.

The existing allowUntrusted toggle is dropped from the UI.
This change adds a new drop-down Minimum Permissions on repository to trigger the build with these options:

  • Only users with admin permission
  • Only users that can push to the repository (default)
  • Allow untrusted users to trigger the build

Use-case for the "admin" part:

  • We have PR builds in our organization that need access to credentials with a high blast radius.
  • For repos with these builds all developers in the organisation have write access, but merging to master is restricted to admins (via .github/CODEOWNERS).
  • Allowing everyone to trigger builds is dangerous, as the Jenkinsfile and other scripts that are used in the build could be modified by people with bad intend / hacked accounts. So we also want to be able to limit triggering of builds to admins only.

Bildschirm­foto 2023-03-06 um 15 53 27

@pascal-hofmann

Copy link
Copy Markdown
Contributor Author

@bluesliverx It would be great to get this merged/released soon.

Our GitHub org has a lot of users, but we trust only a subset of them for certain repositories.

@lprimak

lprimak commented Mar 3, 2023

Copy link
Copy Markdown
Contributor

@pascal-hofmann I am not sure I understand any reason for this change.
The "allow untrusted builds" no longer makes any sense, and creates a combinatorial explosion
with the dropdown box which makes no sense and is very confusing.

For example, "NONE" equals "allow untrusted builds" and wording is confusing.
"READ" makes no sense to me because if there are no "READ" permissions, the user wouldn't
be able to clone nor comment on the PR anyway.
"ADMIN" may make sense but it's really a stretch, I can't think of a single use case for it.

Am I not understanding something critical here?
What's the exact issue that triggered the need for this change?
Can you create a ticket that explains the issue in detail?

@lprimak lprimak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See comments on this PR. It doesn't make sense to me

@pascal-hofmann

pascal-hofmann commented Mar 4, 2023 •

Copy link
Copy Markdown
Contributor Author

Hi,
thanks for the quick and honest feedback. I'll create an issue with more details and will also update this PR.

Edit: The existing issue types don't make much sense and request a lot of information that's not relevant. I'll update the PR description / commit message instead.

@pascal-hofmann
pascal-hofmann force-pushed the configurable-minimum-permissions branch 3 times, most recently from 54ef976 to a2fe5b6 Compare March 4, 2023 11:27
@pascal-hofmann

pascal-hofmann commented Mar 4, 2023 •

Copy link
Copy Markdown
Contributor Author

@lprimak I updated the PR description to make the intent/reasoning behind this PR clearer.

PS: I converted the PR to a draft because I was not able to test the latest code changes yet. I'll also add an updated screenshot once this is done.

@pascal-hofmann
pascal-hofmann marked this pull request as draft March 4, 2023 11:29
@pascal-hofmann
pascal-hofmann force-pushed the configurable-minimum-permissions branch 2 times, most recently from 75fde26 to c8a12d2 Compare March 4, 2023 13:46
@lprimak

lprimak commented Mar 4, 2023

Copy link
Copy Markdown
Contributor

Ok, I can see the issue with private repositories.
I think your solution should work and not break anything.
Please create a ticket nonetheless (you can delete the template if you wish)

@pascal-hofmann
pascal-hofmann force-pushed the configurable-minimum-permissions branch from c8a12d2 to 92c36fd Compare March 4, 2023 18:14
@pascal-hofmann

Copy link
Copy Markdown
Contributor Author

I opened #61 for this.

@pascal-hofmann
pascal-hofmann force-pushed the configurable-minimum-permissions branch 2 times, most recently from 9d1174a to f95d24e Compare March 6, 2023 14:52
@pascal-hofmann
pascal-hofmann marked this pull request as ready for review March 6, 2023 23:45
@pascal-hofmann
pascal-hofmann requested a review from lprimak March 15, 2023 20:05
@lprimak

lprimak commented Mar 16, 2023

Copy link
Copy Markdown
Contributor

@pascal-hofmann I already reviewed it (repeated code comments, etc)
I realize there is already repeated code, but I would rather not have any more repeated code on top of that.
Thank you

@pascal-hofmann

pascal-hofmann commented Mar 16, 2023 •

Copy link
Copy Markdown
Contributor Author

@lprimak I just tried creating an abstract base class AbstractTriggerBranchProperty but I can also see this as selectable in the jenkins UI. Do you know how to get rid of this?

Edit: Found it and pushed the refactored version.

@pascal-hofmann
pascal-hofmann force-pushed the configurable-minimum-permissions branch from f95d24e to a69c6b6 Compare March 16, 2023 08:43
For private repositories people with `Read` role (aka `pull` permission) are seen as collaborators
by the GitHub API. This means, they were able trigger builds with older versions of the plugin.

This change fixes this, and also adds the option to limit triggering of builds to repository admins.

The existing `allowUntrusted` toggle is dropped from the UI.
This change adds a new drop-down `Minimum Permissions on repository to trigger the build` with
these options:
- Only users with admin permission
- Only users that can push to the repository (default)
- Allow untrusted users to trigger the build
@pascal-hofmann
pascal-hofmann force-pushed the configurable-minimum-permissions branch from a69c6b6 to 00d64c4 Compare March 16, 2023 08:48
*
* @return the strategy options.
*/
@NonNull

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Repeated code. Needs refactor

*
* @return the strategy options.
*/
@NonNull

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Repeated code. Needs refactor

@@ -14,12 +19,13 @@
*/
public class TriggerPRReviewBranchProperty extends BranchProperty {
private boolean allowUntrusted;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Needs to be removed along with it's getters and setters

@@ -30,6 +36,18 @@ public void setAllowUntrusted(boolean allowUntrusted) {
this.allowUntrusted = allowUntrusted;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Needs to be removed

@lprimak

lprimak commented Mar 16, 2023

Copy link
Copy Markdown
Contributor

Can we just remove "allow unstrusted" from all the code instead of deprecating it?

@pascal-hofmann

Copy link
Copy Markdown
Contributor Author

I‘m not sure what will happen with existing configurations if I do that. I thought this way things just continue to work as expected. If that’s not desired I can remove it completely.

What do you prefer?

@lprimak

lprimak commented Mar 16, 2023

Copy link
Copy Markdown
Contributor

@bluesliverx what do you think?

@pascal-hofmann

Copy link
Copy Markdown
Contributor Author

Hey,
is there any update on this? Can I help with getting this merged?

@bluesliverx

Copy link
Copy Markdown
Contributor

Sorry, finally getting back to this project. After looking through the code, I believe it is done the correct way. While the allowUntrusted flag still shows up in the code, it is marked deprecated and the value is handled correctly to set the new value. I like this quite a bit, thanks for the improvement!

@bluesliverx

Copy link
Copy Markdown
Contributor

I'm just trying to get the PR to build and then I'll merge. Also, there is a new label type that was just barely merged. I'll work on getting this same functionality added to that after it builds/merges. Unless you beat me to it and then by all means add it to the label trigger (#62) @pascal-hofmann

@bluesliverx
bluesliverx merged commit e96c665 into jenkinsci:master Apr 17, 2023
@pascal-hofmann
pascal-hofmann deleted the configurable-minimum-permissions branch April 17, 2023 18:42
@bluesliverx

Copy link
Copy Markdown
Contributor

This has been released in 96.v9ff13b69dd66.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants