FreeRadius+AD集成认证
FreeRadius+AD集成认证环境
由于公司VPN服务器需要接入AD统一认证,VPN服务对AD的原生支持不是很好,所以基于FreeRadius搭了一套与AD集成的认证环境
1. 基础环境准备
AD域服务器:172.16.20.11/12 (transwarp.io)
Radius服务器:172.16.30.199 (CentOS7.6)
编辑/etc/hosts文件,为本机添加域名和别称,确保本机dns可以ping通域控服务器
172.16.30.199 rdtest.transwarp.io centos
172.16.20.38 SSHVL028.transwarp.io SSHVL028
关闭selinux和firewalld
2.配置samba服务
yum install samba.x86_64 -y
编辑
/etc/samba/smb.conf
[global] # 工作组,domain的左边 workgroup = transwarp # 配置ads security = ads # 域(大写Domain) realm = TRANSWARP.IO # hosts中配置的local名称 netbios name = centos # 配置AD域服务器的IP或者域名 password server = transwarp.io # 开启密码加密 encrypt passwords = yes # 允许ntlm认证 ntlm auth = yes log file = /var/log/samba/log.%m max log size = 50 load printers = yes cups options = raw
3.配置kerberos5服务
yum install krb5-server.x86_64 -y
编辑
/etc/krb5.conf
[libdefaults] dns_lookup_realm = false ticket_lifetime = 24h renew_lifetime = 7d forwardable = true rdns = false pkinit_anchors = FILE:/etc/pki/tls/certs/ca-bundle.crt # 域(大写Domian) default_realm = TRANSWARP.IO default_ccache_name = KEYRING:persistent:%{uid} # 根据域名修改 [realms] TRANSWARP.IO = { kdc = transwarp.io:88 admin_server = transwarp.io:749 default_domain = transwarp.io } [domain_realm] .transwarp.io = TRANSWARP.IO transwarp.io = TRANSWARP.IO # 添加kdc配置 [kdc] profile = /var/kerberos/krb5kdc/kdc.conf
/var/kerberos/krb5kdc/kdc.conf
配置[kdcdefaults] kdc_ports = 88 kdc_tcp_ports = 88 [realms] # 修改为自己的域名称 TRANSWARP.IO = { acl_file = /var/kerberos/krb5kdc/kadm5.acl dict_file = /usr/share/dict/words admin_keytab = /var/kerberos/krb5kdc/kadm5.keytab supported_enctypes = aes256-cts:normal aes128-cts:normal des3-hmac-sha1:normal arcfour-hmac:normal camellia256-cts:normal camellia128-cts:normal des-hmac-sha1:normal des-cbc-md5:normal des-cbc-crc:normal }
4.配置FreeRadius和winbind
yum install freeradius freeradius-utils samba-winbind krb5-server krb5-workstation -y
配置
/etc/nsswitch.conf
passwd: files sss winbind shadow: files sss winbind group: files sss winbind
将
/usr/lib/systemd/system
下的service copy 到/etc/systemd/system/
smb.service,krb5kdc.service,winbind.service配置服务器加入域控
net ads join -U xinchen.luan Enter xinchen.luan's password: ********** Using short domain name -- TRANSWARP Joined 'CENTOS' to dns domain 'transwarp.io'
systemctl restart winbind
重启winbind服务到这里可以用kerberos测试下AD账号了
kinit xinchen.luan@TRANSWARP.IO Password for xinchen.luan@TRANSWARP.IO: ******* # 无输出表示认证通过
5.服务器加域验证
上述结果表明OK, 我们可以到AD server 中可以看到我们将centos 加入了, 在加入的过程中可能会失败,我们加入:
net -s /dev/null groupmap add sid=S-1-5-32-546 unixgroup=nobody type=builtin
然后重新join然后我们可以测试一下用ntlm来验证配置
yum install samba-winbind-clients.x86_64
ntlm_auth --request-nt-key --domain=TRANSWARP.IO --username=xxxxx --password=***** NT_STATUS_OK: The operation completed successfully. (0x0)
上面返回结果表示验证通过
6.配置Radius
编辑
/etc/raddb/mods-enabled/ntlm_auth
exec ntlm_auth { wait = yes program = "/usr/bin/ntlm_auth --request-nt-key --domain=TRANSWARP.IO --username=%{mschap:User-Name} --password=%{User-Password} --allow-mschapv2" }
分别编辑
/etc/raddb/sites-available/default
和/etc/raddb/sites-enabled/inner-tunnel
authorize 中加入 ntdomain authenticate 中加入 ntlm_auth
编辑
raddb/mods-config/files/authorize
DEFAULT Auth-Type = ntlm_auth
7.最终验证
radtest username password 127.0.0.1 0 testing123
Sent Access-Request Id 9 from 0.0.0.0:46480 to 127.0.0.1:1812 length 82
User-Name = "xinchen.luan"
User-Password = "***********"
NAS-IP-Address = 172.16.30.199
NAS-Port = 0
Message-Authenticator = 0x00
Cleartext-Password = "***********"
Received Access-Accept Id 9 from 127.0.0.1:1812 to 0.0.0.0:0 length 20
上面结果表示验证通过
最后记得添加RadiusClient
vim /etc/raddb/clients.conf client 172.16.0.0/16 { secret = transwarp shortname = vpn }
8.开启mschap-v2认证
目前freeradius只支持eap和pap认证,为保证windows可以正常连接,我们需要额外开启mschap认证
# 编辑/etc/raddb/mods-available/mschap
# 取消注释ntlm_auth片段,修改为如下:
ntlm_auth = "/usr/bin/ntlm_auth --request-nt-key --allow-mschapv2 --username=%{%{Stripped-User-Name}:-%{%{User-Name}:-None}} --domain=%{%{mschap:NT-Domain}:-TRANSWARP.IO} --challenge=%{%{mschap:Challenge}:-00} --nt-response=%{%{mschap:NT-Response}:-00}"
修改配置后注意检查权限,否则mschap验证无法通过
# 将radiusd用户添加到winbind组
usermod -a -G wbpriv radiusd
# 检查winbindd_privileged文件夹是否所属winbind组
ll /var/lib/samba/
drwxr-x---. 2 root wbpriv 18 Dec 15 21:51 winbindd_privileged
配置完成后重启radiusd服务即可完成mschap认证