main
nix 80 lines 2.92 KB
Raw
1 { config, pkgs, ... }:
2
3 {
4 systemd.services.ofborg-github-webhook-receiver = {
5 description = "ofBorg Webhook Receiver";
6
7 wantedBy = [ "ofborg.target" ];
8 bindsTo = [ "ofborg.target" ];
9 restartTriggers = [ config.environment.etc."ofborg.json".source ];
10
11 stopIfChanged = false;
12 unitConfig.StartLimitIntervalSec = 0;
13 serviceConfig = {
14 # Filesystem stuff
15 ProtectSystem = "strict"; # Prevent writing to most of /
16 ProtectHome = true; # Prevent accessing /home and /root
17 PrivateTmp = true; # Give an own directory under /tmp
18 PrivateDevices = true; # Deny access to most of /dev
19 ProtectKernelTunables = true; # Protect some parts of /sys
20 ProtectControlGroups = true; # Remount cgroups read-only
21 RestrictSUIDSGID = true; # Prevent creating SETUID/SETGID files
22 PrivateMounts = true; # Give an own mount namespace
23 RemoveIPC = true;
24 UMask = "0077";
25
26 Restart = "always";
27 RestartSec = "5s";
28 ExecStart = "${pkgs.ofborg}/bin/github-webhook-receiver /etc/ofborg.json";
29 User = "ofborg-github-webhook-receiver";
30 Group = "ofborg-github-webhook-receiver";
31
32 # Capabilities
33 CapabilityBoundingSet = ""; # Allow no capabilities at all
34 NoNewPrivileges = true; # Disallow getting more capabilities. This is also implied by other options.
35
36 # Kernel stuff
37 ProtectKernelModules = true; # Prevent loading of kernel modules
38 SystemCallArchitectures = "native"; # Usually no need to disable this
39 ProtectKernelLogs = true; # Prevent access to kernel logs
40 ProtectClock = true; # Prevent setting the RTC
41
42 # Misc
43 LockPersonality = true; # Prevent change of the personality
44 ProtectHostname = true; # Give an own UTS namespace
45 RestrictRealtime = true; # Prevent switching to RT scheduling
46 MemoryDenyWriteExecute = true; # Maybe disable this for interpreters like python
47 PrivateUsers = true; # If anything randomly breaks, it's mostly because of this
48 RestrictNamespaces = true;
49 SystemCallFilter = "@system-service";
50 };
51 };
52
53 services.nginx.virtualHosts."gh-webhook.ofborg.org" = {
54 forceSSL = true;
55 enableACME = true;
56
57 locations."/".proxyPass = "http://[::1]:9899/";
58 };
59
60 users.users.ofborg-github-webhook-receiver = {
61 isSystemUser = true;
62 group = "ofborg-github-webhook-receiver";
63 description = "ofBorg Github webhook receiver system user";
64 };
65 users.groups.ofborg-github-webhook-receiver = { };
66
67 sops.secrets = {
68 "ofborg/github-webhook-secret" = {
69 owner = "ofborg-github-webhook-receiver";
70 restartUnits = [ "ofborg-github-webhook-receiver.service" ];
71 sopsFile = ../../secrets/ofborg.core01.ofborg.org.yml;
72 };
73
74 "ofborg/github-webhook-rabbitmq-password" = {
75 owner = "ofborg-github-webhook-receiver";
76 restartUnits = [ "ofborg-github-webhook-receiver.service" ];
77 sopsFile = ../../secrets/ofborg.core01.ofborg.org.yml;
78 };
79 };
80 }