Skip to content

Commit

Permalink
Fixes tls certificate issue for webhook endpoint (#1120)
Browse files Browse the repository at this point in the history
When `operator-ca-tls` secret is defined operator will use that to
verify tls connections with minio tenants, however that was causing a
problem with kube-apiserver in where the certificate exposed on the
`caBundle` from tenants.minio.min.io crd will not match with the actual certificate operator is using
for the webhook https endpoint

Signed-off-by: Lenin Alevski <alevsk.8772@gmail.com>
  • Loading branch information
Alevsk committed May 17, 2022
1 parent fcf39d0 commit d54c46a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
17 changes: 9 additions & 8 deletions main.go
Expand Up @@ -124,17 +124,18 @@ func main() {
}

ctx := context.Background()
var caContent []byte
operatorCATLSCert, err := kubeClient.CoreV1().Secrets(miniov2.GetNSFromFile()).Get(ctx, "operator-ca-tls", metav1.GetOptions{})
// if custom ca.crt is not present in kubernetes secrets use the one stored in the pod
if err != nil {
caContent = miniov2.GetPodCAFromFile()
} else {

// Default kubernetes CA certificate
caContent := miniov2.GetPodCAFromFile()
// custom ca certificate to be used by operator
operatorCATLSCert, err := kubeClient.CoreV1().Secrets(miniov2.GetNSFromFile()).Get(ctx, cluster.OperatorTLSCASecretName, metav1.GetOptions{})
if err == nil && operatorCATLSCert != nil {
if val, ok := operatorCATLSCert.Data["ca.crt"]; ok {
caContent = val
caContent = append(caContent, val...)
} else if val, ok = operatorCATLSCert.Data["public.crt"]; ok {
caContent = append(caContent, val...)
}
}

if len(caContent) > 0 {
crd, err := extClient.ApiextensionsV1().CustomResourceDefinitions().Get(context.Background(), "tenants.minio.min.io", metav1.GetOptions{})
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions pkg/controller/cluster/operator.go
Expand Up @@ -272,19 +272,20 @@ func (c *Controller) getTransport() *http.Transport {
if c.transport != nil {
return c.transport
}

rootCAs := miniov2.MustGetSystemCertPool()
// Default kubernetes CA certificate
rootCAs.AppendCertsFromPEM(miniov2.GetPodCAFromFile())
var caContent []byte
// Custom ca certificate to be used by operator
operatorCATLSCert, err := c.kubeClientSet.CoreV1().Secrets(miniov2.GetNSFromFile()).Get(context.Background(), OperatorTLSCASecretName, metav1.GetOptions{})
// if custom ca.crt is not present in kubernetes secrets use the one stored in the pod
if err != nil {
caContent = miniov2.GetPodCAFromFile()
} else {
if err == nil && operatorCATLSCert != nil {
if val, ok := operatorCATLSCert.Data["ca.crt"]; ok {
caContent = val
} else if val, ok = operatorCATLSCert.Data["public.crt"]; ok {
caContent = val
}
}

rootCAs := miniov2.MustGetSystemCertPool()
if len(caContent) > 0 {
rootCAs.AppendCertsFromPEM(caContent)
}
Expand Down

0 comments on commit d54c46a

Please sign in to comment.