![Freeradius,通过 BASH 脚本进行身份验证,通过 LDAP 组成员身份授权?](https://linux22.com/image/734883/Freeradius%EF%BC%8C%E9%80%9A%E8%BF%87%20BASH%20%E8%84%9A%E6%9C%AC%E8%BF%9B%E8%A1%8C%E8%BA%AB%E4%BB%BD%E9%AA%8C%E8%AF%81%EF%BC%8C%E9%80%9A%E8%BF%87%20LDAP%20%E7%BB%84%E6%88%90%E5%91%98%E8%BA%AB%E4%BB%BD%E6%8E%88%E6%9D%83%EF%BC%9F.png)
我在 kubernetes 集群中有一个包含 Freeradius 的自定义 ubuntu 容器。由于容器的工作方式,Freeradius/AD 集成的常规 SAMBA/Winbind 方法不是一种选择,因此我编写了一个 BASH 脚本来验证用户凭据,并且还安装了 LDAP 模块以根据组成员身份授权用户使用特定服务。
目前,我只能将 Freeradius 配置为基于组成员身份进行授权,而无需根据脚本的结果做出决定。我尝试了许多不同的授权文件配置,但这里只介绍几种。这个配置即使密码错误也能授予访问权限:
DEFAULT Auth-Type = Accept
Exec-Program = "/path/to/script/auth.sh %{User-Name} %{User-Password}",
Fall-Through = Yes
DEFAULT Ldap-Group == "Admingroup", Auth-Type := Accept
Service-Type = Administrative-User,
cisco-avpair ='shell:priv-lvl=15'
DEFAULT Auth-Type := Reject
Reply-Message = "Authorization failed."
无论提供什么凭证,这个都会拒绝访问:
DEFAULT Ldap-Group == "Admingroup", Exec-Program = "/path/to/script/auth.sh %{User-Name} %{User-Password}", Auth-Type := Accept
Service-Type = Administrative-User,
cisco-avpair ='shell:priv-lvl=15'
DEFAULT Auth-Type := Reject
Reply-Message = "Authorization failed."
我知道我的脚本本身可以工作,因为我已经独立于 Freeradius 对其进行了测试,而且我知道 LDAP 模块本身的配置没有问题,因为它可以连接到 AD 来测试组成员身份。我主要怀疑授权文件的配置是这里的问题,但是请随意询问任何其他配置文件,我会说,除了 radiusd.conf、clients.conf 和 ldap 之外,所有其他文件都将处于安装时的默认状态。
答案1
我能够解决这个问题。这是授权的正确配置:
DEFAULT Ldap-Group == "Admingroup", Auth-Type := Accept
Exec-Program-Wait = "/path/to/script/auth.sh %{User-Name} %{User-Password}",
Service-Type = Administrative-User,
cisco-avpair ='shell:priv-lvl=15'
DEFAULT Auth-Type := Reject
Reply-Message = "Authorization failed."
此外,还必须在 /etc/freeradius/3.0/mods-enabled/exec 处修改 exec 模块。需要将“wait”变量设置为 yes,以便 freeradius 可以使用脚本的退出代码来确定是接受还是拒绝:
exec {
wait = yes
input_pairs = request
shell_escape = yes
timeout = 2
}