-
Notifications
You must be signed in to change notification settings - Fork 137
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
feat: add configurable socket permissions #544
Conversation
A couple of things outstanding for this PR before merging:
|
Test Results 3 files 22 suites 3m 2s ⏱️ Results for commit 1fd2f64. ♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding tests, the way to do it would be to start a daemon with settings that sets specific socket permissions.
A good test that can be used for some guidance is tests/daemon/integration/environment_variables.rs
.
- Modify the settings as you like before passing them to
standalone_daemon
. - Wait for the unix socket to show up (
settings.shared.unix_socket_path()
) - Check its file permissions.
I think it would be nice to have a new unix_socket.rs
test file.
I have a few waiting functions in I also edited my original comment to contain a bit more info, but I noticed you already read it before my edit. You're too quick :D |
Also, a new lint popped up due to Rust 1.79. |
Do you need any further help :)? |
Just need a bit more time 😆 I've had a busy few days lately, but I should have time by the end of the week to finish it up 👍 |
Don't worry, take your time. Just wanted to check in if you need anything :) |
So I finally got back to this PR, and I have some not-so-great news. Unfortunately the The solution in their case is to use the unsafe
I have added a separate commit implementing this, and while it works well for the hardcoded default value, I was unable to get the test with the modified value to work. For some reason, it always defaults back to the value in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about the possible side-effects of using umask
, I'm not convinced that this is the solution we should use, especially since we're dealing with a multi-threaded environment that spawns subprocesses and reads/writes files.
I just played around with the unix socket on my local PC and I could easily change the permissions of the socket via chmod 777
, so there's theoretically no need to set the umask.
There's obviously that bug in the stdlib, but isn't there another way to set file permissions?
For example, the nix crate uses fchmod
:
https://docs.rs/nix/latest/src/nix/sys/stat.rs.html#272-276
Completely agree with your assessment. I wasn't too happy with using
More than happy to use other crates, I just wanted to avoid unnecessarily introducing new dependencies (unless they exist transitively). I've updated the PR to make use of the PS: I'm still not sure why the code is not respecting the modified Unix permissions, and unfortunately I seem unable to step through this with a debugger :/ |
This thread is pretty informative: It would explain why stdlib didn't work as expected. Still, I'm curious why I'm able to change permissions on the unix file socket from the outside. Is that only forbidden for the currently attached process? I'm a bit confused. |
Ok, in theory, we can create our own unix socket, set its permission and attach a UnixListener to it. Tokio allows the creation of a UnixListener from a stdlib UnixListener over here. And a stdlib UnixListener can be created via a socket_addr. We just have to find out how to create raw unix sockets. I'll be able to take a closer look at this at the end of next week, I'm pretty busy right now 😅 |
Wow! That's some good digging! I certainly could implement the logic you're talking about whereby the socket is created first, then I'll look at raising a ticket to request setting permissions with the upstream libraries. It seems like a bit of a gap given what you have found. Lastly, I've been doing this testing in macOS, though I also run Arch Linux (and would need this feature on my small Arch 'server'). Thanks so much for the help though! |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #544 +/- ##
==========================================
- Coverage 79.57% 79.49% -0.09%
==========================================
Files 75 75
Lines 5556 5573 +17
==========================================
+ Hits 4421 4430 +9
- Misses 1135 1143 +8 ☔ View full report in Codecov by Sentry. |
Finally got it to work as intended! Ultimately needed to use tokio's From a pure security perspective, this implementation does have a very minor vulnerability in the time between the binding of the socket to a path, and the subsequent setting of the permissions. I doubt this will be an issue, but I wanted to flag that just in case. I did try setting the permissions on the socket's underlying Footnotes
|
Have `pueue` set the permissions of the socket created. Previously, the permissions where unspecified and (at least for me) defaulted to `755`. As part of this change, the default settings are moving to `700` which is more restricted than the previous default. Signed-off-by: JP-Ellis <josh@jpellis.me>
Awesome, thanks for the contribution :) |
Summary
Have
pueue
set the permissions of the socket created. Previously, the permissions where unspecified and (at least for me) defaulted to755
. The permissions can be configured through the newunix_socket_permissions
setting.As part of this change, the default settings are moving to
700
which is more restricted than the (possibly system-dependent) previous default. The more restricted permissions should not have any practical impact as users without write permissions would not be able to use the socket, though removing read access to others may possibly improve security.Checklist
Please make sure the PR adheres to this project's standards:
CHANGELOG.md
.cargo clippy
andcargo fmt
. The CI will fail otherwise anyway.