skip to content

How do you integrate Kafka GSSAPI with enterprise Active Directory, and how do you map Kerberos principals to Kafka users for ACLs?

level: principalimportance: should knowfreq 30%

answer

  1. AD = KDC; krb5.conf realm + dc as kdc
  2. setspn / ktpass to make SPN + keytab
  3. principal.to.local.rules = auth_to_local RULE:/DEFAULT
  4. principal.builder.class for custom logic
  5. etype overlap (AES) + kvno + clock skew

basics

~20 s

Point krb5.conf at the AD domain controllers (AD is a KDC), create service accounts and SPNs in AD, export keytabs, and use sasl.kerberos.principal.to.local.rules (or a custom KafkaPrincipalBuilder) to turn full principals like [email protected] into Kafka users like alice for ACL matching.

solid answer

~40 s

Active Directory is a Kerberos KDC, so Kafka talks to it as the realm's KDC in krb5.conf ([realms] kdc = dc1.corp.example.com). In AD you create a service account for each broker, register an SPN (e.g. setspn kafka/broker1.corp.example.com), and export a keytab (ktpass) carrying that principal and its kvno. Encryption types must overlap between AD and the JVM (prefer AES; legacy RC4 often disabled). For authorization, the authenticated principal is the full name like CN-derived [email protected]; you normalize it to a KafkaPrincipal with sasl.kerberos.principal.to.local.rules — auth_to_local-style RULE: expressions that strip the realm and rewrite names — so ACLs reference User:alice rather than the full realm-qualified string. For richer logic you implement a custom principal.builder.class (KafkaPrincipalBuilder). Group-based authorization typically needs an external authorizer or LDAP lookups, since Kerberos itself conveys only the principal.

go deeper

for a junior

Know that AD can act as the Kerberos KDC and that principals get mapped to Kafka user names.

for a middle

Set up krb5.conf for AD, export a keytab with ktpass, and apply basic principal.to.local rules.

for a senior

Troubleshoot etype/kvno/clock issues and write auth_to_local rules; know when a custom principal builder is needed.

for a principal

Architect realm topology, cross-realm trusts, group-based authorization via external authorizers, and keytab/SPN lifecycle across a fleet.

## AD is a KDC Microsoft **Active Directory** implements Kerberos v5. So integrating Kafka with AD means treating the AD domain as the **Kerberos realm** and the **domain controllers** as the **KDCs**. There is usually no separate MIT KDC to run. ## Setup steps 1. **krb5.conf**: set `default_realm = CORP.EXAMPLE.COM` (realms are conventionally uppercase), and under `[realms]` list `kdc = dc1.corp.example.com` and `admin_server`. Add `[domain_realm]` to map DNS domains (e.g. `.corp.example.com = CORP.EXAMPLE.COM`). 2. **Service accounts + SPNs**: in AD create a user/service account per broker (or a shared one) and register a **Service Principal Name** with `setspn -S kafka/[email protected] <account>`. The SPN's service part must equal `sasl.kerberos.service.name` (kafka). 3. **Keytab export**: use `ktpass` to export a keytab binding the SPN to the account, choosing an encryption type (AES256/AES128). Distribute it securely to the broker. Watch the **kvno** — re-exporting rotates the key version and old keytabs stop working. 4. **Encryption types (etypes)**: AD and the JVM must share an etype. Modern setups use **AES**; legacy **RC4-HMAC** is often disabled for security. Mismatched etypes cause 'KDC has no support for encryption type' errors. The JVM may also need `allow_weak_crypto` settings or, conversely, unlimited-strength crypto enabled (older JDKs). ## Principal-to-Kafka-user mapping After authentication the identity is a full Kerberos principal such as `[email protected]` or `kafka/host@REALM`. ACLs are easier to manage against short names. Kafka maps via: - **`sasl.kerberos.principal.to.local.rules`**: a list of `RULE:[n:string](regex)s/pattern/replacement/` expressions (the same `auth_to_local` grammar from Hadoop/Kerberos) plus `DEFAULT`. Example: `RULE:[1:$1@$0](.*@CORP.EXAMPLE.COM)s/@CORP.EXAMPLE.COM//` turns `[email protected]` into `alice`. The result becomes `User:alice` for ACLs. - **`principal.builder.class`** (a `KafkaPrincipalBuilder`): a custom Java class for logic that rules cannot express — e.g. deriving identity from a certificate for SSL, or attaching group info. ## Authorization with groups Kerberos itself carries only the principal, not AD group membership. To authorize by AD group you either: (a) sync groups into an external authorizer (e.g. a Ranger/OPA-style authorizer or Confluent's LDAP-backed RBAC), or (b) do LDAP lookups in a custom authorizer. Plain Kafka ACLs match the KafkaPrincipal you produced from the mapping rules. ## Cross-realm and trusts If clients live in a different AD domain than the brokers, you need a **cross-realm trust** and `[capaths]` entries so tickets can traverse realms. Mismatched DNS-to-realm mapping (`[domain_realm]`) is a frequent failure point. ## Operational pitfalls - **kvno drift** between AD and the deployed keytab after a password/key reset. - **Clock skew** beyond ~5 min (AD default) -> ticket rejection; keep NTP tight. - **Hostname/FQDN** mismatch between the SPN and how clients address the broker. - **Etype mismatch** between AD policy and JVM/krb5.conf. - **Case sensitivity**: realms uppercase, and auth_to_local rules are order-sensitive — first match wins.

  • An AD-integrated client gets 'KDC has no support for encryption type'. What is the cause?
    No shared encryption type between AD policy and the JVM/krb5.conf — e.g. AD disabled RC4 but the keytab/JVM is not configured for AES. Re-export the keytab with a supported etype and align krb5.conf permitted etypes.
  • Kafka ACLs do not match after AD auth even though login succeeds. Why?
    The KafkaPrincipal is still the full realm-qualified name (e.g. User:[email protected]) but ACLs were written for User:alice. Add sasl.kerberos.principal.to.local.rules to strip the realm so names match.
  • How would you authorize by AD group membership rather than individual users?
    Kerberos conveys only the principal, so use an external/LDAP-backed authorizer (or custom KafkaPrincipalBuilder + authorizer) that resolves the principal to AD groups; native ACLs only match the mapped principal.

saying these in an interview costs you the question

  • Assuming you must run a separate MIT KDC alongside AD (AD is the KDC)
  • Believing Kerberos passes AD group membership to Kafka for free
  • Ignoring encryption-type alignment between AD and the JVM
  • Writing ACLs against the full realm-qualified principal without principal.to.local mapping

context