tangled
alpha
login
or
join now
pyrox.dev
/
nixpkgs
0
fork
atom
lol
0
fork
atom
overview
issues
pulls
pipelines
nixos/alps: add hardening, extensible options, test
Henri Menke
3 years ago
aeb5a692
46988950
+112
-9
3 changed files
expand all
collapse all
unified
split
nixos
modules
services
web-apps
alps.nix
tests
all-tests.nix
alps.nix
+43
-9
nixos/modules/services/web-apps/alps.nix
reviewed
···
70
70
'';
71
71
};
72
72
};
73
73
+
74
74
+
package = mkOption {
75
75
+
internal = true;
76
76
+
type = types.package;
77
77
+
default = pkgs.alps;
78
78
+
};
79
79
+
80
80
+
args = mkOption {
81
81
+
internal = true;
82
82
+
type = types.listOf types.str;
83
83
+
default = [
84
84
+
"-addr" "${cfg.bindIP}:${toString cfg.port}"
85
85
+
"-theme" "${cfg.theme}"
86
86
+
"imaps://${cfg.imaps.host}:${toString cfg.imaps.port}"
87
87
+
"smpts://${cfg.smtps.host}:${toString cfg.smtps.port}"
88
88
+
];
89
89
+
};
73
90
};
74
91
75
92
config = mkIf cfg.enable {
···
80
97
after = [ "network.target" "network-online.target" ];
81
98
82
99
serviceConfig = {
83
83
-
ExecStart = ''
84
84
-
${pkgs.alps}/bin/alps \
85
85
-
-addr ${cfg.bindIP}:${toString cfg.port} \
86
86
-
-theme ${cfg.theme} \
87
87
-
imaps://${cfg.imaps.host}:${toString cfg.imaps.port} \
88
88
-
smpts://${cfg.smtps.host}:${toString cfg.smtps.port}
89
89
-
'';
90
90
-
StateDirectory = "alps";
91
91
-
WorkingDirectory = "/var/lib/alps";
100
100
+
ExecStart = "${cfg.package}/bin/alps ${escapeShellArgs cfg.args}";
92
101
DynamicUser = true;
102
102
+
## This is desirable but would restrict bindIP to 127.0.0.1
103
103
+
#IPAddressAllow = "localhost";
104
104
+
#IPAddressDeny = "any";
105
105
+
LockPersonality = true;
106
106
+
NoNewPrivileges = true;
107
107
+
PrivateDevices = true;
108
108
+
PrivateIPC = true;
109
109
+
PrivateTmp = true;
110
110
+
PrivateUsers = true;
111
111
+
ProtectClock = true;
112
112
+
ProtectControlGroups = true;
113
113
+
ProtectHome = true;
114
114
+
ProtectHostname = true;
115
115
+
ProtectKernelLogs = true;
116
116
+
ProtectKernelModules = true;
117
117
+
ProtectKernelTunables = true;
118
118
+
ProtectProc = "invisible";
119
119
+
ProtectSystem = "strict";
120
120
+
RemoveIPC = true;
121
121
+
RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
122
122
+
RestrictNamespaces = true;
123
123
+
RestrictRealtime = true;
124
124
+
RestrictSUIDSGID = true;
125
125
+
SystemCallArchitectures = "native";
126
126
+
SystemCallFilter = [ "@system-service @resources" "~@privileged @obsolete" ];
93
127
};
94
128
};
95
129
};
+1
nixos/tests/all-tests.nix
reviewed
···
74
74
agda = handleTest ./agda.nix {};
75
75
airsonic = handleTest ./airsonic.nix {};
76
76
allTerminfo = handleTest ./all-terminfo.nix {};
77
77
+
alps = handleTest ./alps.nix {};
77
78
amazon-init-shell = handleTest ./amazon-init-shell.nix {};
78
79
apfs = handleTest ./apfs.nix {};
79
80
apparmor = handleTest ./apparmor.nix {};
+68
nixos/tests/alps.nix
reviewed
···
1
1
+
let
2
2
+
certs = import ./common/acme/server/snakeoil-certs.nix;
3
3
+
domain = certs.domain;
4
4
+
in
5
5
+
import ./make-test-python.nix {
6
6
+
name = "alps";
7
7
+
8
8
+
nodes = {
9
9
+
server = {
10
10
+
imports = [ ./common/user-account.nix ];
11
11
+
security.pki.certificateFiles = [
12
12
+
certs.ca.cert
13
13
+
];
14
14
+
networking.extraHosts = ''
15
15
+
127.0.0.1 ${domain}
16
16
+
'';
17
17
+
networking.firewall.allowedTCPPorts = [ 25 465 993 ];
18
18
+
services.postfix = {
19
19
+
enable = true;
20
20
+
enableSubmission = true;
21
21
+
enableSubmissions = true;
22
22
+
tlsTrustedAuthorities = "${certs.ca.cert}";
23
23
+
sslCert = "${certs.${domain}.cert}";
24
24
+
sslKey = "${certs.${domain}.key}";
25
25
+
};
26
26
+
services.dovecot2 = {
27
27
+
enable = true;
28
28
+
enableImap = true;
29
29
+
sslCACert = "${certs.ca.cert}";
30
30
+
sslServerCert = "${certs.${domain}.cert}";
31
31
+
sslServerKey = "${certs.${domain}.key}";
32
32
+
};
33
33
+
};
34
34
+
35
35
+
client = { nodes, ... }: {
36
36
+
security.pki.certificateFiles = [
37
37
+
certs.ca.cert
38
38
+
];
39
39
+
networking.extraHosts = ''
40
40
+
${nodes.server.config.networking.primaryIPAddress} ${domain}
41
41
+
'';
42
42
+
services.alps = {
43
43
+
enable = true;
44
44
+
theme = "alps";
45
45
+
imaps = {
46
46
+
host = domain;
47
47
+
port = 993;
48
48
+
};
49
49
+
smtps = {
50
50
+
host = domain;
51
51
+
port = 465;
52
52
+
};
53
53
+
};
54
54
+
};
55
55
+
};
56
56
+
57
57
+
testScript = ''
58
58
+
server.start()
59
59
+
server.wait_for_unit("postfix.service")
60
60
+
server.wait_for_unit("dovecot2.service")
61
61
+
server.wait_for_open_port(465)
62
62
+
server.wait_for_open_port(993)
63
63
+
64
64
+
client.start()
65
65
+
client.wait_for_unit("alps.service")
66
66
+
client.wait_until_succeeds("curl -fvvv -s http://127.0.0.1:1323/", timeout=60)
67
67
+
'';
68
68
+
}