Skip to content

Commit 3510400

Browse files
committed
add yubikey module
1 parent 0614a1b commit 3510400

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

hosts/common/users/gabe.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ in {
4343
];
4444
};
4545

46+
base.yubiauth = {
47+
enable = true;
48+
49+
mappings = [
50+
"gabe:MW9BvJEnapPkyE/UOpnT0skNdNyiTW/zk+ys+NJQIpcS9Ej7rHDL2AOdf8Wb/jYHAC9DSLRqf8SRbpjbW/I8wA==,6D2e7W3byi0MYF4CUfCjMwKTv0JVNL1izKYeKNOpzLlyEG4sKNfmqZWaS+9bfV6A+OlMbCT5g8v++D7nwnkNXg==,es256,+presence:MKn57WF5JlA9mSEhOEqJLJH2LMVS4wb44sR3Q8V/7D2H1xGuBuEMOc5pthRWC+5yN3URP1Ticw/o7bPWpOva0g==,CC6Ber5JNcC0I7IwXyL87reTvfZqZ+FVZQaiizTNS+g7QtxOeh6aDV/ztOoeRkS+wallUlKK9J3u4nco114fjw==,es256,+presence"
51+
];
52+
};
53+
4654
sops.secrets.gabe-pw.neededForUsers = true;
4755

4856
home-manager.users.gabe =

modules/nixos/base/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ in {
1818
./services.nix
1919
./ssh.nix
2020
./virtualization.nix
21+
./yubikey.nix
2122
];
2223

2324
options.base = with lib.types; {

modules/nixos/base/yubikey.nix

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{ config, pkgs, lib, ... }:
2+
3+
let
4+
inherit (lib) mkIf;
5+
cfg = config.base.yubiauth;
6+
in {
7+
options.base.yubiauth = let
8+
inherit (lib) mkOption mkEnableOption;
9+
inherit (lib.types) listOf str bool;
10+
in {
11+
enable = mkEnableOption "Enable YubiAuth";
12+
13+
login = mkOption {
14+
type = bool;
15+
default = true;
16+
description = "Enable U2F authentication for login";
17+
};
18+
19+
sudo = mkOption {
20+
type = bool;
21+
default = true;
22+
description = "Enable U2F authentication for sudo";
23+
};
24+
25+
mappings = mkOption {
26+
type = listOf str;
27+
default = [ ];
28+
description = "List of mappings for U2F devices";
29+
example = ''
30+
[
31+
"<username>:<KeyHandle1>,<UserKey1>,<CoseType1>,<Options1>:<KeyHandle2>,<UserKey2>,<CoseType2>,<Options2>:..."
32+
]
33+
'';
34+
};
35+
};
36+
37+
config = mkIf cfg.enable {
38+
# yibikey required packages
39+
environment.systemPackages = with pkgs; [
40+
yubikey-personalization
41+
yubikey-manager
42+
yubico-pam
43+
];
44+
45+
# enable smartcard support
46+
hardware.gpgSmartcards.enable = true;
47+
48+
# enable polkit to use yubikey for authentication
49+
security.polkit.enable = true;
50+
51+
# enable u2f support in pam for login and sudo
52+
security.pam = {
53+
# enable u2f support in pam
54+
u2f = {
55+
enable = true;
56+
cue = true;
57+
authFile = "/etc/u2f-mappings";
58+
};
59+
60+
# enable u2f for login and sudo
61+
services = {
62+
login.u2fAuth = cfg.login;
63+
sudo.u2fAuth = cfg.sudo;
64+
};
65+
};
66+
67+
# add u2f mappings if they are defined
68+
environment.etc."u2f-mappings".text =
69+
mkIf (builtins.length cfg.mappings > 0)
70+
(lib.concatStringsSep "\n" cfg.mappings);
71+
};
72+
}

0 commit comments

Comments
 (0)