feat: user admin mapping

main
flop 5 days ago
parent 88e3dca322
commit bf4c33042d
  1. 27
      flake.nix
  2. 9
      modules/users.nix

@ -10,27 +10,32 @@
outputs = { self, nixpkgs, nixos-hardware, ... }:
let
# Authorization keys for user mappings (login keys per user)
auth_keys = {
alice = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIALiceKeyPlaceholder alice@host"
# Per-user mapping of auth (login) and sudo keys
key_mappings = {
alice = {
auth = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAliceAuthKeyPlaceholder alice@host"
];
bob = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBobKeyPlaceholder bob@host"
sudo = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAliceSudoKeyPlaceholder alice-admin@host"
];
};
# Sudo keys per user (keys granting sudo, applied to root)
sudo_keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAISudoKeyPlaceholder admin@host"
bob = {
auth = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBobAuthKeyPlaceholder bob@host"
];
sudo = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBobSudoKeyPlaceholder bob-admin@host"
];
};
};
sharedModules = [
./modules/users.nix
];
sharedArgs = {
inherit auth_keys sudo_keys;
inherit key_mappings;
};
in {
nixosConfigurations = {

@ -1,6 +1,11 @@
{ config, lib, pkgs, auth_keys, sudo_keys, ... }:
{ config, lib, pkgs, key_mappings, ... }:
{
let
auth_keys = lib.mapAttrs (_: u: u.auth) key_mappings;
sudo_keys = lib.concatLists
(lib.attrValues
(lib.mapAttrs (_: u: u.sudo) key_mappings));
in {
users.users = {
root.openssh.authorizedKeys.keys = sudo_keys;
} // (lib.mapAttrs (name: keys: {

Loading…
Cancel
Save