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(jenkins): Igor fails to start if only keystore is configured #856

Merged
merged 4 commits into from
Oct 7, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import com.netflix.spinnaker.igor.jenkins.client.JenkinsClient
import com.netflix.spinnaker.igor.jenkins.service.JenkinsService
import com.netflix.spinnaker.igor.service.BuildServices
import com.netflix.spinnaker.retrofit.Slf4jRetrofitLogger
import okhttp3.OkHttpClient
import groovy.transform.CompileStatic
import groovy.util.logging.Slf4j
import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry
import okhttp3.OkHttpClient
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.EnableConfigurationProperties
Expand All @@ -44,7 +44,6 @@ import org.springframework.context.annotation.Configuration
import retrofit.Endpoints
import retrofit.RequestInterceptor
import retrofit.RestAdapter
import retrofit.client.OkClient
import retrofit.converter.JacksonConverter

import javax.net.ssl.KeyManager
Expand Down Expand Up @@ -148,15 +147,7 @@ class JenkinsConfig {
if (host.trustStore.equals("*")) {
trustManagers = [new TrustAllTrustManager()]
} else {
def trustStorePassword = host.trustStorePassword
def trustStore = KeyStore.getInstance(host.trustStoreType)
new File(host.trustStore).withInputStream {
trustStore.load(it, trustStorePassword.toCharArray())
}
def trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
trustManagerFactory.init(trustStore)

trustManagers = trustManagerFactory.trustManagers
trustManagers = createTrustStore(host.trustStore, host.trustStorePassword, host.trustStoreType)
}
}

Expand All @@ -170,13 +161,19 @@ class JenkinsConfig {
keyManagerFactory.init(keyStore, keyStorePassword.toCharArray())

keyManagers = keyManagerFactory.keyManagers

if (trustManagers == null) {
log.warn("${host.name}: okhttp3 (unlike okhttp2) doesn't support configuring only a keystore without " +
"a truststore. Please configure a truststore to get rid of this message. Trying to use the " +
"keystore '${host.keyStore}' as a truststore as well. Your mileage may vary.")
Copy link
Member

Choose a reason for hiding this comment

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

Ah, I'm not sure we want to be advising this.

trustManagers = createTrustStore(host.keyStore, host.keyStorePassword, host.keyStoreType)
}
}

if (trustManagers || keyManagers) {
def sslContext = SSLContext.getInstance("TLS")
sslContext.init(keyManagers, trustManagers, null)

clientBuilder.sslSocketFactory(sslContext.socketFactory,(X509TrustManager) trustManagers[0])
clientBuilder.sslSocketFactory(sslContext.socketFactory, (X509TrustManager) trustManagers[0])
}

new RestAdapter.Builder()
Expand All @@ -195,6 +192,18 @@ class JenkinsConfig {
.build()
.create(JenkinsClient)
}
private static TrustManager[] createTrustStore(String trustStoreName,
String trustStorePassword,
String trustStoreType) {
def trustStore = KeyStore.getInstance(trustStoreType)
new File(trustStoreName).withInputStream {
trustStore.load(it, trustStorePassword.toCharArray())
}
def trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
trustManagerFactory.init(trustStore)

return trustManagerFactory.trustManagers
}

static JenkinsClient jenkinsClient(JenkinsProperties.JenkinsHost host, Registry registry = null, int timeout = 30000) {
OkHttpClient client = new OkHttpClient()
Expand Down