Great guides for using systemd to sandbox services. There may be features in there beyond what we do:
We should look into setting a more restrictive umask per-service (not global like we tried before) and whitelisting IP addresses.
Umask=0077 IPAddressDeny=any IPAddressAllow=...
I tried these but it broke onion-grater. Exactly which IP addresses does onion-grater connect to? We can create a whitelist of them.
Is https://github.com/Whonix/sdwdate/commit/b5f0ea11cfc91613490135213b999dee917455a1 still a problem? I can’t reproduce it with the sandboxing enabled. I can send a PR to strengthen sdwdate’s sandboxing too if that isn’t an issue anymore.
I see no issues on my end. Please test.
I had to remove
MemoryDenyWriteExecute from onion-grater and sdwdate because some python thing seems to be using RWX memory for some reason.
You may get these errors:
Unknown lvalue 'ProtectKernelLogs' in section 'Service', ignoring Unknown lvalue 'ProtectHostname' in section 'Service', ignoring Unknown lvalue 'ProtectProc' in section 'Service', ignoring Unknown lvalue 'ProcSubset' in section 'Service', ignoring
These are harmless. Those options only exist in later versions of systemd but I added them for forward compatibility. Another option to look into: https://github.com/systemd/systemd/commit/407234203b41e0a27b3229347c1ad6b2b17e3c21
Awesome! I will test this over the next days and report back should there be any issues.
sdwdate log will show:
/bin/date: cannot set date: Operation not permitted
During testing might help:
sudo systemctl restart sdwdate
First sets time using
date. The later (after first time after boot setting using
sudo systemctl stop sdwdate also broken. Takes too long. Should be (almost) instant. Probably since the signal is no longer received by sdwdate. (Then systemd uses sigkill after timeout but that’s bad.)
kill getsockopt unlink to
ReadWriteDirectories and commenting
## Sandboxing. AmbientCapabilities=CAP_SYS_TIME CapabilityBoundingSet=CAP_SYS_TIME ProtectSystem=strict ReadWriteDirectories=/run/sdwdate/ /var/lib/sdwdate/ ProtectHome=true ProtectKernelTunables=true ProtectKernelModules=true ProtectControlGroups=true ProtectKernelLogs=true ProtectHostname=true ProtectProc=invisible ProcSubset=pid PrivateTmp=true #PrivateUsers=true PrivateDevices=true NoNewPrivileges=true LockPersonality=true RestrictRealtime=true RestrictSUIDSGID=true RestrictAddressFamilies=AF_UNIX AF_INET RestrictNamespaces=true SystemCallFilter=wait4 select futex read stat close openat fstat lseek mmap rt_sigaction getdents64 mprotect ioctl recvfrom munmap brk rt_sigprocmask fcntl getpid write access socket sendto dup2 clone execve getrandom geteuid getgid madvise getuid getegid readlink pipe rt_sigreturn connect pipe2 prlimit64 set_robust_list dup arch_prctl lstat set_tid_address sysinfo sigaltstack rt_sigsuspend shutdown timer_settime mkdir timer_create statfs getcwd setpgid setsockopt uname bind getpgrp getppid getpeername chdir poll getsockname fadvise64 clock_settime kill getsockopt unlink SystemCallArchitectures=native
Does that fix the issue?
That works better. However one issue remains.
process.wait(timeout_seconds) is broken. Hangs forever. To reproduce, try this:
timeout_seconds = 120
timeout_seconds = 2
And then restart sdwdate.
Meanwhile I will revert these changes to unbreak sdwdate in Whonix developers repository. Once this is fixed, I’ll look into it ASP.
I’m getting this error:
sdwdate - ERROR - General Timeout Error. Internet connection might be down.
However, it appears regardless of whether or not the sandboxing is enabled. It only happens after I change the variable you told me to. Are you sure this is a sandboxing error and not a code error?
There was before no such code error. Cannot totally rule out yet but only happened after enabling sandboxing. I’ll see that I can provide instructions for reproduction.
I couldn’t reproduce this anymore. Perhaps I made a mistake and tested the wrong version. sdwdate sandboxing is re-enabled in Whonix developers, testers, and stable-proposed-updates repository.
Thank you for another great contribution!
sdwdate is getting killed on Debian
buster on the
How to debug systemd hardening? All I get:
sdwdate.service: Main process exited, code=killed, status=31/SYS
Any way to see a more specific error message which systemd hardening was violated? Any other way to debug other than trial and error which the offensive option is?