sshでケルベロス認証を使う

提供: セキュリティ
2015年6月14日 (日) 11:02時点におけるDaemon (トーク | 投稿記録)による版 (設定 sshd)

(差分) ←前の版 | 最新版 (差分) | 次の版→ (差分)
移動: 案内検索
スポンサーリンク

Secure Shell(ssh)の認証を ケルベロス認証(kerberos)を用いることができます。Ubuntu の環境にケルベロス認証の環境を構築しました。同様に CentOS などの環境でも同じことができます。

読み方

kerberos
けるべろす

概要

GSS-API(Generic Security Standard Application Programming Interface)は、ケルベロスなどの複数の認証方式にたいして、統一のAPIを提供します。多くのアプリケーションは、GSS-APIを利用して、ケルベロス認証を利用してます。 OpenSSHは、GSS-APIに対応しています。

通常は、3台用意してやるのが良いのでしょうが、ここでは、2台でやっている例になります。

対象OS

ここでは、Ubuntuを利用しています。

サーバ環境構築

ここでは、u2.local というのがサーバにあたります。 レルムは、LOCAL とします。

インストール

sudo apt install krb5-kdc krb5-admin-server

インストール中に /etc/krb5.conf 用の設定を3つほど、確認されます。

  • レルム
  • ケルベロスサーバ (kdc) のサーバ
  • 管理用サーバ
 ┌────────┤ Configuring Kerberos Authentication ├─────────┐
 │ When users attempt to use Kerberos and specify a principal or user name   │ 
 │ without specifying what administrative Kerberos realm that principal      │ 
 │ belongs to, the system appends the default realm.  The default realm may  │ 
 │ also be used as the realm of a Kerberos service running on the local      │ 
 │ machine.  Often, the default realm is the uppercase version of the local  │ 
 │ DNS domain.                                                               │ 
 │                                                                           │ 
 │ Default Kerberos version 5 realm:                                         │ 
 │                                                                           │ 
 │ _________________________________________________________________________ │ 
 │                                                                           │ 
 │                                  <Ok>                                     │
 
 
 
 ┌─────────┤ ケルベロス認証を設定します ├─────────────┐
 │ 利用者がケルベロスを利用しようとするとき、プリンシパルやユーザ名の属する  │ 
 │ ケルベロスの管理レルムを指定せずに使うと、そこにデフォルトのレルムが加え  │ 
 │ られます。デフォルトのレルムはローカルなマシン上のケルベロスサービスのレ  │ 
 │ ルムとしても使われるでしょう。多くの場合、デフォルトのレルムはローカルな  │ 
 │ DNS ドメインを大文字にしたものです。                                      │ 
 │                                                                           │ 
 │ デフォルトのケルベロスバージョン 5 レルム:                                │ 
 │                                                                           │ 
 │ _________________________________________________________________________ │ 
 │                                                                           │ 
 │                                  <了解>                                   │ 
 │                                                                           │ 
 └──────────────────────────────────────┘

krb5_newrealm

$ sudo krb5_newrealm
This script should be run on the master KDC/admin server to initialize
a Kerberos realm.  It will ask you to type in a master key password.
This password will be used to generate a key that is stored in
/etc/krb5kdc/stash.  You should try to remember this password, but it
is much more important that it be a strong password than that it be
remembered.  However, if you lose the password and /etc/krb5kdc/stash,
you cannot decrypt your Kerberos database.
Loading random data
Initializing database '/var/lib/krb5kdc/principal' for realm 'LOCAL',
master key name 'K/M@LOCAL'
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: 
 
 
Now that your realm is set up you may wish to create an administrative
principal using the addprinc subcommand of the kadmin.local program.
Then, this principal can be added to /etc/krb5kdc/kadm5.acl so that
you can use the kadmin program on other computers.  Kerberos admin
principals usually belong to a single user and end in /admin.  For
example, if jruser is a Kerberos administrator, then in addition to
the normal jruser principal, a jruser/admin principal should be
created.
 
Don't forget to set up DNS information so your clients can find your
KDC and admin servers.  Doing so is documented in the administration
guide.

kadm5.acl

sudo vim /etc/krb5kdc/kadm5.acl

kadm5.acl の

# */admin *

の # を外します。

kadmin.local

sudo kadmin.local
kadmin.local: addprinc root
kadmin.local: addprinc root/admin
kadmin.local: addprinc user00

実行例

$ sudo kadmin.local
Authenticating as principal root/admin@LOCAL with password.
kadmin.local:  addprinc -randkey host/u2.local
WARNING: no policy specified for host/u2.local@LOCAL; defaulting to no policy
Principal "host/u2.local@LOCAL" created.
kadmin.local:  ktadd -k /tmp/u2.local.keytab host/u2.local
Entry for principal host/u2.local with kvno 2, encryption type
aes256-cts-hmac-sha1-96 added to keytab WRFILE:/tmp/u2.local.keytab.
Entry for principal host/u2.local with kvno 2, encryption type arcfour-hmac
added to keytab WRFILE:/tmp/u2.local.keytab.
Entry for principal host/u2.local with kvno 2, encryption type des3-cbc-sha1
added to keytab WRFILE:/tmp/u2.local.keytab.
Entry for principal host/u2.local with kvno 2, encryption type des-cbc-crc
added to keytab WRFILE:/tmp/u2.local.keytab.
kadmin.local:

keytabファイルの作成

sudo kadmin.local
kadmin.local: addprinc -randkey host/u2.local
kadmin.local: ktadd -k /tmp/u2.local.keytab host/u2.local

u2.local.keytab を クライアントにコピーして、クライアント:/etc/krb5.keytab に配置します。

設定 sshd

/etc/ssh/sshd_config の設定を変更します。公開鍵認証などをオフにし、ケルベロス認証を有効にします。

PasswordAuthentication yes
PubkeyAuthentication no
RSAAuthentication no
 
KerberosAuthentication yes
KerberosOrLocalPasswd no
KerberosTicketCleanup yes
 
# GSSAPI options
GSSAPIAuthentication yes
GSSAPICleanupCredentials yes
 
UsePAM no

PasswordAuthentication yes でも、パスワードログインは通りません。 KerberosOrLocalPasswd yes にするとパスワードログインも許可されます。

パスワードログイン or ケルベロス認証

  • PasswordAuthentication yes
  • KerberosOrLocalPasswd yes

ケルベロス認証のみ

  • PasswordAuthentication yes
  • KerberosOrLocalPasswd no

sshdの設定をリロードさせます。

sudo service ssh reload

テスト

kinit で、ケルベロスのテストをします。 kinit で、ケルベロスサーバからチケットを取得します。

kinit

klist で、チケットを確認できます。

klist

クライアント環境構築

インストール

sudo apt install krb5-user

設定 ssh

/etc/ssh/ssh_config

    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials yes

設定 /etc/krb5.keytab

サーバ側で作成した u2.local.keytab をコピーして、/etc/krb5.keytab に置きます。 scp する前に、パーミッションを変更しておかないと、ファイルにアクセスできません(rootでscpする場合を除き)。

scp サーバ:/tmp/u2.local.keytab .
sudo cp u2.local/keytab /etc/krb5.keytab

使い方

こんな感じでログインできます。ssh前に kinit しなくてもsshできる。

u1.local$ ssh user00@u2.local

auth.logの出力は以下の通りです。

Jun 13 23:43:19 u2.local krb5kdc[30564]: AS_REQ (6 etypes {18 17 16 23 25 26})
10.0.60.132: NEEDED_PREAUTH: user00@LOCAL for krbtgt/LOCAL@LOCAL, Additional
pre-authentication required
 
Jun 13 23:43:19 u2.local krb5kdc[30564]: AS_REQ (6 etypes {18 17 16 23 25 26})
10.0.60.132: ISSUE: authtime 1434206599, etypes {rep=18 tkt=18 ses=18},
user00@LOCAL for krbtgt/LOCAL@LOCAL
 
Jun 13 23:43:19 u2.local sshd[34669]: Accepted password for user00 from
10.0.60.131 port 44972 ssh2

kinit/klist

$ kinit user00
Password for user00@LOCAL: 
$ klist
Ticket cache: FILE:/tmp/krb5cc_1002
Default principal: user00@LOCAL
 
Valid starting       Expires              Service principal
2015-06-13T23:45:37  2015-06-14T09:45:37  krbtgt/LOCAL@LOCAL
	renew until 2015-06-14T23:45:33

kdestroy でチケットを削除できます。

チケットがないとき

$ sudo klist
klist: Credentials cache file '/tmp/krb5cc_0' not found
[5]    32419 exit 1     sudo klist

ユーザが見つからない場合

$ sudo kinit
kinit: Client 'root@LOCAL' not found in Kerberos database while getting
initial credentials

関連項目




スポンサーリンク