通过 Radius (Freeradius) 验证 OpenVPN 用户

问题描述 投票:0回答:2

我已经在我的 ubuntu 机器上设置了 OpenVPN 服务器(不是访问服务器,开源社区版本)和 Freeradius 3。 OpenVPN 客户端身份验证已针对使用 Easy-RSA 生成的用户的用户名/密码和证书/密钥机制进行了测试。 freeradius 用户创建和测试分别由 daloradius 和 ntradping 完成。

我想要的是为我的 VPN 客户端使用 RADIUS 身份验证。基本上当客户端提示输入用户名密码时,我想通过我在 freeradius 中创建的凭据登录。

OpenVPN的官方文档页面上关于它的信息很少in this page

在按照指南进行操作时,我发现 openvpn-auth-pam 插件已重命名、重新定位并且现在是预构建的(如果不能随意纠正我,我认为是因为 openvpn-plugin-auth-pam.so文件已经存在)into a different directory

根据指南,我必须将以下行添加到我的服务器配置文件中。

plugin /usr/lib/x86_64-linux-gnu/openvpn/plugins/openvpn-plugin-auth-pam.so [name of the module to be used for authentication] 

所以这里我需要调用一个调用freeradius的模块来进行鉴权。该指南使用“登录”PAM 模块,该模块位于 /etc/pam.d 目录,除非我找错了。在同一个目录下还有一个名为radiusd的文件,文件内容为

/* /etc/pam.d/radiusd - FreeRADIUS 的 PAM 配置 */

/* 我们回退到 /etc/pam.d/common-* 中的系统默认值 */

@include 公共授权

@include 普通账户

@include 公共密码

@include common-session

我不确定下一步该做什么。 freeradius 自己的 PAM 模块是否与我尝试执行的操作相关?或者我是否需要使用一些外部工具和库来将 freeradius 与 OpenVPN 集成?或者我需要自己创建模块文件?提前致谢

authentication openvpn freeradius pam radius
2个回答
0
投票

使用 Debian。 Centos 7 即将停产。 Centos 8+ 在 repos 中没有这个插件,但你可以编译它(见答案结束)。

安装 RADIUS 认证模块并编辑 openvpn 服务器配置

apt update
# apt-cache search ".*openvpn.*radius.*"
apt install openvpn-auth-radius
# find / -name "radiusplugin*"
cp /usr/share/doc/openvpn-auth-radius/examples/radiusplugin.cnf /etc/openvpn/radiusplugin.cnf
nano /etc/openvpn/radiusplugin.cnf

编辑 /etc/openvpn/radiusplugin.cnf 中的下一部分。休息 - 保持原样。

name=ip-of-your-radius
retry=10 # change if needed
wait=600 # change if needed
sharedsecret=paste-here-radius-secret

服务器配置

nano /etc/openvpn/server.conf

添加行:

# For auth plugins. Uncomment if needed
# username-as-common-name
 
# RADIUS Auth
plugin /usr/lib/openvpn/radiusplugin.so /etc/openvpn/radiusplugin.cnf

如果你想编译它(我没有测试):

apt-get install libgcrypt11 libgcrypt11-dev gcc make build-essential
wget http://www.nongnu.org/radiusplugin/radiusplugin_v2.1a_beta1.tar.gz
tar xvfz radiusplugin_v2.1a_beta1.tar.gz
cd radiusplugin_v2.1a_beta1/
make
cp radiusplugin.so /etc/openvpn/
cp radiusplugin.cnf /etc/openvpn/

OpenVPN 插件列表:https://community.openvpn.net/openvpn/wiki/PluginOverview

PS:LDAP 集成的类似算法(在 repo 中找到插件,使用示例配置,将其添加到主配置中)。


0
投票

插件“openvpn-auth-radius”不适用于超过 2.4.x 的 OpenVPN,因此如果您有 OpenVPN 版本 2.5.x,此插件将无法使用。

替代解决方案是结合使用自定义身份验证和 radius 客户端工具,这就是方法。

你需要安装包“freeradius-utils”这个包适用于所有 Linux 仓库。

apt install freeradius-utils

服务器配置文件(server.conf)

将这些行添加到服务器配置

auth-user-pass-verify /etc/openvpn/auth.sh via-env
username-as-common-name
verify-client-cert none
script-security 3

确保给它执行权限

chmod +x /etc/openvpn/auth.sh

在 /etc/openvpn/auth.sh 中创建文件 auth.sh

x="radtest $username $password radius_server_ip 1812 radius_sever_secret"
y=$(eval "$x")
 
if [[ $y == *"Access-Accept"* ]]; then
  exit 0
        else
  exit 1
fi

就是这样

© www.soinside.com 2019 - 2024. All rights reserved.