Skip to content

Commit 2597c60

Browse files
committed
Merge remote-tracking branch 'upstream/master'
2 parents 6ea0e1e + 50351eb commit 2597c60

21 files changed

+866
-226
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Jenkins Security Scan
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types: [ opened, synchronize, reopened ]
9+
workflow_dispatch:
10+
11+
permissions:
12+
security-events: write
13+
contents: read
14+
actions: read
15+
16+
jobs:
17+
security-scan:
18+
uses: jenkins-infra/jenkins-security-scan/.github/workflows/jenkins-security-scan.yaml@v2
19+
with:
20+
java-cache: 'maven' # Optionally enable use of a build dependency cache. Specify 'maven' or 'gradle' as appropriate.
21+
# java-version: 21 # Optionally specify what version of Java to set up for the build, or remove to use a recent default.

pom.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>4.81</version>
7+
<version>4.88</version>
88
<relativePath />
99
</parent>
1010

@@ -33,7 +33,7 @@
3333
<changelist>999999-SNAPSHOT</changelist>
3434
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
3535
<hpi.compatibleSinceVersion>2.2.0</hpi.compatibleSinceVersion>
36-
<jenkins.version>2.414.3</jenkins.version>
36+
<jenkins.version>2.440.3</jenkins.version>
3737
<useBeta>true</useBeta>
3838
<spotless.check.skip>false</spotless.check.skip>
3939
</properties>
@@ -42,8 +42,8 @@
4242
<dependencies>
4343
<dependency>
4444
<groupId>io.jenkins.tools.bom</groupId>
45-
<artifactId>bom-2.414.x</artifactId>
46-
<version>2718.v7e8a_d43b_3f0b_</version>
45+
<artifactId>bom-2.440.x</artifactId>
46+
<version>3234.v5ca_5154341ef</version>
4747
<type>pom</type>
4848
<scope>import</scope>
4949
</dependency>
@@ -107,7 +107,7 @@
107107
<dependency>
108108
<groupId>org.awaitility</groupId>
109109
<artifactId>awaitility</artifactId>
110-
<version>4.2.1</version>
110+
<version>4.2.2</version>
111111
<scope>test</scope>
112112
</dependency>
113113
<dependency>

src/main/java/org/jenkinsci/plugins/github_branch_source/Connector.java

+15-16
Original file line numberDiff line numberDiff line change
@@ -295,23 +295,22 @@ public static StandardCredentials lookupScanCredentials(
295295
@CheckForNull String repoOwner) {
296296
if (Util.fixEmpty(scanCredentialsId) == null) {
297297
return null;
298-
} else {
299-
StandardCredentials c = CredentialsMatchers.firstOrNull(
300-
CredentialsProvider.lookupCredentials(
301-
StandardUsernameCredentials.class,
302-
context,
303-
context instanceof Queue.Task
304-
? ((Queue.Task) context).getDefaultAuthentication()
305-
: ACL.SYSTEM,
306-
githubDomainRequirements(apiUri)),
307-
CredentialsMatchers.allOf(
308-
CredentialsMatchers.withId(scanCredentialsId), githubScanCredentialsMatcher()));
309-
if (c instanceof GitHubAppCredentials && repoOwner != null) {
310-
return ((GitHubAppCredentials) c).withOwner(repoOwner);
311-
} else {
312-
return c;
313-
}
314298
}
299+
StandardCredentials c = CredentialsMatchers.firstOrNull(
300+
CredentialsProvider.lookupCredentialsInItem(
301+
StandardUsernameCredentials.class,
302+
context,
303+
context instanceof Queue.Task
304+
? ((Queue.Task) context).getDefaultAuthentication2()
305+
: ACL.SYSTEM2,
306+
githubDomainRequirements(apiUri)),
307+
CredentialsMatchers.allOf(
308+
CredentialsMatchers.withId(scanCredentialsId), githubScanCredentialsMatcher()));
309+
310+
if (c instanceof GitHubAppCredentials && repoOwner != null) {
311+
c = ((GitHubAppCredentials) c).withOwner(repoOwner);
312+
}
313+
return c;
315314
}
316315

317316
/**

src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubAppCredentials.java

+19-19
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ private static class CredentialsTokenProvider extends TokenProvider {
191191
private final GitHubAppCredentials credentials;
192192

193193
CredentialsTokenProvider(GitHubAppCredentials credentials) {
194-
super(credentials.appID, credentials.privateKey.getPlainText());
194+
super(credentials.getAppID(), credentials.getPrivateKey().getPlainText());
195195
this.credentials = credentials;
196196
}
197197

@@ -284,17 +284,17 @@ private static long getExpirationSeconds(GHAppInstallationToken appInstallationT
284284

285285
@NonNull
286286
String actualApiUri() {
287-
return Util.fixEmpty(apiUri) == null ? "https://api.github.com" : apiUri;
287+
return Util.fixEmpty(getApiUri()) == null ? "https://api.github.com" : getApiUri();
288288
}
289289

290290
private AppInstallationToken getToken(GitHub gitHub) {
291291
synchronized (this) {
292292
try {
293293
if (cachedToken == null || cachedToken.isStale()) {
294-
LOGGER.log(Level.FINE, "Generating App Installation Token for app ID {0}", appID);
294+
LOGGER.log(Level.FINE, "Generating App Installation Token for app ID {0}", getAppID());
295295
cachedToken = generateAppInstallationToken(
296-
gitHub, appID, privateKey.getPlainText(), actualApiUri(), owner);
297-
LOGGER.log(Level.FINER, "Retrieved GitHub App Installation Token for app ID {0}", appID);
296+
gitHub, getAppID(), getPrivateKey().getPlainText(), actualApiUri(), getOwner());
297+
LOGGER.log(Level.FINER, "Retrieved GitHub App Installation Token for app ID {0}", getAppID());
298298
}
299299
} catch (Exception e) {
300300
if (cachedToken != null && !cachedToken.isExpired()) {
@@ -304,14 +304,14 @@ private AppInstallationToken getToken(GitHub gitHub) {
304304
LOGGER.log(
305305
Level.WARNING,
306306
"Failed to generate new GitHub App Installation Token for app ID "
307-
+ appID
307+
+ getAppID()
308308
+ ": cached token is stale but has not expired",
309309
e);
310310
} else {
311311
throw e;
312312
}
313313
}
314-
LOGGER.log(Level.FINEST, "Returned GitHub App Installation Token for app ID {0}", appID);
314+
LOGGER.log(Level.FINEST, "Returned GitHub App Installation Token for app ID {0}", getAppID());
315315

316316
return cachedToken;
317317
}
@@ -328,7 +328,7 @@ public Secret getPassword() {
328328
@NonNull
329329
@Override
330330
public String getUsername() {
331-
return appID;
331+
return getAppID();
332332
}
333333

334334
@Override
@@ -338,9 +338,9 @@ public boolean isUsernameSecret() {
338338

339339
@NonNull
340340
public synchronized GitHubAppCredentials withOwner(@NonNull String owner) {
341-
if (this.owner != null) {
342-
if (!owner.equals(this.owner)) {
343-
throw new IllegalArgumentException("Owner mismatch: " + this.owner + " vs. " + owner);
341+
if (this.getOwner() != null) {
342+
if (!owner.equals(this.getOwner())) {
343+
throw new IllegalArgumentException("Owner mismatch: " + this.getOwner() + " vs. " + owner);
344344
}
345345
return this;
346346
}
@@ -349,8 +349,8 @@ public synchronized GitHubAppCredentials withOwner(@NonNull String owner) {
349349
}
350350
return byOwner.computeIfAbsent(owner, k -> {
351351
GitHubAppCredentials clone =
352-
new GitHubAppCredentials(getScope(), getId(), getDescription(), appID, privateKey);
353-
clone.apiUri = apiUri;
352+
new GitHubAppCredentials(getScope(), getId(), getDescription(), getAppID(), getPrivateKey());
353+
clone.apiUri = getApiUri();
354354
clone.owner = owner;
355355
return clone;
356356
});
@@ -359,7 +359,7 @@ public synchronized GitHubAppCredentials withOwner(@NonNull String owner) {
359359
@NonNull
360360
@Override
361361
public Credentials forRun(Run<?, ?> context) {
362-
if (owner != null) {
362+
if (getOwner() != null) {
363363
return this;
364364
}
365365
Job<?, ?> job = context.getParent();
@@ -498,7 +498,7 @@ long getTokenStaleEpochSeconds() {
498498
* <li>The agent need not be able to contact GitHub.
499499
* </ul>
500500
*/
501-
private Object writeReplace() {
501+
protected Object writeReplace() {
502502
if (
503503
/* XStream */ Channel.current() == null) {
504504
return this;
@@ -523,12 +523,12 @@ private static final class DelegatingGitHubAppCredentials extends BaseStandardCr
523523
DelegatingGitHubAppCredentials(GitHubAppCredentials onMaster) {
524524
super(onMaster.getScope(), onMaster.getId(), onMaster.getDescription());
525525
JenkinsJVM.checkJenkinsJVM();
526-
appID = onMaster.appID;
526+
appID = onMaster.getAppID();
527527
JSONObject j = new JSONObject();
528528
j.put("appID", appID);
529-
j.put("privateKey", onMaster.privateKey.getPlainText());
529+
j.put("privateKey", onMaster.getPrivateKey().getPlainText());
530530
j.put("apiUri", onMaster.actualApiUri());
531-
j.put("owner", onMaster.owner);
531+
j.put("owner", onMaster.getOwner());
532532
tokenRefreshData = Secret.fromString(j.toString()).getEncryptedValue();
533533

534534
// Check token is valid before sending it to the agent.
@@ -541,7 +541,7 @@ private static final class DelegatingGitHubAppCredentials extends BaseStandardCr
541541
LOGGER.log(
542542
Level.FINEST,
543543
"Checking App Installation Token for app ID {0} before sending to agent",
544-
onMaster.appID);
544+
onMaster.getAppID());
545545
onMaster.getPassword();
546546
} catch (Exception e) {
547547
LOGGER.log(

src/main/java/org/jenkinsci/plugins/github_branch_source/GitHubSCMBuilder.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ public GitHubSCMBuilder(
124124
if (repoUrl != null) {
125125
withBrowser(new GithubWeb(repoUrl));
126126
}
127-
withCredentials(credentialsId(), null);
128127
}
129128

130129
/**
@@ -189,7 +188,9 @@ public final RepositoryUriResolver uriResolver() {
189188
* {@code null} to detect the the protocol based on the credentialsId. Defaults to HTTP if
190189
* credentials are {@code null}. Enables support for blank SSH credentials.
191190
* @return {@code this} for method chaining.
191+
* @deprecated Use {@link #withCredentials(String)} and {@link #withResolver(RepositoryUriResolver)}
192192
*/
193+
@Deprecated
193194
@NonNull
194195
public GitHubSCMBuilder withCredentials(String credentialsId, RepositoryUriResolver uriResolver) {
195196
if (uriResolver == null) {
@@ -200,6 +201,12 @@ public GitHubSCMBuilder withCredentials(String credentialsId, RepositoryUriResol
200201
return withCredentials(credentialsId);
201202
}
202203

204+
@NonNull
205+
public GitHubSCMBuilder withResolver(RepositoryUriResolver uriResolver) {
206+
this.uriResolver = uriResolver;
207+
return this;
208+
}
209+
203210
/**
204211
* Returns a {@link RepositoryUriResolver} according to credentials configuration.
205212
*
@@ -215,12 +222,12 @@ public static RepositoryUriResolver uriResolver(
215222
return HTTPS;
216223
} else {
217224
StandardCredentials credentials = CredentialsMatchers.firstOrNull(
218-
CredentialsProvider.lookupCredentials(
225+
CredentialsProvider.lookupCredentialsInItem(
219226
StandardCredentials.class,
220227
context,
221228
context instanceof Queue.Task
222-
? ((Queue.Task) context).getDefaultAuthentication()
223-
: ACL.SYSTEM,
229+
? ((Queue.Task) context).getDefaultAuthentication2()
230+
: ACL.SYSTEM2,
224231
URIRequirementBuilder.create()
225232
.withHostname(RepositoryUriResolver.hostnameFromApiUri(apiUri))
226233
.build()),

0 commit comments

Comments
 (0)