|
660 | 660 | } |
661 | 661 | ); |
662 | 662 |
|
663 | | - systemd.services = toHardenedClientAttrs ( |
664 | | - client: |
665 | | - nameValuePair client.service.name ( |
666 | | - mkIf client.hardened { |
667 | | - serviceConfig = { |
668 | | - RuntimeDirectoryMode = "0750"; |
669 | | - |
670 | | - User = client.user.name; |
671 | | - Group = client.user.group; |
672 | | - |
673 | | - # settings implied by DynamicUser=true, without actually using it, |
674 | | - # see https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#DynamicUser= |
675 | | - RemoveIPC = true; |
676 | | - PrivateTmp = true; |
677 | | - ProtectSystem = "strict"; |
678 | | - ProtectHome = "yes"; |
679 | | - |
680 | | - AmbientCapabilities = [ |
681 | | - # see https://man7.org/linux/man-pages/man7/capabilities.7.html |
682 | | - # see https://docs.netbird.io/how-to/installation#running-net-bird-in-docker |
683 | | - # |
684 | | - # seems to work fine without CAP_SYS_ADMIN and CAP_SYS_RESOURCE |
685 | | - # CAP_NET_BIND_SERVICE could be added to allow binding on low ports, but is not required, |
686 | | - # see https://github.com/netbirdio/netbird/pull/1513 |
687 | | - |
688 | | - # failed creating tunnel interface wt-priv: [operation not permitted |
689 | | - "CAP_NET_ADMIN" |
690 | | - # failed to pull up wgInterface [wt-priv]: failed to create ipv4 raw socket: socket: operation not permitted |
691 | | - "CAP_NET_RAW" |
692 | | - ] |
693 | | - # required for eBPF filter, used to be subset of CAP_SYS_ADMIN |
694 | | - ++ optional (versionAtLeast kernel.version "5.8") "CAP_BPF" |
695 | | - ++ optional (versionOlder kernel.version "5.8") "CAP_SYS_ADMIN" |
696 | | - ++ optional ( |
697 | | - client.dns-resolver.address != null && client.dns-resolver.port < 1024 |
698 | | - ) "CAP_NET_BIND_SERVICE"; |
699 | | - }; |
700 | | - } |
701 | | - ) |
702 | | - ); |
| 663 | + systemd.services = mkMerge [ |
| 664 | + # netbird services |
| 665 | + (toHardenedClientAttrs ( |
| 666 | + client: |
| 667 | + nameValuePair client.service.name ( |
| 668 | + mkIf client.hardened { |
| 669 | + serviceConfig = { |
| 670 | + RuntimeDirectoryMode = "0750"; |
| 671 | + |
| 672 | + User = client.user.name; |
| 673 | + Group = client.user.group; |
| 674 | + |
| 675 | + # settings implied by DynamicUser=true, without actually using it, |
| 676 | + # see https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#DynamicUser= |
| 677 | + RemoveIPC = true; |
| 678 | + PrivateTmp = true; |
| 679 | + ProtectSystem = "strict"; |
| 680 | + ProtectHome = "yes"; |
| 681 | + |
| 682 | + AmbientCapabilities = [ |
| 683 | + # see https://man7.org/linux/man-pages/man7/capabilities.7.html |
| 684 | + # see https://docs.netbird.io/how-to/installation#running-net-bird-in-docker |
| 685 | + # |
| 686 | + # seems to work fine without CAP_SYS_ADMIN and CAP_SYS_RESOURCE |
| 687 | + # CAP_NET_BIND_SERVICE could be added to allow binding on low ports, but is not required, |
| 688 | + # see https://github.com/netbirdio/netbird/pull/1513 |
| 689 | + |
| 690 | + # failed creating tunnel interface wt-priv: [operation not permitted |
| 691 | + "CAP_NET_ADMIN" |
| 692 | + # failed to pull up wgInterface [wt-priv]: failed to create ipv4 raw socket: socket: operation not permitted |
| 693 | + "CAP_NET_RAW" |
| 694 | + ] |
| 695 | + # required for eBPF filter, used to be subset of CAP_SYS_ADMIN |
| 696 | + ++ optional (versionAtLeast kernel.version "5.8") "CAP_BPF" |
| 697 | + ++ optional (versionOlder kernel.version "5.8") "CAP_SYS_ADMIN" |
| 698 | + ++ optional ( |
| 699 | + client.dns-resolver.address != null && client.dns-resolver.port < 1024 |
| 700 | + ) "CAP_NET_BIND_SERVICE"; |
| 701 | + }; |
| 702 | + } |
| 703 | + ) |
| 704 | + )) |
| 705 | + # netbird-login services |
| 706 | + (toHardenedClientAttrs ( |
| 707 | + client: |
| 708 | + nameValuePair "${client.service.name}-login" ( |
| 709 | + mkIf client.hardened { |
| 710 | + serviceConfig = { |
| 711 | + User = client.user.name; |
| 712 | + Group = client.user.group; |
| 713 | + |
| 714 | + RemoveIPC = true; |
| 715 | + PrivateTmp = "disconnected"; # "disconnected" puts /tmp on `tmpfs` |
| 716 | + ProtectSystem = "strict"; |
| 717 | + ProtectHome = "yes"; |
| 718 | + }; |
| 719 | + } |
| 720 | + ) |
| 721 | + )) |
| 722 | + ]; |
703 | 723 |
|
704 | 724 | # see https://github.com/systemd/systemd/blob/17f3e91e8107b2b29fe25755651b230bbc81a514/src/resolve/org.freedesktop.resolve1.policy#L43-L43 |
705 | 725 | # see all actions used at https://github.com/netbirdio/netbird/blob/13e7198046a0d73a9cd91bf8e063fafb3d41885c/client/internal/dns/systemd_linux.go#L29-L32 |
|
736 | 756 | Type = "oneshot"; |
737 | 757 | RemainAfterExit = true; |
738 | 758 |
|
739 | | - User = client.user.name; |
740 | | - Group = client.user.group; |
741 | | - |
742 | | - RemoveIPC = true; |
743 | | - PrivateTmp = "disconnected"; # "disconnected" puts /tmp on `tmpfs` |
744 | | - ProtectSystem = "strict"; |
745 | | - ProtectHome = "yes"; |
746 | | - |
747 | 759 | LoadCredential = [ "setup-key:${client.login.setupKeyFile}" ]; |
748 | 760 | }; |
749 | 761 |
|
|
0 commit comments