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 CONNECT operation in the webhook config for pod/exec subresource #9855

Merged
merged 2 commits into from
May 6, 2024

Conversation

MariamFahmy98
Copy link
Collaborator

@MariamFahmy98 MariamFahmy98 commented Mar 5, 2024

Explanation

This PR checks for the Pod/exec subresource, and if it does exists, we return the operations specified by the user instead of returning back the default operations.

Related issue

Closes #9829

Milestone of this PR

/milestone 1.12.0

Documentation (required for features)

My PR contains new or altered behavior to Kyverno.

What type of PR is this

/kind bug

Proposed Changes

Proof Manifests

  1. policy.yaml:
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: std-shell
spec:
  background: false
  rules:
  - match:
      any:
      - resources:
          kinds:
          - Pod/exec
          operations:
          - CONNECT
    mutate:
      patchesJson6902: |-
        - op: replace
          path: "/command/0"
          value: "bash" 
    name: std-shell-replace
  validationFailureAction: Audit

Check the mutating webhook configuration:

kubectl get mutatingwebhookconfigurations.admissionregistration.k8s.io kyverno-resource-mutating-webhook-cfg -o yaml

apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration
metadata:
  labels:
    webhook.kyverno.io/managed-by: kyverno
  name: kyverno-resource-mutating-webhook-cfg
webhooks:
- admissionReviewVersions:
  - v1
  clientConfig:
    caBundle: <ca-bundle>
    url: https://172.18.0.1:9443/mutate/fail
  failurePolicy: Fail
  matchPolicy: Equivalent
  name: mutate.kyverno.svc-fail
  namespaceSelector:
    matchExpressions:
    - key: kubernetes.io/metadata.name
      operator: NotIn
      values:
      - kyverno
  objectSelector: {}
  reinvocationPolicy: IfNeeded
  rules:
  - apiGroups:
    - ""
    apiVersions:
    - v1
    operations:
    - CONNECT
    resources:
    - pods/exec
    scope: Namespaced
  sideEffects: NoneOnDryRun
  timeoutSeconds: 10

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

…urce

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
Copy link

codecov bot commented Mar 5, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 10.15%. Comparing base (f91bf65) to head (bb851af).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9855   +/-   ##
=======================================
  Coverage   10.15%   10.15%           
=======================================
  Files        1030     1030           
  Lines       91793    91793           
=======================================
  Hits         9322     9322           
  Misses      81452    81452           
  Partials     1019     1019           

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

Copy link
Member

@realshuting realshuting left a comment

Choose a reason for hiding this comment

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

Is there a sample policy for this? If so, do we need to update accordingly?

@realshuting realshuting enabled auto-merge (squash) May 6, 2024 09:22
@realshuting
Copy link
Member

/cherry-pick release-1.12

@realshuting realshuting merged commit 8805620 into kyverno:main May 6, 2024
250 of 276 checks passed
gcp-cherry-pick-bot bot pushed a commit that referenced this pull request May 6, 2024
…urce (#9855)

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
@realshuting realshuting added the cherry-pick-completed The PR was cherry-picked (or merged) to required release branches label May 6, 2024
realshuting pushed a commit that referenced this pull request May 6, 2024
…urce (#9855) (#10179)

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
Co-authored-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
anushkamittal2001 pushed a commit to nirmata/kyverno that referenced this pull request May 24, 2024
…urce (kyverno#9855) (kyverno#10179)

Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
Co-authored-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
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.2 milestone 1.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Mutating webhooks aren't adding CONNECT operation in the webhook config for Pod/exec resource
2 participants