jenkinsci / bitbucket-branch-source-plugin

Bitbucket Branch Source Plugin
https://plugins.jenkins.io/cloudbees-bitbucket-branch-source
MIT License
217 stars 349 forks source link

Introduce a new trust policy: "trust pull request submitter with write right in the destination repository/branch" #842

Open Romain-Geissler-1A opened 3 months ago

Romain-Geissler-1A commented 3 months ago

What feature do you want to see added?

In my corporate environment with thousands of developers using Jenkins daily, the deployment of the latest version of the BitBucket source plugin had quite some effect, because of the fix for SECURITY-3300 / CVE-2024-28152.

My own experience is that most of the time, the people who submit changes to Jenkinsfile are also the "maintainers" of a given repository (at least in corporate environment, it may be less true in an open source project having many external contributors). So in most cases, I would expect the person submitting a change to a Jenkinsfile via pull request also has the "write" right on BitBucket side, so is a rather "trusted" person. The current implementation of who is trusted and who isn't in the BitBucket source plugin assumes that if you can create a fork inside the project, then somehow you have the "write" right into the whole project, so you are "trusted". I think this encourages wrong practices (I honestly don't see why people would create some "my-project2" BitBucket project to be able to test a change targetting "my-project"), and IMO it hardly makes sense to start teaching my colleagues that:

Upstream changes

No response

Are you interested in contributing this feature?

I hardly know anything in Java, and hardly know your code. If maintainers of these repo do accept the idea, but have no time to implement it, I (or someone in my company) may try to have a look to help implementing this.

KalleOlaviNiemitalo commented 3 months ago

Do Bitbucket Cloud and/or Bitbucket Data Center provide an API that Jenkins could use to check whether the author of the pull request has write access? IIRC, Bitbucket Cloud in particular has tightened access to user information because of GDPR.

Romain-Geissler-1A commented 3 months ago

Indeed looking at the API of BitBucket Data Center it really doesn't seem to exist. In BitBucket Cloud it seems there is a notion of "role", the one with write access being "contributor" but I am not sure how restricted is this API.

Since in my case I care more particularly about BitBucket Data Center, and with the privacy in mind as I guess exposing who has right to do what is a bit a sensitive information, I have opened a different feature request on BitBucket Data Center side here: https://jira.atlassian.com/browse/BSERV-19339

KalleOlaviNiemitalo commented 3 months ago

The author of the pull request may be different from

There is a rejected feature request [BSERV-8635] Ability to change the author of a pull request. If that were ever implemented and Jenkins used the author of a pull request for the trust decision, then the following could happen:

  1. A user makes a pull request from a personal fork. This PR does not change Jenkinsfile yet.
  2. A project maintainer takes authorship of the PR, in order to make commits and request approval from the original author. Jenkins now starts trusting the PR.
  3. The original author pushes commits that change Jenkinsfile. Jenkins trusts these.

BSERV-8635 seems unlikely to be implemented so this scenario cannot happen as is. Regardless, I feel it is an indication that the PR authorship might not be the best input for the trust decision. What could be used instead: