root 无法连接到其他用户的符号链接套接字

root 无法连接到其他用户的符号链接套接字

我使用 oh-my-zsh 的 ssh-agent 插件来为我当前SSH_AUTH_SOCK创建的静态符号链接。当通过启用代理转发的 SSH 连接时,文件/tmp/ssh-agent-$USER-screen符号链接到/tmp/ssh-<whatever>/agent.<some numbers>

agross@router ~
$ ls -la /tmp/ssh-agent*
lrwxrwxrwx. 1 agross agross 30 Jan  7 21:35 /tmp/ssh-agent-agross-screen -> /tmp/ssh-uoof1WiDSw/agent.7745

agross@router ~
$ ls -la /tmp/ssh-uoof1WiDSw/
srwxr-xr-x. 1 agross agross  0 Jan  7 21:35 agent.7745

我成功地测试了符号链接ssh-add -l

agross@router ~
$ ssh-add -l
2048 15:5a:dd... /home/agross/.ssh/id_rsa (RSA)

agross@router ~
$ echo $SSH_AUTH_SOCK
/tmp/ssh-agent-agross-screen

一旦我su无法再访问符号链接,但符号链接目标就可以正常工作。

[root@router ~]# socat -v - UNIX-CONNECT:/tmp/ssh-agent-agross-screen
2016/01/07 21:51:04 socat[16054] E connect(3, AF=1 "/tmp/ssh-agent-agross-screen", 30): Permission denied

[root@router ~]# socat - UNIX-CONNECT:/tmp/ssh-uoof1WiDSw/agent.7745
<empty line is printed so I guess I'm connected>

[root@router ~]# echo $SSH_AUTH_SOCK
/tmp/ssh-agent-agross-screen

[root@router ~]# ssh-add -l
Could not open a connection to your authentication agent.

[root@router ~]# SSH_AUTH_SOCK=/tmp/ssh-uoof1WiDSw/agent.7745 ssh-add -l
2048 15:5a:dd... /home/agross/.ssh/id_rsa (RSA)

我研究发现,符号链接上的权限不会被评估,而是符号链接目标上的权限与决定用户(甚至是 root?)是否能够访问文件相关。并且访问符号链接目标可以完美地工作。

这里可能有什么问题?

我正在运行 CentOS 7,以防万一。谢谢你!


更新后的问题:

SSH_AUTH_SOCK已导出

不过,我认为无法连接到符号链接并不重要socat

[root@router ~]# export | grep SSH
declare -x SSH_AUTH_SOCK="/tmp/ssh-agent-agross-screen"

SELinux

看来这也没什么关系了。

[root@router ~]# getenforce
Enforcing
[root@router ~]# setenforce 0
[root@router ~]# socat - UNIX-CONNECT:/tmp/ssh-agent-agross-screen
2016/01/08 09:54:09 socat[21673] E connect(3, AF=1 "/tmp/ssh-agent-agross-screen", 30): Permission denied
[root@router ~]# setenforce 1
[root@router ~]# socat - UNIX-CONNECT:/tmp/ssh-agent-agross-screen
2016/01/08 09:54:45 socat[21675] E connect(3, AF=1 "/tmp/ssh-agent-agross-screen", 30): Permission denied

~ 中的符号链接与 /tmp 中的符号链接

感谢@masm 的指点。我的主目录中的符号链接有效,而 /tmp 中的符号链接无效。

[root@router ~]# ls -lZ /home/agross
lrwxrwxrwx. agross agross unconfined_u:object_r:user_home_t:s0 foo -> /tmp/ssh-QlnhyjUQDp/agent.15895

[root@router ~]# socat -v - UNIX-CONNECT:/home/agross/foo
<empty line>

[root@router ~]# ls -lZ /tmp
lrwxrwxrwx. agross agross unconfined_u:object_r:user_tmp_t:s0 ssh-agent-agross-screen -> /tmp/ssh-QlnhyjUQDp/agent.15895

[root@router ~]# socat -v - UNIX-CONNECT:/tmp/ssh-agent-agross-screen
2016/01/08 18:14:48 socat[15989] E connect(3, AF=1 "/tmp/ssh-agent-agross-screen", 30): Permission denied

答案1

fs.protected_symlinks=1罪魁祸首是:

[root@router ~]# sysctl fs.protected_symlinks
fs.protected_symlinks = 1
[root@router ~]# sysctl -w fs.protected_symlinks=0
fs.protected_symlinks = 0

[root@router ~]# socat -v - UNIX-CONNECT:/tmp/ssh-agent-agross-screen

[root@router ~]# sysctl -w fs.protected_symlinks=1
fs.protected_symlinks = 1

[root@router ~]# socat -v - UNIX-CONNECT:/tmp/ssh-agent-agross-screen
2016/01/09 01:46:21 socat[20591] E connect(3, AF=1 "/tmp/ssh-agent-agross-screen", 30): Permission denied

荣誉:https://askubuntu.com/questions/599719/how-can-i-set-a-symlink-from-tmp-mysql-sock

相关内容