SUDO
部分查看系统安装 sudo
包过滤出 OpenLDAP
rpm -qal | grep sudo | grep -i "OpenLDAP"
/usr/share/doc/sudo-1.8.19p2/schema.OpenLDAP
拷贝该档案到 LDAP
schema
中
cp /usr/share/doc/sudo-1.8.19p2/schema.OpenLDAP /etc/openldap/schema/sudo.schema
SSH
部分安装openssh-ldap
如果不存在
yum -y install openssh-ldap
[root@ldap-server ~]# rpm -qal | grep openssh-ldap
/usr/share/doc/openssh-ldap-7.4p1
/usr/share/doc/openssh-ldap-7.4p1/HOWTO.ldap-keys
/usr/share/doc/openssh-ldap-7.4p1/ldap.conf
/usr/share/doc/openssh-ldap-7.4p1/openssh-lpk-openldap.ldif
/usr/share/doc/openssh-ldap-7.4p1/openssh-lpk-openldap.schema
/usr/share/doc/openssh-ldap-7.4p1/openssh-lpk-sun.ldif
/usr/share/doc/openssh-ldap-7.4p1/openssh-lpk-sun.schema
拷贝档案到schema
中
cp /usr/share/doc/openssh-ldap-7.4p1/openssh-lpk-openldap.schema /etc/openldap/schema
增加自定义的 sudo.schema
与 openssh-lpk-openldap.schema
删除源模式配置文件
rm -rf /etc/openldap/slapd.d/cn=config/cn=schema/*
重新导入 LDAP
模式
# 可根据自己的需要酌情导入, 此处一定注意顺序。
cat schema_convert.conf
# include /etc/openldap/schema/corba.schema
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/cosine.schema
# include /etc/openldap/schema/duaconf.schema
# include /etc/openldap/schema/dyngroup.schema
include /etc/openldap/schema/inetorgperson.schema
# include /etc/openldap/schema/java.schema
# include /etc/openldap/schema/misc.schema
include /etc/openldap/schema/nis.schema
# include /etc/openldap/schema/openldap.schema
# include /etc/openldap/schema/pmi.schema
include /etc/openldap/schema/collective.schema
# include /etc/openldap/schema/ppolicy.schema
include /etc/openldap/schema/sudo.schema
include /etc/openldap/schema/openssh-lpk-openldap.schema
导入LDAP
模式
slaptest -f schema_convert.conf -F /etc/openldap/slapd.d
config file testing succeeded
赋权与验证
# 查看生成的文件
ls -l /etc/openldap/slapd.d/cn=config/cn=schema/
cn={0}corba.ldif
cn={10}pmi.ldif
cn={11}collective.ldif
cn={12}ppolicy.ldif
cn={13}sudo.ldif
cn={14}openssh-lpk-openldap.ldif
cn={1}core.ldif
cn={2}cosine.ldif
cn={3}duaconf.ldif
cn={4}dyngroup.ldif
cn={5}inetorgperson.ldif
cn={6}java.ldif
cn={7}misc.ldif
cn={8}nis.ldif
cn={9}openldap.ldif
# 更改权限
chown -R ldap.ldap /etc/openldap/slapd.d/
# 重启服务
systemctl restart slapd
查看页面配置请移步到: 页面配置
phpldapadmin 預設是不支援 sudo 的設定,所以要到下面的網址抓 template
获取 Templates 网址
sudo
页面配置vim /usr/share/phpldapadmin/templates/creation/sudo.xml
<template>
<title>Sudo Policytitle>
<regexp>^ou=sudoers,dc=.*regexp>
<icon>images/door.pngicon>
<description>New Sudo Policydescription>
<askcontainer>1askcontainer>
<rdn>cnrdn>
<visible>1visible>
<objectClasses>
<objectClass id="sudoRole">objectClass>
objectClasses>
<attributes>
<attribute id="cn">
<display>Policy Namedisplay>
<order>1order>
<page>1page>
attribute>
<attribute id="sudoCommand">
<display>Sudo Commanddisplay>
<order>2order>
<page>1page>
<spacer>1spacer>
attribute>
<attribute id="sudoUser">
<display>Sudo Usersdisplay>
<option>=php.MultiList(/,(objectClass=posixAccount),uid,%uid%
(%cn%),sudoUser)option>
<order>3order>
<page>1page>
<spacer>1spacer>
attribute>
<attribute id="sudoHost">
<display>Sudo Hostsdisplay>
<array>10array>
<order>3order>
<page>1page>
<spacer>1spacer>
attribute>
<attribute id="description">
<type>textareatype>
<display>Descriptiondisplay>
<order>4order>
<page>1page>
attribute>
attributes>
template>
vim /usr/share/phpldapadmin/templates/modification/sudo.xml
<template>
<title>Sudo Policytitle>
<regexp>^cn=.*,ou=sudoers,dc=.*regexp>
<icon>images/door.pngicon>
<description>Sudo Policydescription>
<askcontainer>1askcontainer>
<rdn>cnrdn>
<visible>1visible>
<objectClasses>
<objectClass id="sudoRole">objectClass>
objectClasses>
<attributes>
<attribute id="cn">
<display>Policy Namedisplay>
<order>1order>
<page>1page>
attribute>
<attribute id="sudoCommand">
<display>Sudo Commanddisplay>
<order>2order>
<page>1page>
<spacer>1spacer>
attribute>
<attribute id="sudoUser">
<display>Sudo Usersdisplay>
<order>3order>
<page>1page>
<spacer>1spacer>
attribute>
<attribute id="sudoHost">
<display>Sudo Hostsdisplay>
<order>3order>
<page>1page>
<spacer>1spacer>
attribute>
<attribute id="description">
<type>textareatype>
<display>Descriptiondisplay>
<order>4order>
<page>1page>
<cols>200cols>
<rows>10rows>
attribute>
attributes>
template>
ou
为 sudoers
与 sudo
的规则ou
role
与应用
SUDO
部分sudo-ldap.conf
以支持使用LDAP
服务端配置vim /etc/sudo-ldap.conf
uri ldap://172.16.10.220
# ou 与页面配置的 ou 保持一致
sudoers_base ou=sudoers,dc=laoshiren,dc=com
nsswitch.conf
文件, 支持使用LDAP
配置vim /etc/nsswitch.conf
sudoers: files ldap
与配置信息吻合,成功
➜ ~ ssh [email protected]
[email protected]'s password:
Last login: Tue Jan 8 03:49:49 2019 from 172.16.10.1
-sh-4.2$ whoami
test_user
-sh-4.2$ id
uid=1000(test_user) gid=500(ldap_users) 组=500(ldap_users)
-sh-4.2$ sudo -l
[sudo] test_user 的密码:
匹配 %2$s 上 %1$s 的默认条目:
!visiblepw, always_set_home, match_group_by_gid, env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES",
env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY", secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
用户 test_user 可以在 kubernetes-node1 上运行以下命令:
(root) ALL
SSH
部分LDAP
使用 publicKey
登录openssh-ldap
配置openssh-ldap
yum install openssh-ldap
cp /usr/share/doc/openssh-ldap-7.4p1/ldap.conf /etc/ssh/
TLS
具体配置移步: LDAP开启TLS&LDAPS
TLS_REQCERT [never、allow、try、demand | hard]
设置是否在TLS会话中检查server证书
Never:不检查任何证书。
Allow:检查server证书,没有证书或证书错误,都允许连接。
Try:检查server证书,没有证书(允许连接),证书错误(终止连接)。
demand | hard:检查server证书,没有证书或证书错误都将立即终止连接。
vim /etc/ssh/ldap.conf
# 添加如下几行
# ldap 服务器
uri ldap://172.16.10.220/
# 开启 tls 认证,并且配置证书位置, 以及认证方式
ssl start_tls
tls_cacertdir /etc/openldap/cacerts
tls_cacertfile /etc/openldap/cacerts/laoshirenCA.pem
tls_reqcert never
SSH
服务配置vim /etc/ssh/sshd_config
# 增加如下
# 脚本将从LDAP获取密钥并将其提供给SSH服务器
AuthorizedKeysCommand /usr/libexec/openssh/ssh-ldap-wrapper
AuthorizedKeysCommandUser nobody
PubkeyAuthentication yes
SSH-KEY
登录方式ssh [email protected]
[email protected]'s password:
Creating directory '/home/users/tssh'.
-sh-4.2$ id
uid=1001(tssh) gid=500(linux_group) 组=500(linux_group)
LDAP
该用户中ssh -i ~/.ssh/id_rsa [email protected]
Last login: Wed Jan 9 00:50:10 2019 from 172.16.10.1
-sh-4.2$ id
uid=1001(tssh) gid=500(linux_group) 组=500(linux_group)