我写这个问题是为了自己回答它。我在网上搜索了一整天的时间,却找不到对我有用的解决方案。我甚至编译了自己的GoogleAuthenticator PAM模块来添加更多的日志记录。甚至没有在
strace进程及其子进程上运行OpenVPN,我就找到了一个解决方案。
.ovpn文件下面的脚本将创建一个Linux用户,然后创建一个MFA秘密,保存到PAM配置中指定的位置,注意权限600,MFA_USER是我创建的名为gauth的预先创建的用户。
function generate_mfa() {
user_id=$1
if [ "$user_id" == "" ]; then
echo "ERROR: No user id provided to generate MFA token" >&2
exit 1
fi
echo "INFO: Creating user ${user_id}" >&2
useradd -s /bin/nologin "$user_id"
echo "> Please provide a password for the user" >&2
passwd "$user_id"
echo "INFO: Generating MFA Token" >&2
google-authenticator -t -d -r3 -R30 -f -l "${MFA_LABEL}" -s "${MFA_DIR}/${user_id}"
chown "${MFA_USER}:${MFA_USER}" "$MFA_DIR/${user_id}"
chmod 600 "${MFA_DIR}/${user_id}"
}用于OpenVPN的PAM Config
auth required /usr/lib64/security/pam_google_authenticator.so secret=/etc/openvpn/google-authenticator/${USER} user=gauth forward_pass
auth include system-auth use_first_pass
account include system-auth use_first_pass
password include system-auth use_first_pass
session include system-auth use_first_pass
auth required pam_deny.soclient.ovpn配置的Tunnelblick,然后提示我使用我的用户名和密码登录。forward_pass指令去掉的。tail /var/log/secure。Sep 10 22:33:43 ip-OMITTED openvpn(pam_google_authenticator)[12862]: Accepted google_authenticator for ryan
Sep 10 22:33:43 ip-OMITTED openvpn(pam_google_authenticator)[12862]: Failed to update secret file "/etc/openvpn/google-authenticator/ryan": Permission denied那么检查一下我的权限:
[root@ip-OMITTED centos]# ls -lah /etc/openvpn/google-authenticator/
drwxr-xr-x. gauth gauth .
drwxr-xr-x. root root ..
-rw-------. gauth gauth ryan600似乎是对的。目录是可执行的,我在我的PAM配置中使用gauth用户。gauth用户存在:check::check:发布于 2019-09-11 18:27:44
那些
.'s在我的权限列表的末尾是什么?
[root@ip-OMITTED centos]# ls -lah /etc/openvpn/google-authenticator/
drwxr-xr-x. gauth gauth .
drwxr-xr-x. root root ..
-rw-------. gauth gauth ryan...Searchin' the web...
这就是在运行ls -lah时文件权限末尾的点所在,它表明文件中存在特殊的上下文/ACL内容。
ls -Z一次登录前的
文件上下文为unconfined_u:object_r:openvpn_etc_t:s0
[root@ip-OMITTED centos]# ls -lahZ /etc/openvpn/google-authenticator/
drwxr-xr-x. gauth gauth unconfined_u:object_r:openvpn_etc_t:s0 .
drwxr-xr-x. root root system_u:object_r:openvpn_etc_t:s0 ..
-rw-------. gauth gauth unconfined_u:object_r:openvpn_etc_t:s0 ryansetenforce 0暂时禁用了selinux。一次登录后的
该文件能够被写入,并且上下文被强制到system_u:object_r:openvpn_etc_rw_t:s0。
[root@ip-OMITTED centos]# ls -lahZ /etc/openvpn/google-authenticator/
drwxr-xr-x. gauth gauth unconfined_u:object_r:openvpn_etc_t:s0 .
drwxr-xr-x. root root system_u:object_r:openvpn_etc_t:s0 ..
-r--------. gauth gauth system_u:object_r:openvpn_etc_rw_t:s0 ryansetenforce 1运行以修复打开
semanage fcontext -a -t openvpn_etc_rw_t "${MFA_DIR}/${user}" restorecon "${MFA_DIR}/${user}"
rw比特!https://unix.stackexchange.com/questions/541240
复制相似问题