Commit Graph

24 Commits

Author SHA1 Message Date
W.C.A. Wijngaards
5c041c0ba9 - Fix #773: When used with systemd-networkd, unbound does not start
until systemd-networkd-wait-online.service times out.
2022-12-01 13:04:05 +01:00
Maryse47
8eb5010104
Disable ProtectKernelTunables again
This option was removed in ff8fd0be5c but reintroduced in c32b9e4ba9

Disable it with commentary in hope to prevent slipping it in again.
2021-11-03 13:05:11 +00:00
Bruno Pagani
c32b9e4ba9 unbound.service.in: upgrade hardening to latest standards
Systemd gradually introduced new protection bits, let’s enable them.
2021-07-25 05:27:22 +02:00
David Runge
c48f01445e
Add AF_NETLINK to set of allowed socket address families
contrib/unbound{,_portable}.service.in:
With the changes introduced in f6a527c25a
it is now necessary to also allow access to the AF_NETLINK socket
address family to be able to get information from interfaces.

Without the AF_NETLINK address family the systemd service errors with:

```
error: failed to list interfaces: getifaddrs: Address family not
supported by protocol
```

Fixes #350
2020-11-21 14:10:39 +01:00
W.C.A. Wijngaards
afbc7bb4fe - Fix #296: systemd nss-lookup.target is reached before unbound can
successfully answer queries. Changed contrib/unbound.service.in.
2020-08-31 11:50:11 +02:00
glitsj16
42ee37847f
Fix typo 2020-02-22 01:16:11 +00:00
Maryse47
9aa4b5a7a6 unbound.service.in: don't write pidfile at start
Pidfiles aren't needed while running unbound through systemd.
The PID of the unbound daemon can still be obtained with:
'systemctl show --property MainPID --value unbound'.

While disabling pidfiles we can also drop CAP_CHOWN and writable
/run directory.
2020-01-28 19:03:18 +01:00
Maryse47
939cf38576 unbound.service.in: drop CAP_IPC_LOCK
CAP_IPC_LOCK controls whether a process can lock pages into physical
memory (for instance to prevent passwords or private keys from
being swapped to disk), e.g. mmap() with the MAP_LOCKED flag or
shmctl() with the SHM_LOCK command, neither of which seem to be
used by unbound.
2020-01-28 18:42:41 +01:00
Maryse47
c0789a8785 unbound.service.in: allow CAP_CHOWN
CAP_CHOWN is needed for changing onwership of pidfile before
dropping privileges and truncate pidfile on exit.
2020-01-27 18:31:10 +01:00
Maryse47
cfce0a5e60 unbound.service.in: add StateDirectory
State directory will be created under /var/lib/unbound and will be
useful for writing various files managed at runtime like trust
anchors updates there instead of in ConfigureDirectory which could
be made read-only next. For this chroot needs to be disabled.
2020-01-27 13:46:31 +01:00
Maryse47
1464bedce2 unbound.service.in: add RuntimeDirectory and ConfigurationDirectory
Adding 'RuntimeDirectory' is needed when pidfile path is set to
subdirectory under /run.

Adding ConfigurationDirectory may help in some non-standard setups.

Also add more descriptions about used rules to avoid user confusion
about they meaning and purpose.
2020-01-27 13:44:46 +01:00
Maryse47
89d98564c3
unbound.service.in: stop binding pidfile inside chroot dir
Apparently pidfile isn't used inside chroot and binding it may cause some weird failures with older systemd.

Fixes https://github.com/NLnetLabs/unbound/issues/138
2020-01-08 15:21:22 +00:00
Pascal Ernster
11f22074a9
Drop CAP_KILL, use + prefix for ExecReload= instead
CAP_KILL seems a bit too much privileges for the sole purpose of being able to make ExecReload= work.
Use the + prefix on ExecReload= instead to run "/bin/kill -HUP $MAINPID" with full privileges, ignoring the restrictions from CapabilityBoundingSet=.

See https://www.freedesktop.org/software/systemd/man/systemd.service.html#ExecStart= for further details about the + prefix in ExecReload=.
2019-09-26 08:41:37 +00:00
sam-lunt
6943cab670
Add kill capability to systemd service file
The ExecReload command calls kills on a process owned by the unbound user (or whatever user is configured). To do so, it needs the CAP_KILL capability.
2019-09-21 14:36:12 -05:00
Maryse47
acdd4058d2
unbound.service.in: do not fork into the background
This is needed when unbound config doesn't set "do-daemonize: no" by itself otherwise starting service fails with:
 systemd[1]: unbound.service: Got notification message from PID <PID>, but reception only permitted for main PID which is currently not known

