Skip to content

Commit 4388804

Browse files
authored
refactor!: remove RolePrivilegeValidationRules, add enums to API, remove "cloud" refs and simplify account handling (#357)
## Issue N/A ## Description - Remove RolePrivilegeValidationRules - Document that the `System.View` privilege is required - Make entityType an enum for proper validation --------- Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
1 parent 3c0c928 commit 4388804

22 files changed

Lines changed: 432 additions & 775 deletions

README.md

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,37 @@ The vSphere [validator](https://github.com/validator-labs/validator) plugin ensu
1111
## Description
1212
The vSphere validator plugin reconciles `VsphereValidator` custom resources to perform the following validations against your vSphere environment:
1313

14-
1. Compare the privileges associated with a user against an expected privileges set
15-
2. Compare the privileges associated with a user against an expected privileges set on a particular entity(cluster, resourcepool, folder, vapp, host)
16-
3. Check if enough compute resources are available on a host, resourcepool or cluster against a resource request
17-
4. Compare the tags associated with a datacenter, cluster, host, vm, resourcepool or vm against an expected tag set
18-
5. Check if a given set of host systems have a valid NTP configuration
14+
1. Compare a user's privileges with respect to a particular entity against an expected privilege set.
15+
16+
Supported entities:
17+
- Cluster, Datacenter, Datastore, Folder, ESXi Host, Network, Resource Pool, vApp, vCenter root, vSphere Distributed Switch (VDS)
18+
19+
Required Privileges:
20+
- `System.View`
21+
- TODO: identify and update any additional required privileges
22+
2. Check if sufficient compute resources are available on a particular entity to satify a resource request.
23+
24+
Supported entities:
25+
- Cluster, ESXi Host, Resource Pool
26+
27+
Required Privileges:
28+
- TODO: identify and update
29+
3. Compare the tags associated with a particular entity against an expected tag set.
30+
31+
Supported entities:
32+
- Cluster, Datacenter, ESXi Host, Resource Pool, VM
33+
34+
Required Privileges:
35+
- - TODO: identify and update
36+
4. Check if a given set of ESXi Hosts all have NTP enabled and running, with identical NTP servers configured.
37+
38+
Required Privileges:
39+
- - TODO: identify and update
1940

2041
Each `VsphereValidator` CR is (re)-processed every two minutes to continuously ensure that your vSphere environment matches the expected state.
2142

2243
See the [samples](https://github.com/validator-labs/validator-plugin-vsphere/tree/main/config/samples) directory for example `VsphereValidator` configurations.
2344

24-
> [!NOTE]
25-
> This plugin currently require a user with administrator role to perform all of the validations specified above. Further information on fine-grained permissions required by each validation will be updated in the future.
26-
2745
## Getting Started
2846
You’ll need a Kubernetes cluster to run against. You can use [KIND](https://sigs.k8s.io/kind) to get a local cluster for testing, or run against a remote cluster.
2947
**Note:** Your controller will automatically use the current context in your kubeconfig file (i.e. whatever cluster `kubectl cluster-info` shows).

api/v1alpha1/vspherevalidator_types.go

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ import (
1414

1515
// VsphereValidatorSpec defines the desired state of VsphereValidator
1616
type VsphereValidatorSpec struct {
17-
Auth VsphereAuth `json:"auth" yaml:"auth"`
18-
Datacenter string `json:"datacenter" yaml:"datacenter"`
19-
EntityPrivilegeValidationRules []EntityPrivilegeValidationRule `json:"entityPrivilegeValidationRules,omitempty" yaml:"entityPrivilegeValidationRules,omitempty"`
20-
RolePrivilegeValidationRules []GenericRolePrivilegeValidationRule `json:"rolePrivilegeValidationRules,omitempty" yaml:"rolePrivilegeValidationRules,omitempty"`
21-
TagValidationRules []TagValidationRule `json:"tagValidationRules,omitempty" yaml:"tagValidationRules,omitempty"`
22-
ComputeResourceRules []ComputeResourceRule `json:"computeResourceRules,omitempty" yaml:"computeResourceRules,omitempty"`
23-
NTPValidationRules []NTPValidationRule `json:"ntpValidationRules,omitempty" yaml:"ntpValidationRules,omitempty"`
17+
Auth VsphereAuth `json:"auth" yaml:"auth"`
18+
Datacenter string `json:"datacenter" yaml:"datacenter"`
19+
PrivilegeValidationRules []PrivilegeValidationRule `json:"privilegeValidationRules,omitempty" yaml:"privilegeValidationRules,omitempty"`
20+
TagValidationRules []TagValidationRule `json:"tagValidationRules,omitempty" yaml:"tagValidationRules,omitempty"`
21+
ComputeResourceRules []ComputeResourceRule `json:"computeResourceRules,omitempty" yaml:"computeResourceRules,omitempty"`
22+
NTPValidationRules []NTPValidationRule `json:"ntpValidationRules,omitempty" yaml:"ntpValidationRules,omitempty"`
2423
}
2524

2625
var _ plugins.PluginSpec = (*VsphereValidatorSpec)(nil)
@@ -32,16 +31,17 @@ func (s VsphereValidatorSpec) PluginCode() string {
3231

3332
// ResultCount returns the number of validation results expected for an VsphereValidatorSpec.
3433
func (s VsphereValidatorSpec) ResultCount() int {
35-
return len(s.RolePrivilegeValidationRules) + len(s.EntityPrivilegeValidationRules) + len(s.ComputeResourceRules) +
34+
return len(s.PrivilegeValidationRules) + len(s.ComputeResourceRules) +
3635
len(s.TagValidationRules) + len(s.NTPValidationRules)
3736
}
3837

3938
// VsphereAuth defines authentication configuration for an VsphereValidator.
4039
type VsphereAuth struct {
4140
// SecretName is the name of the secret containing the vSphere credentials
4241
SecretName string `json:"secretName,omitempty" yaml:"secretName,omitempty"`
43-
// CloudAccount is the vSphere cloud account to use for authentication
44-
CloudAccount *vsphere.CloudAccount `json:"cloudAccount,omitempty" yaml:"cloudAccount,omitempty"`
42+
43+
// Account is the vSphere account to use for authentication
44+
Account *vsphere.Account `json:"account,omitempty" yaml:"account,omitempty"`
4545
}
4646

4747
// NTPValidationRule defines the NTP validation rule
@@ -50,8 +50,10 @@ type NTPValidationRule struct {
5050

5151
// RuleName is the name of the NTP validation rule
5252
RuleName string `json:"name" yaml:"name"`
53+
5354
// ClusterName is required when the vCenter Host(s) reside beneath a Cluster in the vCenter object hierarchy
5455
ClusterName string `json:"clusterName,omitempty" yaml:"clusterName,omitempty"`
56+
5557
// Hosts is the list of vCenter Hosts to validate NTP configuration
5658
Hosts []string `json:"hosts" yaml:"hosts"`
5759
}
@@ -74,12 +76,17 @@ type ComputeResourceRule struct {
7476

7577
// RuleName is the name of the compute resource validation rule
7678
RuleName string `json:"name" yaml:"name"`
79+
7780
// ClusterName is required when the vCenter Entity resides beneath a Cluster in the vCenter object hierarchy
7881
ClusterName string `json:"clusterName,omitempty" yaml:"clusterName"`
82+
7983
// Scope is the scope of the compute resource validation rule
84+
// +kubebuilder:validation:Enum=cluster;host;resourcepool
8085
Scope string `json:"scope" yaml:"scope"`
86+
8187
// EntityName is the name of the entity to validate
8288
EntityName string `json:"entityName" yaml:"entityName"`
89+
8390
// NodepoolResourceRequirements is the list of nodepool resource requirements
8491
NodepoolResourceRequirements []NodepoolResourceRequirement `json:"nodepoolResourceRequirements" yaml:"nodepoolResourceRequirements"`
8592
}
@@ -96,65 +103,61 @@ func (r *ComputeResourceRule) SetName(name string) {
96103
r.RuleName = name
97104
}
98105

99-
// EntityPrivilegeValidationRule defines the entity privilege validation rule
100-
type EntityPrivilegeValidationRule struct {
106+
// PrivilegeValidationRule defines the privilege validation rule
107+
type PrivilegeValidationRule struct {
101108
validationrule.ManuallyNamed `json:",inline" yaml:",omitempty"`
102109

103110
// RuleName is the name of the entity privilege validation rule
104111
RuleName string `json:"name" yaml:"name"`
112+
105113
// Username is the username to validate against
106114
Username string `json:"username" yaml:"username"`
115+
107116
// ClusterName is required when the vCenter Entity resides beneath a Cluster in the vCenter object hierarchy
108-
ClusterName string `json:"clusterName,omitempty" yaml:"clusterName"`
117+
ClusterName string `json:"clusterName,omitempty" yaml:"clusterName,omitempty"`
118+
109119
// EntityType is the type of the entity to validate
120+
// +kubebuilder:validation:Enum=cluster;datacenter;datastore;folder;host;network;resourcepool;vapp;vcenterroot;vds;vm
110121
EntityType string `json:"entityType" yaml:"entityType"`
122+
111123
// EntityName is the name of the entity to validate
112124
EntityName string `json:"entityName" yaml:"entityName"`
125+
113126
// Privileges is the list of privileges to validate that the user has
114127
Privileges []string `json:"privileges" yaml:"privileges"`
128+
129+
// TODO: consider propagation somehow
115130
}
116131

117-
var _ validationrule.Interface = (*EntityPrivilegeValidationRule)(nil)
132+
var _ validationrule.Interface = (*PrivilegeValidationRule)(nil)
118133

119134
// Name returns the name of the EntityPrivilegeValidationRule.
120-
func (r EntityPrivilegeValidationRule) Name() string {
135+
func (r PrivilegeValidationRule) Name() string {
121136
return r.RuleName
122137
}
123138

124139
// SetName sets the name of the EntityPrivilegeValidationRule.
125-
func (r *EntityPrivilegeValidationRule) SetName(name string) {
140+
func (r *PrivilegeValidationRule) SetName(name string) {
126141
r.RuleName = name
127142
}
128143

129-
// GenericRolePrivilegeValidationRule defines the generic role privilege validation rule
130-
type GenericRolePrivilegeValidationRule struct {
131-
validationrule.AutomaticallyNamed `json:",inline" yaml:",omitempty"`
132-
133-
// Username is the username to validate against
134-
Username string `json:"username" yaml:"username"`
135-
// Privileges is the list of privileges to validate that the user has
136-
Privileges []string `json:"privileges" yaml:"privileges"`
137-
}
138-
139-
var _ validationrule.Interface = (*GenericRolePrivilegeValidationRule)(nil)
140-
141-
// Name returns the name of the GenericRolePrivilegeValidationRule.
142-
func (r GenericRolePrivilegeValidationRule) Name() string {
143-
return r.Username
144-
}
145-
146144
// TagValidationRule defines the tag validation rule
147145
type TagValidationRule struct {
148146
validationrule.ManuallyNamed `json:",inline" yaml:",omitempty"`
149147

150148
// RuleName is the name of the tag validation rule
151149
RuleName string `json:"name" yaml:"name"`
150+
152151
// ClusterName is required when the vCenter Entity resides beneath a Cluster in the vCenter object hierarchy
153152
ClusterName string `json:"clusterName,omitempty" yaml:"clusterName"`
153+
154154
// EntityType is the type of the entity to validate
155+
// +kubebuilder:validation:Enum=cluster;datacenter;folder;host;resourcepool;vm
155156
EntityType string `json:"entityType" yaml:"entityType"`
157+
156158
// EntityName is the name of the entity to validate
157159
EntityName string `json:"entityName" yaml:"entityName"`
160+
158161
// Tag is the tag to validate on the entity
159162
Tag string `json:"tag" yaml:"tag"`
160163
}
@@ -175,12 +178,16 @@ func (r *TagValidationRule) SetName(name string) {
175178
type NodepoolResourceRequirement struct {
176179
// Name is the name of the nodepool
177180
Name string `json:"name" yaml:"name"`
181+
178182
// NumberOfNodes is the number of nodes in the nodepool
179183
NumberOfNodes int `json:"numberOfNodes" yaml:"numberOfNodes"`
184+
180185
// CPU is the CPU requirement for the nodepool
181186
CPU string `json:"cpu" yaml:"cpu"`
187+
182188
// Memory is the memory requirement for the nodepool
183189
Memory string `json:"memory" yaml:"memory"`
190+
184191
// DiskSpace is the disk space requirement for the nodepool
185192
DiskSpace string `json:"diskSpace" yaml:"diskSpace"`
186193
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 22 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)