Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate CRDs labels in validating webhook #3285

Closed
GraysonWu opened this issue Feb 9, 2022 · 0 comments · Fixed by #3331
Closed

Validate CRDs labels in validating webhook #3285

GraysonWu opened this issue Feb 9, 2022 · 0 comments · Fixed by #3331
Assignees
Labels
kind/design Categorizes issue or PR as related to design.

Comments

@GraysonWu
Copy link
Contributor

GraysonWu commented Feb 9, 2022

Describe what you are trying to solve
Currently while creating K8s resources, for example, Pod, k8s NeworkPolicy, etc., the API server will validate if labels used in those resources are valid. For example, if I use an invalid character '=', it will return:

The Deployment "client" is invalid: metadata.labels: Invalid value: "foo=bar": a valid label must be an empty string or consist of alphanumeric characters, '-', '_' or '.', and must start and end with an alphanumeric character (e.g. 'MyValue',  or 'my_value',  or '12345', regex used for validation is '(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])?')

But now our CRDs with invalid labels can be accepted, for example, the acnp below:

apiVersion: crd.antrea.io/v1alpha1
kind: ClusterNetworkPolicy
metadata:
  name: acnp-invalid-labels
spec:
    priority: 5
    tier: SecurityOps
    appliedTo:
      - podSelector:
          matchLabels:
            app: client
    egress:
      - action: Reject
        to:
          - podSelector:
              matchLabels:
                app: foo=bar

This ACNP won't have any effect since no Pod will have this invalid label app: foo=bar. But Antrea will still waste computing resource to process this ACNP.

Describe the solution you have in mind
I'm wondering if we could add this validation in out validating webhook?

Idea comes from here

@GraysonWu GraysonWu added the kind/design Categorizes issue or PR as related to design. label Feb 9, 2022
@GraysonWu GraysonWu self-assigned this Feb 9, 2022
GraysonWu added a commit to GraysonWu/antrea that referenced this issue Feb 17, 2022
Fixes antrea-io#3285.

This PR added some additional validations to ANP and ACNP in
validating webhook. Antrea will validate labels used in ANP and ACNP
under PodSelector, NamespaceSelector and ExternalEntitySelector.

Signed-off-by: wgrayson <wgrayson@vmware.com>
GraysonWu added a commit to GraysonWu/antrea that referenced this issue Feb 17, 2022
Fixes antrea-io#3285.

This PR added some additional validations to ANP and ACNP in
validating webhook. Antrea will validate labels used in ANP and ACNP
under PodSelector, NamespaceSelector and ExternalEntitySelector.

Signed-off-by: wgrayson <wgrayson@vmware.com>
GraysonWu added a commit to GraysonWu/antrea that referenced this issue Feb 17, 2022
Fixes antrea-io#3285.

This PR added some additional validations to ANP and ACNP in
validating webhook. Antrea will validate labels used in ANP and ACNP
under PodSelector, NamespaceSelector and ExternalEntitySelector.

Signed-off-by: wgrayson <wgrayson@vmware.com>
GraysonWu added a commit to GraysonWu/antrea that referenced this issue Feb 22, 2022
Fixes antrea-io#3285.

This PR added some additional validations to ANP and ACNP in
validating webhook. Antrea will validate labels used in ANP and ACNP
under PodSelector, NamespaceSelector and ExternalEntitySelector.

Signed-off-by: wgrayson <wgrayson@vmware.com>
GraysonWu added a commit to GraysonWu/antrea that referenced this issue Feb 24, 2022
Fixes antrea-io#3285.

This PR added some additional validations to ANP, ACNP and CG in
validating webhook. Antrea will validate labels used in ANP, ACNP and
CG under PodSelector, NamespaceSelector and ExternalEntitySelector.

Signed-off-by: wgrayson <wgrayson@vmware.com>
tnqn pushed a commit that referenced this issue Feb 24, 2022
Fixes #3285.

This PR added some additional validations to ANP, ACNP and CG in
validating webhook. Antrea will validate labels used in ANP, ACNP and
CG under PodSelector, NamespaceSelector and ExternalEntitySelector.

Signed-off-by: wgrayson <wgrayson@vmware.com>
bangqipropel pushed a commit to bangqipropel/antrea that referenced this issue Mar 2, 2022
Fixes antrea-io#3285.

This PR added some additional validations to ANP, ACNP and CG in
validating webhook. Antrea will validate labels used in ANP, ACNP and
CG under PodSelector, NamespaceSelector and ExternalEntitySelector.

Signed-off-by: wgrayson <wgrayson@vmware.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/design Categorizes issue or PR as related to design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant