FTPアカウントにLDAP
LDAPに対応しているアプリケーションは数多く存在するため、
通常であれば、
しかし、
さて、
開発者にとってのメリットとしては、
もう1つの方法は、
それではFTP専用アカウント、
必要な項目 | 必要な理由 | 例 |
---|---|---|
ユーザ | 認証に使用するため | ftpuser |
パスワード | 認証に使用するため | ftppass |
ホームディレクトリ | ログイン時のホームディレクトリ | /home/ |
UID番号 | ファイル作成時などに使用される | 10000 |
GID番号 | ファイル作成時などに使用される | 10000 |
グループ名 | ls-laなどでGID番号だけでなくグループ名が表示されるように | sales |
標準スキーマで用意されている属性を使えば、
# FTPグループ
dn: cn=sales,ou=FTPGroup,dc=example,dc=com
cn: sales
gidNumber: 10000
# FTPユーザ
dn: uid=ftpuser, ou=ftpuser, dc=example, dc=com
uid: ftpuser
userPassword: ftppass
homeDirectory: /home/ftproot/ftpuser
uidNumber: 10000
gidNumber: 10000
とりあえずは必要な属性のみを列挙してみましたが、
gidNumberが含まれるobjectClassは次のように定義されています。
objectclass ( 1.3.6.1.1.1.2.2 NAME 'posixGroup' SUP top STRUCTURAL
DESC 'Abstraction of a group of accounts'
MUST ( cn $ gidNumber )
MAY ( userPassword $ memberUid $ description ) )
ということで、
objectclass ( 1.3.6.1.1.1.2.0 NAME 'posixAccount' SUP top AUXILIARY
DESC 'Abstraction of an account with POSIX attributes'
MUST ( cn $ uid $ uidNumber $ gidNumber $ homeDirectory )
MAY ( userPassword $ loginShell $ gecos $ description ) )
このposixAccountというobjectClassを使用するためには、
よって、
dn: dc=example,dc=com
objectClass: dcObject
objectClass: organization
dc: example
o: example
dn: ou=FTPGroup,dc=example,dc=com
objectClass: organizationalUnit
ou: FTPGroup
dn: ou=FTPUser,dc=example,dc=com
objectClass: organizationalUnit
ou: FTPUser
dn: cn=sales,ou=FTPGroup,dc=example,dc=com
objectClass: posixGroup
cn: sales
gidNumber: 10000
dn: cn=ftpuser, ou=FTPUser, dc=example, dc=com
objectClass: posixAccount
objectClass: account
cn: ftpuser
uid: ftpuser
userPassword: {SSHA}uuj0BIaaMIPrmjBZy8NBD0kTB7XSCSLb
homeDirectory: /home/ftproot/ftpuser
uidNumber: 10000
gidNumber: 10000
スキーマファイルの読み方に関しては、
FTPサーバの設定
冒頭で述べたよう、
% tar xfv proftpd-1.3.0a.tar.bz2 % cd proftpd-1.3.0a % ./configure --with-modules=mod_ldap % make # make install
proftpdの設定
ここでは必要最低限の設定のみを行います。
DefaultServer on
RequireValidShell off
LDAPServer 10.0.100.10
LDAPDoAuth on "dc=example,dc=com" "(&(cn=%v)(objectClass=posixAccount))"
LDAPDoUIDLookups on "ou=FTPUser,dc=example,dc=com"
LDAPDoGIDLookups on "ou=FTPGroup,dc=example,dc=com"
Proftpdはさまざまなオプションを備えていますので、
- LDAP内のFTPユーザにシェルは必要ないためRequireValidShell offを定義
- LDAPサーバの場所をLDAPServerで定義する
- 検索ベースをdc=example,dc=comとし、
検索条件を (&(cn=ユーザ名)(objectClass=posixAccount)) とする (そこで見つかったユーザのDNとFTPセッションで入力されたパスワードを元に再度バインドを行い認証する) - ou=FTPUser,dc=example,dc=comツリー以下よりUID情報の検索を行う
- ou=FTPGroup,dc=example,dc=comツリー以下よりGID情報の検索を行う
設定ファイル中のLDAPDoUIDLookupsとLDAPDoGIDLookupsは必須ではないのですが、
> ls -la drwxr-xr-x 2 (?) (?) 4096 Sep 11 07:48 . drwxr-xr-x 3 root root 4096 Sep 11 07:47 ..
これでは気持ち悪いので、
> ls -la drwxr-xr-x 2 ftpuser sales 4096 Sep 11 07:48 . drwxr-xr-x 3 root root 4096 Sep 11 07:47 ..
このような表示となりすっきりします。設定が終わったら図2のようにproftpdを起動して、
# /usr/local/sbin/proftpd
まとめ
Proftpdには今回紹介したオプション以外にも、
ftpEnabledなどといった独自の属性を定義して、
LDAPDoAuth on "dc=example,dc=com" "(&(cn=%v)(objectClass=posixAccount)(ftpEnabled=1))"
とするのもおもしろそうですね。さまざまなオプションを組み合わせて、