···
1
+
{ config, lib, pkgs, ... }:
9
+
# This is to provide support for old configuration options (as much as is
10
+
# reasonable). This can probably be removed after some time.
12
+
libdefaults = optionalAttrs (cfg.defaultRealm != null)
13
+
{ default_realm = cfg.defaultRealm; };
15
+
realms = optionalAttrs (lib.all (value: value != null) [
16
+
cfg.defaultRealm cfg.kdc cfg.kerberosAdminServer
18
+
"${cfg.defaultRealm}" = {
20
+
admin_server = cfg.kerberosAdminServer;
24
+
domain_realm = optionalAttrs (lib.all (value: value != null) [
25
+
cfg.domainRealm cfg.defaultRealm
27
+
".${cfg.domainRealm}" = cfg.defaultRealm;
28
+
"${cfg.domainRealm}" = cfg.defaultRealm;
32
+
mergedConfig = (recursiveUpdate defaultConfig {
33
+
inherit (config.krb5)
34
+
kerberos libdefaults realms domain_realm capaths appdefaults plugins
38
+
filterEmbeddedMetadata = value: if isAttrs value then
40
+
(attrName: attrValue: attrName != "_module" && attrValue != null)
44
+
mkIndent = depth: concatStrings (builtins.genList (_: " ") (2 * depth));
46
+
mkRelation = name: value: "${name} = ${mkVal { inherit value; }}";
48
+
mkVal = { value, depth ? 0 }:
49
+
if (value == true) then "true"
50
+
else if (value == false) then "false"
51
+
else if (isInt value) then (toString value)
52
+
else if (isList value) then
53
+
concatMapStringsSep " " mkVal { inherit value depth; }
54
+
else if (isAttrs value) then
55
+
(concatStringsSep "\n${mkIndent (depth + 1)}"
56
+
([ "{" ] ++ (mapAttrsToList
57
+
(attrName: attrValue: let
58
+
mappedAttrValue = mkVal {
62
+
in "${attrName} = ${mappedAttrValue}")
63
+
value))) + "\n${mkIndent depth}}"
66
+
mkMappedAttrsOrString = value: concatMapStringsSep "\n"
67
+
(line: if builtins.stringLength line > 0
68
+
then "${mkIndent 1}${line}"
71
+
(if isAttrs value then
72
+
concatStringsSep "\n"
73
+
(mapAttrsToList mkRelation value)
82
+
enable = mkEnableOption "Whether to enable Kerberos V.";
84
+
kerberos = mkOption {
85
+
type = types.package;
86
+
default = pkgs.krb5Full;
87
+
defaultText = "pkgs.krb5Full";
88
+
example = literalExample "pkgs.heimdalFull";
90
+
The Kerberos implementation that will be present in
91
+
<literal>environment.systemPackages</literal> after enabling this
96
+
libdefaults = mkOption {
97
+
type = with types; either attrs lines;
99
+
apply = attrs: filterEmbeddedMetadata attrs;
100
+
example = literalExample ''
102
+
default_realm = "ATHENA.MIT.EDU";
106
+
Settings used by the Kerberos V5 library.
110
+
realms = mkOption {
111
+
type = with types; either attrs lines;
113
+
example = literalExample ''
115
+
"ATHENA.MIT.EDU" = {
116
+
admin_server = "athena.mit.edu";
117
+
kdc = "athena.mit.edu";
121
+
apply = attrs: filterEmbeddedMetadata attrs;
122
+
description = "Realm-specific contact information and settings.";
125
+
domain_realm = mkOption {
126
+
type = with types; either attrs lines;
128
+
example = literalExample ''
130
+
"example.com" = "EXAMPLE.COM";
131
+
".example.com" = "EXAMPLE.COM";
134
+
apply = attrs: filterEmbeddedMetadata attrs;
136
+
Map of server hostnames to Kerberos realms.
140
+
capaths = mkOption {
141
+
type = with types; either attrs lines;
143
+
example = literalExample ''
145
+
"ATHENA.MIT.EDU" = {
146
+
"EXAMPLE.COM" = ".";
149
+
"ATHENA.MIT.EDU" = ".";
153
+
apply = attrs: filterEmbeddedMetadata attrs;
155
+
Authentication paths for non-hierarchical cross-realm authentication.
159
+
appdefaults = mkOption {
160
+
type = with types; either attrs lines;
162
+
example = literalExample ''
166
+
ticket_lifetime = 36000;
167
+
renew_lifetime = 36000;
170
+
initial_timeout = 1;
174
+
apply = attrs: filterEmbeddedMetadata attrs;
176
+
Settings used by some Kerberos V5 applications.
180
+
plugins = mkOption {
181
+
type = with types; either attrs lines;
183
+
example = literalExample ''
186
+
disable = "k5identity";
190
+
apply = attrs: filterEmbeddedMetadata attrs;
192
+
Controls plugin module registration.
196
+
extraConfig = mkOption {
197
+
type = with types; nullOr lines;
201
+
kdc = SYSLOG:NOTICE
202
+
admin_server = SYSLOG:NOTICE
203
+
default = SYSLOG:NOTICE
206
+
These lines go to the end of <literal>krb5.conf</literal> verbatim.
207
+
<literal>krb5.conf</literal> may include any of the relations that are
208
+
valid for <literal>kdc.conf</literal> (see <literal>man
209
+
kdc.conf</literal>), but it is not a recommended practice.
213
+
config = mkOption {
214
+
type = with types; nullOr lines;
218
+
default_realm = EXAMPLE.COM
222
+
admin_server = kerberos.example.com
223
+
kdc = kerberos.example.com
224
+
default_principal_flags = +preauth
228
+
example.com = EXAMPLE.COM
229
+
.example.com = EXAMPLE.COM
232
+
kdc = SYSLOG:NOTICE
233
+
admin_server = SYSLOG:NOTICE
234
+
default = SYSLOG:NOTICE
237
+
Verbatim <literal>krb5.conf</literal> configuration. Note that this
238
+
is mutually exclusive with configuration via
239
+
<literal>libdefaults</literal>, <literal>realms</literal>,
240
+
<literal>domain_realm</literal>, <literal>capaths</literal>,
241
+
<literal>appdefaults</literal>, <literal>plugins</literal> and
242
+
<literal>extraConfig</literal> configuration options. Consult
243
+
<literal>man krb5.conf</literal> for documentation.
247
+
defaultRealm = mkOption {
248
+
type = with types; nullOr str;
250
+
example = "ATHENA.MIT.EDU";
252
+
DEPRECATED, please use
253
+
<literal>krb5.libdefaults.default_realm</literal>.
257
+
domainRealm = mkOption {
258
+
type = with types; nullOr str;
260
+
example = "athena.mit.edu";
262
+
DEPRECATED, please create a map of server hostnames to Kerberos realms
263
+
in <literal>krb5.domain_realm</literal>.
268
+
type = with types; nullOr str;
270
+
example = "kerberos.mit.edu";
272
+
DEPRECATED, please pass a <literal>kdc</literal> attribute to a realm
273
+
in <literal>krb5.realms</literal>.
277
+
kerberosAdminServer = mkOption {
278
+
type = with types; nullOr str;
280
+
example = "kerberos.mit.edu";
282
+
DEPRECATED, please pass an <literal>admin_server</literal> attribute
283
+
to a realm in <literal>krb5.realms</literal>.
289
+
###### implementation
291
+
config = mkIf cfg.enable {
293
+
environment.systemPackages = [ cfg.kerberos ];
295
+
environment.etc."krb5.conf".text = if isString cfg.config
299
+
${mkMappedAttrsOrString mergedConfig.libdefaults}
302
+
${mkMappedAttrsOrString mergedConfig.realms}
305
+
${mkMappedAttrsOrString mergedConfig.domain_realm}
308
+
${mkMappedAttrsOrString mergedConfig.capaths}
311
+
${mkMappedAttrsOrString mergedConfig.appdefaults}
314
+
${mkMappedAttrsOrString mergedConfig.plugins}
315
+
'' + optionalString (mergedConfig.extraConfig != null)
316
+
("\n" + mergedConfig.extraConfig));
318
+
warnings = flatten [
319
+
(optional (cfg.defaultRealm != null) ''
320
+
The option krb5.defaultRealm is deprecated, please use
321
+
krb5.libdefaults.default_realm.
323
+
(optional (cfg.domainRealm != null) ''
324
+
The option krb5.domainRealm is deprecated, please use krb5.domain_realm.
326
+
(optional (cfg.kdc != null) ''
327
+
The option krb5.kdc is deprecated, please pass a kdc attribute to a
328
+
realm in krb5.realms.
330
+
(optional (cfg.kerberosAdminServer != null) ''
331
+
The option krb5.kerberosAdminServer is deprecated, please pass an
332
+
admin_server attribute to a realm in krb5.realms.
337
+
{ assertion = !((builtins.any (value: value != null) [
338
+
cfg.defaultRealm cfg.domainRealm cfg.kdc cfg.kerberosAdminServer
339
+
]) && ((builtins.any (value: value != {}) [
340
+
cfg.libdefaults cfg.realms cfg.domain_realm cfg.capaths
341
+
cfg.appdefaults cfg.plugins
342
+
]) || (builtins.any (value: value != null) [
343
+
cfg.config cfg.extraConfig
346
+
Configuration of krb5.conf by deprecated options is mutually exclusive
347
+
with configuration by section. Please migrate your config using the
348
+
attributes suggested in the warnings.
351
+
{ assertion = !(cfg.config != null
352
+
&& ((builtins.any (value: value != {}) [
353
+
cfg.libdefaults cfg.realms cfg.domain_realm cfg.capaths
354
+
cfg.appdefaults cfg.plugins
355
+
]) || (builtins.any (value: value != null) [
356
+
cfg.extraConfig cfg.defaultRealm cfg.domainRealm cfg.kdc
357
+
cfg.kerberosAdminServer
360
+
Configuration of krb5.conf using krb.config is mutually exclusive with
361
+
configuration by section. If you want to mix the two, you can pass
362
+
lines to any configuration section or lines to krb5.extraConfig.