Request Rule Validator

Enforce topic naming, sizing, and retention conventionsv1.3+

This Request Rule Validator policy enforces topic conventions for a shared Kafka cluster.

In this example:

  • Topic names must start with team-a..
  • Topics can’t have more than 50 partitions.
  • Topics must have a replication factor of at least 3.
  • retention.ms must be set to 24 hours (86400000).

Clients can change a topic after they create it, so the policy enforces the conventions on more than one request type:

  • create_topics: Enforces all the conventions when a client creates a topic. If the request uses a manual replica assignment, the partition count and replication factor are -1, so the rules check context.topic.assignments instead.
  • create_partitions: Prevents clients from growing a topic past 50 partitions.
  • alter_configs: This request replaces the full configuration of a topic, so it must include retention.ms with the required value. Otherwise, retention.ms goes back to the broker default.
  • incremental_alter_configs: Clients can change retention.ms only with the SET operation and the required value. This rule also prevents clients from deleting retention.ms.

Each rule’s expression describes the request state that’s allowed. When an item in the request, for example a topic, doesn’t match a rule, Event Gateway rejects only that item with the Kafka POLICY_VIOLATION error code. Other items in the same batched request are still processed.

Set up the policy

Help us make these docs great!

Kong Developer docs are open source. If you find these useful and want to make them better, contribute today!