mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
fix: add CONNECT operation in the webhook config for pod/exec subresource (#9855)
Signed-off-by: Mariam Fahmy <mariam.fahmy@nirmata.com>
This commit is contained in:
parent
f91bf6529d
commit
8805620574
6 changed files with 78 additions and 1 deletions
|
@ -52,7 +52,7 @@ func newWebhook(timeout int32, failurePolicy admissionregistrationv1.FailurePoli
|
||||||
|
|
||||||
func findKeyContainingSubstring(m map[string][]admissionregistrationv1.OperationType, substring string, defaultOpn []admissionregistrationv1.OperationType) []admissionregistrationv1.OperationType {
|
func findKeyContainingSubstring(m map[string][]admissionregistrationv1.OperationType, substring string, defaultOpn []admissionregistrationv1.OperationType) []admissionregistrationv1.OperationType {
|
||||||
for key, value := range m {
|
for key, value := range m {
|
||||||
if strings.Contains(strings.ToLower(key), strings.ToLower(substring)) || strings.Contains(strings.ToLower(substring), strings.ToLower(key)) {
|
if key == "Pod/exec" || strings.Contains(strings.ToLower(key), strings.ToLower(substring)) || strings.Contains(strings.ToLower(substring), strings.ToLower(key)) {
|
||||||
return value
|
return value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
## Description
|
||||||
|
|
||||||
|
This test verifies the resource mutation webhook is configured correctly when a policy targets the `Pod/exec` subresource.
|
||||||
|
|
||||||
|
## Steps
|
||||||
|
|
||||||
|
1. - Create a policy targeting `Pod/exec`
|
||||||
|
- Assert policy gets ready
|
||||||
|
1. - Assert that the resource mutation webhook is configured correctly
|
||||||
|
|
||||||
|
## Reference Issue(s)
|
||||||
|
|
||||||
|
#9829
|
17
test/conformance/chainsaw/webhooks/pod-exec-subresource/chainsaw-test.yaml
Executable file
17
test/conformance/chainsaw/webhooks/pod-exec-subresource/chainsaw-test.yaml
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
apiVersion: chainsaw.kyverno.io/v1alpha1
|
||||||
|
kind: Test
|
||||||
|
metadata:
|
||||||
|
creationTimestamp: null
|
||||||
|
name: pod-exec-subresource
|
||||||
|
spec:
|
||||||
|
steps:
|
||||||
|
- name: step-01
|
||||||
|
try:
|
||||||
|
- apply:
|
||||||
|
file: policy.yaml
|
||||||
|
- assert:
|
||||||
|
file: policy-assert.yaml
|
||||||
|
- name: step-02
|
||||||
|
try:
|
||||||
|
- assert:
|
||||||
|
file: webhooks.yaml
|
|
@ -0,0 +1,9 @@
|
||||||
|
apiVersion: kyverno.io/v1
|
||||||
|
kind: ClusterPolicy
|
||||||
|
metadata:
|
||||||
|
name: std-shell
|
||||||
|
status:
|
||||||
|
conditions:
|
||||||
|
- reason: Succeeded
|
||||||
|
status: "True"
|
||||||
|
type: Ready
|
|
@ -0,0 +1,21 @@
|
||||||
|
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
|
|
@ -0,0 +1,17 @@
|
||||||
|
apiVersion: admissionregistration.k8s.io/v1
|
||||||
|
kind: MutatingWebhookConfiguration
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
webhook.kyverno.io/managed-by: kyverno
|
||||||
|
name: kyverno-resource-mutating-webhook-cfg
|
||||||
|
webhooks:
|
||||||
|
- rules:
|
||||||
|
- apiGroups:
|
||||||
|
- ""
|
||||||
|
apiVersions:
|
||||||
|
- v1
|
||||||
|
operations:
|
||||||
|
- CONNECT
|
||||||
|
resources:
|
||||||
|
- pods/exec
|
||||||
|
scope: 'Namespaced'
|
Loading…
Add table
Reference in a new issue