Repository navigation
Closed
Labels
bugSomething isn't workingSomething isn't workinggenerationIssues pertaining to the generate ability.Issues pertaining to the generate ability.
Milestone
Description
Kyverno Version
1.11.4
Description
In Kyverno 1.11.4 (and probably others too), if a ClusterPolicy contains both a clone and mutate rule (with targets set), the clone rule in the policy is never applied.
Note the clone rule WILL apply if the mutate rule does not set mutate.targets.
Steps to reproduce:
- Create some namespaces for the clone:
apiVersion: v1
kind: Namespace
metadata:
name: source-namespaceapiVersion: v1
kind: Namespace
metadata:
name: target-namespace-1- Create the source resource:
apiVersion: v1
kind: Secret
metadata:
name: source-secret-1
namespace: source-namespace
data:
key1: "dmFsdWUx"
key2: "dmFsdWUy"- Create some other resource to target in the mutate rule:
apiVersion: v1
kind: ConfigMap
metadata:
name: random-configmap
namespace: source-namespace
data:
key1: "value1"
key2: "value2"- Create the ClusterPolicy
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: clone-secret-1-policy
spec:
generateExisting: true
rules:
- name: clone-secret
match:
any:
- resources:
kinds:
- Namespace
names:
- "target-namespace-1"
generate:
apiVersion: v1
kind: Secret
name: "target-secret-1"
namespace: "{{ request.object.metadata.name }}"
synchronize: true
clone:
namespace: "source-namespace"
name: "source-secret-1"
- name: random-mutate-trigger
match:
any:
## match can be any resource, and the issue still occurs
- resources:
kinds:
- Secret
names:
- "source-secret-1"
namespaces:
- "source-namespace"
mutate:
## targets can be anything (even empty), and the issue still occurs
targets:
- apiVersion: v1
kind: ConfigMap
name: "random-configmap"
namespace: "source-namespace"
## patch can be anything (even empty), and the issue still occurs
patchStrategicMerge:
metadata:
annotations:
my_annotation: "{{ time_now_utc() }}"- Notice that
Secret/target-secret-1is NOT created intarget-namespace-1 - Trigger the mutate rule by patching its
matchresource:
apiVersion: v1
kind: Secret
metadata:
name: source-secret-1
namespace: source-namespace
data:
key1: "dmFsdWUx"
key2: "dmFsdWUy"
key3: "dmFsdWUz"- Notice that
ConfigMap/random-configmapwas annotated withmy_annotation: "2024-01-30T21:50:40Z" - Notice that
Secret/target-secret-1is still NOT created intarget-namespace-1
Slack discussion
No response
Troubleshooting
- I have read and followed the documentation AND the troubleshooting guide.
- I have searched other issues in this repository and mine is not recorded.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinggenerationIssues pertaining to the generate ability.Issues pertaining to the generate ability.
Activity
thesuperzapper commentedon Jan 31, 2024
@chipzoller @realshuting we should either document this as a known issue, or try and fix it in the next release.
It's very common to want a policy that both "clones" a Secret, and also triggers restarts of Deployments that use that secret (listening to updates on the source secret, to avoid the fact that Kyverno ignores its own updates).
But right now (1.11.4), these rules have to be in separate policies, or the clone wont apply.
realshuting commentedon Feb 1, 2024
You need to set
mutateExistingOnPolicyUpdate: trueto trigger the second rule on policy creation. Verified with the latest main and it worked as expected.thesuperzapper commentedon Feb 1, 2024
@realshuting I am very confused by your response. I think we need to reopen this issue.
The issue is not about whether the mutate rule fires on creation of the policy, it's about the clone rule not firing at all.
Specifically, in 1.11.4 if there is a clone rule in a policy in addition to a mutate rule (with a target defined), then the clone rule does not ever trigger.
Are you saying that this issue has been resolved already?
realshuting commentedon Feb 1, 2024
I was testing against the latest main and it has no issue cloning the secret. Let me verify on 1.11.x.
realshuting commentedon Feb 1, 2024
I can confirm that the clone rule in the combined policy doesn't work in 1.11.4.
It looks like the issue has been fixed in main and will be available in 1.12, can you please verify the same?