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

Add a proposal for generating VAPs given an exception #55

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MariamFahmy98
Copy link
Contributor

This PR includes the latest investigation report on the generation of VAP in case of a policy exception.

- expression: "'app' in object.metadata.labels"
```

However, using a `namespaceSelector` will be applied for both matching and excluding deployemnts. The above VAP matches all deployments whose namespace labels set to `environment: staging`, and it also excludes all deployments named `important-tool` whose namespace labels set to `environment: staging`. It means that matching/excluding resources is done in the same namespace. There is no option to match deployments in all namespaces and exclude some in a specific namespace.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MariamFahmy98 - isn't this the same as what this Kyverno declaration would do?

...
  rules:
  - name: check-deployment-labels
    match:
      all:
      - resources:
          namespaceSelector:
            matchLabels:
              environments: staging
    exclude:
      all:
        - resources:
            name: important-tool

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The corresponding VAP could be something like this:

apiVersion: admissionregistration.k8s.io/v1beta1
kind: ValidatingAdmissionPolicy
metadata:
  name: "check-deployment-labels"
spec:
  failurePolicy: Fail
  matchConstraints:
    excludeResourceRules:
    - apiGroups:     ['*']
      apiVersions:   ['*']
      resources:     ['*']
      resourceNames: ["important-tool"]
    namespaceSelector:
      matchLabels:
        environment: staging
  validations:
    - expression: "'app' in object.metadata.labels"

But I need to double-check if this is correct.


- An exception that matches resources based on annotations, subjects, roles, or clusterRoles cannot be converted to VAPs.

In conclusion, exceptions provide the flexibility to exclude resources that VAPs lack, making it impossible to generate a VAP from an exception. As a result, if an exception is created for a Kyverno policy that uses `validate.cel` subrule, the Kyverno engine will handle the resource validation itself instead of generating the corresponding VAPs.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we allow use of some subset of exceptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the following cases, I think a VAP can be generated:

  1. Matching all resources and excluding a specific one.
  2. Matching and excluding in the same namespace.

However, there are a lot of limitations and I don't know if it is worth considering this feature.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we clarify the limitations and propose changes to ValidatingAdmissionPolicy resources?

kubernetes/kubernetes#122205 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants