Skip to content

Commit a82f585

Browse files
authored
Added support for TLS Validation when CA Certs are not provided explicitly (#423)
* Added support for TLS Validation when CA Certs are not provided explicitly * Updated chart version value
1 parent 71aa10b commit a82f585

File tree

3 files changed

+39
-27
lines changed

3 files changed

+39
-27
lines changed

charts/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ apiVersion: v2
22
name: cosi-driver-nutanix
33
description: A Helm chart to deploy Nutanix COSI driver
44
type: application
5-
version: 0.5.0
5+
version: 0.6.0
66

7-
appVersion: "v0.5.0"
7+
appVersion: "v0.6.0"
88

99
icon: https://www.nutanix.com/content/dam/nutanix/global/icons/products/svg/Nutanix-Objects-40.svg
1010
annotations:

charts/templates/secret.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ stringData:
1616
SECRET_KEY: {{ required "secret_key is required." .Values.secret.secret_key | quote }}
1717
S3_INSECURE: {{ .Values.tls.s3.insecure | default "false" | quote }}
1818
PC_INSECURE: {{ .Values.tls.pc.insecure | default "false" | quote }}
19-
{{- if and (not .Values.tls.caSecretName ) (eq .Values.tls.s3.insecure false) }}
20-
S3_CA_CERT: {{ required "CA Certificate required if insecure set to false" .Values.tls.s3.rootCAs }}
21-
{{- end }}
22-
{{- if and (not .Values.tls.caSecretName ) (eq .Values.tls.pc.insecure false) }}
23-
PC_CA_CERT: {{ required "CA Certificate required if insecure set to false" .Values.tls.pc.rootCAs }}
19+
{{- if not .Values.tls.caSecretName }}
20+
S3_CA_CERT: {{ .Values.tls.s3.rootCAs | default "" }}
21+
PC_CA_CERT: {{ .Values.tls.pc.rootCAs | default "" }}
2422
{{- end }}
2523
type: Opaque
2624
{{- end }}

pkg/util/transport/transport.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,35 +28,49 @@ func BuildTransportTLS(tlsConfig TlsConfig) (*http.Transport, error) {
2828
}
2929

3030
klog.InfoS("insecure connection made.", "insecure", tlsConfig.Insecure, "endpoint", tlsConfig.Endpoint)
31-
} else {
32-
var rootCAs []byte
33-
if strings.Contains(tlsConfig.CACert, "-----BEGIN CERTIFICATE-----") && strings.Contains(tlsConfig.CACert, "-----END CERTIFICATE-----") {
34-
rootCAs = []byte(tlsConfig.CACert)
35-
} else {
36-
// Decode base64 CA cert
37-
_rootCAs, err := base64.StdEncoding.DecodeString(tlsConfig.CACert)
38-
if err != nil {
39-
return nil, fmt.Errorf("failed to decode CA cert: %v", err)
40-
}
41-
42-
rootCAs = _rootCAs
43-
}
4431

45-
// Create cert pool and add our CA
46-
caCertPool := x509.NewCertPool()
47-
if !caCertPool.AppendCertsFromPEM(rootCAs) {
48-
return nil, fmt.Errorf("failed to append CA cert: %s", tlsConfig.CACert)
49-
}
32+
return transport, nil
33+
}
5034

35+
if tlsConfig.CACert == "" {
5136
transport = &http.Transport{
5237
TLSClientConfig: &tls.Config{
53-
RootCAs: caCertPool,
5438
InsecureSkipVerify: false,
5539
},
5640
}
5741

58-
klog.InfoS("secure connection made.", "insecure", tlsConfig.Insecure, "endpoint", tlsConfig.Endpoint)
42+
klog.InfoS("secure connection made without CA certs.", "insecure", tlsConfig.Insecure, "endpoint", tlsConfig.Endpoint)
43+
44+
return transport, nil
5945
}
6046

47+
var rootCAs []byte
48+
if strings.Contains(tlsConfig.CACert, "-----BEGIN CERTIFICATE-----") && strings.Contains(tlsConfig.CACert, "-----END CERTIFICATE-----") {
49+
rootCAs = []byte(tlsConfig.CACert)
50+
} else {
51+
// Decode base64 CA cert
52+
_rootCAs, err := base64.StdEncoding.DecodeString(tlsConfig.CACert)
53+
if err != nil {
54+
return nil, fmt.Errorf("failed to decode CA cert: %v", err)
55+
}
56+
57+
rootCAs = _rootCAs
58+
}
59+
60+
// Create cert pool and add our CA
61+
caCertPool := x509.NewCertPool()
62+
if !caCertPool.AppendCertsFromPEM(rootCAs) {
63+
return nil, fmt.Errorf("failed to append CA cert: %s", tlsConfig.CACert)
64+
}
65+
66+
transport = &http.Transport{
67+
TLSClientConfig: &tls.Config{
68+
RootCAs: caCertPool,
69+
InsecureSkipVerify: false,
70+
},
71+
}
72+
73+
klog.InfoS("secure connection made with CA certs.", "insecure", tlsConfig.Insecure, "endpoint", tlsConfig.Endpoint)
74+
6175
return transport, nil
6276
}

0 commit comments

Comments
 (0)