Skip to content

Commit a9e5701

Browse files
authored
Add native webhook configuration to skip certificate verification. (#1128)
1 parent 371a309 commit a9e5701

File tree

7 files changed

+64
-5
lines changed

7 files changed

+64
-5
lines changed

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/client/repository/BitbucketCloudWebhook.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,20 @@
2424
package com.cloudbees.jenkins.plugins.bitbucket.client.repository;
2525

2626
import com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketWebHook;
27+
import com.fasterxml.jackson.annotation.JsonProperty;
2728
import java.util.ArrayList;
2829
import java.util.List;
2930
import org.apache.commons.lang3.ObjectUtils;
3031

3132
public class BitbucketCloudWebhook implements BitbucketWebHook {
3233

3334
private String uuid;
34-
3535
private String description;
36-
3736
private String url;
38-
3937
private String secret;
40-
4138
private boolean active;
42-
39+
@JsonProperty("skip_cert_verification")
40+
private boolean skipCertVerification;
4341
private List<String> events = new ArrayList<>();
4442

4543
@Override
@@ -96,4 +94,12 @@ public void setSecret(String secret) {
9694
this.secret = secret;
9795
}
9896

97+
public boolean isSkipCertVerification() {
98+
return skipCertVerification;
99+
}
100+
101+
public void setSkipCertVerification(boolean skipCertVerification) {
102+
this.skipCertVerification = skipCertVerification;
103+
}
104+
99105
}

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/AbstractBitbucketWebhookConfiguration.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,11 @@ public abstract class AbstractBitbucketWebhookConfiguration implements Bitbucket
8585
*/
8686
private String endpointJenkinsRootURL;
8787

88+
/**
89+
* Allow send webhook to untrusted or self-signed certificates Jenkins host.
90+
*/
91+
private boolean skipCertVerification = false;
92+
8893
private boolean enableCache = false;
8994

9095
/**
@@ -170,6 +175,15 @@ public void setWebhooksCacheDuration(Integer webhooksCacheDuration) {
170175
this.webhooksCacheDuration = webhooksCacheDuration == null || webhooksCacheDuration < 0 ? Integer.valueOf(180) : webhooksCacheDuration;
171176
}
172177

178+
public boolean isSkipCertVerification() {
179+
return skipCertVerification;
180+
}
181+
182+
@DataBoundSetter
183+
public void setSkipCertVerification(boolean skipCertVerification) {
184+
this.skipCertVerification = skipCertVerification;
185+
}
186+
173187
public abstract static class AbstractBitbucketWebhookDescriptorImpl extends BitbucketWebhookDescriptor {
174188
protected abstract void clearCaches();
175189
protected abstract List<String> getStats();

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/cloud/CloudWebhookManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ private BitbucketCloudWebhook buildPayload() {
169169
hook.setActive(true);
170170
hook.setDescription("Jenkins hook");
171171
hook.setUrl(callbackURL);
172+
hook.setSkipCertVerification(configuration.isSkipCertVerification());
172173
if (configuration.isEnableHookSignature()) {
173174
String signatureCredentialsId = configuration.getHookSignatureCredentialsId();
174175
StringCredentials signatureSecret = BitbucketCredentialsUtils.lookupCredentials(Jenkins.get(), BitbucketCloudEndpoint.SERVER_URL, signatureCredentialsId, StringCredentials.class);
@@ -203,6 +204,12 @@ private boolean shouldUpdate(@NonNull BitbucketCloudWebhook current, @NonNull Bi
203204
update = true;
204205
}
205206

207+
if (current.isSkipCertVerification() != expected.isSkipCertVerification()) {
208+
current.setSkipCertVerification(expected.isSkipCertVerification());
209+
logger.info(() -> "Update skipCertVerification to " + expected.isSkipCertVerification());
210+
update = true;
211+
}
212+
206213
List<String> events = current.getEvents();
207214
List<String> expectedEvents = expected.getEvents();
208215
if (!events.containsAll(expectedEvents)) {

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/server/ServerWebhookManager.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ private BitbucketServerWebhook buildPayload() {
168168
hook.setDescription("Jenkins hook");
169169
hook.setEvents(NATIVE_SERVER_EVENTS);
170170
hook.setUrl(callbackURL);
171+
hook.setSslVerificationRequired(!configuration.isSkipCertVerification());
171172
if (configuration.isEnableHookSignature()) {
172173
String signatureCredentialsId = configuration.getHookSignatureCredentialsId();
173174
StringCredentials signatureSecret = BitbucketCredentialsUtils.lookupCredentials(Jenkins.get(), serverURL, signatureCredentialsId, StringCredentials.class);
@@ -202,6 +203,12 @@ private boolean shouldUpdate(@NonNull BitbucketServerWebhook current, @NonNull B
202203
update = true;
203204
}
204205

206+
if (current.isSslVerificationRequired() != expected.isSslVerificationRequired()) {
207+
current.setSslVerificationRequired(expected.isSslVerificationRequired());
208+
logger.info(() -> "Update webhook sslVerificationRequired " + expected.isSslVerificationRequired());
209+
update = true;
210+
}
211+
205212
List<String> events = current.getEvents();
206213
List<String> expectedEvents = expected.getEvents();
207214
if (!events.containsAll(expectedEvents)) {

src/main/java/com/cloudbees/jenkins/plugins/bitbucket/server/client/repository/BitbucketServerWebhook.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class BitbucketServerWebhook implements BitbucketWebHook {
4040
private String url;
4141
private List<String> events = new ArrayList<>();
4242
private boolean active;
43+
private boolean sslVerificationRequired = true;
4344
@JsonProperty("configuration")
4445
private Map<String, String> configuration = new HashMap<>();
4546

@@ -97,4 +98,12 @@ public void setSecret(String secret) {
9798
configuration.put("secret", secret);
9899
}
99100

101+
public boolean isSslVerificationRequired() {
102+
return sslVerificationRequired;
103+
}
104+
105+
public void setSslVerificationRequired(boolean sslVerificationRequired) {
106+
this.sslVerificationRequired = sslVerificationRequired;
107+
}
108+
100109
}

src/main/resources/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/AbstractBitbucketWebhookConfiguration/config.jelly

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ THE SOFTWARE.
3939
</f:entry>
4040
</f:optionalBlock>
4141

42+
<f:entry title="${%Skip certificate verification}" field="skipCertVerification">
43+
<f:checkbox default="false" />
44+
</f:entry>
45+
4246
<f:optionalBlock title="${%Enable cache}" field="enableCache" inline="true">
4347
<f:entry title="${%How long to cache webhook requests, in minutes}" field="webhooksCacheDuration">
4448
<f:number default="180" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div>
2+
<p>
3+
If you're using a self-signed certificate and want to disable certificate verification, select Skip certificate
4+
verification.
5+
</p>
6+
<p>
7+
<b>Note</b> We recommend that you don't disable certificate verification because self-signed certificates are
8+
inherently not secure. Read the next section for more information about why you would or wouldn't use
9+
self-signed
10+
certificates.
11+
</p>
12+
</div>

0 commit comments

Comments
 (0)