はじめに
デフォルトのESXiのパスワードのポリシーはちょっときつめで、今利用している開発環境のパスワードのポリシーと合わない。 そこで、ESXiのパスワードのポリシーを少し緩めることにした。
変更方法
ファイル/etc/pam.d/passwd
にパスワードのポリシーの設定があるので、これを書き換えることで変更できる。
デフォルトの/etc/pam.d/passwd
の内容は以下の通り。
#%PAM-1.0 # Change only through host advanced option "Security.PasswordQualityControl". password requisite /lib/security/$ISA/pam_passwdqc.so retry=3 min=disabled,disabled,disabled,7,7 password sufficient /lib/security/$ISA/pam_unix.so use_authtok nullok shadow sha512 password required /lib/security/$ISA/pam_deny.so
ここで、min=disabled,disabled,disabled,7,7
の部分がパスワードの最小文字数の設定になる。
passwdqcのドキュメントによると、min
のフォーマットはmin=N0,N1,N2,N3,N4
であり、各項目の意味は以下の通りである。
項目 | 対象 | 意味 | 既定値 |
---|---|---|---|
N0 | パスワード | 文字クラス1の場合の長さ | disabled |
N1 | パスワード | 文字クラス2の場合の長さ | 24 |
N2 | パスフレーズ | 全体の長さ | 11 |
N3 | パスワード | 文字クラス3の場合の長さ | 8 |
N4 | パスワード | 文字クラス4の場合の長さ | 7 |
文字クラスとは、パスワードが何種類の文字で構成されているかを示すもの。 passwdqcは、文字を以下の4種類に分けている。
- 数字
- アルファベット小文字
- アルファベット大文字
- その他 (記号など)
例えば、hello
は文字クラス1、hello,world!
は文字クラス2、Hello,World!
は文字クラス3となる。
各項目の値について、0の場合は最小文字数の制限なしとなり、disabledの場合はその文字クラスは利用できなくなる。
これらを踏まえて、min=disabled,6,6,6,6
と書き換えることにした。
書き換え後のファイル/etc/pam.d/passwd
の内容は以下の通り。
#%PAM-1.0 # Change only through host advanced option "Security.PasswordQualityControl". password requisite /lib/security/$ISA/pam_passwdqc.so retry=3 min=disabled,6,6,6,6 password sufficient /lib/security/$ISA/pam_unix.so use_authtok nullok shadow sha512 password required /lib/security/$ISA/pam_deny.so
動作確認
普段のポリシーをもとにパスワードを変更してみる。
$ passwd Changing password for root 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 a 6 character long password with characters from at least 2 of these 4 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, 6 to 40 characters long, and contain enough different characters. Alternatively, if no one else can see your terminal now, you can pick this as your password: "sweet+Jolt$Trip". Enter new password: ←●パスワードを入力 Re-type new password: ←●パスワードを入力 passwd: password updated successfully
無事、パスワードの変更が完了した。
補足 - N0
〜 N4
の大小関係について
結論から言うと、以下のような大小関係を満たす必要がある。
N0 >= N1 >= N2 >= N3 >= N4
つまり、利用している文字の種類が少ない場合は長さでカバーしろ、という方針だと思われる。 読み落としやすいが、passwdqcのドキュメントには、以下の記載がある。
Each subsequent number is required to be no larger than the preceding one.
最初、N2
はパスフレーズのパラメータなので無関係と思い、min=disabled,6,disabled,6,6
としていた。
この設定でパスワードを変更しようとすると、以下のようにInvalid parameter value
とエラーになった。
$ passwd Changing password for root pam_passwdqc: Error parsing parameter "min=disabled,6,disabled,6,6": Invalid parameter value. passwd: Critical error - immediate abort passwd:
エラーメッセージが大雑把で原因が分からないので、passwdqcのソースコードを確認したところ、以下のようであった。
static int parse_option(passwdqc_params_t *params, char **reason, const char *option) { // ... if ((p = skip_prefix(option, "min="))) { for (i = 0; i < 5; i++) { if (!strncmp(p, "disabled", 8)) { v = INT_MAX; ←●disabledの時の値はINT_MAX p += 8; } else { v = strtoul(p, &e, 10); p = e; } if (i < 4 && *p++ != ',') goto parse_error; if (v > INT_MAX) goto parse_error; if (i && (int)v > params->qc.min[i - 1]) ←●ひとつ前と大小関係を比較 goto parse_error; params->qc.min[i] = v; } if (*p) goto parse_error; } else if ((p = skip_prefix(option, "max="))) {
ソースコードによると、disabled
と指定された時の実際の値はINT_MAX(=環境にもよるが2147483647とか)になる。
なので、min=disabled,6,disabled,6,6
はmin=2147483647,6,2147483647,6,6
と解釈され、大小関係を満たせずにエラーになる、という挙動みたいだ。
参考
ESXi Passwords and Account Lockout
passwdqc
passwdqcのパラメータのパーサのソースコード
passwdqcのドキュメントから
min
の説明を抜粋
min=N0,N1,N2,N3,N4
(min=disabled,24,11,8,7) The minimum allowed password lengths for different kinds of passwords/passphrases. The keyword disabled can be used to disallow passwords of a given kind regardless of their length. Each subsequent number is required to be no larger than the preceding one.
N0 is used for passwords consisting of characters from one character class only. The character classes are: digits, lower-case letters, upper-case letters, and other characters. There is also a special class for non-ASCII characters, which could not be classified, but are assumed to be non-digits.
N1 is used for passwords consisting of characters from two character classes that do not meet the requirements for a passphrase.
N2 is used for passphrases. Note that besides meeting this length requirement, a passphrase must also consist of a sufficient number of words (see the passphrase option below).
N3 and N4 are used for passwords consisting of characters from three and four character classes, respectively.
When calculating the number of character classes, upper-case letters used as the first character and digits used as the last character of a password are not counted.
In addition to being sufficiently long, passwords are required to contain enough different characters for the character classes and the minimum length they have been checked against.