-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathauth.nix
More file actions
124 lines (110 loc) · 3.38 KB
/
Copy pathauth.nix
File metadata and controls
124 lines (110 loc) · 3.38 KB
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
{
lib,
config,
pkgs,
...
}:
let
cfg = config.ocf.auth;
keytabSecretPath = ../secrets/master-keyed/keytabs + "/${config.networking.hostName}.age";
hasKeytab = builtins.pathExists keytabSecretPath;
in
{
options.ocf.auth = {
enable = lib.mkEnableOption "Enable OCF authentication";
};
config = lib.mkIf cfg.enable {
age.secrets.root-password-hash.rekeyFile = ../secrets/master-keyed/root-password-hash.age;
# Per-host keytab for GSSAPI SSH authentication
# Only configured if the host has a keytab in secrets/master-keyed/keytabs/<hostname>.age
age.secrets.krb5-keytab = lib.mkIf hasKeytab {
rekeyFile = keytabSecretPath;
path = "/etc/krb5.keytab";
owner = "root";
group = "root";
mode = "0600";
};
users = {
mutableUsers = false;
users.root.hashedPasswordFile = config.age.secrets.root-password-hash.path;
ldap = {
enable = true;
server = "ldaps://ldap.ocf.berkeley.edu";
base = "dc=OCF,dc=Berkeley,dc=EDU";
daemon.enable = true;
extraConfig = ''
tls_reqcert hard
tls_cacert /etc/ssl/certs/ca-certificates.crt
base dc=ocf,dc=berkeley,dc=edu
nss_base_passwd ou=people,dc=ocf,dc=berkeley,dc=edu
nss_base_group ou=group,dc=ocf,dc=berkeley,dc=edu
'';
};
};
security.sudo = {
extraConfig = ''
Defaults passprompt="[sudo] password for %u/root: "
'';
extraRules = [
{
groups = [ "ocfroot" ];
commands = [ "ALL" ];
}
{
users = [ "ocfbackups" ];
commands = [
{
command = lib.getExe pkgs.rsync;
options = [ "NOPASSWD" ];
}
];
}
];
};
security.pam.services.sudo.text =
let
pam_krb5_so = "${pkgs.pam_krb5}/lib/security/pam_krb5.so";
in
''
# use /root principal to sudo
auth required ${pam_krb5_so} minimum_uid=1000 alt_auth_map=%s/root only_alt_auth no_ccache
account required pam_unix.so
# common-session-noninteractive
session [default=1] pam_permit.so
session requisite pam_deny.so
session required pam_permit.so
session optional ${pam_krb5_so} minimum_uid=1000
session required pam_unix.so
# reset user limits
session required pam_limits.so
'';
security.krb5 = {
enable = true;
package = pkgs.heimdal;
settings = {
realms."OCF.BERKELEY.EDU" = {
admin_server = "kerberos.ocf.berkeley.edu";
kdc = [ "kerberos.ocf.berkeley.edu" ];
};
domain_realm = {
"ocf.berkeley.edu" = "OCF.BERKELEY.EDU";
".ocf.berkeley.edu" = "OCF.BERKELEY.EDU";
};
libdefaults = {
default_realm = "OCF.BERKELEY.EDU";
forwardable = true;
};
};
};
services.openssh.settings = {
GSSAPIAuthentication = "yes";
GSSAPICleanupCredentials = "yes";
GSSAPIStrictAcceptorCheck = "yes";
# ssh gssapi currently does not support a post-quantum safe key exchange
# algorithm. lets disable gssapi key exchange and use ssh's default key
# exchanges (which supports post-quantum safe key exchange).
# Only enable key exchange if host has a keytab
#GSSAPIKeyExchange = lib.mkIf hasKeytab "yes";
};
};
}