nixos-config/modules/nixos/kanidm-client.nix

83 lines
2 KiB
Nix
Raw Normal View History

2024-08-25 09:45:58 +00:00
{
config,
pkgs,
lib,
...
}:
2024-01-09 04:27:51 +00:00
with lib;
let
cfg = config.custom.kanidm-client;
in
{
options = {
custom.kanidm-client = {
enable = mkEnableOption "Kanidm client service";
asSSHAuth = mkOption {
type = types.submodule {
options = {
enable = mkEnableOption "Kanidm as system authentication source";
allowedGroups = mkOption {
type = types.listOf types.str;
example = [ "linux_users" ];
};
2024-06-11 10:24:22 +00:00
hardening = mkOption {
type = types.bool;
default = false;
};
2024-01-09 04:27:51 +00:00
};
};
};
sudoers = mkOption {
type = types.listOf types.str;
default = [ ];
};
2024-08-25 09:45:58 +00:00
uri = mkOption { type = types.str; };
2024-01-09 04:27:51 +00:00
};
};
config = mkIf cfg.enable {
2024-08-25 09:45:58 +00:00
services.kanidm = mkMerge [
(mkIf cfg.enable {
enableClient = true;
clientSettings = {
uri = cfg.uri;
};
})
(mkIf cfg.asSSHAuth.enable {
enablePam = true;
unixSettings = {
pam_allowed_login_groups = cfg.asSSHAuth.allowedGroups;
default_shell = "/bin/sh";
};
})
];
2024-01-09 04:27:51 +00:00
services.openssh = mkIf cfg.asSSHAuth.enable {
enable = true;
authorizedKeysCommand = "/etc/ssh/auth %u";
2024-08-25 09:45:58 +00:00
authorizedKeysCommandUser = "kanidm-ssh-runner";
2024-06-11 10:24:22 +00:00
settings = mkIf cfg.asSSHAuth.enable {
PasswordAuthentication = false;
KbdInteractiveAuthentication = false;
PermitRootLogin = lib.mkForce "no";
GSSAPIAuthentication = "no";
KerberosAuthentication = "no";
};
2024-01-09 04:27:51 +00:00
};
2024-06-11 10:24:22 +00:00
2024-01-09 04:27:51 +00:00
environment.etc."ssh/auth" = mkIf cfg.asSSHAuth.enable {
mode = "0555";
text = ''
#!${pkgs.stdenv.shell}
${pkgs.kanidm}/bin/kanidm_ssh_authorizedkeys $1
'';
};
users.groups.wheel.members = cfg.sudoers;
users.groups.kanidm-ssh-runner = { };
2024-08-25 09:45:58 +00:00
users.users.kanidm-ssh-runner = {
isSystemUser = true;
group = "kanidm-ssh-runner";
};
2024-06-11 10:24:22 +00:00
2024-01-09 04:27:51 +00:00
};
}