https://github.com/NLnetLabs/unbound/blob/release-1.9.3/doc/example.conf.in#L236
2019-09-20 10:07:37 +00:00
Pascal Ernster
ae2d5276d2
Downgrade CAP_NET_ADMIN to CAP_NET_RAW in unbound.service
Since kernel 3.2, CAP_NET_RAW instead of CAP_NET_ADMIN is sufficient to allow for the usage of the IP_TRANSPARENT socket option. CAP_NET_ADMIN allows far more mayhem then CAP_NET_RAW, so prefer the safer, more restrictive solution.
2019-09-20 04:47:56 +00:00
Maryse47
ff8fd0be5c Improvements and fixes for systemd unbound.service
1. Remove `ProtectKernelTunables=true`: This prevents various with socket options from working as shown below.
`unbound[] warning: so-rcvbuf 1048576 was not granted. Got 425984. To fix: start with root permissions(linux) or sysctl bigger net.core.rmem_max(linux) or kern.ipc.maxsockbuf(bsd) values.`

2. Add `CAP_NET_ADMIN` to available caps which is needed for `ip-transparent: yes` config option to work as shown below.
`unbound[] warning: setsockopt(.. IP_TRANSPARENT ..) failed: Operation not permitted`

3. Make `ReadWritePaths` less permissive: `UNBOUND_SYSCONF_DIR` equals to `sysconfdir` which usually equals to `/etc` and `UNBOUND_LOCALSTATE_DIR` equals to `localstatedir` which usually equals to `/var`. Allowing write access for those dirs shouldn't be needed. The only dirs unbound should be allow to write to are `/run` ( for pidfile), `@UNBOUND_RUN_DIR@` (for chroot) and `@UNBOUND_CHROOT_DIR@` in case it differs from the previous one.

4. Bind-mount `/run/systemd/notify`, `UNBOUND_PIDFILE`, `/dev/log`, `/dev/urandom` in order to use them inside chroot.

5. Add few extra hardening options: `RestrictNamespaces`, `LockPersonality` and `RestrictSUIDSGID` should be safe to use.
2019-09-18 21:48:12 +02:00
Wouter Wijngaards
070019c9be - Fix #4142: unbound.service.in: improvements and fixes.
Add unit dependency ordering (based on systemd-resolved).
  Add 'CAP_SYS_RESOURCE' to 'CapabilityBoundingSet' (fixes warnings
  about missing privileges during startup). Add 'AF_INET6' to
  'RestrictAddressFamilies' (without it IPV6 can't work). From
  Guido Shanahan.


git-svn-id: file:///svn/unbound/trunk@4834 be551aaa-1e26-0410-a405-d3ace91eadb9
2018-08-07 08:30:22 +00:00
Wouter Wijngaards
6e0ba733f3 - Fix #1265 to use /bin/kill.
git-svn-id: file:///svn/unbound/trunk@4173 be551aaa-1e26-0410-a405-d3ace91eadb9
2017-05-18 07:08:55 +00:00
Wouter Wijngaards
0b10c8da28 Fixup with prefix and exec_prefix expanded.
git-svn-id: file:///svn/unbound/trunk@4172 be551aaa-1e26-0410-a405-d3ace91eadb9
2017-05-17 15:04:05 +00:00
Wouter Wijngaards
0d271cbb09 - Fix #1265: contrib/unbound.service contains hardcoded path.
git-svn-id: file:///svn/unbound/trunk@4171 be551aaa-1e26-0410-a405-d3ace91eadb9
2017-05-17 14:50:10 +00:00
Wouter Wijngaards
4fb762f6e4 - Fix #1229: Systemd service sandboxing, options in wrong sections.
git-svn-id: file:///svn/unbound/trunk@4078 be551aaa-1e26-0410-a405-d3ace91eadb9
2017-03-22 07:22:34 +00:00
Wouter Wijngaards
7e6e9a0155 - Fix #1229: Systemd service sandboxing in contrib/unbound.service.
git-svn-id: file:///svn/unbound/trunk@4032 be551aaa-1e26-0410-a405-d3ace91eadb9
2017-03-06 15:27:36 +00:00
Wouter Wijngaards
cd7db58ce3 - configure --enable-systemd and lets unbound use systemd sockets if
you enable use-systemd: yes in unbound.conf.
  Also there are contrib/unbound.socket and contrib/unbound.service:
  systemd files for unbound, install them in /usr/lib/systemd/system.
  Contributed by Sami Kerola and Pavel Odintsov.



git-svn-id: file:///svn/unbound/trunk@3975 be551aaa-1e26-0410-a405-d3ace91eadb9
2017-01-03 13:43:29 +00:00