-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UNIX socket permission bits #4155
Comments
Changing the default unix socket permission is a bad idea because it opens a security hole. Please note: you can create UNIX socket file before starting listening on it: >>> import socket
>>> s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
>>> s.bind('socket.sock')
>>> s.close()
>>> import os
>>> os.chmod('socket.sock', 0o777)
>>> aiohttp.run(...) |
Normally, you'd want to make the privileges stricter, not more open... @asvetlov should we implement support for the socket privilege adjustment on the framework level? @andreymal can't you just create a shared group for this purpose? |
It's exactly what I want! But the shared group will not work without correct permission bits for the socket (at least |
Unfortunately it does not work, because asyncio
Actually this code works (based on aiohttp
But I think this is too complicated :) |
@andreymal sorry, I didn't check my version before posting.
|
I'm trying to make aiohttp work in a Plesk environment but I'm facing this exact same issue. What I'm doing right to make it work is: s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
os.unlink(SOCKET_NAME)
s.bind(SOCKET_NAME)
os.chmod(SOCKET_NAME, 0o777)
web.run_app(app, sock=s) is it the right way? |
@vitto32 that should work, I guess. But the privileges seem too broad. Though it's up to you and depends on your needs. |
@webknjaz yep that works. |
666 works on my machine with nginx! |
I stumbled into this too. I don't think it's safe if aiohttp would always set the permissions to 666 - we don't know how people are already using aiohttp.
I have prepared code that does this, and I'd be happy to share it, but there are many caveats that need discussing - not only pertaining to my code, but also to Unix sockets in general. Should they be discussed here, or should I open a PR for this? |
Hmm, the longer I look at this, the more difficult it gets. asyncio's loop.create_unix_socket doesn't support permissions, but this is the only place where permissions can be set without creating races, and without code duplication. |
after
solved the issue for me. But I would prefer the better solution of course. |
The permissions of the socket created by aiohttp aren't as permissive as the ones set by the real agent. (see aio-libs/aiohttp#4155) from @devinsba: test agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 60 Aug 1 21:24 . drwxr-xr-x 1 root root 4096 Aug 1 21:24 .. srwxr-xr-x 1 root root 0 Aug 1 21:24 apm.socket ``` real agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 80 Aug 1 21:30 . drwxr-xr-x 1 root root 4096 Aug 1 21:31 .. srwx-w--w- 1 root root 0 Aug 1 21:30 apm.socket ```
The permissions of the socket created by aiohttp aren't as permissive as the ones set by the real agent. (see aio-libs/aiohttp#4155) from @devinsba: test agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 60 Aug 1 21:24 . drwxr-xr-x 1 root root 4096 Aug 1 21:24 .. srwxr-xr-x 1 root root 0 Aug 1 21:24 apm.socket ``` real agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 80 Aug 1 21:30 . drwxr-xr-x 1 root root 4096 Aug 1 21:31 .. srwx-w--w- 1 root root 0 Aug 1 21:30 apm.socket ```
The permissions of the socket created by aiohttp aren't as permissive as the ones set by the real agent. (see aio-libs/aiohttp#4155) from @devinsba: test agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 60 Aug 1 21:24 . drwxr-xr-x 1 root root 4096 Aug 1 21:24 .. srwxr-xr-x 1 root root 0 Aug 1 21:24 apm.socket ``` real agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 80 Aug 1 21:30 . drwxr-xr-x 1 root root 4096 Aug 1 21:31 .. srwx-w--w- 1 root root 0 Aug 1 21:30 apm.socket ``` aiohttp doesn't seem to have a configurable way to set these permissions but it does let us create and manage a socket ourselves, so let's try that.
The permissions of the socket created by aiohttp aren't as permissive as the ones set by the real agent. (see aio-libs/aiohttp#4155) from @devinsba: test agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 60 Aug 1 21:24 . drwxr-xr-x 1 root root 4096 Aug 1 21:24 .. srwxr-xr-x 1 root root 0 Aug 1 21:24 apm.socket ``` real agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 80 Aug 1 21:30 . drwxr-xr-x 1 root root 4096 Aug 1 21:31 .. srwx-w--w- 1 root root 0 Aug 1 21:30 apm.socket ``` aiohttp doesn't seem to have a configurable way to set these permissions but it does let us create and manage a socket ourselves, so let's try that.
The permissions of the socket created by aiohttp aren't as permissive as the ones set by the real agent. (see aio-libs/aiohttp#4155) from @devinsba: test agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 60 Aug 1 21:24 . drwxr-xr-x 1 root root 4096 Aug 1 21:24 .. srwxr-xr-x 1 root root 0 Aug 1 21:24 apm.socket ``` real agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 80 Aug 1 21:30 . drwxr-xr-x 1 root root 4096 Aug 1 21:31 .. srwx-w--w- 1 root root 0 Aug 1 21:30 apm.socket ``` aiohttp doesn't seem to have a configurable way to set these permissions but it does let us create and manage a socket ourselves, so let's try that.
The permissions of the socket created by aiohttp aren't as permissive as the ones set by the real agent. (see aio-libs/aiohttp#4155) from @devinsba: test agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 60 Aug 1 21:24 . drwxr-xr-x 1 root root 4096 Aug 1 21:24 .. srwxr-xr-x 1 root root 0 Aug 1 21:24 apm.socket ``` real agent: ``` cnb@my-app:/var/run/datadog$ ls -la total 4 drwxr-xr-x 2 root root 80 Aug 1 21:30 . drwxr-xr-x 1 root root 4096 Aug 1 21:31 .. srwx-w--w- 1 root root 0 Aug 1 21:30 apm.socket ``` aiohttp doesn't seem to have a configurable way to set these permissions but it does let us create and manage a socket ourselves, so let's try that.
Some commands were made unsafe in old versions, but nowadays they can be run without having special privileges. There was also a bug in which status commands were not available if you are not ahriman user and unix socket is used. It has been fixed by switching to manual socket creation (see also aio-libs/aiohttp#4155)
Some commands were made unsafe in old versions, but nowadays they can be run without having special privileges. There was also a bug in which status commands were not available if you are not ahriman user and unix socket is used. It has been fixed by switching to manual socket creation (see also aio-libs/aiohttp#4155)
Some commands were made unsafe in old versions, but nowadays they can be run without having special privileges. There was also a bug in which status commands were not available if you are not ahriman user and unix socket is used. It has been fixed by switching to manual socket creation (see also aio-libs/aiohttp#4155)
I'll have to take a look at this some time. Recently, I've just been using a systemd hack:
|
Some commands were made unsafe in old versions, but nowadays they can be run without having special privileges. There was also a bug in which status commands were not available if you are not ahriman user and unix socket is used. It has been fixed by switching to manual socket creation (see also aio-libs/aiohttp#4155)
I want to use a unix socket, but it's impossible when umask is 0022 or more strict, because the nginx
www-data
user can't connect and prints "Permission denied" error. I want to change the permission bits for the unix socket without touching umask (a strict umask is needed for other things of my project).There was a PR #4002, but it's closed.
I tried to chmod after
on_startup
signal:But the
on_startup
signal is called before creating the socket, andos.chmod
raises "No such file or directory: 'webapp.sock'" error.Please implement an option for this or explain how to do it with the current version of aiohttp
Or maybe add
on_listen
signal? :)The text was updated successfully, but these errors were encountered: