Skip to content

Commit c18ca88

Browse files
authored
Merge pull request #1053 from yastij/thumbprint-support
set the thumbprint to enable secure communications
2 parents 819457d + 389edf9 commit c18ca88

19 files changed

+209
-12
lines changed

api/v1alpha2/vspherecluster_conversion.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ func (src *VSphereCluster) ConvertTo(dstRaw conversion.Hub) error { // nolint
5858
if restored.Spec.ControlPlaneEndpoint.Port != 0 {
5959
dst.Spec.ControlPlaneEndpoint.Port = restored.Spec.ControlPlaneEndpoint.Port
6060
}
61+
if restored.Spec.Thumbprint != "" {
62+
dst.Spec.Thumbprint = restored.Spec.Thumbprint
63+
}
6164

6265
dst.Status.Conditions = restored.Status.Conditions
6366

api/v1alpha2/zz_generated.conversion.go

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

api/v1alpha3/types.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ type VirtualMachineCloneSpec struct {
7878
// +optional
7979
Server string `json:"server,omitempty"`
8080

81+
// Thumbprint is the colon-separated SHA-1 checksum of the given vCenter server's host certificate
82+
// When this is set to empty, this VirtualMachine would be created
83+
// without TLS certificate validation of the communication between Cluster API Provider vSphere
84+
// and the VMware vCenter server.
85+
// +optional
86+
Thumbprint string `json:"thumbprint,omitempty"`
87+
8188
// Datacenter is the name or inventory path of the datacenter in which the
8289
// virtual machine is created/located.
8390
// +optional

api/v1alpha3/vspherecluster_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ type VSphereClusterSpec struct {
3939
// +optional
4040
Insecure *bool `json:"insecure,omitempty"`
4141

42+
// Thumbprint is the colon-separated SHA-1 checksum of the given vCenter server's host certificate
43+
// When provided, Insecure should not be set to true
44+
// +optional
45+
Thumbprint string `json:"thumbprint,omitempty"`
46+
4247
// CloudProviderConfiguration holds the cluster-wide configuration for the
4348
// vSphere cloud provider.
4449
CloudProviderConfiguration CPIConfig `json:"cloudProviderConfiguration,omitempty"`

api/v1alpha3/vspherecluster_webhook.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1alpha3
1818

1919
import (
20+
"k8s.io/apimachinery/pkg/runtime"
21+
"k8s.io/apimachinery/pkg/util/validation/field"
2022
ctrl "sigs.k8s.io/controller-runtime"
2123
)
2224

@@ -25,3 +27,27 @@ func (r *VSphereCluster) SetupWebhookWithManager(mgr ctrl.Manager) error {
2527
For(r).
2628
Complete()
2729
}
30+
31+
// +kubebuilder:webhook:verbs=create;update,path=/validate-infrastructure-cluster-x-k8s-io-v1alpha3-vspherecluster,mutating=false,failurePolicy=fail,matchPolicy=Equivalent,groups=infrastructure.cluster.x-k8s.io,resources=vsphereclusters,versions=v1alpha3,name=validation.vspherecluster.infrastructure.x-k8s.io,sideEffects=None
32+
33+
// ValidateCreate implements webhook.Validator so a webhook will be registered for the type
34+
func (r *VSphereCluster) ValidateCreate() error {
35+
var allErrs field.ErrorList
36+
spec := r.Spec
37+
38+
if spec.Thumbprint != "" && spec.Insecure != nil && *spec.Insecure {
39+
allErrs = append(allErrs, field.Invalid(field.NewPath("spec", "Insecure"), spec.Insecure, "cannot be set to true at the same time as .spec.Thumbprint"))
40+
}
41+
42+
return aggregateObjErrors(r.GroupVersionKind().GroupKind(), r.Name, allErrs)
43+
}
44+
45+
// ValidateUpdate implements webhook.Validator so a webhook will be registered for the type
46+
func (r *VSphereCluster) ValidateUpdate(old runtime.Object) error {
47+
return nil
48+
}
49+
50+
// ValidateDelete implements webhook.Validator so a webhook will be registered for the type
51+
func (r *VSphereCluster) ValidateDelete() error {
52+
return nil
53+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
Copyright 2020 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1alpha3
18+
19+
import (
20+
"testing"
21+
22+
. "github.com/onsi/gomega"
23+
)
24+
25+
//nolint
26+
func TestVSphereCluster_ValidateCreate(t *testing.T) {
27+
28+
g := NewWithT(t)
29+
tests := []struct {
30+
name string
31+
vsphereCluster *VSphereCluster
32+
wantErr bool
33+
}{
34+
{
35+
name: "insecure true with empty thumbprint",
36+
vsphereCluster: createVSphereCluster("foo.com", true, ""),
37+
wantErr: false,
38+
},
39+
{
40+
name: "insecure false with non-empty thumbprint",
41+
vsphereCluster: createVSphereCluster("foo.com", false, "thumprint:foo"),
42+
wantErr: false,
43+
},
44+
{
45+
name: "insecure true with non-empty thumbprint",
46+
vsphereCluster: createVSphereCluster("foo.com", true, "thumprint:foo"),
47+
wantErr: true,
48+
},
49+
}
50+
for _, tc := range tests {
51+
t.Run(tc.name, func(t *testing.T) {
52+
err := tc.vsphereCluster.ValidateCreate()
53+
if tc.wantErr {
54+
g.Expect(err).To(HaveOccurred())
55+
} else {
56+
g.Expect(err).NotTo(HaveOccurred())
57+
}
58+
})
59+
}
60+
}
61+
62+
func createVSphereCluster(server string, insecure bool, thumbprint string) *VSphereCluster {
63+
vsphereCluster := &VSphereCluster{
64+
Spec: VSphereClusterSpec{
65+
Server: server,
66+
Insecure: &insecure,
67+
Thumbprint: thumbprint,
68+
},
69+
}
70+
return vsphereCluster
71+
}

config/crd/bases/infrastructure.cluster.x-k8s.io_haproxyloadbalancers.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ spec:
255255
used to clone the virtual machine.
256256
minLength: 1
257257
type: string
258+
thumbprint:
259+
description: Thumbprint is the colon-separated SHA-1 checksum
260+
of the given vCenter server's host certificate When this is
261+
set to empty, this VirtualMachine would be created without TLS
262+
certificate validation of the communication between Cluster
263+
API Provider vSphere and the VMware vCenter server.
264+
type: string
258265
required:
259266
- network
260267
- template

config/crd/bases/infrastructure.cluster.x-k8s.io_vsphereclusters.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,11 @@ spec:
527527
server:
528528
description: Server is the address of the vSphere endpoint.
529529
type: string
530+
thumbprint:
531+
description: Thumbprint is the colon-separated SHA-1 checksum of the
532+
given vCenter server's host certificate When provided, Insecure
533+
should not be set to true
534+
type: string
530535
type: object
531536
status:
532537
description: VSphereClusterStatus defines the observed state of VSphereClusterSpec

config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachines.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,13 @@ spec:
519519
used to clone the virtual machine.
520520
minLength: 1
521521
type: string
522+
thumbprint:
523+
description: Thumbprint is the colon-separated SHA-1 checksum of the
524+
given vCenter server's host certificate When this is set to empty,
525+
this VirtualMachine would be created without TLS certificate validation
526+
of the communication between Cluster API Provider vSphere and the
527+
VMware vCenter server.
528+
type: string
522529
required:
523530
- network
524531
- template

config/crd/bases/infrastructure.cluster.x-k8s.io_vspheremachinetemplates.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,13 @@ spec:
579579
template used to clone the virtual machine.
580580
minLength: 1
581581
type: string
582+
thumbprint:
583+
description: Thumbprint is the colon-separated SHA-1 checksum
584+
of the given vCenter server's host certificate When this
585+
is set to empty, this VirtualMachine would be created without
586+
TLS certificate validation of the communication between
587+
Cluster API Provider vSphere and the VMware vCenter server.
588+
type: string
582589
required:
583590
- network
584591
- template

0 commit comments

Comments
 (0)