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

Fix for defect #695: permission check for multibranch pipelines #1544

Merged
merged 7 commits into from
Aug 6, 2023

Conversation

mlynnyk
Copy link
Contributor

@mlynnyk mlynnyk commented Jul 10, 2023

This pull request addresses this issue: #695 . The discussion does provide a detailed description of the defect.

While it is not a critical security problem, the issue does, in fact, results in allowing a user to perform branch indexing action, which is normally restring by the "Job/Build" permission.

Having the plugin with the code change installed, and trying to trigger a webhook against a multibranch pipeline would return not 200 (which is current behavior in all cases) but the correct "Error 403 anonymous is missing the Job/Build permission" response. Likewise, having a Webhook configured with basic auth ( http://username:apitoken@my_jenkins.com:8080/project/pipeline_test/ ) when user "username" does not have sufficient permissions, would result in "Error 403 username is missing the Job/Build permission", which, again, should be the correct behavior.

@mlynnyk mlynnyk requested a review from a team as a code owner July 10, 2023 07:20
@mlynnyk mlynnyk changed the title Fix for defect #635: permission check for multibranch pipelines Fix for defect #695: permission check for multibranch pipelines Jul 10, 2023
@krisstern
Copy link
Member

Thanks @mlynnyk for you code contribution! I will review your PR over the next few days and merge once it is approved and we are ready to do so.

(GitLabConnectionConfig) Jenkins.get().getDescriptor(GitLabConnectionConfig.class);
if (gitlabConfig != null) {
if (gitlabConfig.isUseAuthenticatedEndpoint()) {
if (!project.getACL().hasPermission(authentication, permission)) {
Copy link
Member

Choose a reason for hiding this comment

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

'hasPermission(org.acegisecurity.Authentication, hudson.security.Permission)' is deprecated, suggest using https://javadoc.jenkins-ci.org/hudson/security/AccessControlled.html#hasPermission2(org.springframework.security.core.Authentication,hudson.security.Permission) instead.

Assert.assertThrows(
HttpResponses.HttpResponseException.class,
() -> new PushBuildAction(item, getJson("PushEvent.json"), null).execute(response));
item.onSCMSourceUpdated(source);
Copy link
Member

Choose a reason for hiding this comment

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

'onSCMSourceUpdated(jenkins.scm.api.SCMSource)' is deprecated, implementations of SCMSourceOwner would prefer the SCMEventListener extension point which allows for more fine-grained response to events, so prefer delivering event notification through SCMHeadEvent.fireNow(SCMHeadEvent), SCMSourceEvent.fireNow(SCMSourceEvent) or SCMNavigatorEvent.fireNow(SCMNavigatorEvent) as appropriate.

throw HttpResponses.ok();
}
throw HttpResponses.errorWithoutStack(409, "Push Hook is not supported for this project");
}

private class SCMSourceOwnerNotifier implements Runnable {
private final Authentication authentication;
Copy link
Member

Choose a reason for hiding this comment

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

'org.acegisecurity.Authentication' is deprecated.

throw HttpResponses.ok();
}
throw HttpResponses.errorWithoutStack(409, "Push Hook is not supported for this project");
}

private class SCMSourceOwnerNotifier implements Runnable {
private final Authentication authentication;

public SCMSourceOwnerNotifier(Authentication authentication) {
Copy link
Member

Choose a reason for hiding this comment

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

'org.acegisecurity.Authentication' is deprecated.

Copy link
Member

@krisstern krisstern left a comment

Choose a reason for hiding this comment

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

Aside from some deprecation issues, the PR looks okay.

@krisstern
Copy link
Member

@mlynnyk Would you like to address the deprecations, or are you happy with the code as is?

@mlynnyk
Copy link
Contributor Author

mlynnyk commented Jul 31, 2023

Hi @krisstern , thank you for reviewing this and providing your feedback. I would say that the matter of addressing these deprecation issues appears to be somewhat wider than this particular code change. For example, when replacing "org.acegisecurity.Authentication" with "org.springframework.security.core.Authentication" (I believe that's the correct one) it would make sense to update other classes using it and eliminate its usage completely.

When I added this PR, I merely wanted to fix the defect while keeping the code more or less consistent with the rest of the implementation. I don't really want to get involved with a wider refactoring, this appears to be a whole separate task. Also, I am currently running the plugin with this code change on a production environment and it works perfectly well, so it has been tested. Because of these reasons I would prefer to leave this code as it is now.

@krisstern
Copy link
Member

Hi @mlynnyk Sure, let me check things interactively one more time before merging this. Again, thank you for your contribution!

@krisstern krisstern added the bug For changelog: Minor bug. Will be listed after features label Aug 6, 2023
@krisstern krisstern merged commit 5239b28 into jenkinsci:master Aug 6, 2023
15 checks passed
@MattLud
Copy link

MattLud commented Jul 18, 2024

Hi there - as a follow up to this PR, does the existing Multibranch documentation still apply?

It seems like tokens won't be used going forward (nor were they ever used?) and the official doc should request use of Basic Auth parameters.

https://github.com/jenkinsci/gitlab-plugin?tab=readme-ov-file#pipeline-multibranch-jobs-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug For changelog: Minor bug. Will be listed after features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants