Sec Authentication With Kerberos
Sec Authentication With Kerberos
http://docs.hortonworks.com
Contents
Kerberos Overview................................................................................................... 3
Kerberos Overview
A high-level overview of Kerberos authentication, including the Key Distribution Center, principals, Authentication
Server, Ticket Granting Tickets, and Ticket Granting Server.
Strongly authenticating and establishing a user’s identity is the basis for secure access in Hadoop. Users need to
be able to reliably “identify” themselves and then have that identity propagated throughout the Hadoop cluster.
Once this is done, those users can access resources (such as files or directories) or interact with the cluster (like
running MapReduce jobs). Besides users, Hadoop cluster resources themselves (such as Hosts and Services) need to
authenticate with each other to avoid potential malicious systems or daemon’s “posing as” trusted components of the
cluster to gain access to data.
Hadoop uses Kerberos as the basis for strong authentication and identity propagation for both user and services.
Kerberos is a third party authentication mechanism, in which users and services rely on a third party - the Kerberos
server - to authenticate each to the other. The Kerberos server itself is known as the Key Distribution Center, or KDC.
At a high level, it has three parts:
• A database of the users and services (known as principals) that it knows about and their respective Kerberos
passwords
• An Authentication Server (AS) which performs the initial authentication and issues a Ticket Granting Ticket
(TGT)
• A Ticket Granting Server (TGS) that issues subsequent service tickets based on the initial TGT
A user principal requests authentication from the AS. The AS returns a TGT that is encrypted using the user
principal's Kerberos password, which is known only to the user principal and the AS. The user principal decrypts the
TGT locally using its Kerberos password, and from that point forward, until the ticket expires, the user principal can
use the TGT to get service tickets from the TGS. Service tickets are what allow a principal to access various services.
Because cluster resources (hosts or services) cannot provide a password each time to decrypt the TGT, they use a
special file, called a keytab , which contains the resource principal's authentication credentials. The set of hosts, users,
and services over which the Kerberos server has control is called a realm.
Terminology
Term Description
Key Distribution Center, or KDC The trusted source for authentication in a Kerberos-enabled environment.
Kerberos KDC Server The machine, or server, that serves as the Key Distribution Center (KDC).
Kerberos Client Any machine in the cluster that authenticates against the KDC.
Principal The unique name of a user or service that authenticates against the KDC.
3
Configuring Authentication with Kerberos Kerberos Principals Overview
Term Description
Keytab A file that includes one or more principals and their keys.
Realm The Kerberos network that includes a KDC and a number of Clients.
KDC Admin Account An administrative account used by Ambari to create principals and generate keytabs in the KDC.
Notice in the preceding example the primary name for each service principal. These primary names, such as nn or
hive for example, represent the NameNode or Hive service, respectively. Each primary name has appended to it the
instance name, the FQDN of the host on which it runs. This convention provides a unique principal name for services
that run on multiple hosts, like DataNodes and NodeManagers. Adding the host name serves to distinguish, for
example, a request from DataNode A from a request from DataNode B. This is important for the following reasons:
• Compromised Kerberos credentials for one DataNode do not automatically lead to compromised Kerberos
credentials for all DataNodes.
4
Configuring Authentication with Kerberos Enabling SPNEGO Authentication for Hadoop
• If multiple DataNodes have exactly the same principal and are simultaneously connecting to the NameNode, and
if the Kerberos authenticator being sent happens to have same timestamps, then the authentication is rejected as a
replay request.
In addition to the Hadoop Service Principals, Ambari itself also requires a set of Ambari Principals to perform service
“smoke” checks, perform alert health checks and to retrieve metrics from cluster components. Keytab files for the
Ambari Principals reside on each cluster host, just as keytab files for the service principals.
Smoke and “Headless” Service users Used by Ambari to perform service “smoke” checks and run alert health checks.
Ambari Server user When a cluster is enabled for Kerberos, the component REST endpoints (such as the YARN ATS com
SPNEGO authentication. Ambari Server needs access to these APIs and requires a Kerberos principal
authenticate via SPNEGO against these APIs.
Related Information
Enabling SPNEGO Authentication for Hadoop
Procedure
1. Create a principal in your KDC for the Ambari Server. For example, using kadmin. addprinc -randkey ambari-
[email protected].
2. Generate a keytab for that principal. xst -k ambari.server.keytab [email protected].
3. Place that keytab on the Ambari Server host. Be sure to set the file permissions so the user running the Ambari
Server daemon can access the keytab file. /etc/security/keytabs/ambari.server.keytab.
4. Stop the ambari server. ambari-server stop.
5. Run the setup-security command. ambari-server setup-security.
6. Select 3 for Setup Ambari kerberos JAAS configuration.
7. Enter the Kerberos principal name for the Ambari Server you set up earlier.
8. Enter the path to the keytab for the Ambari principal.
9. Restart Ambari Server. ambari-server restart.
5
Configuring Authentication with Kerberos Enabling SPNEGO Authentication for Hadoop
Procedure
1. Create a secret key used for signing authentication tokens. This file should contain random data and be placed
on every host in the cluster. It should also be owned by the hdfs user and group owned by the hadoop group.
Permissions should be set to 440. For example:
hadoop.http.authentication.simple.anonymous.allowed false
hadoop.http.authentication.signature.secret.file /etc/security/http_secret
hadoop.http.authentication.type kerberos
hadoop.http.authentication.kerberos.keytab /etc/security/keytabs/spnego.service.keytab
hadoop.http.filter.initializers org.apache.hadoop.security.AuthenticationFilterInitializer
hadoop.http.authentication.cookie.domain hortonworks.local
Note:
The entries listed in the above table in bold and italicized are site-specific. The
hadoop.http.authentication.cookie.domain property is based off of the fully qualified domain names of
the servers in the cluster. For example if the FQDN of your NameNode is host1.hortonworks.local, the
hadoop.http.authentication.cookie.domain should be set to hortonworks.local.
4. For HBase, you can enable Kerberos-authentication to HBase Web UIs by configuring SPNEGO.
a) In Ambari Web, browse to Services > HBase > Configs .
b) Add the following configuration properties to the custom hbase-site.xml file:
Property Value
hbase.security.authentication.ui kerberos
hbase.security.authentication kerberos
hbase.security.authentication.spnego.kerberos.principal HTTP/[email protected]
hbase.security.authentication.spnego.kerberos.keytab /etc/security/keytabs/spnego.service.keytab
Hbase.security.authentication.spnego.kerberos.name.rules (Optional)
Hbase.security.authentication.signature.secret.file(Optional)
6
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
Procedure
1. Install Kerberos on your local machine (search for instructions on how to install a Kerberos client on your local
environment).
2. Configure the krb5.conf file on your local machine. For testing on a HDP cluster, copy the /etc/krb5.conf file from
one of the cluster hosts to your local machine at /etc/krb5.conf. Create your own keytabs and run kinit. For testing
on a HDP cluster, copy the "ambari_qa" keytab file from /etc/security/keytabs/smokeuser.headless.keytab on one
of the cluster hosts to your local machine, then run the following command:
[14617:36099:0810/152439.802775:ERROR:browser_gpu_channel_host_factory.cc(103)]
Failed to launch GPU process.
b) For Firefox:
1. Navigate to the about:config URL (type about:config in the address box, then press the Enter key).
2. Scroll down to network.negotiate-auth.trusted-uris and change its value to your cluster domain name (For
example, .hwx.site).
3. Change the value of network.negotiate-auth.delegation-uris to your cluster domain name (For example,
.hwx.site).
7
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
• MIT Kerberos v5
• FreeIPA 4.x and above
There are four ways to install/configure the KDC:
• Using an existing MIT KDC
• Install a new MIT KDC (See "Optional: Install a new MIT KDC")
• Using an existing IPA
• Using an existing AD
• Using manual Kerberos setup
Option Checklist
Using an existing MIT KDC • Ambari Server and cluster hosts have network access to both the
KDC and KDC admin hosts.
• KDC administrative credentials are on-hand.
Install a new MIT KDC See “Optional: Install a new MIT KDC”
Using an existing AD • Ambari Server and cluster hosts have network access to, and be
able to resolve the DNS names of, the Domain Controllers.
• Active Directory secure LDAP (LDAPS) connectivity has been
configured.
• Active Directory User container for service principals
has been created and is on-hand. For example,
"OU=Hadoop,OU=People,dc=apache,dc=org"
• Active Directory administrative credentials with delegated control
of “Create, delete, and manage user accounts” on the previously
mentioned User container are on-hand.
Using manual Kerberos setup • Cluster hosts have network access to the KDC.
• Kerberos client utilities (such as kinit) have been installed on every
cluster host.
• The Java Cryptography Extensions (JCE) have been setup on the
Ambari Server host and all hosts in the cluster.
• The Service and Ambari Principals will be manually created in the
KDC before completing this wizard.
• The keytabs for the Service and Ambari Principals will be
manually created and distributed to cluster hosts before completing
this wizard.
Related Information
Enabling Kerberos Security
Optional: Install a new MIT KDC
Procedure
1. Install the KDC Server:
a) Install a new version of the KDC server:
8
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
OS Flavor Enter
b) Using a text editor, open the KDC server configuration file, located by default here: vi /etc/krb5.conf.
c) Change the [realms] section of this file by replacing the default “kerberos.example.com” setting for the kdc
and admin_server properties with the Fully Qualified Domain Name of the KDC server host. In the following
example, “kerberos.example.com” has been replaced with “my.kdc.server”.
realms]
EXAMPLE.COM = {
kdc = my.kdc.server
admin_server = my.kdc.server
}
Ubuntu/Debian krb5_newrealm
9
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
command line administration utility. Using kadmin.local on the KDC machine allows you to create principals
without needing to create a separate "admin" principal before you start.
a) Create a KDC admin by creating an admin principal: kadmin.local -q "addprinc admin/admin".
b) Confirm that this admin principal has permissions in the KDC ACL. Using a text editor, open the KDC ACL
file:
OS Flavor Enter
SLES vi /var/lib/kerberos/krb5kdc/kadm5.acl
Ubuntu/Debian vi /etc/krb5kdc/kadm5.acl
c) Ensure that the KDC ACL file includes an entry so to allow the admin principal to administer the KDC
for your specific realm. When using a realm that is different than EXAMPLE.COM, be sure there is an
entry for the realm you are using. If not present, principal creation will fail. For example, for an admin/
[email protected] principal, you should have an entry: */[email protected] *.
d) After editing and saving the kadm5.acl file, you must restart the kadmin process:
OS Flavor Enter
Related Information
RHEL Documentation> Configuring A Kerberos 5 Server
SLES Documentation> Installing and Administering Kerberos
10
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
# create a role and and give it privilege to manage users and services
ipa role-add hadoopadminrole
ipa role-add-privilege hadoopadminrole --privileges="User Administrators"
ipa role-add-privilege hadoopadminrole --privileges="Service Administrators"
# login once, or kinit, to reset the initial temporary password for the
hadoopadmin account
kinit hadoopadmin
Procedure
1. On the Ambari Server, obtain the JCE policy file appropriate for the JDK version in your cluster:
11
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
Option
Oracle JDK 1.8 JCE Unlimited Strength Jurisdiction Policy Files 8
Download
Oracle JDK 1.7 JCE Unlimited Strength Jurisdiction Policy Files 7
Download
What to do next
Proceed to “Running the Kerberos Security Wizard”.
Related Information
Running the Kerberos Security Wizard
Prerequisites
• Having the JCE installed on all hosts on the cluster (including the Ambari Server).
• Having the Ambari Server host as part of the cluster.
• Create mappings between principals and UNIX user names. . Creating mappings can help resolve access issues
related to case mismatches between principal and local user names.
Exclusions
Ambari Metrics will not be secured with Kerberos unless it is configured for distributed metrics storage. By default,
it uses embedded metrics storage and will not be secured as part of the Kerberos Wizard. If you wish to have Ambari
Metrics secured with Kerberos, please see “Customizing the Metrics Collector Mode” to enable distributed metrics
storage prior to running the Kerberos Wizard.
12
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
Procedure
• The Base:
The base begins with the number of components in the principal name (excluding the realm), followed by a
colon, and the pattern for building the username from the sections of the principal name. In the pattern section $0
translates to the realm, $1 translates to the first component, and $2 to the second component.
Example
If your default realm was APACHE.ORG, but you also wanted to take all principals from ACME.COM that had a
single component [email protected], the following rule would do this:
Example
To translate names with a second component, you could use these rules:
RULE:[1:$1@$0]([email protected])s/@.//
13
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
RULE:[2:$1@$0]([email protected])s/@.// DEFAULT
Example
To treat all principals from APACHE.ORG with the extension /admin as admin, your rules would look like this:
RULE[2:$1%$2@$0](.%[email protected])s/./admin/
DEFAULT
Example
To force username conversion from CaMeLcase or UPPERCASE to lowercase, you could model the following
auth_to_local rule examples which have the lowercase switch added:
RULE:[1:$1]/L
RULE:[2:$1]/L
RULE:[2:$1;$2](^.*;admin$)s/;admin$///L
RULE:[2:$1;$2](^.*;guest$)s/;guest$//g/L
RULE:[1:$1]/L
RULE:[2:$1]/L
RULE:[2:$1;$2](^.*;admin$)s/;admin$///L
RULE:[2:$1;$2](^.*;guest$)s/;guest$//g/L
And based on these rules, here are the expected output for the following inputs:
"[email protected]" to "joe" "Joe/[email protected]" to "joe" "Joe/[email protected]" to "joe" "Joe/
[email protected]" to "joe"
Automated Setup
When choosing Existing MIT KDC or Existing Active Directory, the Kerberos Wizard prompts for information
related to the KDC, the KDC Admin Account and the Service and Ambari principals. Once provided, Ambari will
automatically create principals, generate keytabs and distribute keytabs to the hosts in the cluster. The services will
be configured for Kerberos and the service components are restarted to authenticate against the KDC. This is the
Automated Setup option. See “Launching the Kerberos Wizard (Automated Setup)” for more details.
If you chose to enable Kerberos using the Automated Kerberos Setup option, as part of the enabling Kerberos
process, Ambari installs the Kerberos clients on the cluster hosts. Depending on your operating system, the following
packages are installed:
SLES 11 krb5-client
14
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
Manual Setup
When choosing Manage Kerberos principals and keytabs manually, you must create the principals, generate and
distribute the keytabs; including you performing the “Ambari Server Kerberos setup”. Ambari will not do this
automatically. This is the Manual Setup option. See “Launching the Kerberos Wizard (Manual Setup)” for more
details.
Related Information
Launch the Kerberos Wizard (Automated Setup)
Launch the Kerberos Wizard (Manual Setup)
Set Up Kerberos for Ambari Server
Procedure
1. Be sure you have installed and configured your KDC and have prepared the JCE on each host in the cluster.
2. Log in to Ambari Web and Browse to Admin > Kerberos.
3. Click “Enable Kerberos” to launch the wizard.
4. Select the type of KDC you are using and confirm you have met the prerequisites.
5. Provide information about the KDC and admin account.
a) In the KDC section, enter the following information:
• In the KDC Host field, the IP address or FQDN for the KDC host. Optionally a port number may be
included.
• In the Realm name field, the default realm to use when creating service principals.
• (Optional) In the Domains field, provide a list of patterns to use to map hosts in the cluster
to the appropriate realm. For example, if your hosts have a common domain in their FQDN
such as host1.hortonworks.local and host2.hortonworks.local, you would set this to:
.hortonworks.local,hortonworks.local
b) In the Kadmin section, enter the following information:
• In the Kadmin Host field, the IP address or FQDN for the KDC administrative host. Optionally a port
number may be included.
• The Admin principal and password that will be used to create principals and keytabs.
• (Optional) If you have configured Ambari for encrypted passwords, the Save Admin Credentials option
will be enabled. With this option, you can have Ambari store the KDC Admin credentials to use when
making cluster changes. Refer to “Managing Admin Credentials” for more information on this option.
6. Modify any advanced Kerberos settings based on your environment.
a) (Optional) To manage your Kerberos client krb5.conf manually (and not have Ambari manage the krb5.conf),
expand the Advanced krb5-conf section and uncheck the "Manage" option. You must have the krb5.conf
configured on each host.
When manually managing the krb5.conf it is recommended to ensure that DNS is not used for looking
up KDC, and REALM entries. Relying on DNS can cause negative performance, and functional impact.
To ensure that DNS is not used, ensure the following entries are set in the libdefaults section of your
configuration.
[libdefaults]
dns_lookup_kdc = false
dns_lookup_realm = false
15
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
b) (Optional) to configure any additional KDC's to be used for this environment, add an entry for each additional
KDC to the realms section of the Advanced krb5-conf's krb5-conf template.
kdc = {{kdc_host}}
kdc = otherkdc.example.com
c) (Optional) To not have Ambari install the Kerberos client libraries on all hosts, expand the Advanced
kerberos-env section and uncheck the “Install OS-specific Kerberos client package(s)” option. You must have
the Kerberos client utilities installed on each host.
d) (Optional) If your Kerberos client libraries are in non-standard path locations, expand the Advanced kerberos-
env section and adjust the “Executable Search Paths” option.
e) (Optional) If your KDC has a password policy, expand the Advanced kerberos-env section and adjust the
Password options.
f) (Optional) Ambari will test your Kerberos settings by generating a test principal and authenticating with that
principal. To customize the test principal name that Ambari will use, expand the Advanced kerberos-env
section and adjust the Test Kerberos Principal value. By default, the test principal name is a combination of
cluster name and date (${cluster_name}-${short_date}). This test principal will be deleted after the test is
complete.
g) (Optional) If you need to customize the attributes for the principals Ambari will create, when using Active
Directory, see “Customizing the Attribute Template” for more information. When using MIT KDC, you can
pass Principal Attributes options in the Advanced kerberos-env section. For example, you can set options
related to pre-auth or max. renew life by passing:
-requires_preauth -maxrenewlife "7 days"
7. Proceed with the install.
8. Ambari will install Kerberos clients on the hosts and test access to the KDC by testing that Ambari can create a
principal, generate a keytab and distribute that keytab.
9. Customize the Kerberos identities used by Hadoop and proceed to kerberize the cluster.
On the Configure Identities step, be sure to review the principal names, particularly the Ambari Principals on the
General tab. These principal names, by default, append the name of the cluster to each of the Ambari principals.
You can leave this as default or adjust these by removing the "-${cluster-name}" from principal name string. For
example, if your cluster is named HDP and your realm is EXAMPLE.COM, the hdfs principal will be created as
[email protected].
10. Confirm your configuration. You can optionally download a CSV file of the principals and keytabs that Ambari
will automatically create.
11. Click Next to start the process.
12. After principals have been created and keytabs have been generated and distributed, Ambari updates the cluster
configurations, then starts and tests the Services in the cluster.
13. Exit the wizard when complete.
14. Ambari Server communicates with components in the cluster, and now with Kerberos setup, you need to make
sure Ambari Server is setup for Kerberos. As part of the automated Kerberos setup process, Ambari Server has
been given a keytab and setup is performed. All you need to do is restart Ambari Server for that to take effect.
Therefore, restart Ambari Server at this time: ambari-server restart.
Related Information
Install the JCE for Kerberos
Update KDC Admin Credentials
Checklist: Installing and Configuring the KDC
Customizing the Attribute Template
16
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
Procedure
1. Be sure you have installed and configured your KDC and have prepared the JCE on each host in the cluster.
2. Log in to Ambari Web and Browse to Admin > Kerberos.
3. Click “Enable Kerberos” to launch the wizard.
4. Select the Manage Kerberos principals and keytabs manually option and confirm you have met the prerequisites.
5. Provide information about the KDC and admin account.
If your Kerberos client libraries are in non-standard path locations, expand the Advanced kerberos-env section and
adjust the “Executable Search Paths” option.
6. Customize the Kerberos identities used by Hadoop and proceed to kerberize the cluster.
On the Configure Identities step, be sure to review the principal names, particularly the Ambari Principals on the
General tab. These principal names, by default, append the name of the cluster to each of the Ambari principals.
You can leave this as default or adjust these by removing the "-${cluster-name}" from principal name string. For
example, if your cluster is named HDP and your realm is EXAMPLE.COM, the hdfs principal will be created as
[email protected].
7. Confirm your configuration. Since you have chosen the Manual Kerberos Setup option, obtain the CSV file for
the list of principals and keytabs required for the cluster to work with Kerberos. Do not proceed until you have
manually created and distributed the principals and keytabs to the cluster hosts.
8. Click Next to continue.
9. Ambari updates the cluster configurations, then starts and tests the Services in the cluster.
10. Exit the wizard when complete.
11. Finish by completing “Set Up Kerberos for Ambari Server”.
Related Information
Set Up Kerberos for Ambari Server
Install the JCE for Kerberos
Checklist: Installing and Configuring the KDC
Note:
17
Configuring Authentication with Kerberos Enabling Kerberos Authentication Using Ambari
If you do not have password encryption enabled for Ambari, the Save Admin Credentials option will not be
enabled.
Procedure
Updating KDC Credentials:
If you have chosen to Save Admin Credentials when enabling Kerberos, you can update or remove the credentials
from Ambari using the following:
a) In Ambari Web, browse to Cluster Admin > Kerberos and click the Manage KDC Credentials button. The Manage
KDC Credentials dialog is displayed.
b) If credentials have been previously saved, click Remove to remove the credentials currently stored in Ambari.
Once removed, if cluster changes that require KDC principal and/or keytab changes (such as adding services,
components and hosts), you will be prompted to enter the KDC Admin Account credentials.
c) Alternatively, to update the KDC Admin Account credentials, enter the Admin principal and password values and
click Save.
Related Information
Encrypt Database and LDAP Passwords in Ambari
$normalized_principal nn/[email protected]
$principal_name nn/c6401.ambari.apache.org
$principal_primary nn
$principal_instance c6401.ambari.apache.org
$realm EXAMPLE.COM
$password password
Related Information
Apache Velocity
18
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
Procedure
1. Log in to Ambari Web and Browse to Admin > Kerberos.
2. Click Disable Kerberos to launch the wizard.
3. Complete the wizard.
Related Information
Enabling Kerberos Security
Ambari-managed cluster with Kafka installed. “Installing, Configuring, and Deploying a Cluster” (link below)
Key Distribution Center (KDC) server installed and running “Installing and Configuring the KDC” (link below)
JCE installed on all hosts on the cluster (including the Ambari server) “Enabling Kerberos Authentication Using Ambari” (link below)
19
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
Related Information
Appendix: Kerberos Kafka Configuration Options
Procedure
1. Run kinit, specifying the Kafka service keytab. For example:
kinit -k -t /etc/security/keytabs/kafka.service.keytab kafka/[email protected]
2. Next, create the topic. Run the kafka-topics.sh command-line tool with the following options:
/bin/kafka-topics.sh --zookeeper <hostname>:<port> --create --topic <topic-name> --partitions <number-of-
partitions> --replication-factor <number-of-replicating-servers>
For more information about kafka-topics.sh parameters, see Basic Kafka Operations on the Apache Kafka
website.
3. Add permissions:
By default, permissions are set so that only the Kafka service user has access; no other user can read or write to
the new topic. In other words, if your Kafka server is running with principal $KAFKA-USER, only that principal
will be able to write to ZooKeeper.
For information about adding permissions, see “Authorizing Access when Kerberos is Enabled”.
Related Information
Authorizing Access when Kerberos is Enabled
Apache Kafka Documentation
Procedure
1. Specify the path to the JAAS configuration file as one of your JVM parameters:
20
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
-Djava.security.auth.login.config=/usr/hdp/current/kafka-broker/config/kafka_client_jaas.conf
For more information about the kafka_client_jaas file, see “JAAS Configuration File for the Kafka Client”.
2. kinit with the principal's keytab.
3. Launch kafka-console-producer.sh with the following configuration options. (Note: these settings are the same as
in previous versions, except for the addition of --security-protocol SASL_PLAINTEXT.)
./bin/kafka-console-producer.sh --broker-list <hostname:port [,hostname:port, …]> --topic <topic-name> --
security-protocol SASL_PLAINTEXT
./bin/kafka-console-producer.sh --broker-list c6401.ambari.apache.org:6667,c6402.ambari.apache.org:6667 --topic
test_topic --security-protocol SASL_PLAINTEXT
Issue: If you launch the producer from the command-line interface without specifying the security-protocol option,
you will see the following error:
package com.hortonworks.example.kafka.producer;
import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.clients.producer.Callback;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import java.util.Properties;
import java.util.Random;
21
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
props.put(ProducerConfig.ACKS_CONFIG, "all");
props.put(ProducerConfig.RETRIES_CONFIG, 0);
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,
"org.apache.kafka.common.serialization.StringSerializer");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,
"org.apache.kafka.common.serialization.StringSerializer");
producer.close();
}
$ java -Djava.security.auth.login.config=/usr/hdp/
current/kafka-broker/config/kafka_client_jaas.conf
com.hortonworks.example.kafka.producer.BasicProducerExample
Related Information
Appendix: Kerberos Kafka Configuration Options
JAAS Configuration File for the Kafka Server
Apache Ranger User Guide> Adding KAFKA Policies
22
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
Procedure
1. Specify the path to the JAAS configuration file as one of your JVM parameters.
For more information about the kafka_client_jaas file, see “JAAS Configuration File for the Kafka Client”.
-Djava.security.auth.login.config=/usr/hdp/current/kafka-broker/config/kafka_client_jaas.conf
2. kinit with the principal's keytab.
3. Launch kafka-console-consumer.sh with the following configuration settings. (Note: these settings are the same as
in previous versions, except for the addition of --security-protocol SASL_PLAINTEXT.)
./bin/kafka-console-consumer.sh --zookeeper c6401.ambari.apache.org:2181 --topic test_topic --from-beginning --
security-protocol SASL_PLAINTEXT
Issue: If you launch the consumer from the command-line interface without specifying the security-protocol option,
you will see the following error:
package com.hortonworks.example.kafka.consumer;
import org.apache.kafka.clients.CommonClientConfigs;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRebalanceListener;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.kafka.clients.consumer.ConsumerRecords;
import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.TopicPartition;
import java.util.Collection;
import java.util.Collections;
import java.util.Properties;
23
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
consumerConfig.put(ConsumerConfig.GROUP_ID_CONFIG, "my-group");
consumerConfig.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG,
"earliest");
consumerConfig.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG,
"org.apache.kafka.common.serialization.StringDeserializer");
consumerConfig.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG,
"org.apache.kafka.common.serialization.StringDeserializer");
KafkaConsumer<byte[], byte[]> consumer = new
KafkaConsumer<>(consumerConfig);
TestConsumerRebalanceListener rebalanceListener = new
TestConsumerRebalanceListener();
consumer.subscribe(Collections.singletonList("test-topic"),
rebalanceListener);
while (true) {
ConsumerRecords<byte[], byte[]> records = consumer.poll(1000);
for (ConsumerRecord<byte[], byte[]> record : records) {
System.out.printf("Received Message topic =%s, partition =%s,
offset = %d, key = %s, value = %s\n", record.topic(), record.partition(),
record.offset(), record.key(), record.value());
}
consumer.commitSync();
}
@Override
public void onPartitionsAssigned(Collection<TopicPartition>
partitions) {
System.out.println("Called onPartitionsAssigned with partitions:"
+ partitions);
}
}
# java -Djava.security.auth.login.config=/usr/hdp/
current/kafka-broker/config/kafka_client_jaas.conf
com.hortonworks.example.kafka.consumer.BasicConsumerExample
24
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
Related Information
Appendix: Kerberos Kafka Configuration Options
JAAS Configuration File for the Kafka Server
Apache Ranger User Guide> Adding KAFKA Policies
listeners
A comma-separated list of URIs that Kafka will listen on, and their protocols.
Required property with three parts:
<protocol>:<hostname>:<port>
Set <protocol> to SASL_PLAINTEXT, to specify the protocol that server accepts connections. SASL authentication
will be used over a plaintext channel. Once SASL authentication is established between client and server, the session
will have the client’s principal as an authenticated user. The broker can only accept SASL (Kerberos) connections,
and there is no wire encryption applied. (Note: For a non-secure cluster, <protocol> should be set to PLAINTEXT.)
Set hostname to the hostname associated with the node you are installing. Kerberos uses this value and "principal"
to construct the Kerberos service name. Specify hostname 0.0.0.0 to bind to all interfaces. Leave hostname empty to
bind to the default interface.
Set port to the Kafka service port. When Kafka is installed using Ambari, the default port number is 6667.
Examples of legal listener lists::
listeners=SASL_PLAINTEXT://kafka1.host1.com:6667
listeners=PLAINTEXT://myhost:9092, TRACE://:9091, SASL_PLAINTEXT://0.0.0.0:9093
25
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
advertised.listeners
A list of listeners to publish to ZooKeeper for clients to use, if different than the listeners specified in the preceding
section.
In IaaS environments, this value might need to be different from the interface to which the broker binds.
If advertised.listeners is not set, the value for listeners will be used.
Required value with three parts:
<protocol>:<hostname>:<port>
Set protocol to SASL_PLAINTEXT, to specify the protocol that server accepts connections. SASL authentication
will be used over a plaintext channel. Once SASL authentication is established between client and server, the session
will have the client’s principal as an authenticated user. The broker can only accept SASL (Kerberos) connections,
and there is no wire encryption applied. (Note: For a non-secure cluster, <protocol> should be set to PLAINTEXT.)
Set hostname to the hostname associated with the node you are installing. Kerberos uses this and "principal" to
construct the Kerberos service name.
Set port to the Kafka service port. When Kafka is installed using Ambari, the default port number is 6667.
For example:
advertised.listeners=SASL_PLAINTEXT://kafka1.host1.com:6667
security.inter.broker.protocol
Specifies the inter-broker communication protocol. In a Kerberized cluster, brokers are required to communicate over
SASL. (This approach supports replication of topic data.) Set the value to SASL_PLAINTEXT:
security.inter.broker.protocol=SASL_PLAINTEXT
authorizer.class.name
Configures the authorizer class.
Set this value to kafka.security.auth.SimpleAclAuthorizer:
authorizer.class.name=kafka.security.auth.SimpleAclAuthorizer
For more information, see "Authorizing Access when Kerberos is Enabled."
principal.to.local.class
Transforms Kerberos principals to their local Unix usernames.
Set this value to kafka.security.auth.KerberosPrincipalToLocal:
principal.to.local.class=kafka.security.auth.KerberosPrincipalToLocal
super.users
Specifies a list of user accounts that will have all cluster permissions. By default, these super users have all
permissions that would otherwise need to be added through the kafka-acls.sh script. Note, however, that their
permissions do not include the ability to create topics through kafka-topics.sh, as this involves direct interaction with
ZooKeeper.
Set this value to a list of user:<account> pairs separated by semicolons. Note that Ambari adds user:kafka when
Kerberos is enabled.
Here is an example:
super.users=user:bob;user:alice
26
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
KafkaServer {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
keyTab="/etc/security/keytabs/kafka.service.keytab"
storeKey=true
useTicketCache=false
serviceName="kafka"
principal="kafka/[email protected]";
};
KafkaClient {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
keyTab="/etc/security/keytabs/storm.service.keytab"
storeKey=true
useTicketCache=false
serviceName="kafka"
principal="[email protected]";
};
27
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
KafkaClient {
com.sun.security.auth.module.Krb5LoginModule required
useTicketCache=true
renewTicket=true
serviceName="kafka";
};
KafkaClient {
com.sun.security.auth.module.Krb5LoginModule required
useTicketCache=true
renewTicket=true
serviceName="kafka";
};
Before you enable Kerberos, your cluster must meet the following prerequisites. (Note: )
Prerequisite References
Ambari-managed cluster with Storm installed and running. “Installing, Configuring, and Deploying a Cluster” (link below)
Key Distribution Center (KDC) server installed and running. “Installing and Configuring the KDC” (link below)
JCE installed on all hosts on the cluster (including the Ambari server). “Enabling Kerberos Authentication Using Ambari” (link below)
When all prerequisites are fulfilled, enable Kerberos security. For more information, see “Launching the Kerberos
Wizard (Automated Setup)”.
Related Information
Enabling Kerberos Authentication Using Ambari
Launch the Kerberos Wizard (Automated Setup)
Checklist: Installing and Configuring the KDC
Apache Ambari Installation> Installing, Configuring, and Deploying a Cluster
28
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
Procedure
1. Install the storm package on the node: sudo yum install storm_<version>.
For HDP 2.4: sudo yum install storm_2_4*
2. Create a file at /etc/storm/conf/client_jaas.conf, and add the following entry to it:
StormClient {
com.sun.security.auth.module.Krb5LoginModule required
useTicketCache=true
renewTicket=true
serviceName="nimbus"
};
nimbus.seeds: <nimbus-host-array>
nimbus.thrift.port: 6627
java.security.auth.login.config: "/etc/storm/conf/client_jaas.conf"
storm.thrift.transport:
"org.apache.storm.security.auth.kerberos.KerberosSaslTransportPlugin"
where <nimbus-host-array> is an array of hostnames running Nimbus. (The value should come from /etc/storm/
conf/storm.yaml.)
nimbus.seeds: ["c6401.ambari.apache.org", "c6402.ambari.apache.org"]
Procedure
1. Create a .storm directory in the user's home directory. For example, user john should have a directory called /
home/john/.storm/.
2. Add the following settings to the /etc/storm/conf/storm.yaml configuration file:
nimbus.seeds: <nimbus-host-array>
nimbus.thrift.port: 6627
java.security.auth.login.config: "/etc/storm/conf/client_jaas.conf"
storm.thrift.transport:
"org.apache.storm.security.auth.kerberos.KerberosSaslTransportPlugin"
where <nimbus-host-array> is an array of hostnames running Nimbus (the value should come from /etc/storm/
conf/storm.yaml).
nimbus.seeds: ["c6401.ambari.apache.org", "c6402.ambari.apache.org"]
29
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
What to do next
Repeat these steps for every user who requires Storm access.
Procedure
1. Make sure all users who are going to deploy topologies have a UNIX account on all of the Storm nodes. Workers
will run under the UNIX account for topologies deployed by the user.
For user testuser1 and principal testuser1/c6401.ambari.apache.org, make sure there is a corresponding testuser1
UNIX account.
2. Add the following configuration under "Custom storm-site" in the Ambari Storm configuration screen:
supervisor.run.worker.as.user : true.
3. Restart Storm components.
Procedure
1. Before accessing the UI, configure your browser for SPNEGO authorization, as shown in the following table:
Browser Configuration
30
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
Procedure
1. Make sure UI Kerberos authentication-to-local rules are configured properly. Once a principal from Active
Directory is used for negotiation with MIT KDC, you need a rule to translate it to the local account on the Storm
UI node. Many times those can be copied from core-site.xml.
ui.filter.params:
"type": "kerberos"
"kerberos.principal": "HTTP/nimbus.host1.com"
"kerberos.keytab": "/vagrant/keytabs/http.keytab"
"kerberos.name.rules": "RULE:[2:$1@$0]([jt]t@.*EXAMPLE.COM)s/.*/
$MAPRED_USER/ RULE:[2:$1@$0]([nd]n@.*EXAMPLE.COM)s/.*/$HDFS_USER/DEFAULT"
Note: Rules are listed as strings, and are not separated by commas.
2. Create mappings for MIT domain KDC and associated resources used for the domain, in this case Storm UI.
On a Windows workstation, you would run the following commands from the command line:
ksetup /AddKDC $DOMAIN $KDC
ksetup /AddHostToRealmMap $hadoop_resource $Domain
Note: this step adds registry entries in HKLM\System\CurrentControlSet\Control\Lsa\Kerberos\HostToRealm.
To troubleshoot configuration issues, try accessing the Storm UI within the cluster using the curl command.
For example:
curl -i --negotiate -u:anyUser -b ~/cookiejar.txt -c ~/cookiejar.txt http://storm-ui-hostname:8080/api/v1/cluster/
summary
This will help you determine whether the Kerberos UI configuration is working.
To isolate the issue, use Storm service keytabs and user principals.
Two other important things to check are:
• Make sure that the trust is working properly.
• Make sure that the encryption types match on both KDCs.
31
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
32
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
6. On the supervisor node, edit /etc/storm/conf/storm.yaml. Change the ui.filter.parameters as follows, replacing
<supervisor-hostname> with the hostname of your supervisor process:
"type": "kerberos"
"kerberos.principal": "HTTP/<supervisor-hostname>"
"kerberos.keytab": "/vagrant/keytabs/http.keytab"
7. On each supervisor machine change the Kerberos.principal hostname to that supervisor’s hostname.
8. Restart the log viewer.
9. Add supervisor hosts to network.negotiate-auth.trusted-uris (similar to the steps needed to access the Storm UI).
Related Information
STORM-633
Procedure
1. Log in to Ambari .
2. From the Actions menu, click Add Service.
3. From the services list, select HBase and click Next.
4. Select the location to install HBase Master.
5. Select the nodes to install HBase Region Servers.
6. Review the configuration details and modify it based on your performance tuning needs and then click Next.
You can customize the services later as well.
7. Review the Kerberos Service Principal Name (SPNs) that will be created for HBase deployment and click Next.
8. Review the configuration details and click Deploy.
If Kerberos admin credentials were not stored while enabling Kerberos on HDFS, Ambari will prompt you for the
credentials again.
9. Click Save once credentials are entered.
10. Wait for the installation to complete.
11. Review any errors encountered during installation and click Next.
33
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
Procedure
1. Log in to the Ambari node where HBase client is installed.
2. Start the HBase shell.
3. On the HBase Master host machine, execute the status command:
In this example, the command fails with a stack trace, because there is no TGT. therefore can’t authenticate to
HBase using Kerberos.
4. Get a Ticket Granting Ticket (TGT).
Here are the examples that shows the input and the output for creating a local TGT when you run a kinit operation.
In the first example, you run a `kinit` on the command line first and then run the application. The second example
automatically obtains a TGT through a keytab.
Examplen 1 of secure client:
package com.hortonworks.hbase.examples;
import java.io.IOException;
import java.util.Objects;
34
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.util.Bytes;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Write and read data from HBase, expects HBASE_CONF_DIR and
HADOOP_CONF_DIR on the classpath and a valid Kerberos
* ticket in a ticket cache (e.g. kinit).
*/
public class ExampleSecureClient implements Runnable {
private static final Logger LOG =
LoggerFactory.getLogger(ExampleSecureClient.class);
private static final TableName TABLE_NAME =
TableName.valueOf("example_secure_client");
private static final byte[] CF = Bytes.toBytes("f1");
admin.createTable(TableDescriptorBuilder.newBuilder(tn).setColumnFamily(
ColumnFamilyDescriptorBuilder.of(family)).build());
35
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
table.put(p);
5. Execute the status command again by logging in through principal and keytab.
Example 2 of secure client with keytab login:
package com.hortonworks.hbase.examples;
import java.io.File;
import java.security.PrivilegedAction;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.security.UserGroupInformation;
36
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
UserGroupInformation.setConfiguration(conf);
UserGroupInformation ugi =
UserGroupInformation.loginUserFromKeytabAndReturnUGI(
principal, keytab.getAbsolutePath());
ugi.doAs(new PrivilegedAction<Void>() {
@Override public Void run() {
new ExampleSecureClient(conf).run();
return null;
}
});
}
}
The following example shows the output resulting from the keytab login:
Procedure
1. “Download configurations”
2. “Set up client account”
3. “Access Kerberos-Enabled HBase cluster using a Java client”
37
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
Related Information
Download configurations
Set up client account
Create the Java client
Download configurations
Follow these steps to download the required configurations:
Procedure
1. From Ambari, extract the HBase and HDFS files to conf directory, which will save all the configuration details.
These files must be extracted under the $HBASE_CONF_DIR directory, where $HBASE_CONF_DIR is the
directory to store the HBase configuration files. For example, /etc/hbase/conf.
2. From KDC, download the krb5.conf file from /etc/krb5.con. You can also place the configuration snippets in the
directory.
includedir /etc/krb5.conf.d/
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
dns_lookup_realm = false
ticket_lifetime = 24h
renew_lifetime = 7d
forwardable = true
rdns = false
default_realm = HWFIELD.COM
default_ccache_name = KEYRING:persistent:%{uid}
[realms]
HWFIELD.COM = {
kdc = ambud-hdp-3.field.hortonworks.com
admin_server = ambud-hdp-3.field.hortonworks.com
}
[domain_realm]
.hwfield.com = HWFIELD.COM
hwfield.com = HWFIELD.COM
Procedure
1. Log in to KDC.
2. Switch to root directory.
3. Run kadmin.local:
$ sudo kadmin.local
kadmin.local: addprinc myself
WARNING: no policy specified for [email protected]; defaulting to no
policy
Enter password for principal "[email protected]":
Re-enter password for principal "[email protected]":
38
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
klist -k /etc/security/keytabs/hbase.headless.keytab
Optional step: You should secure the keytab file so that only the HBase process has access to the keytab. This can
be accomplished by running a command.
6. Authorize admin permissions to the user. You can also customize this to restrict this account for minimal access.
For more information see, http://hbase.apache.org/0.94/book/hbase.accesscontrol.configuration.html#d1984e4744
Example
hbase(main):001:0> grant 'myself', 'C'
Procedure
1. Launch Eclipse.
2. Create a simple Maven project.
3. Add the hbase-client and hadoop-auth dependencies.
The client uses the Hadoop UGI utility class to perform a Kerberos authentication using the keytab file. It sets
up the context so that all operations are performed under the hbase-user2 security context. Then, it performs the
required HBase operations, namely check / create table and perform a put and get operations.
<dependencies>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-client</artifactId>
<version>${hbase.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-aws</artifactId>
</exclusion>
</exclusions>
39
Configuring Authentication with Kerberos Configuring HDP Components for Kerberos
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-auth</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>${hadoop.version}</version>
</dependency>
<dependency>
4. Execute the HBase Java client code from a node that can be reverse-DNS resolved.
This is part of Kerberos authentication. Therefore, running it from a machine that does not share the same DNS
infrastructure as the HDP cluster results in authentication failure.
5. To validate that your Kerberos authentication / keytab / principal does indeed work, you can also perform a simple
Kerberos authentication from Java. This provides you with some insight into how Java JAAS and Kerberos works.
It is highly recommended that you use either Maven Shade Plugin or Maven Jar Plugin to automatically package
dependencies into a fat-client JAR. You can also use Eclipse Export feature, however this is not recommended for
production code base.
40