-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsops.yaml.nix
53 lines (47 loc) · 1.38 KB
/
sops.yaml.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# To update .sops.yaml:
# $ inv update-sops-files
let
mapAttrsToList = f: attrs:
map (name: f name attrs.${name}) (builtins.attrNames attrs);
renderPermissions = (attrs: mapAttrsToList
(path: keys: {
path_regex = path;
key_groups = [{
age = keys ++ groups.admins;
}];
})
attrs);
# command to add a new age key for a new host
# inv print-age-key --hosts "host1,host2"
keys = builtins.fromJSON (builtins.readFile ./pubkeys.json);
groups = {
admins = builtins.attrValues keys.admins;
all = builtins.attrValues (keys.admins // keys.machines);
};
secretsMachines = builtins.listToAttrs (mapAttrsToList (hostname: key: {
name = "hosts/${hostname}/secrets/.+$";
value = [ key ];
}) keys.machines);
secretsByGroup = {
# "secrets.yml$" = [ ];
# "modules/secrets.yml$" = groups.all;
};
secretsByMachine = builtins.mapAttrs (name: value: (map (x: keys.machines.${x}) value)) {
# "modules/nfs/secrets.yml$" = [ "nfs-1.pl" "nfs-2.pl" ];
# "modules/k3s/secrets.yml$" = [ "kube-1.pl" "kube-2.pl" "kube-3.pl" ];
};
sopsPermissions = secretsMachines // secretsByGroup // secretsByMachine;
in
{
creation_rules = [
# example:
#{
# path_regex = "foobar.yaml$";
# key_groups = [
# {age = groups.admin ++ [
# "key3"
# ];}
# ];
#}
] ++ (renderPermissions sopsPermissions);
}