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

fix: add error check in jmespath type conversion in context variables #10152

Merged
merged 6 commits into from
May 1, 2024

Conversation

vishal-chdhry
Copy link
Member

Explanation

The following policy and pod caused panic in admission and reports-controller

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: test-panic
spec:
  validationFailureAction: Enforce 
  background: true 
  rules:
    - name: test-panic
      match:
        any:
        - resources:
            kinds:
              - Pod
      context:
      - name: image
        variable:
          jmesPath: '{{ request.object.spec.[containers,initContainers, ephemeralContainers][].image[] }}'
      validate:
        deny:
          conditions:
            all:
            - key: "{{ image }}"
              operator: AnyNotIn
              value: 
              - "gcr.io/datadoghq/agent" 

Apply the following pod

$ kubectl run test --image nginx     
Error from server (InternalError): Internal error occurred: failed calling webhook "validate.kyverno.svc-fail": failed to call webhook: Post "[https://kyverno-svc.kyverno.svc:443/validate/fail?timeout=10s](https://kyverno-svc.kyverno.svc/validate/fail?timeout=10s)": dial tcp 10.96.166.0:443: connect: connection refused

This is because the path variable resolves to empty value and its type conversion caused a panic, this PR makes that type conversion safer.

Related issue

NA

Milestone of this PR

Documentation (required for features)

My PR contains new or altered behavior to Kyverno.

What type of PR is this

Proposed Changes

Proof Manifests

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.
  • This is a feature and I have added CLI tests that are applicable.
  • My PR needs to be cherry picked to a specific release branch which is .
  • My PR contains new or altered behavior to Kyverno and
    • CLI support should be added and my PR doesn't contain that functionality.

Further Comments

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
Copy link

codecov bot commented May 1, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 10.15%. Comparing base (5d50022) to head (1584589).

Files Patch % Lines
pkg/engine/context/loaders/variable.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10152      +/-   ##
==========================================
- Coverage   10.15%   10.15%   -0.01%     
==========================================
  Files        1030     1030              
  Lines       91779    91782       +3     
==========================================
  Hits         9323     9323              
- Misses      81438    81441       +3     
  Partials     1018     1018              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
realshuting
realshuting previously approved these changes May 1, 2024
@realshuting
Copy link
Member

/cherry-pick release-1.12

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
@realshuting realshuting merged commit c403a49 into kyverno:main May 1, 2024
247 of 250 checks passed
gcp-cherry-pick-bot bot pushed a commit that referenced this pull request May 1, 2024
…#10152)

* fix: add error check in jmespath type conversion in context variables

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>

* fix(lint): new line in tests

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>

* fix: properly update path variable

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>

* fix: remove log statemet

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>

---------

Signed-off-by: Vishal Choudhary <vishal.choudhary@nirmata.com>
@realshuting realshuting added the cherry-pick-completed The PR was cherry-picked (or merged) to required release branches label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-completed The PR was cherry-picked (or merged) to required release branches cherry-pick-required milestone 1.12.1 milestone 1.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants