Skip to content

Commit 78ef371

Browse files
committed
Allow setting unix socket mode
Signed-off-by: Marco Rebhan <[email protected]>
1 parent 02bae49 commit 78ef371

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

crates/cli/src/server.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
// Please see LICENSE in the repository root for full details.
66

77
use std::{
8+
fs,
89
future::ready,
910
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr, TcpListener, ToSocketAddrs},
1011
os::unix::net::UnixListener,
12+
os::unix::fs::PermissionsExt,
1113
};
1214

1315
use anyhow::Context;
@@ -329,8 +331,16 @@ pub fn build_listeners(
329331
listener.try_into()?
330332
}
331333

332-
HttpBindConfig::Unix { socket } => {
334+
HttpBindConfig::Unix { socket, mode } => {
333335
let listener = UnixListener::bind(socket).context("could not bind socket")?;
336+
337+
if let Some(mode) = mode {
338+
let mut permissions = fs::metadata(socket).context("could not read socket metadata")?.permissions();
339+
let mode = u32::from_str_radix(mode, 8).with_context(|| format!("could not parse mode: {}", mode))?;
340+
permissions.set_mode(mode);
341+
fs::set_permissions(socket, permissions).context("could not set socket permissions")?;
342+
}
343+
334344
listener.try_into()?
335345
}
336346

crates/config/src/sections/http.rs

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ pub enum BindConfig {
124124
/// Path to the socket
125125
#[schemars(with = "String")]
126126
socket: Utf8PathBuf,
127+
128+
/// Socket file mode
129+
mode: Option<String>,
127130
},
128131

129132
/// Accept connections on file descriptors passed by the parent process.

docs/reference/configuration.md

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ http:
5858

5959
# Third option: listen on the given UNIX socket
6060
- socket: /tmp/mas.sock
61+
mode: "660" # optional
6162

6263
# Fourth option: grab an already open file descriptor given by the parent process
6364
# This is useful when using systemd socket activation

0 commit comments

Comments
 (0)