Skip to content
This repository was archived by the owner on May 21, 2025. It is now read-only.

Commit 5664d9d

Browse files
committed
socket permissions
1 parent c112813 commit 5664d9d

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

nix/module.nix

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ in {
2121
};
2222

2323
config = lib.mkIf cfg.enable {
24+
users.users.demostf-sync = {
25+
group = "demostf-sync";
26+
isSystemUser = true;
27+
};
28+
users.groups.demostf-sync = {};
29+
2430
systemd.services.demostf-sync = {
2531
wantedBy = ["multi-user.target"];
2632
environment = {
2733
SOCKET = cfg.socket;
2834
};
2935

3036
serviceConfig = {
31-
DynamicUser = true;
37+
User = "demostf-sync";
3238
ExecStart = "${cfg.package}/bin/sync";
3339
Restart = "on-failure";
3440

src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod session;
22

33
use serde::{Deserialize, Serialize};
44
use std::fmt::{Display, Formatter};
5-
use std::fs::remove_file;
5+
use std::fs::{remove_file, set_permissions, Permissions};
66
use crate::session::Session;
77
use dashmap::DashMap;
88
use futures_channel::mpsc::{channel, Sender};
@@ -12,6 +12,7 @@ use futures_util::TryStreamExt;
1212
use main_error::MainResult;
1313
use real_ip::{real_ip, IpNet};
1414
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
15+
use std::os::unix::fs::PermissionsExt;
1516
use std::path::{Path, PathBuf};
1617
use std::pin::pin;
1718
use std::sync::atomic::{AtomicU64, Ordering};
@@ -284,6 +285,7 @@ async fn listen_tcp(listen_address: SocketAddr) -> impl Stream<Item=Result<(Box<
284285

285286
async fn listen_unix(path: &Path) -> impl Stream<Item=Result<(Box<dyn StreamTrait>, IpAddr), std::io::Error>> {
286287
let listener = UnixListener::bind(path).expect("Failed to bind");
288+
set_permissions(path, Permissions::from_mode(0o660)).expect("Failed to set socket permissions");
287289

288290
info!("listening on: {}", path.display());
289291

0 commit comments

Comments
 (0)