Audit events fails for secret creation

Kyverno Version

1.12

Kubernetes Version

1.28

Kubernetes Platform

EKS

Description

With the Kyverno policy shared below, we aim to achieve the following:

For the following Kubernetes objects: Deployment Pod Service ConfigMap Secret We want to generate events for create, update, and delete actions.

While we successfully generate events for all actions except the create action of the Secret object, we can generate events for delete and update actions for the Secret object without any issues.

This behavior occurs with Helm chart version 3.3.3 and app version v1.13.1.

apiVersion: kyverno.io/v2beta1
kind: ClusterPolicy
metadata:
  name: z-audit-events
  annotations:
    policies.kyverno.io/title: Audit Events for Update and Delete
    policies.kyverno.io/category: Audit
    policies.kyverno.io/description: >-
      Generates Kubernetes Events when CREATE, UPDATE or DELETE operations are performed on resources.
      The log message includes operation type, resource name, and the username performing the action.
spec:
  background: false
  rules:
  - name: audit-events
    match:
      any:
      - resources:
          kinds:
          - Deployment
          - Pod
          - Service
          - ConfigMap
          - Secret
          operations:
          - CREATE
          - DELETE
          - UPDATE
    generate:
      apiVersion: v1
      kind: Event
      name: "audit.{{ random('[a-z0-9]{6}') }}"
      namespace: "{{request.namespace}}"
      synchronize: false
      data:
        firstTimestamp: "{{ time_now_utc() }}"
        involvedObject:
          apiVersion: v1
          kind: "{{ request.kind.kind }}"
          name: "{{ request.name }}"
          namespace: "{{ request.namespace }}"
        lastTimestamp: "{{ time_now_utc() }}"
        message: "{{ request.operation }} operation on {{ request.kind.kind }}/{{ request.name }} was performed by {{ request.userInfo.username }}"
        reason: Audit
        source:
          component: kyverno
        type: Warning

Steps to reproduce

1.Kyverno was installed in Kubernetes using Helm chart version 3.3.3 and app version v1.13.1. 2.The Kyverno ClusterPolicy shared above was created. 3.A dummy Secret object was created, and the events were monitored using the command: kubectl get events --watch 4. The create event for the Secret object is not generated, while the update and delete events are successfully generated.

Expected behavior

LAST SEEN       TYPE        REASON        OBJECT                          MESSAGE
0s                      Warning   Audit              secret/dummy-secret    CREATE operation on Secret/dummy-secret was performed by kubernetes-admin

Screenshots

image Delete action can be seen but create is not

Kyverno logs

No response

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.