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

Bug fix | CLI panic | Context policy validation #2336

Merged
merged 2 commits into from
Aug 30, 2021

Conversation

NoSkillGirl
Copy link
Contributor

@NoSkillGirl NoSkillGirl commented Aug 29, 2021

Signed-off-by: NoSkillGirl singhpooja240393@gmail.com

Related issue

closes #2289

Milestone of this PR

/milestone 1.4.3.

What type of PR is this

/kind bug

Proposed Changes

Currently, Kyverno CLI panics when context is added to rule, but not actually used in the rule.
I have added a validation check for the above case.

With the chenges:

  • policy will fail in webhook
  • policy will be not valid when tried with Kyverno CLI validate command
  • policy will be skipped when tried with Kyverno CLI apply command

Proof Manifests

Try the following policy:

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: enforce-pod-name
spec:
  validationFailureAction: enforce
  background: true
  rules:
    - name: validate-name
      context:
      - name: test
        configMap:
          name: game-demo
          namespace: default
      match:
        resources:
          kinds:
            - Pod
      validate:
        message: "The Pod must end with -nginx"
        pattern:
          metadata:
            name: "*-nginx"
$ kyverno validate policy.yaml
----------------------------------------------------------------------
Policy enforce-pod-name is invalid.
Error: invalid policy.
Cause: path: spec.rules[0]: context variable `test` is not used in the policy

exit status 1

Checklist

  • I have read the contributing guidelines.
  • [] I have added tests that prove my fix is effective or that my feature works.
  • [] My PR contains new or altered behavior to Kyverno and
    • [] I have added or changed the documentation myself in an existing PR and the link is:
    • [] I have raised an issue in kyverno/website to track the doc update and the link is:
    • [] I have read the PR documentation guide and followed the process including adding proof manifests to this PR.

Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
Signed-off-by: NoSkillGirl <singhpooja240393@gmail.com>
@NoSkillGirl NoSkillGirl changed the title 2289/context policy validation Bug fix | CLI panic | Context policy validation Aug 29, 2021
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.

[BUG] Kyverno CLI panics when context is added to rule, but not actually used
2 participants