Compare commits
No commits in common. "0220dbbcdd04a6b5f483481d2bc28eb27e12d180" and "41a52d55a32ffdd159f4de37d4721a34e12e2fca" have entirely different histories.
0220dbbcdd
...
41a52d55a3
@ -38,7 +38,6 @@
|
|||||||
group = "event";
|
group = "event";
|
||||||
modules = [
|
modules = [
|
||||||
./users/criese-nethinks
|
./users/criese-nethinks
|
||||||
./users/isa
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
backup-4 = { name = "backup-4"; };
|
backup-4 = { name = "backup-4"; };
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
[
|
[
|
||||||
./hardware-configuration.nix
|
./hardware-configuration.nix
|
||||||
|
|
||||||
|
./isa.nix
|
||||||
./users.nix
|
./users.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
11
hosts/astatine/isa.nix
Normal file
11
hosts/astatine/isa.nix
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{ ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
users.users.isa = {
|
||||||
|
isNormalUser = true;
|
||||||
|
extraGroups = [ "guests" ];
|
||||||
|
openssh.authorizedKeys.keys = [
|
||||||
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGrvhqC/tZzpLMs/qy+1xNSVi2mfn8LXPIEhh7dcGn9e"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
67
secrets.nix
67
secrets.nix
@ -16,15 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
let
|
let
|
||||||
/*
|
|
||||||
Returns an attrset for a given directory,
|
|
||||||
having the name of a subdirectory as its attribute names
|
|
||||||
and the contents of the containing ssh.pub file as their value
|
|
||||||
|
|
||||||
{
|
|
||||||
clerie = "ssh-ed25519 AAAA...";
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
pubkeysFor = directory: let
|
pubkeysFor = directory: let
|
||||||
instances = builtins.attrNames (builtins.readDir directory);
|
instances = builtins.attrNames (builtins.readDir directory);
|
||||||
instancesWithPubkey = builtins.filter (i: builtins.pathExists (directory + "/${i}/ssh.pub")) instances;
|
instancesWithPubkey = builtins.filter (i: builtins.pathExists (directory + "/${i}/ssh.pub")) instances;
|
||||||
@ -34,63 +25,13 @@ let
|
|||||||
users = pubkeysFor ./users;
|
users = pubkeysFor ./users;
|
||||||
hosts = pubkeysFor ./hosts;
|
hosts = pubkeysFor ./hosts;
|
||||||
|
|
||||||
/*
|
|
||||||
Returns secret configuration for a given hostname
|
|
||||||
*/
|
|
||||||
secretsForHost = hostname: let
|
secretsForHost = hostname: let
|
||||||
/*
|
|
||||||
Returns a list of all file names in the secrets directory of the specified host
|
|
||||||
*/
|
|
||||||
secretsFiles = builtins.attrNames (builtins.readDir (./hosts + "/${hostname}/secrets"));
|
secretsFiles = builtins.attrNames (builtins.readDir (./hosts + "/${hostname}/secrets"));
|
||||||
|
listOfSecrets = builtins.filter (i: (builtins.stringLength i) > 4 && builtins.substring ((builtins.stringLength i) - 4) (builtins.stringLength i) i == ".age") secretsFiles;
|
||||||
/*
|
|
||||||
Returns all file names that end with .age
|
|
||||||
*/
|
|
||||||
listOfSecrets = builtins.filter (i:
|
|
||||||
# Make sure the file name is longer than the file extension
|
|
||||||
(builtins.stringLength i) > 4
|
|
||||||
# Take the last four letters of the file name and check if it is .age
|
|
||||||
&& builtins.substring ((builtins.stringLength i) - 4) (builtins.stringLength i) i == ".age"
|
|
||||||
) secretsFiles;
|
|
||||||
|
|
||||||
in
|
in
|
||||||
if
|
if builtins.pathExists (./hosts + "/${hostname}/secrets") && builtins.pathExists (./hosts + "/${hostname}/ssh.pub") then
|
||||||
# Make sure the host has a secrets directory
|
map (secret: { name = "hosts/${hostname}/secrets/${secret}"; value = { publicKeys = [ users.clerie hosts."${hostname}" ]; }; }) (listOfSecrets ++ [ "new" ])
|
||||||
builtins.pathExists (./hosts + "/${hostname}/secrets")
|
|
||||||
# Make sure the host has a public ssh key provided
|
|
||||||
&& builtins.pathExists (./hosts + "/${hostname}/ssh.pub")
|
|
||||||
then
|
|
||||||
/*
|
|
||||||
This map specifies all public keys for which a given secret file should be encrypted
|
|
||||||
It returns a list of name value pairs
|
|
||||||
The name is the path to the secret file
|
|
||||||
The value is an attribute set containing a list of public keys as a string
|
|
||||||
*/
|
|
||||||
map
|
|
||||||
(secret: {
|
|
||||||
name = "hosts/${hostname}/secrets/${secret}";
|
|
||||||
value = {
|
|
||||||
publicKeys = [
|
|
||||||
# Hardcode clerie's public key here
|
|
||||||
users.clerie
|
|
||||||
# No other user should have access to any secrets
|
|
||||||
|
|
||||||
# A host should only have access to their own secrets
|
|
||||||
hosts."${hostname}"
|
|
||||||
];
|
|
||||||
};
|
|
||||||
})
|
|
||||||
# All file names of already existing secrets plus the magic "new" secret
|
|
||||||
(listOfSecrets ++ [ "new" ])
|
|
||||||
else
|
else
|
||||||
# Answer with an empty list, if no secrets are provided for a host
|
|
||||||
[];
|
[];
|
||||||
in
|
in
|
||||||
# We just have a list of name value pairs that need to get transformed into an attribute set
|
builtins.listToAttrs (builtins.concatMap (hostname: secretsForHost hostname) (builtins.attrNames (builtins.readDir ./hosts)))
|
||||||
builtins.listToAttrs (
|
|
||||||
builtins.concatMap
|
|
||||||
# Provide a list of secrets for a given hostname
|
|
||||||
(hostname: secretsForHost hostname)
|
|
||||||
# Names of all hosts
|
|
||||||
(builtins.attrNames (builtins.readDir ./hosts))
|
|
||||||
)
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
users.users.criese-nethinks = {
|
users.users.criese-nethinks = {
|
||||||
isNormalUser = true;
|
isNormalUser = true;
|
||||||
openssh.authorizedKeys.keys = [
|
openssh.authorizedKeys.keys = [
|
||||||
(builtins.readFile ./ssh.pub)
|
(builtins.readFile ./ssh-criese.pub)
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
{ ... }:
|
|
||||||
|
|
||||||
{
|
|
||||||
users.users.isa = {
|
|
||||||
isNormalUser = true;
|
|
||||||
openssh.authorizedKeys.keys = [
|
|
||||||
(builtins.readFile ./ssh.pub)
|
|
||||||
];
|
|
||||||
};
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGrvhqC/tZzpLMs/qy+1xNSVi2mfn8LXPIEhh7dcGn9e
|
|
Loading…
Reference in New Issue
Block a user