Kerberizing NiFi's ZooKeeper Client
Note: The NiFi nodes running the embedded zookeeper server will also need to follow the below procedure since they will also be acting as a client at the same time.
The preferred mechanism for authenticating users with ZooKeeper is to use Kerberos.
In order to use Kerberos to authenticate, we must configure a few system properties, so
that the ZooKeeper client knows who the user is and where the KeyTab file is. All nodes
configured to store cluster-wide state using ZooKeeperStateProvider
and using Kerberos should follow these steps.
First, we must create the Principal that we will use when communicating with
ZooKeeper. This is generally done via the kadmin
tool:
kadmin: addprinc "nifi@EXAMPLE.COM"
A Kerberos Principal is made up of three parts: the primary, the instance, and the
realm. Here, we are creating a Principal with the primary nifi
, no
instance, and the realm EXAMPLE.COM
. The primary
(nifi
, in this case) is the identifier that will be used to
identify the user when authenticating via Kerberos.
After we have created our Principal, we will need to create a KeyTab for the Principal:
kadmin: xst -k nifi.keytab nifi@EXAMPLE.COM
This keytab file can be copied to the other NiFi nodes with embedded zookeeper servers.
This will create a file in the current directory named
nifi.keytab
. We can now copy that file into the
$NIFI_HOME/conf/ directory. We should ensure that only the user
that will be running NiFi is allowed to read this file.
Next, we need to configure NiFi to use this KeyTab for authentication. Since
ZooKeeper uses the Java Authentication and Authorization Service (JAAS), we need to
create a JAAS-compatible file. In the $NIFI_HOME/conf/
directory,
create a file named zookeeper-jaas.conf
and add to it the following
snippet:
Client { com.sun.security.auth.module.Krb5LoginModule required useKeyTab=true keyTab="conf/nifi.keytab" storeKey=true useTicketCache=false principal="nifi@EXAMPLE.COM"; };
We then need to tell NiFi to use this as our JAAS configuration. This is done by setting a JVM System Property, so we will edit the conf/bootstrap.conf file. We add the following line anywhere in this file in order to tell the NiFi JVM to use this configuration:
java.arg.15=-Djava.security.auth.login.config=./conf/zookeeper-jaas.conf
Finally we need to update nifi.properties
to ensure that NiFi
knows to apply SASL specific ACLs for the Znodes it will create in ZooKeeper for cluster
management. To enable this, in the $NIFI_HOME/conf/nifi.properties
file and edit the following properties as shown below:
nifi.zookeeper.auth.type=sasl nifi.zookeeper.kerberos.removeHostFromPrincipal=true nifi.zookeeper.kerberos.removeRealmFromPrincipal=true
Note: The kerberos.removeHostFromPrincipal and kerberos.removeRealmFromPrincipal should be consistent with what is set in ZooKeeper configuration.
We can initialize our Kerberos ticket by running the following command:
kinit -kt nifi.keytab nifi@EXAMPLE.COM
Now, when we start NiFi, it will use Kerberos to authentication as the
nifi
user when communicating with ZooKeeper.