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

Make SCMBinder try to abort builds in which Jenkinsfile has been modified by an untrusted contributor #69

Merged
merged 4 commits into from Mar 7, 2019

Conversation

@jglick
Copy link
Member

jglick commented Dec 18, 2017

jenkinsci/ssh-slaves-plugin#79 and the like are pretty annoying: the historical behavior of SCMBinder is to allow a build which includes an untrusted edit to Jenkinsfile to proceed, but actually reading the Jenkinsfile contents from the corresponding trusted revision instead. If you get a green check mark, no one is going to go looking for the one-line warning about this. It is better to behave as if the script started with

readTrusted 'Jenkinsfile'

In other words, to just fail immediately in such a case. I cannot think of any good reason for anyone to be relying on the old behavior, but just in case I kept it as an option which can be enabled by system property.

Note that this change will not have any effect on GitHub PR merge jobs until JENKINS-43194 is implemented. Performing a rev-to-tip comparison of script contents in a heavyweight checkout would be pretty awkward, as SCMBinder could not then rely on CpsScmFlowDefinition for script checkout; ReadTrustedStep would need to be refactored to make its main logic reusable, and there would be a lot of different code paths to maintain code coverage for. I think the effort is better put into JENKINS-43194.

@reviewbybees

…fied by an untrusted contributor.
@jglick jglick requested review from abayer and svanoort Dec 18, 2017
Copy link
Member

abayer left a comment

Change looks fine code-wise, but I want a little time to think about whether this is actually the right behavior.

Copy link
Member

svanoort left a comment

Seems okay to me, despite a PR description that only a Jesse could love. @rsandell might be better able to see any issues this would pose though.

@svanoort
Copy link
Member

svanoort commented Dec 18, 2017

Agree with @abayer that this needs some extra consideration for unexpected impacts

@jglick jglick requested a review from rsandell Dec 18, 2017
@reviewbybees
Copy link

reviewbybees commented Jan 11, 2018

This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation.

@rsandell
Copy link
Member

rsandell commented Jan 18, 2018

I don't have the context to see any potential consequences on this.

Another mode that would be nice would be if Jenkins could pause and ask something like

"WARNING The script has been modified by a non trusted party, please review before proceeding. Proceed? Yes / No"

@jglick
Copy link
Member Author

jglick commented Jan 18, 2018

@rsandell that would be a reasonable enhancement, although the link could only safely be clicked by someone with Item.CONFIGURE, so it would not for example help the case on ci.jenkins.io where few developers have anything beyond r/o permissions on Jenkins, even when they do have write access to the repository backing a job. Also note that the link would not survive Jenkins restart (the program has not started at this point, and you are blocking a native thread until someone interacts with the build).

Anyway that is something that could be added later—this PR at least fixes the current confusing behavior, and does so with minimal code changes.

@jglick jglick mentioned this pull request Jan 18, 2018
3 of 4 tasks complete
@jglick jglick requested a review from abayer Mar 9, 2018
Copy link
Member

abayer left a comment

I'm still not 100% on this - I'd expect to see bug reports trickle in once this is released from people not expecting their PR build to fail because it also happened to contain a change to the Jenkinsfile. But we can cross that bridge when we get to it, I guess.

@jglick
Copy link
Member Author

jglick commented Mar 12, 2018

people not expecting their PR build to fail because it also happened to contain a change to the Jenkinsfile

My attitude is that this is better than silently ignoring the change. You can always request that a maintainer refile the same branch. Or if JENKINS-46795 were implemented, it would suffice for the maintainer to approve the PR and kick off a new build.

@jglick
Copy link
Member Author

jglick commented Mar 27, 2018

Just remember that this was mentioned in JENKINS-45970.

@abayer
Copy link
Member

abayer commented Mar 27, 2018

@jglick Yeah, I think I might prefer loud logging in these cases rather than aborting, as mentioned in JENKINS-45970.

@jglick
Copy link
Member Author

jglick commented Mar 27, 2018

Well decide what you want one way or another and the PR can be adjusted accordingly. The worst thing you can do is leave things the way they are.

@abayer
Copy link
Member

abayer commented Mar 27, 2018

@jglick Yeah, let's go with logging a loud warning, then. =)

@jglick
Copy link
Member Author

jglick commented Mar 27, 2018

OK. I still think a simple build failure is a lot more discoverable than any kind of build logging, but will do whatever is necessary to get something merged.

public static class WarningNote extends ConsoleNote {

@Override public ConsoleAnnotator annotate(Object context, MarkupText text, int charPos) {
text.addMarkup(0, text.length(), "<span class='warning-inline'>", "</span>");

This comment has been minimized.

Copy link
@jglick

jglick Mar 27, 2018

Author Member

Thus:

screenshot

@jglick jglick dismissed stale reviews from svanoort and abayer Mar 27, 2018

stale

@jglick jglick requested review from abayer and svanoort Mar 27, 2018
@jglick
Copy link
Member Author

jglick commented Aug 16, 2018

Would add @dwnusbaum as a reviewer if I had write permission.

@abayer
Copy link
Member

abayer commented Aug 16, 2018

Huh, I don't have write access either. That's...wrong.

@abayer abayer requested a review from dwnusbaum Aug 16, 2018
@abayer
Copy link
Member

abayer commented Aug 16, 2018

And fixed - the developers group didn't have write access for some reason.

@abayer
abayer approved these changes Aug 16, 2018
@jglick jglick mentioned this pull request Nov 8, 2018
@rsandell rsandell merged commit f9b5cd0 into jenkinsci:master Mar 7, 2019
1 check passed
1 check passed
continuous-integration/jenkins/pr-merge This commit looks good
Details
@jglick jglick deleted the jglick:SCMBinder-reject-untrusted-edits branch Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

6 participants
You can’t perform that action at this time.