Server-Server mutual authentication - Apache ZooKeeper (2024)

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 Kerberosor DIGEST-MD5 as your authentication scheme.

Presently, this feature is supported only in ZooKeeper 3.4.10+ version. Thisis implemented using JIRA issueZOOKEEPER-1045,and thepatch is availablelinked from that JIRA.The feature code will be forward ported to ZooKeeper 3.5.x and 3.6.x versions viaseparate JIRA task ZOOKEEPER-2639.

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

Sample zoo.cfg:

quorum.auth.enableSasl=truequorum.auth.learnerRequireSasl=truequorum.auth.serverRequireSasl=truequorum.auth.learner.saslLoginContext=QuorumLearnerquorum.auth.server.saslLoginContext=QuorumServerquorum.auth.kerberos.servicePrincipal=servicename/_HOSTquorum.cnxn.threads.size=20
  1. Sets to enable quorum authentication using SASL.

    zoo.cfg

    # Defaulting to falsequorum.auth.enableSasl=true
  2. 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.

    zoo.cfg

    # Defaulting to falsequorum.auth.learnerRequireSasl=true
  3. 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.

    zoo.cfg

    # Defaulting to falsequorum.auth.serverRequireSasl=true
  4. (Optional) If you want to use different login context for learner/server other than the default values, then configure the following.

    zoo.cfg

    # Defaulting to QuorumLearnerquorum.auth.learner.saslLoginContext=QuorumLearner# Defaulting to QuorumServerquorum.auth.server.saslLoginContext=QuorumServer
  5. The maximum number of threads to allow in the “connectionExecutors” thread pool, which will be used to process quorum server connection requests during Leader Election. This has to be tuned 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.

    zoo.cfg

    # Defaulting to 20quorum.cnxn.threads.size=20

conf/java.env

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

java.env

SERVER_JVMFLAGS="-Djava.security.auth.login.config=/path/to/server/jaas/file.conf"

ZooKeeper servers will talk to each other using the credentials configured in “jaas/file.conf” file. They will act like learner-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.

ZooKeeper uses Kerberos principals and Keytabs to support quorum peermutual authentication. Kerberos assigns tickets to Kerberos principals to enable them todo the Kerberos-secured communication.

You can use principal in the form of servicename/fully.qualified.domain.name@EXAMPLE.COM,here "servicename" has to be substituted with the proper service name. For example, for ZooKeeper quorum service you can substitute "servicename" with "zkquorum". Assume, we have two hosts (myhost1.foo.com and myhost2.foo.com) we would have Kerberos principals like, zkquorum/myhost1.foo.com@EXAMPLE.COM and zkquorum/myhost2.foo.com@EXAMPLE.COM

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.

zoo.cfg

quorum.auth.kerberos.servicePrincipal

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

servicename/localhost@EXAMPLE.COM

Admin has to be configure the below property with the principal name in zoo.cfg file,

zoo.cfg

quorum.auth.kerberos.servicePrincipal=servicename/localhost

Important Note: Authorization is not supported in this format.

2) Host based Kerberos principal name with _HOST wildcard

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 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.

ZooKeeper ensemble server details will be configured in zoo.cfg of the form

server.id=host:port:port

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

server.id=FQDN:port:port

JAAS configuration file, Kerberos mechanism

QuorumServer { com.sun.security.auth.module.Krb5LoginModule required useKeyTab=true keyTab="/path/to/keytab" storeKey=true useTicketCache=false debug=false principal="zkquorum/fully.qualified.domain.name@EXAMPLE.COM";};QuorumLearner { com.sun.security.auth.module.Krb5LoginModule required useKeyTab=true keyTab="/path/to/keytab" storeKey=true useTicketCache=false debug=false principal="learner/fully.qualified.domain.name@EXAMPLE.COM";};

Supports authorization:

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 as below,

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 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.

zoo.cfg

server.1=FQDN1:port:portserver.2=FQDN2:port:portserver.3=FQDN3:port:port

JAAS 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

This 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.enableSasl: If false, no authentication at all. If true, could be either in rolling upgrade, or finished rolling upgrade.

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. This flag can’t be set to false if quorum.auth.serverRequireSasl isset to true.

quorum.auth.serverRequireSasl: Initially false. Sets to true in third step of rolling upgrade (quorum.auth.learnerRequireSaslshould 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-1) Loop through each server, update zoo.cfg with quorum.auth.enableSasl=true, then restart the server with the new ZooKeeper 3.4.10+ binaries. Verify everything works well after restarting the server.

Step-2) Loop through each server, update zoo.cfg with quorum.auth.learnerRequireSasl=true, then restart the server. Each server is now ready to talk with other servers in an auth­ enabled way but on the other end the receiving server is not auth enabled yet. Verify everything works well after restarting the server.

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.

Server-Server mutual authentication - Apache ZooKeeper (2024)

FAQs

What type of authentication does ZooKeeper client use? ›

ZooKeeper authentication overview

x, ZooKeeper supports mutual TLS (mTLS) authentication. As of version 2.5, Kafka supports authenticating to ZooKeeper with SASL and mTLS–either individually or together.

What is the minimum quorum for ZooKeeper? ›

Zookeeper Quorum

Zookeeper needs to have a strict majority of servers to form a consensus when votes happen. Therefore a Zookeeper quorum can have 1, 3, 5, 7, and up to (2N+1) servers. This allows 0, 1, 2, 3, and N servers to go down without making the cluster unusable.

What are the limitations and constraints of ZooKeeper and when might it not be the best choice for a particular use case? ›

Because Zookeeper requires a majority, it is best to use an odd number of machines. For example, with four machines ZooKeeper can only handle the failure of a single machine; if two machines fail, the remaining two machines do not constitute a majority.

What are the minimum requirements for Apache ZooKeeper? ›

Required Software

ZooKeeper runs in Java, release 1.8 or greater (JDK 8 LTS, JDK 11 LTS, JDK 12 - Java 9 and 10 are not supported). It runs as an ensemble of ZooKeeper servers. Three ZooKeeper servers is the minimum recommended size for an ensemble, and we also recommend that they run on separate machines.

What are the three major ways of authenticating users? ›

There are three common factors used for authentication:
  • Something you know (such as a password)
  • Something you have (such as a smart card)
  • Something you are (such as a fingerprint or other biometric method)
Jun 6, 2011

Which server is used for authentication? ›

Different types of authentication servers

RADIUS is one of the most commonly used authentication methods. Terminal Access Controller Access Control System Plus (TACACS+) is similar to RADIUS but is used with Unix networks. RADIUS employs User Datagram Protocol, and TACACS+ employs TCP.

What happens if ZooKeeper quorum is down? ›

If multiple nodes fail and ZooKeeper loses its quorum, it will drop into read-only mode and reject requests for changes. The remaining ZooKeeper instance(s) are neither a leader nor a standby. All clients will receive SUSPENDED and eventually LOST state.

How to check ZooKeeper quorum? ›

  1. Zookeeper process runs on infra VM's. ...
  2. To start the zookeeper service use command: /usr/share/zookeeper/bin/zkServer.sh start.
  3. To check whether process is running: ps -ef | grep zookeeper.
  4. Errorlogs can be checked in Infra nodes: /var/log/zookeeper/zookeeper.log. ...
  5. Check the free memory: free -mh.
Jun 15, 2019

What does Apache ZooKeeper do? ›

ZooKeeper is an open-source Apache project that provides a centralized service for providing configuration information, naming, synchronization and group services over large clusters in distributed systems. The goal is to make these systems easier to manage with improved, more reliable propagation of changes.

Is ZooKeeper obsolete? ›

Note: ZooKeeper is marked as deprecated since the 3.5. 0 release.

Which protocol does ZooKeeper use? ›

ZooKeeper can be viewed as an atomic broadcast system, through which updates are totally ordered. The ZooKeeper Atomic Broadcast (ZAB) protocol is the core of the system.

Why you shouldn't be a ZooKeeper? ›

Working in a zoo is an inherently dangerous job. Many tragic incidents have been reported across the United States that have resulted in a zookeeper losing a limb or being killed, according to the Future of Working. Zookeepers can be attacked out of the blue while working in or near an enclosure.

Can we use Apache Kafka without ZooKeeper? ›

People have been using Apache ZooKeeper and Apache Kafka together for years. However, recent features have made it possible to run Kafka without ZooKeeper.

What port does ZooKeeper run on? ›

By default, the Apache ZooKeeper server runs on port 2181.

Can you run Kafka without ZooKeeper? ›

Apache Kafka has officially deprecated ZooKeeper in version 3.5. You can use Kafka Raft metadata mode(KRaft). In KRaft mode each Kafka server can be configured as a controller, a broker, or both using the process.

Which protocol is used for client authentication? ›

Kerberos is the most widely used protocol for authenticating users in a distributed system using shared keys [3]. It is based on the Needham-Schroeder protocol and uses an authentication server, which acts as a trusted third party.

What is client authentication method? ›

Client Authentication is the process by which users securely access a server or remote computer by exchanging a Digital Certificate.

What authenticates clients to a network? ›

In authentication, the user or computer has to prove its identity to the server or client. Usually, authentication by a server entails the use of a user name and password. Other ways to authenticate can be through cards, retina scans, voice recognition, and fingerprints.

References

Top Articles
Latest Posts
Article information

Author: Reed Wilderman

Last Updated:

Views: 6127

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Reed Wilderman

Birthday: 1992-06-14

Address: 998 Estell Village, Lake Oscarberg, SD 48713-6877

Phone: +21813267449721

Job: Technology Engineer

Hobby: Swimming, Do it yourself, Beekeeping, Lapidary, Cosplaying, Hiking, Graffiti

Introduction: My name is Reed Wilderman, I am a faithful, bright, lucky, adventurous, lively, rich, vast person who loves writing and wants to share my knowledge and understanding with you.