Skip to content

Commit

Permalink
Fixup the mgmt nomad token generation
Browse files Browse the repository at this point in the history
  • Loading branch information
johnalotoski committed Sep 24, 2021
1 parent ce0990f commit 1932f62
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
6 changes: 4 additions & 2 deletions modules/nomad-policies.nix
Expand Up @@ -3,7 +3,7 @@ let
inherit (builtins) mapAttrs typeOf listToAttrs length attrNames;
inherit (lib)
flip mkOption mkIf mkEnableOption mapAttrsToList remove concatStringsSep;
inherit (lib.types) str enum submodule nullOr attrsOf listOf;
inherit (lib.types) addCheck str enum submodule nullOr attrsOf listOf;
inherit (pkgs) toPrettyJSON ensureDependencies;

sanitize = set:
Expand Down Expand Up @@ -40,7 +40,9 @@ let
nomadPoliciesType = submodule ({ name, ... }: {
options = {
name = mkOption {
type = str;
# Disallow "management" to avoid collision with a
# default Vault nomad/creds/management role
type = addCheck str (x: x != "management");
default = name;
};

Expand Down
5 changes: 3 additions & 2 deletions modules/vault-policies.nix
Expand Up @@ -115,11 +115,12 @@ in {
fi
done
# Nomad Policies
# Nomad Policies and Default Management Role
${concatStringsSep "\n" createNomadRoles}
vault write "nomad/role/management" "policies=" "type=management"
keepNames=(${toString (attrNames config.services.nomad.policies)})
keepNames=(${toString (attrNames config.services.nomad.policies ++ [ "management" ])})
nomadRoles=($(nomad acl policy list -json | jq -r -e '.[].Name'))
for role in "''${nomadRoles[@]}"; do
Expand Down
2 changes: 2 additions & 0 deletions modules/vault-snapshots.nix
Expand Up @@ -171,8 +171,10 @@ let
}
exportToken () {
set +x
VAULT_TOKEN="$(< /run/keys/vault-token)"
export VAULT_TOKEN
set -x
}
isNotLeader () {
Expand Down

0 comments on commit 1932f62

Please sign in to comment.