Skip to content

Commit

Permalink
Add validating webhooks for Egress and ExternalIPPool
Browse files Browse the repository at this point in the history
The webhook for Egress validates that the EgressIP must be within the IP
ranges of the ExternalIPPool if both are set.

The webhook for ExternalIPPool validates that the ExternalIPPool must
not shrink.

Signed-off-by: Quan Tian <qtian@vmware.com>
  • Loading branch information
tnqn committed Jul 9, 2021
1 parent 5313dd7 commit ad4a3fe
Show file tree
Hide file tree
Showing 14 changed files with 710 additions and 13 deletions.
43 changes: 43 additions & 0 deletions build/yamls/antrea-aks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
43 changes: 43 additions & 0 deletions build/yamls/antrea-eks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4541,6 +4541,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
43 changes: 43 additions & 0 deletions build/yamls/antrea-gke.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4539,6 +4539,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
43 changes: 43 additions & 0 deletions build/yamls/antrea-ipsec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4588,6 +4588,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
43 changes: 43 additions & 0 deletions build/yamls/antrea.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4544,6 +4544,49 @@ webhooks:
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/externalippool
name: externalippoolvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- UPDATE
resources:
- externalippools
scope: Cluster
sideEffects: None
timeoutSeconds: 5
- admissionReviewVersions:
- v1
- v1beta1
clientConfig:
service:
name: antrea
namespace: kube-system
path: /validate/egress
name: egressvalidator.antrea.io
rules:
- apiGroups:
- crd.antrea.io
apiVersions:
- v1alpha2
operations:
- CREATE
- UPDATE
resources:
- egresses
scope: Cluster
sideEffects: None
timeoutSeconds: 5
---
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration
Expand Down
30 changes: 30 additions & 0 deletions build/yamls/base/controller.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,36 @@ webhooks:
admissionReviewVersions: ["v1", "v1beta1"]
sideEffects: None
timeoutSeconds: 5
- name: "externalippoolvalidator.antrea.io"
clientConfig:
service:
name: "antrea"
namespace: "kube-system"
path: "/validate/externalippool"
rules:
- operations: ["UPDATE"]
apiGroups: ["crd.antrea.io"]
apiVersions: ["v1alpha2"]
resources: ["externalippools"]
scope: "Cluster"
admissionReviewVersions: ["v1", "v1beta1"]
sideEffects: None
timeoutSeconds: 5
- name: "egressvalidator.antrea.io"
clientConfig:
service:
name: "antrea"
namespace: "kube-system"
path: "/validate/egress"
rules:
- operations: ["CREATE", "UPDATE"]
apiGroups: ["crd.antrea.io"]
apiVersions: ["v1alpha2"]
resources: ["egresses"]
scope: "Cluster"
admissionReviewVersions: ["v1", "v1beta1"]
sideEffects: None
timeoutSeconds: 5
---
apiVersion: apiregistration.k8s.io/v1
kind: APIService
Expand Down
7 changes: 6 additions & 1 deletion cmd/antrea-controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ var allowedPaths = []string{
"/validate/acnp",
"/validate/anp",
"/validate/clustergroup",
"/validate/externalippool",
"/validate/egress",
"/convert/clustergroup",
}

Expand Down Expand Up @@ -274,6 +276,7 @@ func run(o *Options) error {
endpointQuerier,
networkPolicyController,
networkPolicyStatusController,
egressController,
statsAggregator,
o.config.EnablePrometheusMetrics,
cipherSuites,
Expand Down Expand Up @@ -364,6 +367,7 @@ func createAPIServerConfig(kubeconfig string,
endpointQuerier networkpolicy.EndpointQuerier,
npController *networkpolicy.NetworkPolicyController,
networkPolicyStatusController *networkpolicy.StatusController,
egressController *egress.EgressController,
statsAggregator *stats.Aggregator,
enableMetrics bool,
cipherSuites []uint16,
Expand Down Expand Up @@ -424,5 +428,6 @@ func createAPIServerConfig(kubeconfig string,
controllerQuerier,
networkPolicyStatusController,
endpointQuerier,
npController), nil
npController,
egressController), nil
}
19 changes: 14 additions & 5 deletions pkg/apiserver/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import (
"antrea.io/antrea/pkg/apiserver/registry/system/controllerinfo"
"antrea.io/antrea/pkg/apiserver/registry/system/supportbundle"
"antrea.io/antrea/pkg/apiserver/storage"
"antrea.io/antrea/pkg/controller/egress"
controllernetworkpolicy "antrea.io/antrea/pkg/controller/networkpolicy"
"antrea.io/antrea/pkg/controller/querier"
"antrea.io/antrea/pkg/controller/stats"
Expand Down Expand Up @@ -98,6 +99,7 @@ type ExtraConfig struct {
controllerQuerier querier.ControllerQuerier
endpointQuerier controllernetworkpolicy.EndpointQuerier
networkPolicyController *controllernetworkpolicy.NetworkPolicyController
egressController *egress.EgressController
caCertController *certificate.CACertController
statsAggregator *stats.Aggregator
networkPolicyStatusController *controllernetworkpolicy.StatusController
Expand Down Expand Up @@ -139,7 +141,8 @@ func NewConfig(
controllerQuerier querier.ControllerQuerier,
networkPolicyStatusController *controllernetworkpolicy.StatusController,
endpointQuerier controllernetworkpolicy.EndpointQuerier,
npController *controllernetworkpolicy.NetworkPolicyController) *Config {
npController *controllernetworkpolicy.NetworkPolicyController,
egressController *egress.EgressController) *Config {
return &Config{
genericConfig: genericConfig,
extraConfig: ExtraConfig{
Expand All @@ -154,6 +157,7 @@ func NewConfig(
endpointQuerier: endpointQuerier,
networkPolicyController: npController,
networkPolicyStatusController: networkPolicyStatusController,
egressController: egressController,
},
}
}
Expand Down Expand Up @@ -292,10 +296,10 @@ func installHandlers(c *ExtraConfig, s *genericapiserver.GenericAPIServer) {
// Get new NetworkPolicyValidator
v := controllernetworkpolicy.NewNetworkPolicyValidator(c.networkPolicyController)
// Install handlers for NetworkPolicy related validation
s.Handler.NonGoRestfulMux.HandleFunc("/validate/tier", webhook.HandleValidationNetworkPolicy(v))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/acnp", webhook.HandleValidationNetworkPolicy(v))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/anp", webhook.HandleValidationNetworkPolicy(v))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/clustergroup", webhook.HandleValidationNetworkPolicy(v))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/tier", webhook.HandlerForValidateFunc(v.Validate))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/acnp", webhook.HandlerForValidateFunc(v.Validate))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/anp", webhook.HandlerForValidateFunc(v.Validate))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/clustergroup", webhook.HandlerForValidateFunc(v.Validate))

// Install handlers for CRD conversion between versions
s.Handler.NonGoRestfulMux.HandleFunc("/convert/clustergroup", webhook.HandleCRDConversion(controllernetworkpolicy.ConvertClusterGroupCRD))
Expand All @@ -306,4 +310,9 @@ func installHandlers(c *ExtraConfig, s *genericapiserver.GenericAPIServer) {
return nil
})
}

if features.DefaultFeatureGate.Enabled(features.Egress) {
s.Handler.NonGoRestfulMux.HandleFunc("/validate/externalippool", webhook.HandlerForValidateFunc(c.egressController.ValidateExternalIPPool))
s.Handler.NonGoRestfulMux.HandleFunc("/validate/egress", webhook.HandlerForValidateFunc(c.egressController.ValidateEgress))
}
}
Loading

0 comments on commit ad4a3fe

Please sign in to comment.