hashicorp / go-plugin

Golang plugin system over RPC.
Mozilla Public License 2.0
5.18k stars 445 forks source link

permission denied on sharing unix domain sockets with different user #151

Open msays2000 opened 4 years ago

msays2000 commented 4 years ago

Mother host process running as user A. Plugin process running with sudo i.e root.

Plugin creates a unix domain socket at /tmp/plugin226668393 but mother host is unable to connect.

rpc error: code = Unavailable desc = connection error: desc = "transport: error while dialing: dial unix /tmp/plugin226668393: connect: permission denied"

Possible solutions:

Shared directory

Use tcp instead in linux

tomhjp commented 11 months ago

This will be because the plugin's UDS listener is owned by root with 0o600 permissions. The library recently got a new ClientConfig.UnixSocketConfig option which offers a solution to this situation. You can set Group to any group that user A is in, and it will change the group owner of the socket to that group, and set the permissions on the socket to 0o660 so that user A gets rw permission to the socket via its group membership.

Note that the plugin's group membership (and whether it's root or not) doesn't matter because it retains rw permission through the user owner and permission bits, just like it did previously.