首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GoogleAuthenticator PAM模块权限问题--在运行CentOS的AWS EC2中使用MFA

GoogleAuthenticator PAM模块权限问题--在运行CentOS的AWS EC2中使用MFA
EN

Unix & Linux用户
提问于 2019-09-11 18:27:19
回答 1查看 492关注 0票数 0

全面披露:

我写这个问题是为了自己回答它。我在网上搜索了一整天的时间,却找不到对我有用的解决方案。我甚至编译了自己的GoogleAuthenticator PAM模块来添加更多的日志记录。甚至没有在strace进程及其子进程上运行OpenVPN,我就找到了一个解决方案。

用例

  • 在OpenVPN中使用EC2启动VPN
  • 使用PAM GoogleAuthenticator模块
  • OS: CentOS

设置

  • 登录到EC2
  • 创建一个客户端
  • 使用所提供的令牌生成器将MFA令牌添加到用户(客户端),同时将此令牌保存到PAM模块检测它的的适当位置
    • 为该用户创建.ovpn文件

下面的脚本将创建一个Linux用户,然后创建一个MFA秘密,保存到PAM配置中指定的位置,注意权限600MFA_USER是我创建的名为gauth的预先创建的用户。

代码语言:javascript
复制
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

代码语言:javascript
复制
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.so

问题

  • 使用使用我的client.ovpn配置的Tunnelblick,然后提示我使用我的用户名和密码登录。
    • 密码的格式是内联的:,这是用forward_pass指令去掉的。

  • 我输入了正确的证书,总是会遇到未经授权的情况。

日志

  • 为了检查我的问题,我通过ssh登录到VPN实例,并检查了我的PAM/auth日志tail /var/log/secure
代码语言:javascript
复制
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

啊哈!“权限被拒绝”

那么检查一下我的权限:

代码语言:javascript
复制
[root@ip-OMITTED centos]# ls -lah /etc/openvpn/google-authenticator/
drwxr-xr-x. gauth gauth .
drwxr-xr-x. root  root  ..
-rw-------. gauth gauth ryan
  • 嗯,这些权限600似乎是对的。目录是可执行的,我在我的PAM配置中使用gauth用户。

我的配置到底可能出了什么问题?

  • gauth用户存在:check:
  • 权限是正确的,:check:
EN

回答 1

Unix & Linux用户

发布于 2019-09-11 18:27:44

AHA矩

那些.'s在我的权限列表的末尾是什么?

代码语言:javascript
复制
[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...

  • 所以很明显有一个叫做SELinux (安全增强的linux)的东西

这就是在运行ls -lah时文件权限末尾的点所在,它表明文件中存在特殊的上下文/ACL内容。

一次登录前的

文件上下文为unconfined_u:object_r:openvpn_etc_t:s0

代码语言:javascript
复制
[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 ryan
  • 然后我用setenforce 0暂时禁用了selinux。

一次登录后的

该文件能够被写入,并且上下文被强制到system_u:object_r:openvpn_etc_rw_t:s0

代码语言:javascript
复制
[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 ryan
  • 可重新启用SELinux:setenforce 1
  • 还能登录。:)

运行以修复打开

的文件的SELinux命令:

semanage fcontext -a -t openvpn_etc_rw_t "${MFA_DIR}/${user}" restorecon "${MFA_DIR}/${user}"

  • 这允许rw比特!
票数 2
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/541240

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档