Skip to content

Commit 969ccec

Browse files
committed
[SECURITY-3040]
1 parent 8bfe104 commit 969ccec

File tree

9 files changed

+84
-1
lines changed

9 files changed

+84
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,8 @@ These traits can be selected by selecting `Add` in the `Behaviours` section.
468468
469469
* `Discover group/subgroup projects` - Discover subgroup projects inside a group/subgroup. Only applicable to `GitLab Group` Job type whose owner is a `Group`/`Subgroup` but not `User`.
470470
471+
* `Discover shared projects` - Discover projects that are shared with the configured owner group from another group. Up until version 684 of the plugin this used to be the default behavior but is now a separate trait that is not added by default due to potential security concerns.
472+
471473
* `Log build status as comment on GitLab` - Enable logging build status as comment on GitLab. A comment is logged on the commit or merge request once the build is completed. You can decide if you want to log success builds or not. You can also use sudo user to comment the build status as commment e.g. `jenkinsadmin` or something similar.
472474
473475
* `Trigger build on merge request comment` - Enable trigger a rebuild of a merge request by comment with your desired comment body (default: `jenkins rebuild`). The job can only be triggered by trusted members of the project i.e. users with Developer/Maintainer/Owner accesslevel (also includes inherited from ancestor groups). By default only trusted members of project can trigger MR.

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<jenkins.version>2.387.3</jenkins.version>
3535
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
3636
<spotless.check.skip>false</spotless.check.skip>
37+
<hpi.compatibleSinceVersion>685</hpi.compatibleSinceVersion>
3738
</properties>
3839

3940
<dependencyManagement>

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ public void visitSources(@NonNull final SCMSourceObserver observer) throws IOExc
244244
GroupProjectsFilter groupProjectsFilter = new GroupProjectsFilter();
245245
wantSubGroupProjects = request.wantSubgroupProjects();
246246
groupProjectsFilter.withIncludeSubGroups(wantSubGroupProjects);
247+
groupProjectsFilter.withShared(request.wantSharedProjects());
247248
// If projectOwner is a subgroup, it will only return projects in the subgroup
248249
projects = gitLabApi.getGroupApi().getProjects(projectOwner, groupProjectsFilter);
249250
}

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorContext.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ public class GitLabSCMNavigatorContext
1010

1111
private boolean wantSubgroupProjects;
1212

13+
private boolean wantSharedProjects;
14+
1315
private int projectNamingStrategy = 1;
1416

1517
/** If true, archived repositories will be ignored. */
@@ -33,6 +35,15 @@ public GitLabSCMNavigatorContext wantSubgroupProjects(boolean include) {
3335
return this;
3436
}
3537

38+
public boolean wantSharedProjects() {
39+
return wantSharedProjects;
40+
}
41+
42+
public GitLabSCMNavigatorContext wantSharedProjects(boolean include) {
43+
this.wantSharedProjects = include;
44+
return this;
45+
}
46+
3647
/**
3748
* Returns the project naming strategy id.
3849
*

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigatorRequest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
public class GitLabSCMNavigatorRequest extends SCMNavigatorRequest {
99

10+
private final boolean wantSharedProjects;
1011
private boolean wantSubgroupProjects;
1112

1213
private int projectNamingStrategy;
@@ -17,6 +18,7 @@ protected GitLabSCMNavigatorRequest(
1718
@NonNull SCMSourceObserver observer) {
1819
super(source, context, observer);
1920
wantSubgroupProjects = context.wantSubgroupProjects();
21+
wantSharedProjects = context.wantSharedProjects();
2022
projectNamingStrategy = context.withProjectNamingStrategy();
2123
}
2224

@@ -27,6 +29,14 @@ public boolean wantSubgroupProjects() {
2729
return wantSubgroupProjects;
2830
}
2931

32+
/**
33+
*
34+
* @return wether to include projects that are shared with the group from other groups.
35+
*/
36+
public boolean wantSharedProjects() {
37+
return wantSharedProjects;
38+
}
39+
3040
/**
3141
* Returns the project naming strategy id.
3242
*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.jenkins.plugins.gitlabbranchsource;
2+
3+
import edu.umd.cs.findbugs.annotations.NonNull;
4+
import hudson.Extension;
5+
import jenkins.scm.api.SCMNavigator;
6+
import jenkins.scm.api.trait.SCMNavigatorContext;
7+
import jenkins.scm.api.trait.SCMNavigatorTrait;
8+
import jenkins.scm.api.trait.SCMNavigatorTraitDescriptor;
9+
import jenkins.scm.impl.trait.Discovery;
10+
import org.jenkinsci.Symbol;
11+
import org.kohsuke.stapler.DataBoundConstructor;
12+
13+
public class SharedProjectsDiscoveryTrait extends SCMNavigatorTrait {
14+
15+
@DataBoundConstructor
16+
public SharedProjectsDiscoveryTrait() {}
17+
18+
@Override
19+
protected void decorateContext(SCMNavigatorContext<?, ?> context) {
20+
if (context instanceof GitLabSCMNavigatorContext) {
21+
GitLabSCMNavigatorContext ctx = (GitLabSCMNavigatorContext) context;
22+
ctx.wantSharedProjects(true);
23+
}
24+
}
25+
26+
/**
27+
* Our descriptor.
28+
*/
29+
@Symbol("gitLabSharedProjectsDiscovery")
30+
@Extension
31+
@Discovery
32+
public static class DescriptorImpl extends SCMNavigatorTraitDescriptor {
33+
34+
/**
35+
* {@inheritDoc}
36+
*/
37+
@Override
38+
@NonNull
39+
public String getDisplayName() {
40+
return Messages.SharedProjectsDiscoveryTrait_displayName();
41+
}
42+
43+
@Override
44+
public Class<? extends SCMNavigator> getNavigatorClass() {
45+
return GitLabSCMNavigator.class;
46+
}
47+
}
48+
}

src/main/resources/io/jenkins/plugins/gitlabbranchsource/Messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ProjectNamingStrategyTrait.contextualProjectPath=Contextual Project Path
2222
ProjectNamingStrategyTrait.simpleProjectPath=Simple Project Path
2323
ProjectNamingStrategyTrait.projectName=Project Name
2424
SubGroupProjectDiscoveryTrait.displayName=Discover subgroup projects
25+
SharedProjectsDiscoveryTrait.displayName=Discover shared projects
2526
TagDiscoveryTrait.authorityDisplayName=Trust origin tags
2627
TagDiscoveryTrait.displayName=Discover tags
2728
GitLabSCMSource.TagCategory=Tags
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<p>
2+
Discovers all shared projects for an owner (Group/Subgroup) but not User.
3+
</p>
4+
<p>
5+
<strong>NOTE</strong> this trait used to be enabled by default,
6+
but it is potentially dangerous to allow repositories that are controlled by another group
7+
to execute on the Jenkins controller/folder.
8+
So the default behavior was changed and this trait is now optional.
9+
</p>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<div>
2-
Discovers all subgroup projects for a owner (Group/Subgroup) but not User.
2+
Discovers all subgroup projects for an owner (Group/Subgroup) but not User.
33
</div>

0 commit comments

Comments
 (0)