PAM

提供: ArchWiki
2016年5月28日 (土) 22:33時点におけるKusakata (トーク | 投稿記録)による版 (ページの作成:「Category:カーネル Category:セキュリティ en:PAM {{Related articles start}} {{Related|セキュリティ}} {{Related|pam_mount}} {{Related|pam_usb}} {...」)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

関連記事

Linux Pluggable Authentication Modules (PAM) はシステム共通のユーザー認証フレームワークです。プロジェクトホームページ からの引用:

PAM は認証スキームに依存しないプログラムを開発する道筋を提供します。認証時には「認証モジュール」が使用されます。どの認証モジュールが使用されるかはローカルのシステム設定にあわせて決められるため、ローカルのシステム管理者が自由に設定することができます。

この記事ではローカル・リモートユーザーを認証するために Arch Linux で使われている PAM の設定について説明します。デフォルト設定に変更を加える方法はトピックごとに別々に分かれています。

インストール

pam パッケージは base グループに含まれているため、最初からシステムにインストールされています。PAM モジュールは /usr/lib/security にインストールされます。

リポジトリには多数の PAM パッケージが存在します。#設定方法に例を示します。

設定

PAM に関係する /etc のパスは多数存在します。pacman -Ql pam |grep /etc を実行して、作成されているデフォルト設定ファイルを確認してください。モジュールの セキュリティパラメータPAM ベーススタックの設定を変えることができます。

セキュリティパラメータ

/etc/security には認証メソッドが用意している変数のシステム全体の設定が含まれます。ベースインストールを行うことでデフォルトの設定ファイルが作られます。

Arch Linux は上流に存在しない設定を作ることはないので注意してください。例えば、/etc/security/pwquality.conf ファイルを使うことでパスワードの品質についてシステム全体のデフォルト設定を定義することができます。さらに、その設定を有効にするには pam_pwquality.so モジュールを PAM ベーススタックに追加しなくてはなりません。

Arch Linux でデフォルトで有効になっていない設定はセキュリティパラメータの設定を見てください。

PAM ベーススタック

The /etc/pam.d/ path is exclusive for the PAM configuration to link the applications to the individual systems' authentication schemes. During installation of the system base it is populated by:

  • the pambase package, which contains the base-stack of Arch Linux specific PAM configuration to be used by applications, and
  • other base packages. For example, util-linux adds configuration for the central login and other programs, the shadow package adds the Arch Linux defaults to secure and modify the user database (see Users and groups).

The different configuration files of the base installation link together, are stacked during runtime. For example, on a local user logon, the login application sources the system-local-login policy, which in turn sources others:

/etc/pam.d/
login -> system-local-login -> system-login -> system-auth

For a different application, a different path may apply. For example, openssh installs its sshd PAM policy:

/etc/pam.d/
sshd -> system-remote-login -> system-login -> system-auth

Consequently, the choice of the configuration file in the stack matters. For the above example, a special authentication method could be required for sshd only, or all remote logins by changing system-remote-login; both changes would not affect local logins. Applying the change to system-login or system-auth instead would affect local and remote logins.

Like the example of sshd, any pam-aware application is required to install its policy to /etc/pam.d in order to integrate and rely on the PAM stack appropriately. If an application fails to do it, the /etc/pam.d/other policy is applied per default. A permissive policy for it is installed per default (FS#48650).

ヒント: PAM is dynamically linked at runtime. For example:
$ ldd /usr/bin/login |grep pam
libpam.so.0 => /usr/lib/libpam.so.0 (0x000003d8c32d6000)
libpam_misc.so.0 => /usr/lib/libpam_misc.so.0 (0x000003d8c30d2000)
the login application is pam-aware and must, therefore, have a policy.

The PAM package manual pages pam(8) and pam.d(5) describe the standardized content of the configuration files. In particular they explain the four PAM groups: account, authentication, password, and session management, as well as the control values that may be used to configure stacking and behaviour of the modules.

Additionally, an extensive documentation is installed to /usr/share/doc/Linux-PAM/index.html which, among various guides, contains browsable man pages for each of the standard modules.

警告: Changes to the PAM configuration fundamentally affect user authentication. Erroneous changes can result in that no or any user can log in. Since changes are not effective for already authenticated users, a good precaution is to perform changes with one user and test the result with another user in a separate console.

サンプル

Two short examples to illustrate the above warning.

First, we take the following two lines:

/etc/pam.d/system-auth
auth      required  pam_unix.so     try_first_pass nullok
auth      optional  pam_permit.so

From man pam_unix: "The authentication component pam_unix.so performs the task of checking the users credentials (password). The default action of this module is to not permit the user access to a service if their official password is blank. " - the latter being what pam_permit.so is used for. Simply swapping the control values required and optional for both lines is enough to disable password authentication, i.e. any user may logon without providing a password.

Second, as the contrary example, per default configuration creating the following file:

# touch /etc/nologin 

results in that no user other than root may login (if root logins are allowed, another default for Arch Linux). To allow logins again, remove the file from the console you created it with.

With that as background, see #PAM stack and module configuration for particular use-case configuration.

設定方法

このセクションでは PAM の設定に変更を適用する方法や新しい PAM モジュールを PAM スタックに追加する方法が載っている記事をまとめています。大抵の場合、モジュールの man ページは .so 拡張子を省くことで閲覧することができます。

セキュリティパラメータの設定

以下のセクションでは PAM パラメータのデフォルト設定を変更する例を提示しています:

pam_cracklib.so を使って強固なパスワードを強制する方法。
pam_tally.so を使ってログインの試行回数を制限する方法。
pam_wheel.so を使ってユーザーのログインを制限する。
pam_limits.so を付かてシステムのプロセス数を制限する方法。

PAM スタックとモジュールの設定

以下の記事では特定のユースケースにあわせて PAM ベーススタックを変更する方法が載っています。

公式リポジトリに存在する PAM モジュール:

pam_mount.so を使ってユーザーのログイン時に暗号化されたディレクトリパスを自動的にマウントする例が載っています。
pam_ecryptfs.so を使用して暗号化されたディレクトリを自動でマウントします。
pam_exec.so を使用してユーザーのログイン時にカスタムスクリプトを実行する方法。
pam_winbind.sopam_krb5.so を使用して Active Directory (LDAP, Kerberos) サービスでユーザーの認証を行います。
pam_ldap.so による LDAP クライアントの統合やサーバーサイド認証に関する記事。
PAM スタックの pam_yubico.so を使ってプロプライエタリな Yubikey を使って認証を行う。
pam_oath.so による二段階認証を使用するソフトウェアを実装する例。

Arch User Repository に存在する PAM モジュール:

USB デバイスを使って認証を行うように pam_usb.so を設定する方法。
pam_ssh.so を使ってリモートユーザーとして認証。
pam_abl.so を使って SSH からのブルートフォース攻撃を抑える方法。
pam_encfs.so で自動マウント。
pam_google_authenticator.so で二段階認証を設定する方法。
pam_pwdfile.so で FTP chroot を設定してローカルのシステムアカウントがなくてもユーザーを認証する方法。

他の PAM パッケージ

上記で紹介したパッケージ以外にも、Arch User Repository には多数の PAM モジュールやツールが存在します。

PAM に関連する汎用的なユーティリティは以下の通りです:

  • libx32_pam — Arch Linux PAM x32 ABI ライブラリ。
http://linux-pam.org/ || libx32-pamAUR
  • Pamtester — Pluggable Authentication Module (PAM) の機能をテストするプログラム。
http://pamtester.sourceforge.net/ || pamtesterAUR

AUR には PAM というキーワードタグが存在しますが、全てのパッケージにタグが付いているわけではありません。そのため、場合によっては パッケージの説明文 で検索する必要があります。

参照