我有一个运行CentOS 6的docker容器,使用非root用户和OpenLDAP。 当我使用getent passwd它只是返回来自/etc/passwd的数据。 configuration文件/etc/nsswitch.conf是相应的自定义(见下文), authconfig-gtk用于configuration。 有趣的是,我能够获取所有的用户信息
ldapsearch -x -b "dc=physik,dc=rwth-aachen,dc=de"
但是在Docker容器内不可访问或不使用。 我错了configuration或错过了什么?
已安装的软件包:
openldap openldap-clients nss-pam-ldapd authconfig-gtk
/etc/nsswitch.conf中
passwd: files ldap shadow: files ldap group: files ldap hosts: files dns bootparams: nisplus [NOTFOUND=return] files ethers: files netmasks: files networks: files protocols: files rpc: files services: files netgroup: files ldap publickey: nisplus automount: files ldap aliases: files nisplus
将/etc/pam.d/system-auth
#%PAM-1.0 # This file is auto-generated. # User changes will be destroyed the next time authconfig is run. auth required pam_env.so auth sufficient pam_unix.so nullok try_first_pass auth requisite pam_succeed_if.so uid >= 500 quiet auth sufficient pam_ldap.so use_first_pass auth required pam_deny.so account required pam_access.so account required pam_unix.so broken_shadow account sufficient pam_localuser.so account sufficient pam_succeed_if.so uid < 500 quiet account [default=bad success=ok user_unknown=ignore] pam_ldap.so account required pam_permit.so password requisite pam_cracklib.so try_first_pass retry=3 type= password sufficient pam_unix.so md5 shadow nullok try_first_pass use_authtok password sufficient pam_ldap.so use_authtok password required pam_deny.so session optional pam_keyinit.so revoke session required pam_limits.so session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid session required pam_unix.so session optional pam_ldap.so
用nslcd -d我看到这个地址已经被主机系统占用了。 我执行docker run时通过挂载套接字来修复它
-v /var/run/nslcd/socket:/var/run/nslcd/socket
我只是在今天下午尝试运行一个似乎需要在根启动容器内的服务(nslcd),并以非root用户的身份运行容器(-u NON_ROOT_USER),这是很好的安全要求。 正如你的docker专家已经知道的那样,你不能这样做,因为docker容器不使用典型的init.d进程,所以所有的(包括CMD和ENTRYPOINT)作为指定的容器用户运行。
Bonzai自己的回答是解决这个问题的一个有趣的方法,但是应该注意的是,通过这样做,您使用的是主机的nslcd守护程序,而不是在容器中启动的任何东西。 我也得到了这个为我工作,而不是在容器内启动nslcd,但通过简单地configuration容器,就好像nslcd在init.d中启动。 然后使用docker run -u NON_ROOT_USER运行容器,并从主机“借”nslcd守护进程。
我绝不是这方面的专家,所以在这个讨论下面的评论是值得欢迎的…