Skip to content

Commit

Permalink
nixos/jellyfin: sync up with hardening provided in upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
Mic92 committed Jun 18, 2022
1 parent cc83d35 commit 4258952
Showing 1 changed file with 36 additions and 31 deletions.
67 changes: 36 additions & 31 deletions nixos/modules/services/misc/jellyfin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,56 +49,61 @@ in
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];

# This is mostly follows: https://github.com/jellyfin/jellyfin/blob/master/debian/jellyfin.service
# Upstream also disable some hardenings when running in LXC, we do the same with the isContainer option
serviceConfig = rec {
Type = "simple";
User = cfg.user;
Group = cfg.group;
StateDirectory = "jellyfin";
StateDirectoryMode = "0700";
CacheDirectory = "jellyfin";
CacheDirectoryMode = "0700";
UMask = "0077";
WorkingDirectory = "/var/lib/jellyfin";
ExecStart = "${cfg.package}/bin/jellyfin --datadir '/var/lib/${StateDirectory}' --cachedir '/var/cache/${CacheDirectory}'";
Restart = "on-failure";
TimeoutSec = 15;
SuccessExitStatus = ["0" "143"];

# Security options:

NoNewPrivileges = true;

AmbientCapabilities = "";
CapabilityBoundingSet = "";

# ProtectClock= adds DeviceAllow=char-rtc r
DeviceAllow = "";

LockPersonality = true;

PrivateTmp = true;
# Disabled to allow Jellyfin to access hw accel devices endpoints
# PrivateDevices = true;
PrivateUsers = true;

# Disabled as it does not allow Jellyfin to interface with CUDA devices
# ProtectClock = true;
ProtectControlGroups = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;

RemoveIPC = true;

RestrictNamespaces = true;
SystemCallArchitectures = "native";
# AF_NETLINK needed because Jellyfin monitors the network connection
RestrictAddressFamilies = [ "AF_NETLINK" "AF_INET" "AF_INET6" "AF_UNIX" ];
RestrictAddressFamilies = [ "AF_UNIX" "AF_INET" "AF_INET6" "AF_NETLINK" ];
RestrictNamespaces = !config.boot.isContainer;
RestrictRealtime = true;
RestrictSUIDSGID = true;
ProtectControlGroups = !config.boot.isContainer;
ProtectHostname = true;
ProtectKernelLogs = !config.boot.isContainer;
ProtectKernelModules = !config.boot.isContainer;
ProtectKernelTunables = !config.boot.isContainer;
LockPersonality = true;
PrivateTmp = !config.boot.isContainer;
# needed for hardware accelaration
PrivateDevices = false;
PrivateUsers = true;
RemoveIPC = true;

SystemCallArchitectures = "native";
SystemCallErrorNumber = "EPERM";
SystemCallFilter = [
"@system-service"
"~@cpu-emulation" "~@debug" "~@keyring" "~@memlock" "~@obsolete" "~@privileged" "~@setuid"
"~@clock"
"~@aio"
"~@chown"
"~@cpu-emulation"
"~@debug"
"~@keyring"
"~@memlock"
"~@module"
"~@mount"
"~@obsolete"
"~@privileged"
"~@raw-io"
"~@reboot"
"~@setuid"
"~@swap"
];
SystemCallErrorNumber = "EPERM";
};
};

Expand Down

0 comments on commit 4258952

Please sign in to comment.