feat: add 'yubikey' module to 'andromache' host
This commit is contained in:
@@ -42,6 +42,7 @@ in
|
|||||||
../../modules/docker
|
../../modules/docker
|
||||||
../../modules/syncthing
|
../../modules/syncthing
|
||||||
../../modules/nvidia
|
../../modules/nvidia
|
||||||
|
../../modules/yubikey
|
||||||
];
|
];
|
||||||
|
|
||||||
home-manager.users.${username} = import ../../home/hosts/andromache {
|
home-manager.users.${username} = import ../../home/hosts/andromache {
|
||||||
@@ -91,6 +92,25 @@ in
|
|||||||
inputs.colmena.packages.${pkgs.stdenv.hostPlatform.system}.colmena
|
inputs.colmena.packages.${pkgs.stdenv.hostPlatform.system}.colmena
|
||||||
];
|
];
|
||||||
|
|
||||||
|
my.yubikey = {
|
||||||
|
enable = false;
|
||||||
|
inherit username;
|
||||||
|
keys = [
|
||||||
|
{
|
||||||
|
handle = "<KeyHandle1>";
|
||||||
|
userKey = "<UserKey1>";
|
||||||
|
coseType = "<CoseType1>";
|
||||||
|
options = "<Options1>";
|
||||||
|
}
|
||||||
|
{
|
||||||
|
handle = "<KeyHandle2>";
|
||||||
|
userKey = "<UserKey2>";
|
||||||
|
coseType = "<CoseType2>";
|
||||||
|
options = "<Options2>";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
services = {
|
services = {
|
||||||
locate = {
|
locate = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|||||||
75
modules/yubikey/default.nix
Normal file
75
modules/yubikey/default.nix
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.my.yubikey;
|
||||||
|
formatKey = key: ":${key.handle},${key.userKey},${key.coseType},${key.options}";
|
||||||
|
authfileContent = username: keys: username + lib.concatMapStrings formatKey keys;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.my.yubikey = {
|
||||||
|
enable = mkEnableOption "yubiKey U2F authentication";
|
||||||
|
|
||||||
|
username = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "h";
|
||||||
|
};
|
||||||
|
|
||||||
|
origin = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "pam://yubi";
|
||||||
|
};
|
||||||
|
|
||||||
|
keys = mkOption {
|
||||||
|
type = types.listOf (
|
||||||
|
types.submodule {
|
||||||
|
options = {
|
||||||
|
handle = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "<KeyHandle1>";
|
||||||
|
};
|
||||||
|
userKey = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
example = "<UserKey1>";
|
||||||
|
};
|
||||||
|
coseType = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "es256";
|
||||||
|
};
|
||||||
|
options = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
|
security.pam = {
|
||||||
|
u2f = {
|
||||||
|
enable = true;
|
||||||
|
settings = {
|
||||||
|
interactive = true;
|
||||||
|
cue = true;
|
||||||
|
inherit (cfg) origin;
|
||||||
|
authfile = pkgs.writeText "u2f-mappings" (authfileContent cfg.username cfg.keys);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
services = {
|
||||||
|
login.u2fAuth = true;
|
||||||
|
sudo.u2fAuth = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.udev.packages = [ pkgs.yubikey-personalization ];
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user