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

Commit b26f26d

Browse files
committed
fix: force insecure: false with additionalTrustBundle
1 parent c706536 commit b26f26d

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
@@ -33,14 +33,48 @@ func TestGeneratePatches(
3333
Name: "unset variable",
3434
},
3535
capitest.PatchTestDef{
36-
Name: "all fields set",
36+
Name: "all required fields set",
3737
Vars: []runtimehooksv1.Variable{
3838
capitest.VariableWithValue(
3939
variableName,
4040
v1alpha1.NutanixPrismCentralEndpointSpec{
4141
Host: "prism-central.nutanix.com",
4242
Port: 9441,
43-
Insecure: false,
43+
Insecure: true,
44+
Credentials: corev1.LocalObjectReference{
45+
Name: "credentials",
46+
},
47+
},
48+
variablePath...,
49+
),
50+
},
51+
RequestItem: request.NewNutanixClusterTemplateRequestItem(""),
52+
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{
53+
{
54+
Operation: "replace",
55+
Path: "/spec/template/spec/prismCentral",
56+
ValueMatcher: gomega.SatisfyAll(
57+
gomega.HaveKeyWithValue(
58+
"address",
59+
gomega.BeEquivalentTo("prism-central.nutanix.com"),
60+
),
61+
gomega.HaveKeyWithValue("port", gomega.BeEquivalentTo(9441)),
62+
gomega.HaveKeyWithValue("insecure", true),
63+
gomega.HaveKey("credentialRef"),
64+
gomega.Not(gomega.HaveKey("additionalTrustBundle")),
65+
),
66+
},
67+
},
68+
},
69+
capitest.PatchTestDef{
70+
Name: "additional trust bundle is set",
71+
Vars: []runtimehooksv1.Variable{
72+
capitest.VariableWithValue(
73+
variableName,
74+
v1alpha1.NutanixPrismCentralEndpointSpec{
75+
Host: "prism-central.nutanix.com",
76+
Port: 9441,
77+
Insecure: true,
4478
Credentials: corev1.LocalObjectReference{
4579
Name: "credentials",
4680
},
@@ -60,6 +94,7 @@ func TestGeneratePatches(
6094
gomega.BeEquivalentTo("prism-central.nutanix.com"),
6195
),
6296
gomega.HaveKeyWithValue("port", gomega.BeEquivalentTo(9441)),
97+
// Assert the insecure field was set to false as the additional trust bundle is set
6398
gomega.HaveKeyWithValue("insecure", false),
6499
gomega.HaveKey("credentialRef"),
65100
gomega.HaveKey("additionalTrustBundle"),

0 commit comments

Comments
 (0)