-
Notifications
You must be signed in to change notification settings - Fork 98
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
ipc: set gid on unix sockets #173
Conversation
When creating a unix socket it's default gid is that of the parent directory. If the SOCKETDIR is owned by root:wheel with 1777 mode some of the pacemaker daemons end up unable to communicate with one another due to having insufficient permissions on the sockets. This can be fixed by setting the client sockets gid to the primary group of the server socket owner it's attempting to connect to. And, on the server side by setting the gid to the already captured gid stored in the connection info. This ensures that regardless of who owns the socket directory, as long as the applications have r/w access to it they should work.
Nice work. Comments:
|
* remove pid/euid from qb_ipcc_connection * use proper #elif defines * return NULL instead of 0 for pointers * return -ENOMEM when malloc fails * remove redundant if check * use -1 for uid to chown()
In qb_ipc_auth_creds(), I think "#elif SO_PASSCRED" should be "#elif defined(SO_PASSCRED)" (that oversight pre-dated your changes, but this is a good opportunity to fix it).
If you want I'll also rename destroy_ipc_auth_data/init_ipc_auth_data to qb_ipc_auth_data_destroy/qb_ipc_auth_data_init. The reason I used init_ipc_auth_data was because destroy_ipc_auth_data was already there and I wanted to keep it consistent even though it seemed against the coding standard. Also, qb_ipc_us_recv_msghdr(struct ipc_auth_data *) should probably be renamed to qb_ipc_us_recvmsg(struct msghdr *) which I can add too if you want, that way it'll be reusable later on if anybody finds a need for it and it'll be more obvious what it does. |
Changes look good. No need to rename anything. For symbols exposed in the library, the qb_ prefix is essential, but for static functions, it's not a big deal. The recvmsg name would make more sense, but we generally leave existing usages alone unless there's a compelling reason to change. I'll need to spend a little more time understanding the recv handling, but this is looking good. |
Looking at the code history, qb_ipc_us_recv() and qb_ipc_us_recv_msghdr() originally were very similar, but they evolved differently with regards to EAGAIN handling. Originally, they both simply looped on EAGAIN. 709b32d changed qb_ipc_us_recv() to instead call qb_ipc_us_ready() and loop, to prevent CPU spin. This wasn't done for qb_ipc_us_recv_msghdr(), probably only because it wasn't used as much. Then, 7f56f58 changed qb_ipc_us_recv_msghdr() to not loop on EAGAIN at all, instead relying on the mainloop to get back to process_auth(), the only caller. I'm guessing that's why you added the qb_ipc_us_ready() call before qb_ipc_us_recv_msghdr(). That seems like a reasonable approach, but I'm not sure. I'm wondering if we should loop the same way in qb_ipc_us_recv_msghdr() that qb_ipc_us_recv() does (though it would have to be configurable so process_auth() could keep its same behavior). What do you think -- is calling qb_ipc_us_ready() once sufficient, or would a loop be warranted? |
In theory, qb_ipc_us_recv_msghdr() should probably have an option to loop. In practice I don't think it will ever need it as the qb_ipc_connection_request is the first thing to be sent down a newly connected socket so I can't see how it will ever get fragmented into two or more messages. |
Correct, that's why I had to use qb_ipc_us_ready(). I ran into the same dilemma and decided to go with the less invasive approach; as @chrissie-c mentioned it's a call that only happens once on the initial client connection. Ideally it should probably loop just for the sake of consistency and eliminating some edge case that might pop up, but I'm not sure it's really needed. |
ipc: set gid on unix sockets
When creating a unix socket it's default gid is that of the parent
directory. If the SOCKETDIR is owned by root:wheel with 1777 mode
some of the pacemaker daemons end up unable to communicate with one
another due to having insufficient permissions on the sockets.
This can be fixed by setting the client sockets gid to the primary
group of the server socket owner it's attempting to connect to. And,
on the server side by setting the gid to the already captured gid
stored in the connection info. This ensures that regardless of who
owns the socket directory, as long as the applications have r/w
access to it they should work.