libnss-ldapを設定すると、Linux起動時に以下のようなメッセージが出力されることがある。
udevd[]: nss_ldap: could not connect to any LDAP server as (null) - Can't contact LDAP server udevd[]: nss_ldap: failed to bind to LDAP server ldaps://LDAPSERVER.HERE: Can't contact LDAP server udevd[]: nss_ldap: could not connect to any LDAP server as (null) - Can't contact LDAP server udevd[]: nss_ldap: failed to bind to LDAP server ldaps://LDAPSERVER.HERE: Can't contact LDAP server udevd[]: nss_ldap: could not connect to any LDAP server as (null) - Can't contact LDAP server udevd[]: nss_ldap: failed to bind to LDAP server ldaps://LDAPSERVER.HERE: Can't contact LDAP server udevd[]: nss_ldap: reconnecting to LDAP server (sleeping 4 seconds)
これはLDAPサーバに接続しにいってるんだけど、NICが有効になっていないために接続できず、リトライを繰り返しているという状態。
で、そもそもなんで接続しにいってるかというと、/etc/udev/rules.d/91-permissions.rulesの記述に従ってユーザおよびグループを探すため。
通常LDAPを利用する場合、/etc/nsswitch.confでpasswdとgroupは以下のような感じになってると思う。
passwd: compat ldap group: compat ldap
で、udevがユーザやグループを捜しにまず/etc/passwdやら/etc/groupをみるんだけども、見つからなかったらldapに問い合わせにいくわけで、上記の問題が発生する。
ということで、/etc/passwdやら/etc/groupでそれらが見つかればいい。
ということで以下を打ち込めばOK。
addgroup --system nvram addgroup --system rdma addgroup --system fuse addgroup --system kvm addgroup --system scanner adduser --system --group --shell /usr/sbin/nologin --home /var/lib/tpm tss
ちなみにldapの方を先に参照するように設定していたりする場合は、udevdの起動よりも先にネットワークを起動しないとだめだろう。
proftpdをインストール。
# aptitude install proftpd
debian lennyだと一緒にproftpd-mod-ldapもインストールされる。
なければ入れること。
/etc/proftpd/proftpd.conf
認証時、最初にldapで行うようにし、ldap.confを読み込むように。
ほかは普通に設定。
AuthOrder mod_ldap.c* mod_auth_pam.c* mod_auth_unix.c Include /etc/proftpd/ldap.conf # ログインシェルが定義されていないなら以下も RequireValidShell off
/etc/proftpd/modules.conf
LoadModule mod_ldap.c
/etc/proftpd/ldap.conf
<IfModule mod_ldap.c> # # This is used for ordinary LDAP connections, with or without TLS # LDAPServer 192.168.1.x LDAPDNInfo "cn=admin,dc=waterblue,dc=net" "somepassword" LDAPDoAuth on "ou=Users,dc=waterblue,dc=net" # 以下はLDAP認証したユーザを強制的に特定ユーザにマッピングする設定 # うちの都合 LDAPDefaultUID xx LDAPDefaultGID yy LDAPForceDefaultUID on LDAPForceDefaultGID on </IfModule>
LDAPDNInfoでrootdnのパスワードを記述することになるので、/etc/proftpd/ldap.confのパーミッションを変更。
# chmod 600 /etc/proftpd/ldap.conf
もしくは、LDAPDNInfoを使わず、anonymousでもLDAP認証可能なようにLDAPサーバのアクセス制御を構成しておく。
LDAPサーバの/etc/ldap/slapd.confで
access to attrs=userPassword
by self write
by anonymous auth
by * none
access to *
by self write
by * read
みたいな感じ。
さて、これでリモートからのアクセスが可能になったのはいいんだけども、ぶっちゃけいちいち新規利用ユーザが増えるたびにhtpasswdでユーザを追加しないといけないのはめんどくさい。
じゃあLDAP使えばいいじゃない、という話でmod_ldapを利用することに。
ところが、aptitude search mod_ldapとかしても出てこない。
とりあえずapacheのモジュールディレクトリを眺めてると、authnz_ldapとかいうのが入ってるみたい。
ということでこれを使う。
以前、SambaをWindows NTのドメインコントローラにしようとして結局挫折したんだけど、今日ちこっといじってみたらうまくいったので書き書き。
とりあえず、そこまでの過程は前の記事やらLDAPのタグクラウドから。
で、そこからやってみたこと。
/etc/samba/smb.cnfのglobalセクションに以下を追加
admin users = Administrator
/etc/smbldap-tools/smbldap.confの以下を修正
#hash_encrypt=”SSHA”
hash_encrypt=”CRYPT”
それからsambaを再起動してsmbldap-passwd Administratorをたたいてみた。
ログインできた。
いえっふー。
だいぶ近いところまでいってたんですね、まえまでで。
今のようにXenで仮想化してマシンをもこもこ増やしていると、正直マシンの名前解決が面倒くさい。
かといってDNSは大げさな感じ。
なので、hostsを使う。
でも、毎回新しくドメインを立ち上げるたびにhosts書くのもめんどくさい。
じゃあLDAPにホストの情報登録すればいいじゃない、という話。
リモートからPAMを使ったLDAP認証をするためには、簡単に流れを整理すると
こんな感じになるわけだけども、この間新規にXenの32bitのDomainUを、64bitのDomain0上に立ち上げたときに設定したとき、うまく動かなかった。
症状としては、
とりあえずこの状況で放置プレイしていたんだけども、ようやく時間ができたのでいじってみた。
結果。
# /etc/init.d/nscd restart
キャッシュかよ。
一週間以上たっても変わらないって事は、通知きてない&取りに行ってないないんだな。
罠すぎる。
既存LinuxアカウントをLDAPに移行する際にmigrationtoolsを利用したんだけども、そのとき書き忘れていたことが。
migrationtoolsのスクリプトはshadowパスワードに対応していない。
普通はshadowパスワードを利用しているだろうから、このスクリプトを使って既存LinuxアカウントをLDAPに移行する際には、一旦shadowパスワードを利用しないようにしなければならない。
この変換に使うのがpwunconv, grpunconvだ。
それぞれshadow, gshadowを用いる形式からpasswd, groupに埋め込む形式に変換する。
元通りshadow形式を用いる場合はpwconv, grpconvをたたけばいい。
さて、漸く佳境へ入って参りました。
ドメイン0でLDAPサーバの設定が完了したので、ドメインUの認証をドメイン0のLDAPサーバで行います。
まずはLinuxから。
# aptitude install libnss-ldap libpam-ldap ldap-utils
初期設定の質問に答えて/etc/nsswitch.confでldapを参照するように書き換える。
で、/etc/pam.d以下を編集しようとしたら。。。既に書き換わってる!
ドメインUの方はsid使ってるんですよ。
すげー。
pam.dの設定しないでいいじゃん。
sufficientは推奨しないらしくて使っていない。
理由は、LDAP認証が通っただけでOKとしたくないアプリもあるからだそうだ。
いわれてみればそうだ。
一応設定をさらす。
# grep ^[^#] common-*
common-account:account [success=2 new_authtok_reqd=done default=ignore] pam_unix.so
common-account:account [success=1 default=ignore] pam_ldap.so
common-account:account requisite pam_deny.so
common-account:account required pam_permit.socommon-auth:auth [success=2 default=ignore] pam_unix.so nullok_secure
common-auth:auth [success=1 default=ignore] pam_ldap.so use_first_pass
common-auth:auth requisite pam_deny.so
common-auth:auth required pam_permit.socommon-password:password [success=2 default=ignore] pam_unix.so obscure md5
common-password:password [success=1 user_unknown=ignore default=die] pam_ldap.so use_authtok try_first_pass
common-password:password requisite pam_deny.so
common-password:password required pam_permit.so
common-password:password optional pam_gnome_keyring.socommon-session:session [default=1] pam_permit.so
common-session:session requisite pam_deny.so
common-session:session required pam_permit.so
common-session:session required pam_unix.so
common-session:session optional pam_ldap.so
common-session:session optional pam_ck_connector.so nox11
pamの方の設定はインストールするだけで終わっちゃったよ。
で、/etc/ldap/ldap.confを設定してLDAPサーバをみるようにする。
BASE dc=waterblue,dc=net
URI ldap://192.168.1.x
みえるかテスト。
# ldapsearch -x
見える。一瞬で終わってしまった。
で、次にWindowsをドメイン参加させようとしたんだが、うまくいかない。
smbldap-adduser -w でマシンを登録して smbldap-adduser -aでWindowsユーザとうろくして、Windows側からドメインに参加しようとしてもうまくいかない。
完全につまったのでここまで。
手がかりは以下のエラーログ。
[2009/06/14 15:37:27, 0] lib/smbldap.c:smbldap_open(1029)
smbldap_open: cannot access LDAP when not root
とりあえず権限はこんな感じ。
# net -U administrator rpc rights list
SeMachineAccountPrivilege Add machines to domain
SeTakeOwnershipPrivilege Take ownership of files or other objects
SeBackupPrivilege Back up files and directories
SeRestorePrivilege Restore files and directories
SeRemoteShutdownPrivilege Force shutdown from a remote system
SePrintOperatorPrivilege Manage printers
SeAddUsersPrivilege Add users and groups to the domain
SeDiskOperatorPrivilege Manage disk shares
なにが悪いんだろうか。
LDAPを構築した時点ではユーザは大抵管理者ユーザくらいしかいないので、LDAP認証を用いたい一般ユーザが空っぽ。
で、これを一から作るのは面倒くさい。
ldifなるファイルを作って読こませるのが一般的な流れだ。
今回は既存のLinuxアカウントが結構ある。
こいつらをいちいち取り込むのはハゲる。
で、この子たちをLDAPに移行する素敵なツールがある。
それがmigrationtools。
結局Samba4のActive Directory+LDAPの統一認証機構は諦めて、ひとまずSamba3系でLDAP認証統合をしようと思った。
ということで、インストール開始。
なお、LDAPとPAMの連携はできているものとする。
やり方はこちらのエントリ参照。
samba2系でも動作確認。
まず、smbldap-toolsとsamba、samba-docをインストール
# aptitude install samba samba-doc smbldap-tools
LDAPのスキーマを展開する。
# zcat /usr/share/doc/samba-doc/examples/LDAP/samba.schema.gz >/etc/ldap/schema/samba.schema
/etc/ldap/slapd.confにスキーマの追加と属性へのアクセス制御を修正。
# grep ^[^#] slapd.conf include /etc/ldap/schema/core.schema include /etc/ldap/schema/cosine.schema include /etc/ldap/schema/inetorgperson.schema include /etc/ldap/schema/nis.schema include /etc/ldap/schema/samba.schema pidfile /var/run/slapd/slapd.pid argsfile /var/run/slapd/slapd.args loglevel none modulepath /usr/lib/ldap moduleload back_hdb sizelimit 500 tool-threads 1 backend hdb database hdb suffix "dc=waterblue,dc=net" rootdn "cn=admin,dc=waterblue,dc=net" directory "/var/lib/ldap" dbconfig set_cachesize 0 2097152 0 dbconfig set_lk_max_objects 1500 dbconfig set_lk_max_locks 1500 dbconfig set_lk_max_lockers 1500 index objectClass eq,pres index ou,cn,sn,mail,givenname eq,pres,sub index uidNumber,gidNumber,memberUid eq,pres index loginShell eq,pres index uid pres,sub,eq index displayName pres,sub,eq index nisMapName,nisMapEntry eq,pres,sub index sambaSID eq index sambaPrimaryGroupSID eq index sambaDomainName eq index default sub lastmod on checkpoint 512 30 access to attrs=userPassword,sambaNTPassword,sambaLMPassword,sambaPwdMustChange,sambaPwdLastSet by anonymous auth by self write by * none access to attrs=shadowLastChange,shadowMax by self write by * read access to dn.base="" by * read access to * by * read
/etc/samba/smb.confを設定
[global] workgroup = WATERBLUE netbios name = ms-09 security = user enable privileges = yes server string = Samba Server %v encrypt passwords = true min passwd length = 3 pam password change = yes obey pam restrictions = yes passwd program = /usr/sbin/smbldap-passwd -u "%u" passwd chat = "Changing *\nNew password*" %n\n "*Retype new password*" %n\n" log level = 0 syslog = 0 log file = /var/log/samba/log.%U max log size = 100000 time server = Yes socket options = TCP_NODELAY SO_RCVBUF=8192 SO_SNDBUF=8192 mangling method = hash2 Dos charset = CP932 Unix charset = UTF-8 display charset = UTF-8 domain logons = Yes domain master = Yes os level = 65 preferred master = Yes passdb backend = ldapsam:ldap://127.0.0.1/ ldap admin dn = cn=admin,dc=waterblue,dc=net ldap suffix = dc=waterblue,dc=net ldap group suffix = ou=Groups ldap user suffix = ou=Users ldap machine suffix = ou=Computers add user script = /usr/sbin/smbldap-useradd -m "%u" delete user script = /usr/sbin/smbldap-userdel "%u" add machine script = /usr/sbin/smbldap-useradd -t 0 -w "%u" add group script = /usr/sbin/smbldap-groupadd -p "%g" add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g" delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g" set primary group script = /usr/sbin/smbldap-usermod -g '%g' '%u' load printers = Yes create mask = 0640 directory mask = 0750 nt acl support = No printing = cups printcap name = cups deadtime = 10 guest account = nobody map to guest = Bad User dont descend = /proc,/dev,/etc,/lib,/lost+found,/initrd show add printer wizard = yes preserve case = yes short preserve case = yes case sensitive = no [netlogon] path = /home/netlogon/ browseable = No read only = yes [profiles] path = /home/profiles read only = no create mask = 0600 directory mask = 0700 browseable = No guest ok = Yes profile acls = yes csc policy = disable [printers] comment = Network Printers guest ok = yes printable = yes path = /home/spool/ browseable = No read only = Yes printable = Yes print command = /usr/bin/lpr -P%p -r %s lpq command = /usr/bin/lpq -P%p lprm command = /usr/bin/lprm -P%p %j [print$] path = /home/printers guest ok = No browseable = Yes read only = Yes valid users = @"Print Operators" write list = @"Print Operators" create mask = 0664 directory mask = 0775 [public] path = /tmp guest ok = yes browseable = Yes writable = yes
リモートのldapサーバを利用する場合は、
passdb backend = ldapsam:ldap://LDAPサーバのアドレス/
とする。
ldapのrootdnのパスワードを設定する。
# smbpasswd -W
または
# smbpasswd -w SOMEPASSWD
これをしてないと以下のようなエラーログがでて、smbdが起動しているにもかかわらずポート139にバインドしてくれないっていう悲劇が起きる。
あまりにもこっそり過ぎて数時間はまった。
[2010/06/29 23:41:11, 0] passdb/secrets.c:fetch_ldap_pw(888)
fetch_ldap_pw: neither ldap secret retrieved!
[2010/06/29 23:41:11, 0] lib/smbldap.c:smbldap_connect_system(952)
ldap_connect_system: Failed to retrieve password from secrets.tdb
smbldap-toolsの設定
/etc/smbldap-tools/smbldap.conf
SID=”S-1-5-21-3543083706-895038863-253071269″
sambaDomain=”WATERBLUE”
slaveLDAP=”127.0.0.1″
slavePort=”389″
masterLDAP=”127.0.0.1″
masterPort=”389″
ldapTLS=”0″
verify=”require”
cafile=”/etc/smbldap-tools/ca.pem”
clientcert=”/etc/smbldap-tools/smbldap-tools.pem”
clientkey=”/etc/smbldap-tools/smbldap-tools.key”
suffix=”dc=waterblue,dc=net”
usersdn=”ou=Users,${suffix}”
computersdn=”ou=Computers,${suffix}”
groupsdn=”ou=Groups,${suffix}”
idmapdn=”ou=Idmap,${suffix}”
sambaUnixIdPooldn=”sambaDomainName=${sambaDomain},${suffix}”
scope=”sub”
hash_encrypt=”SSHA”
crypt_salt_format=”%s”
userLoginShell=”/bin/bash”
userHome=”/home/%U”
userHomeDirectoryMode=”701″
userGecos=”System User”
defaultUserGid=”513″
defaultComputerGid=”515″
skeletonDir=”/etc/skel”
defaultMaxPasswordAge=”45″
userSmbHome=”\\ms-09\%U”
userProfile=”\\ms-09\profiles\%U”
userHomeDrive=”Z:”
userScript=”logon.bat”
mailDomain=”waterblue.net”
with_smbpasswd=”0″
smbpasswd=”/usr/bin/smbpasswd”
with_slappasswd=”0″
slappasswd=”/usr/sbin/slappasswd”
rootdn “cn=admin,dc=waterblue,dc=net”
/etc/smbldap-tools/smbldap_bind.conf
slaveDN=”cn=admin,dc=waterblue,dc=net”
slavePw=”SOMEPASSWD”
masterDN=”cn=admin,dc=waterblue,dc=net”
masterPw=”SOMEPASSWD”
なお、SIDは以下のコマンドで取得。
# net getlocalsid
設定が完了したらsambaとldapの連携の実行
# smbldap-populate -k 0
んでもってindexの作成。
# sudo -u openldap slapindex
これで完了。
ふいー、ちかれた。
あともちっと残ってるけどそれは明日。

Categories
Tag Cloud
Blog RSS
Comments RSS
Last 50 Posts
Back
Void « Default
Life
Earth
Wind
Water
Fire
Light 