Skip to main content

17  Compliance Checks

You decided how krafter, the Kafka cluster under test, should be built: three brokers and three controllers, one of each per zone, durable defaults for every topic, and authentication on every listener. That decision lives in a design review and a values file. The cluster that serves traffic today is whatever the last upgrade, scale-out and hand edit left behind, and nothing tells you when the two drift apart. A compliance check closes that gap: you write the architecture down as a file, and Kates holds the live cluster to it, rule by rule, without changing anything. On panda, the lab cluster, the checks in this chapter find two such gaps, and you decide what to do about each.

In this chapter you’ll:

17.1 Your First Reference

The smallest useful reference says three things about the brokers: there are at least three, they run in at least three zones, and no node runs more than one. This is minimal.yaml from cli/examples/conformity, shown without the comment line that points editors at the JSON Schema:

apiVersion: conformity.kates.io/v1alpha1
kind: KafkaReference
metadata:
  name: minimal
spec:
  brokers:
    count: {min: 3}
    zones: {min: 3}
    perNode: {max: 1}

The file has the shape of a Kubernetes object, but it never goes into the cluster: it stays in your repository, and the check reads it. apiVersion names the version of the language, so the format can change later without an old file being misread. kind says the document is a KafkaReference, and metadata.name is the name the report shows. spec holds the rules. Each value under spec is one rule, and its path is its name: brokers.count, brokers.zones and brokers.perNode.

Check the file on your own machine first. kates compliance lint needs no cluster and no Kates API: it reads the file the way the Kates API does, so a typo never reaches a cluster.

kates compliance lint minimal.yaml

Output:

1 file: no problems

Then ask the Kates API to check krafter against the file:

kates compliance check -f minimal.yaml

Output on panda, the lab’s three-node Kind cluster, with the banner trimmed:

✓ PASS: 0 fail, 0 warn, 0 waived, 3 pass, 0 unknown
  3 passing rules not shown; -o json lists them

Read it from the top:

  1. The first line is the check’s overall result, followed by how many rules ended in each status. PASS means every rule that can fail the check holds.
  2. The table above that line lists only the rules that need your attention, so this check prints none. -o json prints every rule with what it observed: three brokers, one in each of the zones alpha, gamma and sigma, and one broker per node.
  3. The command exits 0, which is what a pipeline reads.

The trimmed banner names the reference and the cluster, with its Kafka cluster id, and says whether the Kafka resource is Ready. When it isn’t, the banner warns that results may change while the cluster settles.

TipTry it: what does a gap look like?

Raise zones to {min: 4} in a copy of minimal.yaml and run the check again. Read the failing row: what does Expected say, and which zones does -o json list in the rule’s detail?

17.2 Why Compliance

An architecture is a set of promises a cluster keeps for its clients. A write acknowledged with acks=all survives the loss of a broker. A zone can fail without taking a partition offline. No client connects without authenticating. Three places hold those promises, and only one of them serves traffic:

flowchart TB
    design["Design review"] --> values["Values files"]
    design --> ref["Reference file"]
    values -->|"Helm, the operator"| cluster["Running cluster"]
    ref -->|"compliance check"| cluster
    subgraph drift["Changes that skip the design"]
        direction LR
        scale["Pool scaled<br/>or added"]
        move["Pod<br/>rescheduled"]
        upgrade["Chart or<br/>operator upgrade"]
        topic["Topic created<br/>by a client"]
    end
    scale & move & upgrade & topic --> cluster
Figure 17.1: The architecture lives in three places, and only the running cluster serves traffic; everyday changes reach it without passing through the design.

The design is where you decided, the values files are one way to carry the decision out, and the running cluster is what Helm, the Strimzi operator and Kubernetes made of them, plus everything that happened since. The changes in the tinted zone never pass through the design. A node pool is scaled down to save money, or a pool is added with both the broker and controller roles. Kubernetes reschedules a broker onto a node that already runs one, because the pods only prefer to stay apart. New nodes join without a zone label. A chart upgrade changes a default. A client creates a topic with two replicas while the broker default is three.

None of these breaks the cluster on the day it happens, so every health check stays green. The cost arrives on the day a promise is called in. Two brokers that share a node look fine until that node fails. Then every partition with replicas on both loses two of its three, and with min.insync.replicas at 2, acks=all writes to those partitions are refused until a broker returns. A drifted cluster isn’t broken. It is less redundant than the design promised, and you find out during the outage the design was meant to survive.

A reference file is the design in a form a machine can check, and it says something different from a values file. A values file says how to build one cluster, with exact numbers. A reference says what any acceptable cluster must satisfy, often with bounds: at least three brokers, at least 8Gi of memory each. A cluster can then grow, or change its sizing, without failing the check, as long as it keeps its promises. If you write tests for code, the analogy is close: the values file is the implementation, and the reference is the test suite it must pass.

Kates already asks several questions about a cluster, and a compliance check is the one that compares it with something you wrote down:

Command The question it answers
kates cluster check Is the cluster healthy right now: brokers up, partitions in sync, a controller elected?
kates detect What runs on this Kubernetes cluster, and what does Kates recommend for it?
kates security audit How secure is the cluster, as a security grade?
kates test apply --wait Is the cluster fast enough, against a scenario’s gates?
kates compliance check Is the cluster still built the way you declared, rule by rule?

The first four judge the cluster against what is healthy, safe or fast in general. Only the compliance check judges it against your own design, so it’s the one that notices a cluster that works but has drifted from what you meant to build.

How a Check Runs

A check has two halves, one on your machine and one in the Kates API, and neither writes anything to the cluster:

flowchart TB
    file["Reference file"] --> lint["kates compliance lint<br/>on your machine"]
    lint --> check["kates compliance check"]
    check --> api["Kates API"]
    api --> k8s["Kubernetes API<br/>Strimzi resources, pods,<br/>nodes, volume claims"]
    api -.-> admin["Kafka Admin API<br/>topics, broker configs"]
    api --> report["Report: one result per rule"]
    report --> exit["Exit code 0, 1 or 2"]
Figure 17.2: A check reads the cluster and changes nothing: the file goes to the Kates API, which compares it with what it reads and answers with one result per rule.

kates compliance check lints the file again before it sends anything, and stops on an error. The Kates API then reads what the rules need: the Strimzi Kafka and KafkaNodePool resources, the Kafka pods and the nodes they run on, their PersistentVolumeClaims and the Kubernetes version. It talks to the Kafka Admin API only when a rule needs a broker’s or a topic’s own answer, which the dotted edge shows. The API key needs only the read scope.

Two properties follow from that shape. Because the check only reads, you can run it against a production cluster at any hour, as often as you like, with nothing to roll back. The Kates API keeps every report, with who ran the check and when, so the history of a cluster’s checks is there to show an auditor; GET /api/conformity/checks lists them.

Statuses and the Overall Result

Kates decides each rule’s status in two steps. First it reads and compares: a rule it can’t read is UNKNOWN, a rule that holds is PASS, and a rule that doesn’t is FAIL or WARN by its severity. Then it applies the file’s waivers, which turn any result but PASS into WAIVED while they last:

flowchart LR
    read{"Could Kates read<br/>what the rule needs?"} -->|"yes"| holds{"Does the<br/>rule hold?"}
    read -->|"no"| unknown["UNKNOWN"]
    holds -->|"yes"| pass["PASS"]
    holds -->|"no"| sev{"Its severity?"}
    sev -->|"fail"| fail["FAIL"]
    sev -->|"warn"| warn["WARN"]
    unknown -.->|"active waiver"| waived["WAIVED"]
    fail -.->|"active waiver"| waived
    warn -.->|"active waiver"| waived
Figure 17.3: A rule’s status comes from whether Kates could read it, whether it holds and its severity; an active waiver then turns any result but PASS into WAIVED.

The status then decides whether the rule can fail the check:

Status When Can it fail the check?
PASS The rule holds No
FAIL The rule doesn’t hold, and its severity is fail, the default Yes
WARN The rule doesn’t hold, and its severity is warn No
UNKNOWN Kates couldn’t read what the rule needs, such as a broker that doesn’t answer Yes, when its severity is fail
WAIVED The rule isn’t PASS, but an active waiver in the file covers it No

A rule Kates can’t read is UNKNOWN, never FAIL, so a report never claims a gap it didn’t see.

The overall result, the report’s verdict field, is FAIL when any rule is FAIL. Otherwise it is UNKNOWN when any rule with severity fail is UNKNOWN, and PASS in every other case. kates compliance check turns it into its exit code:

Exit code Meaning
0 PASS: every rule with severity fail holds or is waived
1 FAIL: at least one rule with severity fail doesn’t hold
2 The check couldn’t tell or couldn’t run: an UNKNOWN rule, an invalid file, another cluster’s file, or an unreachable API

A FAIL beats an UNKNOWN, so a run with both exits 1: a definite gap is the more useful signal, and the UNKNOWN still shows in the report.

17.3 Writing Constraints

Every rule is a constraint on one value, written either bare or as a map. The bare form means exactly that value, and the map form says how to compare:

Written Means
count: 3 Exactly 3
{min: 3}, {max: 1}, {min: 3, max: 5} At least, at most, or between, both ends included
{oneOf: [jbod, persistent-claim]} Any one of the listed values
{equals: required, severity: warn} Exactly that value; the map form exists to carry a severity

equals and oneOf stand alone, while min and max combine. A severity of fail is the default, so you write severity only to make a rule a warning.

Pick the form that says what you require, because the form is the requirement. A broker count is a floor: three brokers are the fewest that can hold three replicas of a partition, and a fourth broker should never fail the check, so write {min: 3}. A controller count is a decision: a quorum of three tolerates one failed controller and a quorum of four tolerates no more, so write 3 exactly. A storage type is a set of acceptable answers, so write oneOf. A reference full of exact values describes one cluster on one day, and fails the first time anyone resizes it for good reason.

The language knows what kind of value each field holds, and compares it that way. Counts are whole numbers. CPU, memory and storage are Kubernetes quantities, so 8Gi is more than 8000Mi and 500m is less than 1. Versions compare part by part, so 4.10 is newer than 4.9. That last rule is why a version must be quoted: unquoted, YAML reads 4.10 as the number 4.1. Lint catches the mistake, together with a misspelled field, in a file, payments-typos.yaml, whose spec reads (the output’s line numbers are the full file’s):

spec:
  versions:
    kafka: {min: 4.10}

  brokers:
    cuont: 3

Lint it:

kates compliance lint payments-typos.yaml

Output, with each long finding wrapped onto two lines:

payments-typos.yaml:7:18: error: spec.versions.kafka.min: expected text, not the
  number 4.10: unquoted, YAML reads it as a number, so quote it ("4.10") [type]
  7 |     kafka: {min: 4.10}
    |                  ^
payments-typos.yaml:10:5: error: spec.brokers.cuont: unknown field
  (did you mean "count"?) [unknown-field]
  10 |     cuont: 3
     |     ^
2 errors, 0 warnings in 1 file

Each finding names the file, line and column, the path in the file, what is wrong and a code in brackets, with the source line and a caret under it. Lint exits 1 when it finds an error, and kates compliance check refuses the same file with exit 2 without calling the Kates API.

Sizing the Brokers

Sizes are where a reference meets a budget. Suppose you require 16Gi of memory per broker, along with the versions, the controllers and the storage the payments workload needs:

apiVersion: conformity.kates.io/v1alpha1
kind: KafkaReference
metadata:
  name: payments-sizing
spec:
  versions:
    kubernetes: {min: "1.32.0"}
    strimzi: {min: "1.2.0"}
    kafka: {min: "4.2.0"}

  controllers:
    count: 3
    dedicated: true

  brokers:
    count: {min: 3}
    requests:
      memory: {min: 16Gi}
    storage:
      type: {oneOf: [jbod, persistent-claim]}
      size: {min: 100Gi}

The controllers form the KRaft quorum that keeps the cluster’s metadata, so they get rules of their own. dedicated: true requires that no node pool combines the broker and controller roles, which keeps a broker’s load and restarts away from the quorum. Run the check:

kates compliance check -f payments-sizing.yaml

Output on panda, with the banner trimmed:

  Status  Rule                     Expected  Observed
  ──────  ───────────────────────  ────────  ────────
  ✖ FAIL  brokers.requests.memory  min 16Gi  11Gi
          krafter-brokers-alpha-0, krafter-brokers-gamma-1, krafter-brokers-sigma-2

✖ FAIL: 1 fail, 0 warn, 0 waived, 8 pass, 0 unknown
  8 passing rules not shown; -o json lists them

Read the failing row like this:

  1. Expected is the constraint as you wrote it, and Observed is what Kates found.
  2. The line under the row names the subjects that fall short: here every broker pod requests 11Gi for its kafka container, so all three are listed. A row’s waiver, detail and note follow on lines of their own, each cut to the terminal’s width, and -o json keeps them whole.
  3. The command exits 1.

A failure asks a question: either the cluster is short of what you need, or the file asks for more than you need. If the payments load runs of Part II met their targets on these brokers, the file asks too much. Change the rule to memory: {min: 8Gi}, and the same check on panda passes all nine rules.

Storage size has a detail of its own. brokers.storage.size adds up the capacity of each broker’s bound claims, which is what the broker has, not what its node pool asks for. On panda each broker pool’s spec asks for 122Gi while each broker’s claim holds 200Gi, so the rule observes 200Gi.

17.4 Placing Pods Across Zones and Nodes

Placement rules are the ones a working cluster breaks most quietly, because a misplaced pod serves traffic exactly as well as a well-placed one until its node or zone fails. Each rule reads the pods of a role, brokers or controllers, and the nodes they run on, and each one guards against a different failure:

Field What it reads What it protects against
zones How many distinct zones host the role’s pods, by the nodes’ zone label One zone’s outage taking every replica, or most of the quorum
skew Most pods in one zone minus fewest pods in another One zone carrying more of the cluster than the others
perNode The most pods of the role on any one node One node’s failure taking two brokers, or two controllers, at once
antiAffinity Whether each pod’s anti-affinity rule on the node hostname is required, preferred or none Kubernetes placing two pods together when it runs short of nodes
dedicated For controllers only: whether any node pool also has the broker role A broker’s load and restarts reaching the quorum

The zone label is topology.kubernetes.io/zone unless spec.zoneLabel names another one. A pod that isn’t scheduled, or runs on a node without the label, fails zones and skew by name, because its zone can’t be shown.

The rules count what the figure below shows for krafter on panda. Each of the three nodes carries the zone label with its own name, and each zone’s two node pools, brokers-<zone> and controllers-<zone>, put one broker and one controller on it:

flowchart LR
    subgraph za["zone alpha"]
        na["node alpha<br/>broker 0<br/>controller 3"]
    end
    subgraph zs["zone sigma"]
        ns["node sigma<br/>broker 2<br/>controller 5"]
    end
    subgraph zg["zone gamma"]
        ng["node gamma<br/>broker 1<br/>controller 4"]
    end
    na ~~~ ns ~~~ ng
    style za fill:#16a34a24,stroke:#16a34a
    style zs fill:#0284c724,stroke:#0284c7
    style zg fill:#c026d324,stroke:#c026d3
Figure 17.4: On panda each zone holds one node, and each node one broker and one controller, so for both roles zones is 3, skew is 0 and perNode is 1.

Read the rules off the figure. zones counts the zones a role’s pods appear in: three for brokers and three for controllers. skew compares the busiest zone with the quietest, one pod against one, so it is 0. perNode counts the pods of one role on one node, which is 1. If a broker moved onto node sigma, brokers.zones would drop to 2, and brokers.perNode would rise to 2 and name node sigma.

This file holds both roles to one pod per zone and per node, and asks Kubernetes to keep the brokers apart:

apiVersion: conformity.kates.io/v1alpha1
kind: KafkaReference
metadata:
  name: payments-placement
spec:
  controllers:
    count: 3
    zones: {min: 3}
    perNode: {max: 1}

  brokers:
    count: {min: 3}
    zones: {min: 3}
    skew: {max: 1}
    perNode: {max: 1}
    antiAffinity: required

Check krafter against it:

kates compliance check -f payments-placement.yaml

Output on panda, with the banner trimmed:

  Status  Rule                  Expected  Observed
  ──────  ────────────────────  ────────  ─────────
  ✖ FAIL  brokers.antiAffinity  required  preferred
          krafter-brokers-alpha-0, krafter-brokers-gamma-1, krafter-brokers-sigma-2

✖ FAIL: 1 fail, 0 warn, 0 waived, 7 pass, 0 unknown
  7 passing rules not shown; -o json lists them

The two rules answer different questions. brokers.perNode passes, because today each node runs one broker. brokers.antiAffinity fails, because krafter’s broker pods only prefer to stay apart, so Kubernetes is allowed to place two on one node when it has nowhere else to put them. Whether to require more is your decision. If you want the gap in front of you without failing the check, write the rule as antiAffinity: {equals: required, severity: warn}; the complete reference later in this chapter does exactly that.

What Lint Catches Before the Cluster Does

Some combinations of rules can never pass, whatever the cluster looks like, and lint reports them before you run a check. This file, payments-quorum.yaml, has two problems:

spec:
  controllers:
    count: 4

  brokers:
    count: 2
    zones: {min: 3}

Lint it:

kates compliance lint payments-quorum.yaml

Output, with the long findings wrapped:

payments-quorum.yaml:7:12: warning: spec.controllers.count: is 4: a KRaft quorum
  of an even size tolerates no more failed controllers than one controller fewer,
  and every commit waits on one more. Use an odd count. [controller-quorum-even]
payments-quorum.yaml:11:12: error: spec.brokers.zones: allows at least 3, but
  spec.brokers.count allows 2: each zone that counts hosts a pod, and with any
  pod every pod must run in a zone, so no cluster can meet both. [zones-unreachable]
1 error, 1 warning in 1 file

The source lines and carets are trimmed. The error stops a check, because two brokers can’t run in three zones. The warning doesn’t: an even quorum works; it buys nothing over one controller fewer. Lint runs these cross-rule checks only on a file with no other errors. They cover placement, quorum and durability, such as a replication factor above the broker count or a min.insync.replicas that acks=all writes can never meet. Lint Findings, in the Compliance Language Reference, lists every code.

17.5 Kafka Settings and Monitoring

The pods can be placed perfectly and the cluster can still lose data, so the next rules read Kafka’s own settings. The payments workload writes with acks=all, a replication factor of 3 and a min.insync.replicas of 2. Those three settings work as one promise: a write is acknowledged only once two replicas hold it, so losing any one broker loses no acknowledged write and refuses no new one. A fourth setting keeps the promise honest. With unclean leader election off, a replica that fell behind can never become leader and silently discard writes the old leader acknowledged.

The payments topics get their values when Kates creates them, but every other topic takes the brokers’ defaults, so the defaults should agree:

apiVersion: conformity.kates.io/v1alpha1
kind: KafkaReference
metadata:
  name: payments-kafka
spec:
  kafka:
    rackAwareness: true
    authorization: simple
    listeners:
      require:
        - name: tls
          port: 9093
          tls: true
          auth: tls
      every:
        auth: {oneOf: [tls, scram-sha-512]}
    config:
      default.replication.factor: {min: 3}
      min.insync.replicas: {min: 2}
      unclean.leader.election.enable: false

  monitoring:
    metrics: jmxPrometheusExporter
    kafkaExporter: true

Each rule in this file reads one thing, and the table names the rule id the report uses:

Field What it reads Rule id
rackAwareness The Kafka resource’s rack key, and every broker’s node label kafka.rackAwareness
authorization The resource’s authorization type; simple is Kafka’s own ACLs kafka.authorization
listeners.require A listener that must exist, with the type, port, TLS and authentication you list kafka.listeners.require[tls]
listeners.every Every listener’s type, TLS or authentication kafka.listeners.every.auth
config A broker setting by name kafka.config[min.insync.replicas]
monitoring The metrics type, whether Kafka Exporter runs, and a Prometheus Operator PodMonitor selecting every broker monitoring.kafkaExporter, monitoring.podMonitor

rackAwareness passes when the resource sets its rack from the zone label and every broker runs on a labeled node, so Kafka spreads each partition’s replicas across zones. Here every listener must authenticate clients with tls (mTLS) or scram-sha-512 (SCRAM-SHA-512); the other values are oauth, custom and none.

Check krafter against it:

kates compliance check -f payments-kafka.yaml

Output on panda, with the banner trimmed:

  Status  Rule                      Expected  Observed
  ──────  ────────────────────────  ────────  ────────
  ✖ FAIL  monitoring.kafkaExporter  true      false

✖ FAIL: 1 fail, 0 warn, 0 waived, 8 pass, 0 unknown
  8 passing rules not shown; -o json lists them

Every Kafka rule passes. Kafka Exporter is off on panda, because both the kafka-cluster chart’s Kind overlay and the values kates deploy generates turn it off, and this gap is the subject of When the Cluster Falls Short.

Where Broker Settings Come From

By default the config and rackAwareness rules read the Kafka resource, which is fast and needs no connection to Kafka. A setting that the resource leaves to Kafka’s own default then fails as “not set in the Kafka CR”, because the resource doesn’t hold it. Set kafka.source: brokers to ask every broker instead:

kafka.source config reads Needs
cr, the default What the Kafka resource’s spec.kafka.config sets The Kubernetes API only
brokers The value each broker uses, its default included, one subject per broker The Kates API’s connection to Kafka

With brokers, a broker that doesn’t answer makes the rule UNKNOWN, so no gap hides behind it. Lint refuses a sensitive setting, such as a password, under kafka.source: brokers, because Kafka never returns its value.

Every Topic, Not Only the Defaults

A broker default applies only to a topic created without a value of its own, so default.replication.factor: {min: 3} passes even when someone created a topic with two replicas. The topics section reads each topic instead:

spec:
  topics:
    replicationFactor: {min: 3}
    minInsyncReplicas: {min: 2}
    exclude: [kates-]

A topic’s replication factor is its smallest replica set across its partitions, and its min.insync.replicas is the value Kafka applies to it, its own or the broker default. Kafka’s internal topics are included. exclude takes name prefixes, not patterns: kates- skips every topic whose name starts with it. These rules always read through the Kates API’s connection to Kafka, whatever kafka.source says, and the report names each topic that falls short.

17.6 When the Cluster Falls Short

A failing rule leaves you three moves: change the cluster, change the reference, or record the gap. Changing the cluster is a pull request to its values; changing the reference is a pull request to the file. Recording the gap comes in two forms, and they mean different things:

Use When What every check shows
A waiver The gap is known, owned and temporary WAIVED with its reason, owner and end date; the check can pass until that date
severity: warn The rule is advice you keep, not a requirement WARN on every check; it never fails one

A waiver goes in spec.waivers, and all four of its fields are required: the rule it covers, a reason, who it is by, and the date it lasts until. That date is inclusive and read in UTC. A waiver must name a rule the file declares, and each rule takes at most one waiver. The report keeps the rule’s real status and observed value next to the waiver, so the gap stays visible while it is waived.

The end date is the point of a waiver. A gap accepted without one is a decision nobody revisits; with one, the next review happens on its own, because the rule starts counting again. A waiver moves a rule through these states:

stateDiagram-v2
    state "PASS, waiver can go" as noted
    [*] --> FAIL: the rule fails
    FAIL --> WAIVED: you add a waiver
    WAIVED --> FAIL: its date passes
    WAIVED --> noted: the cluster is fixed
    noted --> PASS: you remove the waiver
Figure 17.5: A waiver holds a failing rule as WAIVED until its date passes, when the rule counts again; fixing the cluster first turns the rule to PASS, with a note that the waiver can go.

Both ways out of WAIVED end with someone looking at the file. If the date passes first, the rule fails the check again, and you either fix the cluster or renew the waiver with a new reason. If the cluster is fixed first, the report says the waiver can go, so stale waivers don’t pile up. Lint warns about a waiver whose date has passed, so the expiry shows in review before it fails a pipeline. Output, wrapped, without the source line:

payments-expired.yaml:58:14: warning: spec.waivers[0].until: the waiver expired on
  2026-09-30, so monitoring.kafkaExporter counts again: renew the date or remove
  the waiver [waiver-expired]
TipTry it: what happens when a waiver expires?

In a copy of payments-krafter.yaml, set the waiver’s until to yesterday. Run kates compliance lint on it: which code does the warning carry? Then run the check: what is monitoring.kafkaExporter’s status now, and what does the command exit?

The Complete Reference for krafter

Put the pieces together and you have the architecture the payments workload needs from krafter, with the two gaps panda showed: the anti-affinity requirement becomes a warning, and the missing Kafka Exporter gets a waiver. The file ships as cli/examples/conformity/payments-krafter.yaml:

apiVersion: conformity.kates.io/v1alpha1
kind: KafkaReference
metadata:
  name: payments-krafter
  description: What the payments workload needs from krafter, the Kafka cluster under test
spec:
  target:
    namespace: kafka
    name: krafter

  versions:
    kubernetes: {min: "1.32.0"}
    strimzi: {min: "1.2.0"}
    kafka: {min: "4.2.0"}

  controllers:
    count: 3
    zones: {min: 3}
    perNode: {max: 1}
    dedicated: true

  brokers:
    count: {min: 3}
    requests:
      memory: {min: 8Gi}
    storage:
      type: {oneOf: [jbod, persistent-claim]}
      size: {min: 100Gi}
    zones: {min: 3}
    skew: {max: 1}
    perNode: {max: 1}
    antiAffinity: {equals: required, severity: warn}

  kafka:
    rackAwareness: true
    authorization: simple
    listeners:
      require:
        - name: tls
          port: 9093
          tls: true
          auth: tls
      every:
        auth: {oneOf: [tls, scram-sha-512]}
    config:
      default.replication.factor: {min: 3}
      min.insync.replicas: {min: 2}
      unclean.leader.election.enable: false

  monitoring:
    metrics: jmxPrometheusExporter
    kafkaExporter: true

  waivers:
    - rule: monitoring.kafkaExporter
      reason: The Kind overlay turns Kafka Exporter off; enable it before payments traffic
      by: platform-team
      until: 2027-03-31

target pins the file to krafter in the kafka namespace. One Kates API checks one Kafka cluster, and a file written for another one is refused with exit 2 before any rule runs. To also catch a cluster rebuilt under the same name, add target.clusterId, which must match the Kafka resource’s cluster id.

Check krafter against it:

kates compliance check -f payments-krafter.yaml

Output on panda, with the banner trimmed and the waiver’s line cut to fit the page:

  Status    Rule                      Expected  Observed
  ────────  ────────────────────────  ────────  ─────────
  ▲ WARN    brokers.antiAffinity      required  preferred
            krafter-brokers-alpha-0, krafter-brokers-gamma-1, krafter-brokers-sigma-2
  ○ WAIVED  monitoring.kafkaExporter  true      false
            FAIL, waived until 2027-03-31 by platform-team: The Kind overlay turns…

✓ PASS: 0 fail, 1 warn, 1 waived, 22 pass, 0 unknown
  22 passing rules not shown; -o json lists them

Read it from the top:

  1. The warning row keeps the anti-affinity gap on every report without failing the check.
  2. The waived row still shows Expected true and Observed false, and the line under it gives the waiver: the rule’s own status, FAIL, then the end date, the owner and the reason.
  3. The summary counts 24 rules, and the check exits 0.

17.7 Installing Kates for Compliance Checks

The Kates API runs a check with its own rights: its ServiceAccount’s grants in Kubernetes and its KafkaUser’s ACLs in Kafka. You decide those grants when you install it, and which install fits depends on the rights your account has:

With cluster admin Without cluster admin
Install kates deploy, or the chart’s default rbac.scope=cluster The chart with rbac.scope=namespace, by a team with edit
Kubernetes grants One ClusterRole, which also holds chaos’s writes One read-only Role in the Kafka namespace, and optionally node reads
Zones Read from the nodes, with any zoneLabel Read from EndpointSlices or the brokers’ racks, or from the nodes with the node grant
PodMonitors Looked for in every namespace Looked for in the Kafka namespace

Every rule can be checked either way, given the node grant where a zoneLabel needs it. The second column trades a few sources for an install that needs no cluster admin day to day. Both need a KafkaUser, unless kates deploy created the cluster and its user.

The KafkaUser

The Kates API connects to Kafka as a KafkaUser, named by the chart’s kafka.sasl.username, kates-backend by default. On a cluster that enforces ACLs, the topics rules need Describe and DescribeConfigs on every topic, and kafka.source: brokers needs DescribeConfigs on the cluster; a topic the user can’t describe isn’t judged. The Kates API also reads and writes a few topics of its own from the moment it starts, for run events and its dead-letter queue. This KafkaUser holds what a check reads, plus the Kates API’s own event topic and dead-letter queue, which it writes whether or not a test ever runs; it grants nothing a test needs:

apiVersion: kafka.strimzi.io/v1
kind: KafkaUser
metadata:
  name: kates-backend
  namespace: kafka
  labels:
    strimzi.io/cluster: krafter
spec:
  authentication:
    type: scram-sha-512
  authorization:
    type: simple
    acls:
      # What a compliance check reads
      - resource: {type: topic, name: "*", patternType: literal}
        operations: [Describe, DescribeConfigs]
      - resource: {type: cluster}
        operations: [DescribeConfigs]
      # The Kates API's own run events and dead-letter queue
      - resource: {type: topic, name: kates-test-events, patternType: literal}
        operations: [Create, Describe, Write, Read]
      - resource: {type: group, name: kates-webhooks, patternType: literal}
        operations: [Read]
      - resource: {type: topic, name: kates-dlq, patternType: literal}
        operations: [Describe, Read]
      - resource: {type: group, name: kates-dlq-consumer, patternType: literal}
        operations: [Read]

Strimzi writes the user’s password into a Secret of the same name in the Kafka namespace. The chart reads it from the Secret kates-backend in the namespace Kates runs in, so the installs below copy it there. To run tests from the same install, the user needs the test topics’ ACLs too, which Step 1 — Grant the Team’s Kates Access to Kafka in the Deployment Guide lists.

With Cluster Admin

On a cluster you administer, kates deploy installs the whole stack, Strimzi and krafter included, with the Kates API, its KafkaUser and its API key, and a compliance check works as soon as it finishes. panda, where this chapter’s other outputs come from, is such a cluster, and Quick Deployment in the Deployment Guide covers it.

To add Kates to a Kafka cluster that is already running, install the chart with its defaults, which set rbac.scope=cluster:

PASSWORD=$(kubectl get secret kates-backend -n kafka \
  -o jsonpath='{.data.password}' | base64 -d)
kubectl create namespace kates
kubectl create secret generic kates-backend -n kates \
  --from-literal=password="$PASSWORD"
helm upgrade --install kates oci://ghcr.io/bmscomp/charts/kates -n kates \
  --set networkPolicy.kafka.namespace=kafka \
  --set kafka.clusterName=krafter \
  --set kafka.bootstrapServers=krafter-kafka-bootstrap.kafka.svc:9092

The three kafka values are the chart’s defaults here, and they are the ones to change on another cluster. networkPolicy.kafka.namespace and kafka.clusterName name the one Kafka cluster this Kates API checks, and a reference whose spec.target names another is refused with a 409. The chart’s NetworkPolicy lets the pod reach Kafka only in that namespace, on networkPolicy.kafka.port, 9092 by default. The defaults expect a plaintext SCRAM-SHA-512 listener; for a TLS listener, set kafka.security.protocol, kafka.ssl and the port as the chart’s README describes. If the cluster can’t pull from GHCR, Deploying Without GHCR shows how to mirror the images.

The install creates the ClusterRole kates and binds it to the Kates API’s ServiceAccount. For a check, it reads the Kafka resources and node pools, pods, PersistentVolumeClaims and nodes, and PodMonitors in every namespace. It holds no Secrets. Reach the API with kates ports, which finds the Service in any namespace when your account may list them all. A check then reads each zone from the node’s own label:

kates compliance check -f minimal.yaml -o json \
  | jq -r '.results[] | select(.rule == "brokers.zones") | .source, .detail'

Output on a Kind cluster that kates deploy --adminless built, with Kates installed this way by its admin:

Kubernetes: pods kafka/strimzi.io/cluster=krafter, nodes' topology.kubernetes.io/zone
alpha: 1, gamma: 1, sigma: 1

The ClusterRole is the one chaos needs too, so it also deletes and patches pods, scales node pools, and writes NetworkPolicies, KafkaTopics and KafkaConnectors. A check never uses those rights. If an install should only run checks, install it the admin-less way even on a cluster you administer: rbac.scope=namespace, with the Role and the node grant applied by you. It reads the same zones from the nodes and writes nothing.

Without Cluster Admin

On a shared cluster, your account usually has the built-in edit role in a team namespace, and someone else runs Strimzi and the Kafka cluster. That is enough for a compliance check. Install the kates chart with rbac.scope=namespace, and it creates nothing cluster-scoped. The check then reads the Kafka namespace through one read-only Role, which the cluster’s owner applies once, and nodes only through an optional ClusterRole. Running Without Cluster Admin in the Deployment Guide gives the install, step by step, and the grants of the Role.

The outputs in this section come from a Kind cluster that kates deploy --adminless built, with a second Kates installed into the namespace payments from an account with edit there and nothing else. It checks krafter in the namespace kafka. The figure shows what each grant lets the Kates API read:

flowchart LR
    subgraph team["namespace payments (edit)"]
        api["Kates API"]
    end
    subgraph kafka["namespace kafka"]
        role["Role<br/>kates-kafka-reader-payments"]
        brokers["krafter brokers"]
    end
    nodes["nodes"]
    api -- "reads through" --> role
    api -- "KafkaUser payments-kates:<br/>describe topics, configs" --> brokers
    api -. "optional ClusterRole" .-> nodes
Figure 17.6: The Kates API in payments reads the Kafka namespace through the owner’s Role, Kafka itself through its KafkaUser, and nodes only through the optional ClusterRole.

If the owner hasn’t applied the Role yet, kates compliance check -f minimal.yaml stops before its first rule and exits 2. The Kates API answers 503 and names the first read it was refused, here the Kafka resource. Output, with the message cut at the page’s width:

  ✖ minimal.yaml: [503] Service Unavailable: The Kates API's service account may
  not get kafkas.kafka.strimzi.io in kafka: bind it a Role there that grants it, …

The message ends by pointing at the kates chart’s Role with rbac.scope=namespace. If you want a Kafka cluster of your own, Deploying Without Cluster Admin installs the whole stack into namespaces you already have, once Strimzi is installed.

To remove the install, uninstall the release and its Secret:

helm uninstall kates -n payments
kubectl delete secret kates-backend -n payments

The owner then deletes the KafkaUser, and the Role and node grant, by piping the same helm template commands that created them into kubectl delete -f -.

What the Namespace Scope Changes

Most rules read the same objects as in a cluster-scoped install. Three groups differ, and each rule’s source in -o json says what it read:

  • zones, skew and kafka.rackAwareness with kafka.source: cr take each pod’s zone from the EndpointSlices of Strimzi’s headless Service, which carry only topology.kubernetes.io/zone. With a custom zoneLabel that is the Kafka CR’s spec.kafka.rack.topologyKey, they take it from the racks the brokers report. With any other zoneLabel, they are UNKNOWN until the owner applies the node grant, and the reason names the grant and the zoneLabel that would let the check read the zones.
  • monitoring.podMonitor looks for PodMonitors in the Kafka namespace only.
  • The topics rules judge only the topics the KafkaUser may describe.

To see where the zones came from, print the rule’s detail:

kates compliance check -f minimal.yaml -o json \
  | jq -r '.results[] | select(.rule == "brokers.zones") | .detail'

Output:

alpha: 1, gamma: 1, sigma: 1; zones from the EndpointSlices of kafka/krafter-kafka-brokers

The EndpointSlice controller copies each pod’s zone from its node’s topology.kubernetes.io/zone label. Managed clusters set that label on every node. A cluster you built yourself may not, and then every pod counts as in no zone, so zones fails. Ask the owner to label the nodes, or to apply the node grant and name the label your nodes do carry in zoneLabel.

With the node grant, the zones come from the nodes, and the detail drops its EndpointSlices note. The grant makes a rule readable, not true. A reference with zoneLabel: example.com/zone, a label no node on the lab carries, has brokers.zones UNKNOWN without the grant. With it, the rule is FAIL, with the detail 3 not scheduled on a node with example.com/zone, which is the cluster’s real state. A cluster-scoped install gives the same FAIL, and its monitoring.podMonitor finds kafka/krafter-kafka wherever the PodMonitor lives.

TipTry it: which read is missing?

Before the owner applies the Role, run kates compliance check -f minimal.yaml. Which resource does the 503 name? Apply the Role and run the check again: which rule’s source names the EndpointSlices?

17.8 Running It in a Pipeline

A reference earns its keep when every change to the cluster, or to the file, is checked against it. Three moments call for a check. A pull request that changes a reference gets the offline commands, so a broken file never merges. A deploy or an upgrade gets a full check right after it, because that is when the cluster changes on purpose. A schedule, nightly for example, catches the changes that happen between deploys, which is where drift lives.

Three commands cover a pipeline, cheapest first:

kates compliance fmt --check platform/*.yaml
kates compliance lint platform/*.yaml
kates compliance check -f platform/payments-krafter.yaml \
  --output-junit compliance.xml

kates compliance fmt writes a reference in one canonical form: keys in the schema’s order, each constraint in its shortest form, and no exact duplicates, with comments kept. --check only lists the files that aren’t formatted and exits 1, so a reviewer reads a diff of meaning rather than of layout. lint needs no cluster, so it can run on every pull request to the files. check needs the Kates API, a key with the read scope and a CLI context that reaches it, so it runs where the pipeline can reach the cluster.

--output-junit writes the report as JUnit XML, which most CI systems show as a test report, with one test suite per section of the file. A FAIL becomes a failure, an UNKNOWN rule with severity fail becomes an error, and a WAIVED rule is skipped. A WARN passes, with its finding in the test’s output. This is the waived rule from the complete reference:

<testcase name="monitoring.kafkaExporter" classname="compliance.monitoring" time="0.000">
  <skipped message="FAIL, waived until 2027-03-31 by platform-team: …"></skipped>
</testcase>

The table is still printed when you ask for JUnit, and -o json prints the whole report for a script. This picks out every rule that didn’t pass:

kates compliance check -f payments-krafter.yaml -o json \
  | jq -r '.results[] | select(.status != "PASS") | "\(.status) \(.rule)"'

Output on panda:

WARN brokers.antiAffinity
WAIVED monitoring.kafkaExporter

kates compliance belongs to the topology and deploy command profiles. A context whose profiles leave both out refuses all three subcommands, lint and fmt included, so a pipeline’s context needs one of them or none. The Compliance entries in the CLI Reference list every flag, and POST /api/conformity/check documents the report’s JSON for callers that skip the CLI.

17.9 Proving the Results Were Not Changed

An auditor who reads a stored check months later needs to know it still says what the check said. Whoever administers the Kates API’s database can edit any row by hand. They can turn a failed rule into a passed one, change who ran the check, or delete it. Kates can’t stop that, but it makes the change show, as long as you keep one value outside the database on the day the check runs.

Three records stand behind each check, and each one guards the record above it:

Record Where it lives What it holds
The stored check The database, read with GET /api/conformity/checks/{id} The full report, the reference’s SHA-256, and reportSha256, computed from the stored report when you ask
The check’s audit row The database, in the audit log’s hash chain Who ran the check and when, the verdict, the report’s SHA-256 and the reference’s SHA-256
The anchor Outside the database, where its administrators can’t write The audit row’s id and rowHash, kept on the day of the check

An edited stored report doesn’t match the hash in its audit row. An edit to the audit row breaks the chain at that row. A rewrite of the whole chain, every hash recomputed so that it verifies, changes the anchored row’s rowHash. Audit Logging explains how the chain is built.

Keep the Anchor When the Check Runs

The anchor is the check’s own audit row, read right after the check. The command-line check doesn’t print the stored check’s id, so the step below finds the newest compliance row of the pipeline’s own principal. Give each gate its own API key, so that its newest row is its own check. Run the step whether the check passed or not, because a failed check is evidence too. With kates ports running, the API answers on localhost:8080; on panda, make all also exposes it on NodePort 30083:

API=http://localhost:8080
curl -s -H "X-API-Key: $KATES_API_KEY" \
  "$API/api/audit?type=compliance&actor=ci-gate&size=1" \
  | jq '.items[0] | {check: .target, auditId: .id, rowHash, details}' \
  > compliance-anchor.json

The file names the stored check, its audit row and that row’s hash, and repeats the hashes the row holds:

{
  "check": "1f0c6a52-…",
  "auditId": 4529,
  "rowHash": "9c1e…",
  "details": "verdict FAIL, report sha256 5d41…, reference sha256 44136f…"
}

Keep it where the database’s administrators can’t change it. Your pipeline’s artifacts, a ticket, or a file you sign with your own key all qualify. An anchor inside the same database proves nothing.

To cover a whole period, kates evidence export --from <time> --out <dir> writes the stored checks, the audit rows and the chain’s verification to a new directory, with a SHA256SUMS file. Keep that file’s hashes as you keep the anchor.

Verify a Stored Check

Verifying a check later takes three answers from the Kates API, and the check holds only if all three agree. The first is the chain: GET /api/audit/verify walks the whole audit log and must answer "intact": true. The second is the anchor: the audit row named by auditId must still have the rowHash you kept. The third is the report: the check’s reportSha256 must equal the report sha256 in that row’s details.

This script asks all three for the anchor kept above, and prints the three results:

H="X-API-Key: $KATES_API_KEY"; API=http://localhost:8080
a=compliance-anchor.json
curl -s -H "$H" "$API/api/audit/verify" | jq '{intact, brokenAt, problem}'
curl -s -H "$H" "$API/api/audit?type=compliance&size=200" \
  | jq --argjson a "$(cat $a)" \
      '.items[] | select(.id == $a.auditId) | {sameRow: (.rowHash == $a.rowHash)}'
curl -s -H "$H" "$API/api/conformity/checks/$(jq -r .check $a)" \
  | jq --argjson a "$(cat $a)" \
      '.reportSha256 as $r | {sameReport: ($a.details | contains("report sha256 " + $r))}'

A clean check prints "intact": true, "sameRow": true and "sameReport": true. Each other answer names a different change:

What you see What changed
"intact": false A row of the audit log was changed, removed or added; brokenAt names the first one
No sameRow line The anchored audit row is not on the page the script read, or was deleted
"sameRow": false The audit log was rewritten up to that row, every hash recomputed
"sameReport": false The stored report was changed after the check
A 404 for the check The stored check was deleted; its audit row still names it

A deleted audit row breaks the chain as surely as an edited one, so "intact": false covers it.

What the Proof Covers

The proof covers what the check stored. It shows that a report is the one the Kates API wrote, and says nothing about whether the cluster was read truthfully.

An anchor protects the rows up to its own. Rows written after it are covered by the next anchor you keep.

Audit rows written before the Kates API chained its log aren’t covered; GET /api/audit/verify counts them as unchained.

The script reads the newest 200 compliance rows, the most one page of the audit listing returns. For an older check, add page=1, then page=2, until the row appears; GET /api/audit/verify covers every row whatever its page.

Someone who can change both the database and the place you keep anchors can hide a change. Keep the anchors where the database’s administrators have no access.

17.10 The Language at a Glance

A reference holds two kinds of field. Settings say which cluster to check and how to read it; they aren’t rules, and a waiver can’t name one. Every other field is a rule, named by its path under spec. The tables below are a summary; the Compliance Language Reference gives every field’s values, what the check reads for it, and when it’s UNKNOWN.

Settings

The settings all have defaults, so a reference needs none of them:

Field Default What it sets
target.namespace, target.name The cluster the Kates API checks Which Kafka resource the file is for
target.clusterId None The Kafka cluster id the Kafka resource must report
target.platform strimzi The platform; v1alpha1 knows only Strimzi
zoneLabel topology.kubernetes.io/zone The node label that names a zone
kafka.source cr Whether config and rackAwareness read the Kafka resource or every broker
topics.exclude None Topic name prefixes the topic rules skip, at most 50

Rules

The rules fall into six sections. controllers and brokers take the same fields, except that only controllers takes dedicated:

Section Fields Reads
versions kubernetes, strimzi, kafka, each a quoted version The Kubernetes API and the Kafka resource’s status
controllers, brokers count, requests.cpu, requests.memory, limits.cpu, limits.memory The role’s pods and their kafka container
controllers, brokers storage.type, storage.size, storage.class The node pools and the pods’ bound volume claims
controllers, brokers zones, skew, perNode, antiAffinity; dedicated for controllers The role’s pods, their nodes and the node pools
kafka rackAwareness, authorization, listeners.require, listeners.every, config The Kafka resource, or the brokers for config
topics replicationFactor, minInsyncReplicas Every topic, through the Kafka Admin API
monitoring metrics, kafkaExporter, podMonitor The Kafka resource and the cluster’s PodMonitors

A rule id is the field’s path under spec, without the spec. prefix, such as brokers.storage.size. A broker setting with a dot in its name goes in brackets, as in kafka.config[min.insync.replicas], and a required listener goes by its name, as in kafka.listeners.require[tls]. A waiver names a rule by exactly that id, and so does the report.

Lint refuses anything it doesn’t understand: an unknown field, a value of the wrong kind, an empty section, a min above its max, or a waiver for a rule the file doesn’t declare. The Kates API reads the file as strictly, and answers a request that skips the CLI with a 400 that names the field. Size Limits in the Compliance Language Reference lists what lint and the Kates API refuse.

What the Check Doesn’t Judge

The check reports what it can read, and some things are deliberately outside it. Each row names what to use instead:

What the check doesn’t judge Where to look
Whether Kafka sees every broker: count counts the role’s pods, Ready or not, so a rolling restart doesn’t fail it kates cluster check
A pool’s requested size: storage.size reads the capacity of the bound claims The node pool’s spec
Kafka’s default for a setting the Kafka resource doesn’t set, under kafka.source: cr kafka.source: brokers
Topics and broker settings without the Kates API’s connection to Kafka, which are UNKNOWN The Kates API’s Kafka connection
Zones, racks and PodMonitors under rbac.scope=namespace What the Namespace Scope Changes
A second Kafka cluster per Kates API, or a platform other than Strimzi One Kates API per cluster
PodDisruptionBudgets, Kafka users and ACLs, Kafka Connect, MirrorMaker 2 and Cruise Control kates security audit, for users and ACLs

The check never changes the cluster. The Kates API stores every report, and the pipeline’s JUnit files are a second copy of each; kates evidence export writes a period’s checks, with the audit chain, for an auditor.

17.11 Summary

  • A reference file states the architecture you require, one rule per path, and lint checks it on your machine before any cluster is involved.
  • A check reads the cluster, changes nothing, and reports every rule as passing, failing, warning, waived or unknown.
  • A failed rule means fixing the cluster, fixing the file, or recording the gap with an owner and an end date.
  • A check needs only reads, so a team without cluster admin runs it through one read-only Role the cluster’s owner applies.
  • The exit code makes the check a pipeline step, and a hash kept outside the database shows whether a stored report was changed since.

The reference checks that every listener authenticates its clients, but not who those clients are or what they may do once connected. Security & Compliance covers authentication, authorization, network policies and certificates.

Back to top