Skip to content

Allow setting unix socket mode #4344

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

2xsaiko
Copy link

@2xsaiko 2xsaiko commented Apr 4, 2025

No description provided.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@2xsaiko 2xsaiko force-pushed the push-uqsozolyrlor branch from 78ef371 to 0c7495f Compare April 4, 2025 22:29
@2xsaiko 2xsaiko force-pushed the push-uqsozolyrlor branch from 0c7495f to 9d1d341 Compare April 5, 2025 10:49
Copy link
Member

@sandhose sandhose left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this!

Comment on lines +336 to +345
if let Some(mode) = mode {
let mut permissions = fs::metadata(socket)
.context("could not read socket metadata")?
.permissions();
let mode = u32::from_str_radix(mode, 8)
.with_context(|| format!("could not parse mode: {mode}"))?;
permissions.set_mode(mode);
fs::set_permissions(socket, permissions)
.context("could not set socket permissions")?;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid any potential race conditions, I would appreciate if we used the opened file descriptor directly.

This is a little bit annoying to do, but basically, you can:

This way we're sure that if for some reason the socket gets deleted, gets moved or whatever, we don't end up doing operations on the wrong file. It only ever gets opened once

@@ -124,6 +124,9 @@ pub enum BindConfig {
/// Path to the socket
#[schemars(with = "String")]
socket: Utf8PathBuf,

/// Socket file mode
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add in the comment what form you expect this to be. You could also use schemars' example attribute, which will appear in the generate JSONSchema

@@ -58,6 +58,7 @@ http:

# Third option: listen on the given UNIX socket
- socket: /tmp/mas.sock
mode: "660" # optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mode: "660" # optional
mode: "660" # permissions to set on the socket, optional

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants