Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit 691c713

Browse files
committed
refactor: use a string type for Nutanix's AdditionalTrustBundle
Use a string instead of a ConfigMap reference to make it easier for both the handlers to use, and the clients to set in the API.
1 parent aa6feca commit 691c713

File tree

11 files changed

+77
-57
lines changed

11 files changed

+77
-57
lines changed

api/v1alpha1/nutanix_clusterconfig_types.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ type NutanixPrismCentralEndpointSpec struct {
4949
// +optional
5050
Insecure bool `json:"insecure"`
5151

52-
// A reference to the ConfigMap containing a PEM encoded x509 cert for the RootCA that was used to create
52+
// A base64 PEM encoded x509 cert for the RootCA that was used to create
5353
// the certificate for a Prism Central that uses certificates that were issued by a non-publicly trusted RootCA.
5454
// The trust bundle is added to the cert pool used to authenticate the TLS connection to the Prism Central.
5555
// +optional
56-
AdditionalTrustBundle *corev1.LocalObjectReference `json:"additionalTrustBundle,omitempty"`
56+
AdditionalTrustBundle *string `json:"additionalTrustBundle,omitempty"`
5757

5858
// A reference to the Secret for credential information for the target Prism Central instance
5959
Credentials corev1.LocalObjectReference `json:"credentials"`
@@ -82,19 +82,13 @@ func (NutanixPrismCentralEndpointSpec) VariableSchema() clusterv1.VariableSchema
8282
Type: "boolean",
8383
},
8484
"additionalTrustBundle": {
85-
Description: "A reference to the ConfigMap containing a PEM encoded x509 cert for the RootCA " +
85+
Description: "A base64 PEM encoded x509 cert for the RootCA " +
8686
"that was used to create the certificate for a Prism Central that uses certificates " +
8787
"that were issued by a non-publicly trusted RootCA." +
8888
"The trust bundle is added to the cert pool used to authenticate the TLS connection " +
8989
"to the Prism Central.",
90-
Type: "object",
91-
Properties: map[string]clusterv1.JSONSchemaProps{
92-
"name": {
93-
Description: "The name of the ConfigMap",
94-
Type: "string",
95-
},
96-
},
97-
Required: []string{"name"},
90+
Type: "string",
91+
Format: "byte",
9892
},
9993
"credentials": {
10094
Description: "A reference to the Secret for credential information" +

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/content/customization/nutanix/prism-central-endpoint.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ spec:
2929
3030
Applying this configuration will result in the following value being set:
3131
32-
- control-plane NutanixClusterTemplate:
32+
- `NutanixClusterTemplate`:
3333

3434
```yaml
3535
spec:
@@ -43,3 +43,43 @@ spec:
4343
kind: Secret
4444
name: secret-name
4545
```
46+
47+
### Provide an Optional Trusted CA Bundle
48+
49+
If the Prism Central endpoint uses a self-signed certificate, you can provide an additional trust bundle
50+
to be used by the Nutanix provider.
51+
This is a base64 PEM encoded x509 cert for the RootCA that was used to create the certificate for a Prism Central
52+
53+
```yaml
54+
apiVersion: cluster.x-k8s.io/v1beta1
55+
kind: Cluster
56+
metadata:
57+
name: <NAME>
58+
spec:
59+
topology:
60+
variables:
61+
- name: clusterConfig
62+
value:
63+
nutanix:
64+
prismCentralEndpoint:
65+
# ...
66+
additionalTrustBundle: "LS0...="
67+
```
68+
69+
Applying this configuration will result in the following value being set:
70+
71+
- `NutanixClusterTemplate`:
72+
73+
```yaml
74+
spec:
75+
template:
76+
spec:
77+
prismCentral:
78+
# ...
79+
additionalTrustBundle:
80+
kind: String
81+
data: |-
82+
-----BEGIN CERTIFICATE-----
83+
...
84+
-----END CERTIFICATE-----
85+
```

examples/capi-quick-start/nutanix-cluster-calico-crs.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
apiVersion: v1
2-
binaryData:
3-
ca.crt: ${NUTANIX_ADDITIONAL_TRUST_BUNDLE=""}
4-
kind: ConfigMap
5-
metadata:
6-
labels:
7-
cluster.x-k8s.io/provider: nutanix
8-
name: ${CLUSTER_NAME}-pc-trusted-ca-bundle
9-
---
10-
apiVersion: v1
112
data:
123
nutanix-ccm.yaml: |
134
---

examples/capi-quick-start/nutanix-cluster-calico-helm-addon.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
apiVersion: v1
2-
binaryData:
3-
ca.crt: ${NUTANIX_ADDITIONAL_TRUST_BUNDLE=""}
4-
kind: ConfigMap
5-
metadata:
6-
labels:
7-
cluster.x-k8s.io/provider: nutanix
8-
name: ${CLUSTER_NAME}-pc-trusted-ca-bundle
9-
---
10-
apiVersion: v1
112
data:
123
nutanix-ccm.yaml: |
134
---

examples/capi-quick-start/nutanix-cluster-cilium-crs.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
apiVersion: v1
2-
binaryData:
3-
ca.crt: ${NUTANIX_ADDITIONAL_TRUST_BUNDLE=""}
4-
kind: ConfigMap
5-
metadata:
6-
labels:
7-
cluster.x-k8s.io/provider: nutanix
8-
name: ${CLUSTER_NAME}-pc-trusted-ca-bundle
9-
---
10-
apiVersion: v1
112
data:
123
nutanix-ccm.yaml: |
134
---

examples/capi-quick-start/nutanix-cluster-cilium-helm-addon.yaml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
apiVersion: v1
2-
binaryData:
3-
ca.crt: ${NUTANIX_ADDITIONAL_TRUST_BUNDLE=""}
4-
kind: ConfigMap
5-
metadata:
6-
labels:
7-
cluster.x-k8s.io/provider: nutanix
8-
name: ${CLUSTER_NAME}-pc-trusted-ca-bundle
9-
---
10-
apiVersion: v1
112
data:
123
nutanix-ccm.yaml: |
134
---

hack/examples/bases/nutanix/cluster/kustomization.yaml.tmpl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ patches:
2828
- target:
2929
kind: Cluster
3030
path: ../../../patches/nutanix/initialize-variables.yaml
31+
32+
# Remove Additional Trust Bundle ConfigMap
33+
- target:
34+
kind: ConfigMap
35+
name: ".*-pc-trusted-ca-bundle"
36+
path: ../../../patches/nutanix/remove-additional-trust-bundle/cm.yaml
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright 2024 D2iQ, Inc. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
$patch: delete
5+
apiVersion: v1
6+
kind: ConfigMap
7+
metadata:
8+
name: ${CLUSTER_NAME}-pc-trusted-ca-bundle

pkg/handlers/nutanix/mutation/prismcentralendpoint/inject.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ package prismcentralendpoint
55

66
import (
77
"context"
8+
"encoding/base64"
9+
"fmt"
810

911
"github.com/nutanix-cloud-native/prism-go-client/environment/credentials"
1012
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1113
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
14+
"k8s.io/utils/ptr"
1215
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1"
1316
ctrl "sigs.k8s.io/controller-runtime"
1417
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -105,12 +108,17 @@ func (h *nutanixPrismCentralEndpoint) Mutate(
105108
Namespace: clusterKey.Namespace,
106109
},
107110
}
108-
if prismCentralEndpointVar.AdditionalTrustBundle != nil {
111+
additionalTrustBundle := ptr.Deref(prismCentralEndpointVar.AdditionalTrustBundle, "")
112+
if additionalTrustBundle != "" {
113+
var decoded []byte
114+
decoded, err = base64.StdEncoding.DecodeString(additionalTrustBundle)
115+
if err != nil {
116+
log.Error(err, "error decoding additional trust bundle")
117+
return fmt.Errorf("error decoding additional trust bundle: %w", err)
118+
}
109119
prismCentral.AdditionalTrustBundle = &credentials.NutanixTrustBundleReference{
110-
Kind: credentials.NutanixTrustBundleKindConfigMap,
111-
Name: prismCentralEndpointVar.AdditionalTrustBundle.Name,
112-
// Assume the ConfigMap is in the same namespace as Cluster
113-
Namespace: clusterKey.Namespace,
120+
Kind: credentials.NutanixTrustBundleKindString,
121+
Data: string(decoded),
114122
}
115123
}
116124

pkg/handlers/nutanix/mutation/prismcentralendpoint/tests/generate_patches.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import (
1717
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request"
1818
)
1919

20+
const testCertBundle = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUVjekNDQTF1Z0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRUUZBRC4uQWtHQTFVRUJoTUNSMEl4CkV6QVJCZ05WQkFnVENsTnZiV1V0VTNSaGRHVXhGREFTQmdOVkJBb1RDMC4uMEVnVEhSa01UY3dOUVlEClZRUUxFeTVEYkdGemN5QXhJRkIxWW14cFl5QlFjbWx0WVhKNUlFTmxjbi4uWFJwYjI0Z1FYVjBhRzl5CmFYUjVNUlF3RWdZRFZRUURFd3RDWlhOMElFTkJJRXgwWkRBZUZ3MHdNRC4uVFV3TVRaYUZ3MHdNVEF5Ck1EUXhPVFV3TVRaYU1JR0hNUXN3Q1FZRFZRUUdFd0pIUWpFVE1CRUdBMS4uMjl0WlMxVGRHRjBaVEVVCk1CSUdBMVVFQ2hNTFFtVnpkQ0JEUVNCTWRHUXhOekExQmdOVkJBc1RMay4uREVnVUhWaWJHbGpJRkJ5CmFXMWhjbmtnUTJWeWRHbG1hV05oZEdsdmJpQkJkWFJvYjNKcGRIa3hGRC4uQU1UQzBKbGMzUWdRMEVnClRIUmtNSUlCSWpBTkJna3Foa2lHOXcwQkFRRUZBQU9DQVE4QU1JSUJDZy4uVHoybXI3U1ppQU1mUXl1CnZCak05T2lKalJhelhCWjFCalA1Q0UvV20vUnI1MDBQUksrTGg5eDVlSi4uL0FOQkUwc1RLMFpzREdNCmFrMm0xZzdvcnVJM2RZM1Z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JIWC4uYWRzR2VGS2t5TnJ3R2kvCjd2UU1mWGRHc1JyWE5HUkduWCt2V0RaMy96V0kwam9EdENrTm5xRXBWbi4uSG9YCi0tLS0tRU5EIENFUlRJRklDQVRFLS0tLS0="
21+
2022
func TestGeneratePatches(
2123
t *testing.T,
2224
generatorFunc func() mutation.GeneratePatches,
@@ -42,9 +44,7 @@ func TestGeneratePatches(
4244
Credentials: corev1.LocalObjectReference{
4345
Name: "credentials",
4446
},
45-
AdditionalTrustBundle: ptr.To(corev1.LocalObjectReference{
46-
Name: "bundle",
47-
}),
47+
AdditionalTrustBundle: ptr.To(testCertBundle),
4848
},
4949
variablePath...,
5050
),

0 commit comments

Comments
 (0)