• Bind-Mount in ein chroot mit systemd

    From Marc Haber@21:1/5 to All on Wed Jun 28 08:50:01 2023
    Hallo,

    ich starte meinen bind9 in einem chroot, indem ich ihm in der
    systemd-unit im ExecStart den Parameter -t /var/local/chroot/bind9
    mitgebe.

    In bookworm wird der bind als "Type=notify" gestartet, dazu muss ich
    den /run/systemd/notify socket in das chroot bind-mounten.

    Gibt es da eine Standardlösung mit systemd? Muss ich da für jedes
    einzelne chroot eine dedizierte mount-unit schreiben und diese mit
    meiner bind9-Unit so verkoppeln dass sie zuerst gestartet wird?

    BindPaths scheint keine Lösung zu sein, die scheint nur zu
    funktionieren wenn man das chroot direkt von systemd einrichten lässt.
    Oder ist das sogar der richtige Weg um bind9 in ein Chroot zu sperren,
    in dem man das von systemd erledigen lässt und das chroot-Feature von
    bind selbst gar nicht mehr benutzt?

    Grüße
    Marc
    --
    -------------------------------------- !! No courtesy copies, please !! ----- Marc Haber | " Questions are the | Mailadresse im Header Mannheim, Germany | Beginning of Wisdom " |
    Nordisch by Nature | Lt. Worf, TNG "Rightful Heir" | Fon: *49 621 72739834

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sven Hartge@21:1/5 to Marc Haber on Thu Jun 29 12:00:01 2023
    Marc Haber <mh+debian-user-german@zugschlus.de> wrote:

    BindPaths scheint keine Lösung zu sein, die scheint nur zu
    funktionieren wenn man das chroot direkt von systemd einrichten lässt.
    Oder ist das sogar der richtige Weg um bind9 in ein Chroot zu sperren,
    in dem man das von systemd erledigen lässt und das chroot-Feature von
    bind selbst gar nicht mehr benutzt?

    Was spricht dagegen, die systemd-Funktion dafür zu nutzen? Wenn diese
    das gleich Ergebnis hat, erscheint mir das wartbarer wie ein manuells
    chroot zu sein.



    --
    Sigmentation fault. Core dumped.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Haber@21:1/5 to All on Fri Jun 30 07:20:01 2023
    On Thu, 29 Jun 2023 11:37:20 +0200, Sven Hartge <sven@svenhartge.de>
    wrote:
    Marc Haber <mh+debian-user-german@zugschlus.de> wrote:
    BindPaths scheint keine Lösung zu sein, die scheint nur zu
    funktionieren wenn man das chroot direkt von systemd einrichten lässt.
    Oder ist das sogar der richtige Weg um bind9 in ein Chroot zu sperren,
    in dem man das von systemd erledigen lässt und das chroot-Feature von
    bind selbst gar nicht mehr benutzt?

    Was spricht dagegen, die systemd-Funktion dafür zu nutzen? Wenn diese
    das gleich Ergebnis hat, erscheint mir das wartbarer wie ein manuells
    chroot zu sein.

    Du meinst BindPaths, oder bind direkt von systemd chrooten zu lassen?

    Ersteres funktioniert nicht weil man dort keinen Zielpfad angeben
    kann, hier wird wohl /foo/bar/baz an denselben Platz im
    systemd-erzeugten chroot eingehängt.

    Bei zweiterem habe ich den Verdacht, dass die bind-Community das
    ungerner supporten dürfte als ein eigenchrooteter bind.

    Grüße
    Marc
    --
    -------------------------------------- !! No courtesy copies, please !! ----- Marc Haber | " Questions are the | Mailadresse im Header Mannheim, Germany | Beginning of Wisdom " |
    Nordisch by Nature | Lt. Worf, TNG "Rightful Heir" | Fon: *49 621 72739834

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Sven Hartge@21:1/5 to Manuel Leiner on Fri Oct 27 13:10:02 2023
    Manuel Leiner <manuel.leiner@noris.net> wrote:

    ich bin gerade mit Kollegen ebenfalls auf dieses Problem gestossen und
    haben dafuer nun tatsaechlich einen funktionierenden Weg gefunden,
    welcher in der Kombination von systemd + bind9 + chroot funktioniert.

    Wäre die Nutzung von "BindPaths=" (siehe systemd.exec(5)) nicht besser
    als die manuellen ExecStartPre-Statements, sofern man das Chroot auch
    von systemd erzeugen läßt?



    --
    Sigmentation fault. Core dumped.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Haber@21:1/5 to All on Sat Oct 28 13:20:01 2023
    On Fri, 27 Oct 2023 12:42:27 +0200, Sven Hartge <sven@svenhartge.de>
    wrote:
    Manuel Leiner <manuel.leiner@noris.net> wrote:

    ich bin gerade mit Kollegen ebenfalls auf dieses Problem gestossen und
    haben dafuer nun tatsaechlich einen funktionierenden Weg gefunden,
    welcher in der Kombination von systemd + bind9 + chroot funktioniert.

    Wäre die Nutzung von "BindPaths=" (siehe systemd.exec(5)) nicht besser
    als die manuellen ExecStartPre-Statements, sofern man das Chroot auch
    von systemd erzeugen läßt?

    Hier meine seit ein paar Wochen produktive Lösung:

    |1 [1/4996]mh@torres:~ $ sudo systemctl cat bind9
    |# /lib/systemd/system/named.service
    |[Unit]
    |Description=BIND Domain Name Server
    |Documentation=man:named(8)
    |After=network.target
    |Wants=nss-lookup.target
    |Before=nss-lookup.target
    |
    |[Service]
    |Type=notify
    |EnvironmentFile=-/etc/default/named
    |ExecStart=/usr/sbin/named -f $OPTIONS
    |ExecReload=/usr/sbin/rndc reload
    |ExecStop=/usr/sbin/rndc stop
    |Restart=on-failure
    |
    |[Install]
    |WantedBy=multi-user.target
    |Alias=bind9.service
    |
    |# /etc/systemd/system/named.service.d/options.conf
    |[Service]
    |ExecStart=
    |ExecStart=/usr/sbin/named -f -u bind -c /etc/bind/named.conf -t /var/local/ch> |
    |
    |# /etc/systemd/system/named.service.d/order.conf
    |[Unit]
    |After=network-online.target
    |Wants=network-online.target
    |
    |
    |# /etc/systemd/system/named.service.d/restart.conf
    |[Unit]
    |StartLimitIntervalSec=90s
    |StartLimitBurst=5
    |
    |[Service]
    |Restart=on-failure
    |RestartSec=5s
    |
    |# /etc/systemd/system/named.service.d/security.conf
    |[Service]
    |WorkingDirectory=/var/local/chroot/bind
    |# this would end up in a "too many symlinks" message.
    |#RootDirectory=/
    |ProtectProc=invisible
    |ProcSubset=pid |BindReadOnlyPaths=/run/systemd/notify:/var/local/chroot/bind/run/systemd/noti> |BindReadOnlyPaths=/usr/share/dns:/var/local/chroot/bind/usr/share/dns |User=bind
    |Group=bind
    |UMask=077
    |CapabilityBoundingSet=cap_net_admin cap_net_bind_service cap_sys_chroot |AmbientCapabilities= cap_net_admin cap_net_bind_service cap_sys_chroot |NoNewPrivileges=true
    |#not explicitly set: works automatically.
    |#AppArmorProfile
    |ProtectSystem=strict
    |ProtectHome=yes
    |# {Runtime,Cache,Configuration}Directory cannot be used
    |# because our bind chroots itself and those directives only
    |# create directories under the standard paths.
    |#RuntimeDirectory=bind
    |ReadWritePaths=/var/local/chroot/bind/run
    |#CacheDirectory=bind
    |ReadWritePaths=/var/local/chroot/bind/var/cache/bind |#ConfigurationDirectory=bind
    |ReadOnlyPaths=/
    |InaccessiblePaths=-/lost+found
    |NoExecPaths=/
    |# /lib is necessary here, or execve will fail without indication for reason |ExecPaths=/usr/sbin/named /usr/sbin/rndc /lib
    |PrivateTmp=true
    |PrivateDevices=true
    |PrivateIPC=true
    |# enabling PrivateUsers=true causes
    |# "couldn't add command channel 127.0.0.1#953: permission denied" |ProtectHostname=true
    |ProtectClock=true
    |ProtectKernelTunables=true
    |ProtectKernelModules=true
    |ProtectKernelLogs=true
    |ProtectControlGroups=true
    |RestrictAddressFamilies=AF_NETLINK AF_UNIX AF_INET AF_INET6 |RestrictNamespaces=~user pid net uts mnt cgroup ipc
    |LockPersonality=true
    |MemoryDenyWriteExecute=true
    |RestrictRealtime=true
    |RestrictSUIDSGID=true
    |RemoveIPC=true
    |SystemCallFilter=~@mount @swap @resources @reboot @privileged @obsolete @modu> |SystemCallFilter=chroot setuid
    |SystemCallArchitectures=native
    |[2/4996]mh@torres:~ $

    Grüße
    Marc
    --
    -------------------------------------- !! No courtesy copies, please !! ----- Marc Haber | " Questions are the | Mailadresse im Header Mannheim, Germany | Beginning of Wisdom " |
    Nordisch by Nature | Lt. Worf, TNG "Rightful Heir" | Fon: *49 621 72739834

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Manfred Schmitt@21:1/5 to Marc Haber on Sun Oct 29 01:20:01 2023
    Marc Haber schrieb:

    On Fri, 27 Oct 2023 12:42:27 +0200, Sven Hartge <sven@svenhartge.de>
    wrote:
    Manuel Leiner <manuel.leiner@noris.net> wrote:

    ich bin gerade mit Kollegen ebenfalls auf dieses Problem gestossen und
    haben dafuer nun tatsaechlich einen funktionierenden Weg gefunden,
    welcher in der Kombination von systemd + bind9 + chroot funktioniert.

    Wäre die Nutzung von "BindPaths=" (siehe systemd.exec(5)) nicht besser
    als die manuellen ExecStartPre-Statements, sofern man das Chroot auch
    von systemd erzeugen läßt?

    Hier meine seit ein paar Wochen produktive Lösung:
    [wall of text]

    So viel zu "Systemd Units sind so schön einfach, übersichtlich" ;-)
    Im Ernst: Schon echt mächtig.
    Aber wer steigt da durch, 5 Units nur für bind, puh...

    Bad paste, müsste es nicht @module sein?

    |SystemCallFilter=~@mount @swap @resources @reboot @privileged @obsolete @modu>

    Tschau,
    Manne

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul Muster@21:1/5 to Marc Haber on Sun Oct 29 08:40:01 2023
    On 28.10.23 13:02, Marc Haber wrote:

    |ExecStart=/usr/sbin/named -f -u bind -c /etc/bind/named.conf -t /var/local/ch>

    |BindReadOnlyPaths=/run/systemd/notify:/var/local/chroot/bind/run/systemd/noti>

    |SystemCallFilter=~@mount @swap @resources @reboot @privileged @obsolete @modu>

    Da war an ein paar Stellen das Terminal zu schmal, oder?


    mfG Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Haber@21:1/5 to expires-231231@slashproc.org on Sun Oct 29 14:20:01 2023
    On Sun, 29 Oct 2023 00:46:55 +0200, Manfred Schmitt <expires-231231@slashproc.org> wrote:
    Marc Haber schrieb:
    Hier meine seit ein paar Wochen produktive Lösung:
    [wall of text]

    So viel zu "Systemd Units sind so schön einfach, übersichtlich" ;-)

    Nun, hierbei ziehe ich Register, die ich in 25 Jahren Linux in einem
    per sysvinit gestarteten Dienst nicht ansatzwise in Benutzung gesehen
    hätte.

    Ich behaupte: Würde es auf dieser Welt auch nur EIN initscript gebenn,
    das den Service auf diesem Sicherheitsniveau startet, wäre es noch
    viel weniger lesbar.

    Und jetzt darf jemand mit "braucht kein Mensch" um die Ecke kommen.

    Im Ernst: Schon echt mächtig.
    Aber wer steigt da durch, 5 Units nur für bind, puh...

    Das ist eine einzige in fünf Files aufgeteilte Unit. Die Aufteilung
    ist geschuldet, dass diese Konfiguration aus einem Ansible fällt, das
    den bind auf unterschiedlichen Systemen mit unterschiedlichen Features
    startet. So wird z.B. das Override-File mit den ganzen
    Securityfeatures nur auf Debian Bookworm verteilt.

    Das könnte man auch templaten oder manuell in einem einzigen File hinschreiben, ich fand es so aber übersichtlicher und einfacher in
    ansible abzubilden.

    Grüße
    Marc
    --
    -------------------------------------- !! No courtesy copies, please !! ----- Marc Haber | " Questions are the | Mailadresse im Header Mannheim, Germany | Beginning of Wisdom " |
    Nordisch by Nature | Lt. Worf, TNG "Rightful Heir" | Fon: *49 621 72739834

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Marc Haber@21:1/5 to exp-311223@news.muster.net on Sun Oct 29 14:20:01 2023
    On Sun, 29 Oct 2023 08:18:14 +0100, Paul Muster
    <exp-311223@news.muster.net> wrote:
    On 28.10.23 13:02, Marc Haber wrote:

    |ExecStart=/usr/sbin/named -f -u bind -c /etc/bind/named.conf -t /var/local/ch>

    |BindReadOnlyPaths=/run/systemd/notify:/var/local/chroot/bind/run/systemd/noti>

    |SystemCallFilter=~@mount @swap @resources @reboot @privileged @obsolete @modu>

    Da war an ein paar Stellen das Terminal zu schmal, oder?

    Oh ja natürlich. Ich bitte um Entschuldigung.

    |[2/4996]mh@torres:~ $ sudo systemctl cat bind9 | cat
    |# /lib/systemd/system/named.service
    |[Unit]
    |Description=BIND Domain Name Server
    |Documentation=man:named(8)
    |After=network.target
    |Wants=nss-lookup.target
    |Before=nss-lookup.target
    |
    |[Service]
    |Type=notify
    |EnvironmentFile=-/etc/default/named
    |ExecStart=/usr/sbin/named -f $OPTIONS
    |ExecReload=/usr/sbin/rndc reload
    |ExecStop=/usr/sbin/rndc stop
    |Restart=on-failure
    |
    |[Install]
    |WantedBy=multi-user.target
    |Alias=bind9.service
    |
    |# /etc/systemd/system/named.service.d/options.conf
    |# this file is managed by ansible
    |
    |# this puts bind into a chroot (which is done on all Debian systems)
    |
    |[Service]
    |ExecStart=
    |ExecStart=/usr/sbin/named -f -u bind -c /etc/bind/named.conf -t /var/local/chroot/bind
    |
    |
    |# /etc/systemd/system/named.service.d/order.conf
    |# this file is managed by ansible
    |
    |# this forced bind to start after the network
    |
    |[Unit]
    |After=network-online.target
    |Wants=network-online.target
    |
    |
    |# /etc/systemd/system/named.service.d/restart.conf
    |# this file is managed by ansible
    |
    |# this makes bind restart after a failure
    |
    |[Unit]
    |StartLimitIntervalSec=90s
    |StartLimitBurst=5
    |
    |[Service]
    |Restart=on-failure
    |RestartSec=5s
    |
    |# /etc/systemd/system/named.service.d/security.conf
    |# this file is managed by ansible
    |
    |# this reduces bind's exposure to local security risks
    |# this is only done on bookworm and newer
    |
    |[Service]
    |WorkingDirectory=/var/local/chroot/bind
    |# this will end up in a "too many symlinks" message.
    |#RootDirectory=/
    |ProtectProc=invisible
    |ProcSubset=pid |BindReadOnlyPaths=/run/systemd/notify:/var/local/chroot/bind/run/systemd/notify
    |BindReadOnlyPaths=/usr/share/dns:/var/local/chroot/bind/usr/share/dns |User=bind
    |Group=bind
    |UMask=077
    |CapabilityBoundingSet=cap_net_admin cap_net_bind_service cap_sys_chroot |AmbientCapabilities= cap_net_admin cap_net_bind_service cap_sys_chroot |NoNewPrivileges=true
    |#not explicitly set: works automatically.
    |#AppArmorProfile
    |ProtectSystem=strict
    |ProtectHome=yes
    |# {Runtime,Cache,Configuration}Directory cannot be used
    |# because our bind chroots itself and those directives only
    |# create directories under the standard paths.
    |#RuntimeDirectory=bind
    |ReadWritePaths=/var/local/chroot/bind/run
    |#CacheDirectory=bind
    |ReadWritePaths=/var/local/chroot/bind/var/cache/bind |#ConfigurationDirectory=bind
    |ReadOnlyPaths=/
    |InaccessiblePaths=-/lost+found
    |NoExecPaths=/
    |# /lib is necessary here, or execve will fail without indication for reason |ExecPaths=/usr/sbin/named /usr/sbin/rndc /lib
    |PrivateTmp=true
    |PrivateDevices=true
    |PrivateIPC=true
    |# enabling PrivateUsers=true causes
    |# "couldn't add command channel 127.0.0.1#953: permission denied" |ProtectHostname=true
    |ProtectClock=true
    |ProtectKernelTunables=true
    |ProtectKernelModules=true
    |ProtectKernelLogs=true
    |ProtectControlGroups=true
    |RestrictAddressFamilies=AF_NETLINK AF_UNIX AF_INET AF_INET6 |RestrictNamespaces=~user pid net uts mnt cgroup ipc
    |LockPersonality=true
    |MemoryDenyWriteExecute=true
    |RestrictRealtime=true
    |RestrictSUIDSGID=true
    |RemoveIPC=true
    |SystemCallFilter=~@mount @swap @resources @reboot @privileged @obsolete @module @debug @cpu-emulation @clock
    |SystemCallFilter=chroot setuid
    |SystemCallArchitectures=native
    |[3/4997]mh@torres:~ $

    Grüße
    Marc
    --
    -------------------------------------- !! No courtesy copies, please !! ----- Marc Haber | " Questions are the | Mailadresse im Header Mannheim, Germany | Beginning of Wisdom " |
    Nordisch by Nature | Lt. Worf, TNG "Rightful Heir" | Fon: *49 621 72739834

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)