#author("2024-09-25T12:59:02+00:00;2021-08-04T20:18:32+00:00","default:sysosa","sysosa") #author("2024-09-25T13:00:37+00:00;2021-08-04T20:18:32+00:00","default:sysosa","sysosa") 下図のように別のネットワーク(private.local)に存在する&color(orangered){''AD''};で&color(blueviolet){''LinuxPC/MacOSX''}; のアカウント管理を行いたい。 間には、&color(mediumvioletred){''NATルータ''};が存在している。 素直に &color(blueviolet){''LinuxPC/MacOSX''}; をsybyl.localに存在したまま、private.localのADドメインに参加させればいいのだが、 それは&color(mediumvioletred){''NAT''};のため kerberosの仕様的に無理みたい。 &ref(2016y09m12d_183550161.png,nolink,noborder); なので&color(mediumvioletred){''NATルータ(pfsense)''};にLDAPの&color(magenta){ポートフォワード};を適用させ、&color(mediumvioletred){''NATルータ''};をLDAPサーバに見立てた(sybyl.local側から見て)。 基本的にSAMBA ActiveDirectoryをLDAPサーバとして使用する感じでしょうか MacOSXの場合[[samba/LDAP/MacOSX]] NAT越しのNFS設定[[router/NFS]] [[samba/LDAP/smb]] ***pfsenseの設定 [#gf95b0e4] 「Firewall」-->「NAT」-->「PortForward」ページにて、下記のように&color(magenta){ポートフォワード};を用意する &ref(2016y09m18d_004728134.png,nolink,noborder); &color(red){*};&size(10){LDAPのport 389に穴を開けます}; &color(red){*};&size(10){pfsenseの設定なのだが、WAN側(sybyl.local)からpfsense「This Firewall」へのport386は、10.10.0.102のport386へ転送させている}; ***接続方法 [#i6cee2c4] 方法は[[https://wiki.samba.org/index.php/Nslcd>+https://wiki.samba.org/index.php/Nslcd]]に記載されている。 ここでは、ADサーバに仲介役のユーザを設けて、そのユーザを使う方法「Method 1: Connecting to AD via Bind DN and password」を使用する。 &color(white,red){注意}; CVE-2016-2112でsambaのLDAP通信が脆弱と指摘され、 #code(nonumber){{ ldap server require strong auth = yes }} が定義された。これで既定で署名されたあるいは暗号化された通信になったのだが、以下に示す方法を用いて samba(LDAP)と繋ぐとエラーになります。なのでこのオプションを''no''としてsambaを動かしてます。 &color(red){*};&size(10){いずれば tls とかで対処すべきなのだが、規模次第かなって思う}; ***ADサーバで仲介役ユーザを作成 [#d49eba05] #code(nonumber){{ [root@ad ~]# /opt/samba/bin/samba-tool user add ldap-connect --random-password --description="LDAP接続ユーザ" [root@ad ~]# /opt/samba/bin/samba-tool user setpassword ldap-connect --newpassword=ldap [root@ad ~]# /opt/samba/bin/samba-tool user setexpiry ldap-connect --noexpiry }} これでユーザ「ldap-connect」、パスワード「ldap」なる"LDAP接続ユーザ"が作成された。 ***CentOS8で接続なら [#wed2b142] 参照先: [[https://alfa.faqserv.com/pukiwiki/?Linux/RHEL8/LDAP%E8%AA%8D%E8%A8%BC]] [[https://tylersguides.com/guides/configuring-ldap-authentication-on-centos-8/]] 「nss-pam-ldapd」と「nscd」パッケージをインストールして、authselect向けの「nslcd」プロファイルを作成する. #code(nonumber){{ dnf install nss-pam-ldapd nscd cp -Rp /usr/share/authselect/default/sssd /etc/authselect/custom/nslcd cd /etc/authselect/custom/nslcd sed -i 's/sss/ldap/g' fingerprint-auth sed -i 's/sss/ldap/g' password-auth sed -i 's/sss/ldap/g' smartcard-auth sed -i 's/sss/ldap/g' system-auth sed -i 's/sss/ldap/g' nsswitch.conf sed -i 's/SSSD/NSLCD/g' REQUIREMENTS echo "Enable nslcd for system authentication" > README cp /etc/nslcd.conf /etc/nslcd.conf.orig sed '/^#/d' /etc/nslcd.conf.orig | sed '/^$/d' > /etc/nslcd.conf }} 「/etc/nslcd.conf」を修正 #code(nonumber){{ uid nslcd gid ldap uri ldap://192.168.0.72/ base dc=private,dc=local ssl no tls_cacertdir /etc/openldap/cacerts pagesize 1000 referrals off filter passwd (objectClass=user) filter group (objectClass=group) map passwd uid sAMAccountName map passwd homeDirectory unixHomeDirectory map passwd gecos displayName map passwd gidNumber gidNumber map group cn msSFU30Name map group gidNumber gidNumber binddn cn=ldap-connect,cn=Users,dc=private,dc=local <-- 「binddn ldap-connect@private」でも可 bindpw ldap }} #code(nonumber){{ mkdir /etc/openldap/cacerts systemctl enable nslcd systemctl restart nslcd authselect select custom/nslcd --force }} ***CentOS7で接続なら [#gf967ef5] 「&color(magenta){nss-pam-ldapd};」と「&color(magenta){nscd};」パッケージをインストールします。 #code(nonumber){{ [root@c101 ~]# yum install nss-pam-ldapd nscd }} そして「authconfig-tui」でLDAPを有効にさせて &ref(2020y04m04d_093805956.png,nolink); LDAPの設定は下記のようにします。 &ref(2020y04m04d_093943964.png,nolink); ですが、このままだとsssdがLDAP(AD)との中継に入ります。ここではsssdではなくnscdを使いたいので #code(nonumber){{ [root@c101 ~]# authconfig --enableforcelegacy --disablesssd --enablemkhomedir --update }} を実行します。これでnslcdが稼働します。 そして設定ファイル「&color(darkgreen){/etc/nslcd.conf};」を修正してADの仲介役ユーザで認証を行わせます。 #code(nonumber){{ [root@c101 ~]# cp /etc/nslcd.conf /etc/nslcd.conf.orig [root@c101 ~]# sed '/^#/d' /etc/nslcd.conf.orig | sed '/^$/d' > /etc/nslcd.conf [root@c101 ~]# vi /etc/nslcd.conf uid nslcd gid ldap uri ldap://192.168.0.72/ base dc=private,dc=local ssl no tls_cacertdir /etc/openldap/cacerts pagesize 1000 referrals off filter passwd (objectClass=user) filter group (objectClass=group) map passwd uid sAMAccountName map passwd homeDirectory unixHomeDirectory map passwd gecos displayName map passwd gidNumber gidNumber map group cn msSFU30Name map group gidNumber gidNumber binddn cn=ldap-connect,cn=Users,dc=private,dc=local bindpw ldap [root@c101 ~]# chmod 600 /etc/nslcd.conf [root@c101 ~]# systemctl restart nslcd }} &color(red){*};&size(10){参照サイトにはpasswdのgidNumberをprimaryGroupIDにしているが正しく取れないので、gidNumberへ変更}; &color(red){*};&size(10){あとgroupのcn、gidNumberも修正してます}; &color(red){*};authconfigで修正なら下記のようになるかな #code(nonumber){{ [root@c101 ~]# authconfig --enableldap --enableldapauth --ldapserver="192.168.0.72" \ --ldapbasedn="dc=private,dc=local" --disableldaptls --enableforcelegacy --disablesssd --enablemkhomedir --update (それでも/etc/nslcd.confの修正は必要です) [root@c101 ~]# systemctl restart nslcd }} &color(red){*};&size(10){nslcd.serviceは自動的にenableになるみたい}; もし「&color(red){ldap_result() failed: Can't contact LDAP server};」がmessageに表示されるようなら 「/etc/nslcd.conf」に下記を加える #code(nonumber){{ idle_timelimit 240 }} ***CentOS6で繋げる [#t085053f] 「&color(magenta){pam_ldap};」「&color(magenta){nss-pam-ldapd};」「&color(magenta){nscd};」パッケージが必要 #code(nonumber){{ [root@c102 ~]# yum install pam_ldap nss-pam-ldapd nscd }} インストール後に LDAPからユーザ情報を入手する&color(magenta){nss-pam-ldapd};の設定ファイル ''/etc/nslcd.conf'' と LDAPでユーザ認証する&color(magenta){pam_ldap};の設定ファイル ''/etc/pam_ldap.conf'' をそれぞれ修正します。 -/etc/nslcd.conf #code(nonumber){{ uid nslcd gid ldap uri ldap://192.168.0.72 base dc=private,dc=local pagesize 1000 referrals off filter passwd (objectClass=user) filter group (objectClass=group) map passwd uid sAMAccountName map passwd homeDirectory unixHomeDirectory map passwd gecos displayName map passwd gidNumber gidNumber map group cn msSFU30Name map group gidNumber gidNumber binddn cn=ldap-connect,cn=Users,dc=private,dc=local bindpw ldap ssl no }} -/etc/pam_ldap.conf #code(nonumber){{ base dc=private,dc=local binddn cn=ldap-connect,cn=Users,dc=private,dc=local bindpw ldap bind_policy soft pam_login_attribute sAMAccountName uri ldap://192.168.0.72/ ssl no }} そして&color(orangered){authconfig};で認証・ユーザ情報取得を変更します。nslcdが自動的に起動しますが、再起動時自動稼動にします。 #code(nonumber){{ [root@c102 ~]# authconfig --enableldap --enableldapauth --ldapserver="192.168.0.72" \ --ldapbasedn="dc=private,dc=local" --disableldaptls --update [root@c102 ~]# chkconfig nslcd on }} これでOK 参考:[[https://wiki.samba.org/index.php/Nslcd>+https://wiki.samba.org/index.php/Nslcd]] ***rockylinux9 [#a1166c02] samba-adをLDAPサーバと見做して、ldapクライアントを作ってみる rockylinux9はnslcdは提供していないので sssd 経由で作るしかない. #code(nonumber){{ [root@rockylinux9 ~]# dnf install sssd-ldap [root@rockylinux9 ~]# vi /etc/sssd/sssd.conf [sssd] services = nss, pam domains = chaperone.jp [nss] [domain/chaperone.jp] id_provider = ldap ldap_uri = ldaps://192.168.0.131 ldap_search_base = dc=chaperone,dc=jp ldap_id_use_start_tls = True ldap_tls_reqcert = never ldap_default_bind_dn = cn=nfs-user,cn=Users,dc=chaperone,dc=jp ldap_default_authtok = nfsuser ldap_default_bind_dn = cn=ldap-connect,cn=Users,dc=chaperone,dc=jp ldap_default_authtok = ldap ldap_schema = rfc2307bis ldap_user_home_directory = unixHomeDirectory [root@rockylinux9 ~]# systemctl start sssd }}