Skip to content

Deny policy for specific string in section data in ConfigMap #1320

@zaval1976

Description

@zaval1976

Hello,

I want write policy for deny deploy ConfigMap, if in some keys value, in section data, will be specific string with contain, for example "postgresql".

I wrote this policy, but it work for specific key name.
I need that check in all key values in section data.

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: disallow-credential-composite-design
spec:
  rules:
  - name: validate-data-design
    match:
      resources:
        kinds:
        - ConfigMap
    validate:
      allowExistingViolations: true
      failureAction: Enforce
      message: "Use of composite structures to assemble credentials is prohibited by cybersecurity policy."
      foreach:
      - list: request.object.data
        deny:
          conditions:
            all:
            - key: '{{ element }}'
              operator: Equals
              value: "*postgresql*"

Do you have any ideas?
I use Kyverno v.1.14.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions