blob: edb4796ac127fa7607c75810d6d428d18193add1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
{
config,
lib,
pkgs,
...
}:
let
cfg = config.services.openbao;
settingsFormat = pkgs.formats.json { };
in
{
options = {
services.openbao = {
enable = lib.mkEnableOption "OpenBao daemon";
package = lib.mkPackageOption pkgs "openbao" {
example = "pkgs.openbao.override { withHsm = false; withUi = false; }";
};
settings = lib.mkOption {
description = ''
Settings of OpenBao.
See [documentation](https://openbao.org/docs/configuration) for more details.
'';
example = lib.literalExpression ''
{
ui = true;
listener.default = {
type = "tcp";
tls_acme_email = config.security.acme.defaults.email;
tls_acme_domains = [ "example.com" ];
tls_acme_disable_http_challenge = true;
};
cluster_addr = "http://127.0.0.1:8201";
api_addr = "https://example.com";
storage.raft.path = "/var/lib/openbao";
}
'';
type = lib.types.submodule {
freeformType = settingsFormat.type;
options = {
ui = lib.mkEnableOption "the OpenBao web UI";
listener = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submodule (
{ config, ... }:
{
freeformType = settingsFormat.type;
options = {
type = lib.mkOption {
type = lib.types.enum [
"tcp"
"unix"
];
description = ''
The listener type to enable.
'';
};
address = lib.mkOption {
type = lib.types.str;
default = if config.type == "unix" then "/run/openbao/openbao.sock" else "127.0.0.1:8200";
defaultText = lib.literalExpression ''if config.services.openbao.settings.listener.<name>.type == "unix" then "/run/openbao/openbao.sock" else "127.0.0.1:8200"'';
description = ''
The TCP address or UNIX socket path to listen on.
'';
};
};
}
)
);
description = ''
Configure a listener for responding to requests.
'';
};
};
};
};
extraArgs = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
description = ''
Additional arguments given to OpenBao.
'';
};
};
};
config = lib.mkIf cfg.enable {
environment.systemPackages = [ cfg.package ];
systemd.services.openbao = {
description = "OpenBao - A tool for managing secrets";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
restartIfChanged = false; # do not restart on "nixos-rebuild switch". It would seal the storage and disrupt the clients.
serviceConfig = {
Type = "notify";
ExecStart = lib.escapeShellArgs (
[
(lib.getExe cfg.package)
"server"
"-config"
(settingsFormat.generate "openbao.hcl.json" cfg.settings)
]
++ cfg.extraArgs
);
ExecReload = "${lib.getExe' pkgs.coreutils "kill"} -SIGHUP $MAINPID";
StateDirectory = "openbao";
StateDirectoryMode = "0700";
RuntimeDirectory = "openbao";
RuntimeDirectoryMode = "0755";
DynamicUser = true;
User = "openbao";
Group = "openbao";
CapabilityBoundingSet = "";
LimitCORE = 0;
LockPersonality = true;
MemorySwapMax = 0;
MemoryZSwapMax = 0;
PrivateUsers = "identity";
ProcSubset = "pid";
ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectHostname = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectProc = "invisible";
Restart = "on-failure";
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
"AF_UNIX"
];
RestrictNamespaces = true;
RestrictRealtime = true;
SystemCallArchitectures = "native";
SystemCallFilter = [
"@system-service"
"@resources"
"~@privileged"
"@chown"
];
UMask = "0077";
};
};
};
}
|