pam_passwdqcを使う

最近の多くのlinuxディストリビューションでは比較的安全なパスワードを使うようにpam_cracklibが有効になっているが、pam_cracklibではrootへのポリシー強制はできない。そりゃrootなんだから当たり前なのだが、最近のVPSや専用サーバの普及でグローバルIPを持ったサーバ管理者(root)が増加して来ており、おかげでクラッカー天国となってきている。
pam_passwdqcとは、pam_cracklibとほぼ同様のBSD界隈でよく使われているpamのプラグインだが、大きな特徴としてrootへのポリシーの強制が可能である事があげられる。
そこで、自信のないグローバルIPを持った情弱サーバ管理者はぜひともpam_passwdqcで自分自身を律してほしいところだ。ツールを入れればそれで完璧という訳ではなく、サーバ管理者自身の自覚が最も大事である事は言うまでもない。

pam_passwdqcのインストール

CentOSの場合、yumで気楽にインストール/アップデートできる。

$ sudo yum install pam_passwdqc
Repository base is listed more than once in the configuration
Repository addons is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package pam_passwdqc.i386 0:1.0.2-1.2.2 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
 Package                Arch           Version                Repository      Size
===================================================================================
Updating:
 pam_passwdqc           i386           1.0.2-1.2.2            base            33 k

Transaction Summary
===================================================================================
Install       0 Package(s)
Upgrade       1 Package(s)

Total download size: 33 k
Is this ok [y/N]: y
Downloading Packages:
pam_passwdqc-1.0.2-1.2.2.i386.rpm                           |  33 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : pam_passwdqc                                                1/2 
  Cleanup        : pam_passwdqc                                                2/2 

Updated:
  pam_passwdqc.i386 0:1.0.2-1.2.2                                                  

Complete!
$ 

設定

インストールしただけでは有効ではないため、/etc/pam.d/system-authを編集して組み込みを行う。pam_cracklibと同居しても構わないがかなりうざいため、入れ替える。

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      /lib/security/$ISA/pam_env.so
auth        sufficient    /lib/security/$ISA/pam_unix.so likeauth nullok
auth        required      /lib/security/$ISA/pam_deny.so

account     required      /lib/security/$ISA/pam_unix.so
account     sufficient    /lib/security/$ISA/pam_succeed_if.so uid < 100 quiet
account     required      /lib/security/$ISA/pam_permit.so

#password    requisite     /lib/security/$ISA/pam_cracklib.so retry=3 reject_username
password    requisite     /lib/security/$ISA/pam_passwdqc.so
password    sufficient    /lib/security/$ISA/pam_unix.so nullok use_authtok md5 shadow
password    required      /lib/security/$ISA/pam_deny.so

session     required      /lib/security/$ISA/pam_limits.so
session     required      /lib/security/$ISA/pam_unix.so

これでどのくらい強力かというと、下手なパスワードを設定すると、パスワードのお手本を示してくれるくらい強力なうえ、rootでも下手なパスワードを無理矢理設定できなくなる。

[root@ns pam.d]# passwd testuser
Changing password for user testuser.

You can now choose the new password or passphrase.

A valid password should be a mix of upper and lower case letters,
digits, and other characters.  You can use an 8 character long
password with characters from at least 3 of these 4 classes, or
a 7 character long password containing characters from all the
classes.  An upper case letter that begins the password and a
digit that ends it do not count towards the number of character
classes used.

A passphrase should be of at least 3 words, 12 to 40 characters
long and contain enough different characters.

Alternatively, if noone else can see your terminal now, you can
pick this as your password: "fig-plank_celery".

Enter new password: 
Weak password: not enough different characters or classes for this length.
Try again.

You can now choose the new password or passphrase.

A valid password should be a mix of upper and lower case letters,
digits, and other characters.  You can use an 8 character long
password with characters from at least 3 of these 4 classes, or
a 7 character long password containing characters from all the
classes.  An upper case letter that begins the password and a
digit that ends it do not count towards the number of character
classes used.

A passphrase should be of at least 3 words, 12 to 40 characters
long and contain enough different characters.

Alternatively, if noone else can see your terminal now, you can
pick this as your password: "cellar!ride-basic".

Enter new password: 
Weak password: not enough different characters or classes for this length.
Try again.

You can now choose the new password or passphrase.

A valid password should be a mix of upper and lower case letters,
digits, and other characters.  You can use an 8 character long
password with characters from at least 3 of these 4 classes, or
a 7 character long password containing characters from all the
classes.  An upper case letter that begins the password and a
digit that ends it do not count towards the number of character
classes used.

A passphrase should be of at least 3 words, 12 to 40 characters
long and contain enough different characters.

Alternatively, if noone else can see your terminal now, you can
pick this as your password: "trap,escape:clergy".

Enter new password: 
Re-type new password: 

このデフォルトの場合、大文字、小文字、数字、記号といった4つの文字クラスで以下の条件となる。

  • 8文字以上で3クラス以上を使うか
  • 7文字以上ですべてのクラスを使う必要がある。
  • 先頭の大文字と最後の数字は使用クラスのカウントに入らない。

この条件はカスタマイズでき、system-authのpam_passwdqcの行に引数を書けば良い。

min=N0,N1,N2,N3,N4 [min=disabled,24,11,8,7]

  • N0 一つの文字クラスだけでパスワードを構成する場合の最小値であり、デフォルトは無効、つまり、一つの文字クラスではパスワードとしては許可しない。
  • N1 二つの文字クラスでパスワードを構成する場合の最小値で、デフォルトは24文字
  • N2 パスフレーズで用いる。
  • N3,N4 三つ/四つの文字クラスでパスワードを構成する場合の最小値

他にもカスタマイズできるが、詳しくはman pam_passwdqcするということで。

デフォルトの状態でも充分強力というのが凄い。