Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

During leader activation(leader-election) phase, all the servers in an ensemble will participate to form quorum. By default, this communication is not authenticated. This guide describes how to enable secure communication between the quorum peer servers using SASL mechanism. ZooKeeper supports Kerberos Kerberos or DIGEST-MD5 as your authentication scheme.

JIRA and Source Code

Presently, this feature is supported only in ZooKeeper 3.4.10+ versionand . This is implemented using JIRA JIRA issue ZOOKEEPER-1045. The , and the patch is available linked from that JIRA. The feature code will be forward ported to ZooKeeper 3.5.x and 3.6.x versions in a separate versions via separate JIRA task ZOOKEEPER-2639.

ZooKeeper SASL configurations

...

Following configurations should be added in $conf/zoo.cfg configuration file.

Code Block
title Sample zoo.cfg:
quorum.auth.enableSasl=true
quorum.auth.learnerRequireSasl=true
quorum.auth.serverRequireSasl=true
quorum.auth.learner.loginContextsaslLoginContext=QuorumLearner
quorum.auth.server.loginContextsaslLoginContext=QuorumServer
quorum.auth.kerberos.servicePrincipal=servicename/_HOST
quorum.cnxn.threads.size=20 

...

  1. Sets to enable quorum authentication using SASL.

    Code Block
    titlezoo.cfg
    # Defaulting to false
    quorum.auth.enableSasl=true

...


  1. Sets to connect using quorum authentication. If this is true, quorum peer learner will send authentication packet to quorum peer server then proceeds with LE on successful authentication. If false, then proceeds with LE without any authentication. This can be used while upgrading ZooKeeper server.

    Code Block
    titlezoo.cfg
    # Defaulting to false
    quorum.auth.learnerRequireSasl=true

...


  1. Sets to connect using quorum authentication. If this is true, then all unauthenticated quorum peer learner connection requests will be rejected. If false, then quorum peer server will accept quorum peer learner connection request and then proceeds with Leader Election even if the authentication did not succeed. This can be used while upgrading ZK server.

    Code Block
    titlezoo.cfg
    # Defaulting to false
    quorum.auth.serverRequireSasl=true

...


  1. (Optional) If you want to use different login context for learner/server other than the default values, then configure the following

...

  1. .

    Code Block
    titlezoo.cfg
    # Defaulting to QuorumLearner
    quorum.auth.learner.

...

  1. saslLoginContext=QuorumLearner
    
    # Defaulting to QuorumServer
    quorum.auth.server.

...

  1. saslLoginContext=QuorumServer

...


  1. The maximum number of threads to allow in the

...

  1. connectionExecutorsthread pool, which will be used to process quorum server connection requests during Leader Election. This

...

  1. has to be tuned

...

  1. depending on the cluster size. For example, consider a 3-node cluster, during quorum formation at least 3 outgoing connection requests and 3 incoming connection requests will occur. So total 6 threads will be used. It is recommended to configure 2x number of threads for smooth execution, where 'x' represents the cluster size.

    Code Block
    titlezoo.cfg
    # Defaulting to 

...

  1. 20
    quorum.cnxn.threads.size=20


conf/java.env

Add the following settings to the java.env file located in the ZooKeeper configuration directory. (Create the file if it does not already exist.)

Code Block
titlejava.env
export SERVER_JVMFLAGS="-Djava.security.auth.login.config=/etcpath/zkto/confserver/jaas/file.conf"

 ZooKeeper servers will talk to each other using the credentials configured in “jaas/file.conf” file. They will act like clientlearner-server when creating connections during quorum formation. Set up the Java Authentication and Authorization Service (JAAS) by creating a “jaas/file.conf” file in the ZooKeeper configuration directory and add configuration entries into this file specific to your selected authentication schemes. 


Following section describes the details of supported authentication schemes, Kerberos or DIGEST-MD5.

Kerberos based authentication

...

ZooKeeper uses Kerberos principals and Keytabs to support quorum peer mutual authentication. Kerberos assigns tickets to Kerberos principals to enable them to do the Kerberos-secured communication.

...

Configure service name and host details servicename/fully.qualified.domain.name of quorum peer server to the following configuration property in zoo.cfg file. This service principal will be used by the quorum learner to send authentication packet to the peer quorum server.

Code Block
titlezoo.cfg
  quorum.auth.kerberos.servicePrincipal


The principal name should be in either of the following formats:

1)  Single shared Kerberos principal nameconfigured in all the servers

...

Code Block
servicename/localhost@EXAMPLE.COM

...

 Important Note: Authorization is not supported in this format.

2)  Host based Kerberos principal name with _HOST wildcard

...

Code Block
servicename/fully.qualified.domain.name@EXAMPLE.COM

ZooKeeper simplifies the deployment of configuration files by allowing the fully qualified domain name component of the service principal to be specified as the _HOST wildcard. Internally each quorum learner will substitute _HOST with the respective FQDN from zoo.cfg at runtime and then send authentication packet to that server. This allows administrators to avoid the overhead of configuring all others other's principal names on all nodes. However, the keytab files will be different. A keytab file for a ZooKeeper server is unique to each host if the principal name contains the hostname. This file is used to authenticate a principal on a host to Kerberos without human interaction or storing a password in a plain text file. Access to the keytab files should be tightly secured because having access to the keytab file for a principal allows one to act as that principal.

...

Code Block
server.id=host:port:port

Make sure that you should use FQDN in zoo.cfg like below, FQDN value will be used to replace the special string pattern “_HOST

...

ZooKeeper server will support authorization if the principal name is in the format servicename/fully.qualified.domain.name@EXAMPLE.COM and configure “_HOST” wildcard in quorum server principal in zoo.cfg file likeas below,

Code Block
quorum.auth.kerberos.servicePrincipal= servicename/_HOST

Now, QuorumServer will do the authorization checks against configured authorized hosts. This authorized host list will be prepared using the ensemble server details in zoo.cfg file. During LE, QuorumLearner will send an authentication packet to QuorumServer. Now, QuorumServer will check that the connecting QuorumLearner’s hostname should exists in the authorized hosts. If not exists then connecting peer is not authorized to join this ensemble and the request will be rejected immediately.

For example, zoo.cfg contains the below server details. Now, only FQDN1, FQDN2, FQDN3 hosts are allowed to join ZooKeeper cluster. All others will be rejected as unauthorized connections.

Code Block
titlezoo.cfg
server.1=FQDN1:port:port
server.2=FQDN2:port:port
server.3=FQDN3:port:port

Note:-

It is recommended to set JVM flag (Optional)

Code Block
titleSystem property
javax.security.auth.useSubjectCredsOnly=false

 Reference Links:-

http://docs.oracle.com/javase/7/docs/technotes/guides/security/jgss/tutorials/Troubleshooting.html

http://docs.oracle.com/javase/7/docs/technotes/guides/security/jgss/tutorials/BasicClientServer.html


DIGEST-MD5 based authentication

...

Code Block
titleJAAS configuration file, DIGEST-MD5 mechanism
QuorumServer {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       user_test="test";
};

QuorumLearner {
       org.apache.zookeeper.server.auth.DigestLoginModule required
       username="test"
       password="test";
};

Important Note: Authorization is not supported in this format


Rolling upgrade

...

This feature is targeted for 3.4 branch which is the current stable branch and is widely used in production clusters. So it is critical to support rolling upgrade of existing cluster without any down time. This section describing the possible rolling upgrade.section describes the possible rolling upgrade to use ZOOKEEPER-1045 feature. The rolling upgrade in ZOOKEEPER-1045 is designed based on a key observation that a Quorum Peer can be configured such that a ZooKeeper ensemble can be composed of a mixed servers, both old and new. Rolling upgrade is achieved by a combination of configuration flags in zoo.cfg configuration file. 

...

quorum.auth.learnerRequireSasl: Initially false. Sets to true in second step of rolling upgrade, this is to prepare each server ready to send authentication packet to other servers. Can’t This flag can’t be set to false if quorum.auth.serverRequireSasl serverRequireSasl is set to true.

quorum.auth.serverRequireSasl: Initially false. Sets to true in third step of rolling upgrade (quorum.auth.learnerRequireSasl should be true) to enable server-to-­server SASL authentication strictly.

How to perform rolling upgrade

...

Prior to enabling ZooKeeper to work with security on your cluster, make sure ZooKeeper cluster works well in no-authentication setup. Rolling upgrade should be completed in three steps. After every step, admin has to ensure that all the servers have completed this step before moving on to the next step.

...

Step-3) Loop through each server, update zoo.cfg with quorum.auth.serverRequireSasl=true, then restart server. Now for each server, both its sending part (modeled as QuorumLearner) and its receiving part (modeled as QuorumServer) are auth enabled. Verify everything works correctly after restarting the server.

For verification, you can use ZooKeeper client operations like, create/delete znode.

...