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

Commit 0d6a9b1

Browse files
committed
fix: force insecure: false with additionalTrustBundle
1 parent 671d347 commit 0d6a9b1

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ func (h *nutanixPrismCentralEndpoint) Mutate(
122122
}
123123
}
124124

125+
// Always force insecure to false if additional trust bundle is provided.
126+
// This ensures that the trust bundle is actually used to validate the connection.
127+
if additionalTrustBundle != "" && prismCentral.Insecure {
128+
log.Info("AdditionalTrustBundle is provided, setting insecure to false")
129+
prismCentral.Insecure = false
130+
}
131+
125132
obj.Spec.Template.Spec.PrismCentral = prismCentral
126133

127134
return nil

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

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,48 @@ func TestGeneratePatches(
3434
Name: "unset variable",
3535
},
3636
capitest.PatchTestDef{
37-
Name: "all fields set",
37+
Name: "all required fields set",
3838
Vars: []runtimehooksv1.Variable{
3939
capitest.VariableWithValue(
4040
variableName,
4141
v1alpha1.NutanixPrismCentralEndpointSpec{
4242
Host: "prism-central.nutanix.com",
4343
Port: 9441,
44-
Insecure: false,
44+
Insecure: true,
45+
Credentials: corev1.LocalObjectReference{
46+
Name: "credentials",
47+
},
48+
},
49+
variablePath...,
50+
),
51+
},
52+
RequestItem: request.NewNutanixClusterTemplateRequestItem(""),
53+
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
54+
{
55+
Operation: "replace",
56+
Path: "/spec/template/spec/prismCentral",
57+
ValueMatcher: gomega.SatisfyAll(
58+
gomega.HaveKeyWithValue(
59+
"address",
60+
gomega.BeEquivalentTo("prism-central.nutanix.com"),
61+
),
62+
gomega.HaveKeyWithValue("port", gomega.BeEquivalentTo(9441)),
63+
gomega.HaveKeyWithValue("insecure", true),
64+
gomega.HaveKey("credentialRef"),
65+
gomega.Not(gomega.HaveKey("additionalTrustBundle")),
66+
),
67+
},
68+
},
69+
},
70+
capitest.PatchTestDef{
71+
Name: "additional trust bundle is set",
72+
Vars: []runtimehooksv1.Variable{
73+
capitest.VariableWithValue(
74+
variableName,
75+
v1alpha1.NutanixPrismCentralEndpointSpec{
76+
Host: "prism-central.nutanix.com",
77+
Port: 9441,
78+
Insecure: true,
4579
Credentials: corev1.LocalObjectReference{
4680
Name: "credentials",
4781
},
@@ -61,6 +95,7 @@ func TestGeneratePatches(
6195
gomega.BeEquivalentTo("prism-central.nutanix.com"),
6296
),
6397
gomega.HaveKeyWithValue("port", gomega.BeEquivalentTo(9441)),
98+
// Assert the insecure field was set to false as the additional trust bundle is set
6499
gomega.HaveKeyWithValue("insecure", false),
65100
gomega.HaveKey("credentialRef"),
66101
gomega.HaveKey("additionalTrustBundle"),

0 commit comments

Comments
 (0)