Kerberos for Hadoop: KDC, Principals, Keytabs and Cluster Setup

Big Data and Hadoop Administrator 20 min min read Updated: Nov 16, 2026 Advanced
Kerberos for Hadoop: KDC, Principals, Keytabs and Cluster Setup
Advanced Topic 2 of 5

Kerberos in Simple Words

Kerberos is a ticket system. You prove your identity once to a trusted server (the KDC) and get a ticket. You show tickets to services instead of sending passwords.

text 1. alice -> KDC (AS): "I am alice" (password / keytab) -> Ticket Granting Ticket (TGT) 2. alice -> KDC (TGS): "I want to talk to nn/master1@EXAMPLE.COM" (shows TGT) -> service ticket 3. alice -> NameNode: shows service ticket -> NameNode trusts alice
TermMeaning
RealmSecurity domain, written in capitals: EXAMPLE.COM
PrincipalIdentity: user@REALM or service/host@REALM (e.g. nn/master1.example.com@EXAMPLE.COM)
KDCKey Distribution Center: authentication server plus ticket granting server
KeytabFile with a service's long-term key so daemons can log in without a password
TGT / Service ticketTicket proving you logged in / ticket for one service
Time and DNS matter: Kerberos tolerates only about 5 minutes of clock difference, and it needs correct forward and reverse DNS. Most first-time failures are NTP or DNS issues.

Step 1: Set Up an MIT KDC (Lab)

bash # on kdc.example.com dnf install -y krb5-server krb5-libs krb5-workstation # /etc/krb5.conf and /var/kerberos/krb5kdc/kdc.conf: set realm EXAMPLE.COM kdb5_util create -s -r EXAMPLE.COM systemctl enable --now krb5kdc kadmin kadmin.local -q "addprinc admin/admin"
ini # /etc/krb5.conf (on EVERY cluster node and client) [libdefaults] default_realm = EXAMPLE.COM dns_lookup_kdc = false ticket_lifetime = 24h renew_lifetime = 7d forwardable = true rdns = false [realms] EXAMPLE.COM = { kdc = kdc.example.com admin_server = kdc.example.com } [domain_realm] .example.com = EXAMPLE.COM
Production tip: In production use your enterprise Active Directory or FreeIPA as the KDC and a separate MIT KDC only if policy requires it. Make the KDC highly available.

Step 2: Create Principals and Keytabs

bash # for every service on every host (script this loop!) kadmin -q "addprinc -randkey nn/master1.example.com@EXAMPLE.COM" kadmin -q "addprinc -randkey HTTP/master1.example.com@EXAMPLE.COM" kadmin -q "addprinc -randkey dn/worker1.example.com@EXAMPLE.COM" kadmin -q "addprinc -randkey HTTP/worker1.example.com@EXAMPLE.COM" kadmin -q "addprinc -randkey rm/master1.example.com@EXAMPLE.COM" kadmin -q "addprinc -randkey nm/worker1.example.com@EXAMPLE.COM" # export to keytabs on each host kadmin -q "xst -k /etc/security/keytabs/nn.service.keytab nn/master1.example.com HTTP/master1.example.com" chown hdfs:hadoop /etc/security/keytabs/nn.service.keytab && chmod 400 /etc/security/keytabs/nn.service.keytab klist -kt /etc/security/keytabs/nn.service.keytab # list keys kinit -kt /etc/security/keytabs/nn.service.keytab nn/master1.example.com@EXAMPLE.COM # test logi
Protect keytabs like passwords: Anyone who copies a keytab can act as that service. Mode 400, owned by the service user, never in Git, never on shared folders. xst with -randkey changes the key so older keytabs stop working.

Step 3: Secure HDFS

xml <!-- core-site.xml --> <property><name>hadoop.security.authentication</name><value>kerberos</value></property> <property><name>hadoop.security.authorization</name><value>true</value></property> <property><name>hadoop.rpc.protection</name><value>privacy</value></property> <property><name>hadoop.security.auth_to_local</name> <value>RULE:[2:$1/$2@$0](nn/.*@EXAMPLE.COM)s/.*/hdfs/ RULE:[2:$1/$2@$0](dn/.*@EXAMPLE.COM)s/.*/hdfs/ RULE:[2:$1/$2@$0](rm/.*@EXAMPLE.COM)s/.*/yarn/ RULE:[2:$1/$2@$0](nm/.*@EXAMPLE.COM)s/.*/yarn/ RULE:[1:$1@$0](.*@EXAMPLE.COM)s/@.*// DEFAULT</value></property>
xml <!-- hdfs-site.xml --> <property><name>dfs.block.access.token.enable</name><value>true</value></property> <property><name>dfs.namenode.kerberos.principal</name><value>nn/_HOST@EXAMPLE.COM</value></property> <property><name>dfs.namenode.keytab.file</name><value>/etc/security/keytabs/nn.service.keytab</value></property> <property><name>dfs.namenode.kerberos.internal.spnego.principal</name><value>HTTP/_HOST@EXAMPLE.COM</value></property> <property><name>dfs.web.authentication.kerberos.principal</name><value>HTTP/_HOST@EXAMPLE.COM</value></property> <property><name>dfs.web.authentication.kerberos.keytab</name><value>/etc/security/keytabs/spnego.service.keytab</value></property> <property><name>dfs.datanode.kerberos.principal</name><value>dn/_HOST@EXAMPLE.COM</value></property> <property><name>dfs.datanode.keytab.file</name><value>/etc/security/keytabs/dn.service.keytab</value></property> <property><name>dfs.data.transfer.protection</name><value>privacy</value></property> <property><name>dfs.http.policy</name><value>HTTPS_ONLY</value></property> <property><name>dfs.datanode.address</name><value>0.0.0.0:9866</value></property>
_HOST placeholder: Hadoop replaces _HOST with each machine's own fully qualified name, so one config file works on all hosts.

Hadoop 3 DataNodes can run on high ports with SASL data transfer protection (dfs.data.transfer.protection) together with dfs.http.policy=HTTPS_ONLY, so the old privileged-port jsvc setup is not needed.

Step 4: Secure YARN

xml <!-- yarn-site.xml --> <property><name>yarn.resourcemanager.principal</name><value>rm/_HOST@EXAMPLE.COM</value></property> <property><name>yarn.resourcemanager.keytab</name><value>/etc/security/keytabs/rm.service.keytab</value></property> <property><name>yarn.nodemanager.principal</name><value>nm/_HOST@EXAMPLE.COM</value></property> <property><name>yarn.nodemanager.keytab</name><value>/etc/security/keytabs/nm.service.keytab</value></property> <property><name>yarn.nodemanager.container-executor.class</name> <value>org.apache.hadoop.yarn.server.nodemanager.LinuxContainerExecutor</value></property> <property><name>yarn.nodemanager.linux-container-executor.group</name><value>hadoop</value></property>
ini # $HADOOP_HOME/etc/hadoop/container-executor.cfg (root-owned, mode 0400) yarn.nodemanager.linux-container-executor.group=hadoop banned.users=hdfs,yarn,mapred,bin min.user.id=1000 allowed.system.users=
bash # container-executor binary must be setuid root group hadoop chown root:hadoop $HADOOP_HOME/bin/container-executor chmod 6050 $HADOOP_HOME/bin/container-executor $HADOOP_HOME/bin/container-executor --checksetup

The LinuxContainerExecutor runs each job's containers as the submitting user, so file access inside tasks follows normal OS and HDFS rules.

Using a Secure Cluster

bash hdfs dfs -ls / # fails: no ticket (GSSException: No valid credentials) kinit alice@EXAMPLE.COM klist hdfs dfs -ls /user/alice kdestroy # long running or batch jobs use keytabs kinit -kt /etc/security/keytabs/etl.keytab etl@EXAMPLE.COM spark-submit --principal etl@EXAMPLE.COM --keytab /etc/security/keytabs/etl.keytab ...

Common Kerberos Errors

ErrorMeaning and fix
Clock skew too greatFix NTP (chrony) on the node
Server not found in Kerberos databasePrincipal missing or wrong host name. Check DNS and _HOST
Cannot find KDC for realmkrb5.conf realm/domain mapping wrong
Pre-authentication failed / Preauthentication failedWrong password or keytab key version (kvno) out of date
GSSException: No valid credentials providedUser has no ticket, or ticket expired. Run kinit
Failed on local exception: ... SASLMismatch of rpc protection or principals between client and server
Unsupported encryption typeUse AES types; old DES/RC4 may be disabled
bash export HADOOP_ROOT_LOGGER=DEBUG,console export HADOOP_OPTS="-Dsun.security.krb5.debug=true" hdfs dfs -ls / # shows the full Kerberos exchange

Rotating Keytabs and Tickets

  • Automate keytab creation and distribution (Ansible Vault, HashiCorp Vault, or your manager tool)
  • Rotate on a schedule and after staff changes
  • Monitor ticket expiry for long-running service accounts
  • Back up the KDC database and keep a replica KDC

Conclusion

Kerberos issues tickets so services and users can prove who they are. Create principals and protected keytabs, set Kerberos properties for HDFS and YARN, use auth_to_local to map names and LinuxContainerExecutor to run tasks as users, and debug with clock, DNS and klist.

Quick Summary: principals + keytabs + hadoop.security.authentication=kerberos; check time and DNS first.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators