Help us understand the problem. What is going on with this article?

Kerberosインストール手順

More than 1 year has passed since last update.

HadoopをKerberos化するために頑張った手順。まずはKerberosのインストール編。

環境

  • CentOS 7.2

準備

ドメイン名の設定

nmcliを使って、ドメイン名を設定します。今回はKerberosのレルムをEXAMPLE.COMにするので、それの小文字版にします。

# nmcli c modify enp0s3 ipv4.dns-search example.com
# systemctl restart NetworkManager
# cat /etc/resolv.conf 
# Generated by NetworkManager
search example.com
nameserver 220.152.38.233
nameserver 220.152.38.201

ホスト名の設定

nmcliで同様にホスト名を設定します。好きな名前を付けます。

# nmcli general hostname
localhost.localdomain
# nmcli general hostname locke.example.com
# nmcli general hostname
locke.example.com
# cat /etc/hostname
locke.example.com

Chronyの設定

時刻同期サービスの設定をします。

# vim /etc/chrony.conf
# systemctl start chronyd.service
# systemctl enable chronyd.service
# chronyc sources -v
210 Number of sources = 4

  .-- Source mode  '^' = server, '=' = peer, '#' = local clock.
 / .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| /   '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
||                                                 .- xxxx [ yyyy ] +/- zzzz
||      Reachability register (octal) -.           |  xxxx = adjusted offset,
||      Log2(Polling interval) --.      |          |  yyyy = measured offset,
||                                \     |          |  zzzz = estimated error.
||                                 |    |           \
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^- 122x215x240x51.ap122.ftth     2   8   377   154  -1541us[-1786us] +/-   44ms
^* balthasar.gimasystem.jp       3   8   377    20  -3096us[-3368us] +/-   13ms
^- s97.GchibaFL4.vectant.ne.     2   8   377   154  +1543us[+1298us] +/-   38ms
^- srcf-ntp.stanford.edu         1   8   377   148  +3873us[+3629us] +/-   67ms

Kerberosのインストール

Kerberosのサーバパッケージとクライアントパッケージをインストールします。

# yum install krb5-server krb5-workstation

KDCの設定

Kerberosの鍵を保管するKDCの設定を行います。
暗号化方式としてDESを除外しておきます。

/var/kerberos/krb5kdc/kdc.conf
[kdcdefaults]
 kdc_ports = 88
 kdc_tcp_ports = 88

[realms]
 EXAMPLE.COM = {
  master_key_type = aes256-cts
  acl_file = /var/kerberos/krb5kdc/kadm5.acl
  dict_file = /usr/share/dict/words
  admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab
  supported_enctypes = aes256-cts:normal aes128-cts:normal arcfour-hmac:normal
  #supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal
 }

KDCの初期化を行います。

# kdb5_util create -r EXAMPLE.COM -s
Loading random data
Initializing database '/var/kerberos/krb5kdc/principal' for realm 'EXAMPLE.COM',
master key name 'K/M@EXAMPLE.COM'
You will be prompted for the database Master Password.
It is important that you NOT FORGET this password.
Enter KDC database master key: 
Re-enter KDC database master key to verify: 

クライアントの設定

Kerberosのクライアント設定をします。
利用するレルムの設定とKDCサーバの設定がメインです。

/etc/krb5.conf
[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 = EXAMPLE.COM
 # default_ccache_name = KEYRING:persistent:%{uid}

[realms]
 EXAMPLE.COM = {
  kdc = locke.example.com
  admin_server = locke.example.com
 }

[domain_realm]
 .example.com = EXAMPLE.COM
 example.com = EXAMPLE.COM

ハマりどころ

default_ccache_nameの設定を残していると、HadoopをKerberos化した際にHadoop関連コマンドが動作しなくなった。

16/03/17 02:19:30 WARN security.UserGroupInformation: PriviledgedActionException as:alice (auth:KERBEROS) cause:java.io.IOException: javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos txt)]

MIT Kerberosのマニュアルを読んだところ、このパラメータはチケットキャッシュの保存名を制御するらしい。で、もともと書かれているKEYRINGはカレントユーザしかアクセスできないメモリ上に保存する挙動になるとのこと。

default_ccache_name
This relation specifies the name of the default credential cache. The default is DEFCCNAME. This relation is subject to parameter expansion (see below). New in release 1.11.

http://web.mit.edu/Kerberos/krb5-1.12/doc/admin/conf_files/krb5_conf.html#krb5-conf-5

KEYRING is Linux-specific, and uses the kernel keyring support to store credential data in unswappable kernel memory where only the current user should be able to access it. The following residual forms are supported:

http://web.mit.edu/KERBEROS/krb5-1.13/doc/basic/ccache_def.html

デフォルトはDEFCCNAMEで、これはファイルシステム上(/tmp/krb5cc_%{uid})に保存する挙動になる。どうやらHadoopのコマンドはこの挙動を前提としているようだ。

KDC起動

KDCとKadminサーバを起動しておきます。

# systemctl start krb5kdc
# systemctl start kadmin

プリンシパル設定

ここまででKerberosを使った認証が利用できるはずなので、適当なユーザで試します。

まずは、kadmin.localを使ってプリンシパルを作成します。作成するのはaliceユーザのプリンシパルです。

# kadmin.local 
Authenticating as principal root/admin@EXAMPLE.COM with password.
kadmin.local:  listprincs 
K/M@EXAMPLE.COM
kadmin/admin@EXAMPLE.COM
kadmin/changepw@EXAMPLE.COM
kadmin/locke.example.com@EXAMPLE.COM
kiprop/locke.example.com@EXAMPLE.COM
krbtgt/EXAMPLE.COM@EXAMPLE.COM
kadmin.local:  addprinc alice/locke.example.com
WARNING: no policy specified for alice/locke.example.com@EXAMPLE.COM; defaulting to no policy
Enter password for principal "alice/locke.example.com@EXAMPLE.COM": 
Re-enter password for principal "alice/locke.example.com@EXAMPLE.COM": 
Principal "alice/locke.example.com@EXAMPLE.COM" created.
kadmin.local:  quit

動作確認

作成したプリンシパルで認証が通るかを確認します。

# su - alice
$ kinit alice/locke.example.com
Password for alice/locke.example.com@EXAMPLE.COM: 
[alice@locke ~]$ klist -e
Ticket cache: KEYRING:persistent:1000:1000
Default principal: alice/locke.example.com@EXAMPLE.COM

Valid starting       Expires              Service principal
2016-03-17T00:08:27  2016-03-18T00:08:27  krbtgt/EXAMPLE.COM@EXAMPLE.COM
    Etype (skey, tkt): aes256-cts-hmac-sha1-96, aes256-cts-hmac-sha1-96 

以上!

HadoopのKerberos化」編につづく。。。

bwtakacy
お仕事:データリサーチエンジニア 技術:C/Java/Python, PostgreSQL/Hadoop/Spark/TreasureData, 機械学習, DeepLearning
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした