4

I created a test user and want to limit this "test" user to run only the following command via visudo.

echo "show stat" | socat stdio /var/run/haproxy.sock

visudo

test    ALL=(root)NOPASSWD:/usr/bin/socat stdio /var/run/haproxy.sock

ls -lat /var/run/haproxy.sock

srwxr-xr-x 1 munin haproxy 0 May 22 22:32 /var/run/haproxy.sock

I ran the following command

test#sudo echo "show stat" | socat stdio /var/run/haproxy.sock

The error message

2013/05/22 23:13:14 socat[21289] E connect(3, AF=1 "/var/run/haproxy.sock", 23): Permission denied

May I know what was incorrectly configured in visudo

Diden
  • 129
  • 3
  • 12

4 Answers4

7

The echo is running as root, but the socat isn't. Try this instead:

echo "show stat" | sudo socat stdio /var/run/haproxy.sock
Flup
  • 7,978
  • 2
  • 32
  • 43
4

In your pipe, only echo is run with elevated privileges, I believe you need a sudo before socat.

Kyle Brandt
  • 83,619
  • 74
  • 305
  • 448
1

You can define a normal (non-privileged) unix socket like:

    stats socket /var/run/haproxy/socket.sock mode 666
Law29
  • 3,557
  • 1
  • 16
  • 28
0

You can avoid permission denied if you change configuration like below.

stats socket /var/run/haproxy/socket.sock level admin

Result:

echo "set server"|nc -U /var/run/haproxy/socket.sock
Require 'backend/server'
kenlukas
  • 3,101
  • 2
  • 16
  • 26
zino.k
  • 1