sops: Add assertion to validate that all secrets are actually used

This commit is contained in:
SebastianStork 2026-02-28 00:06:19 +01:00
parent 1fc79bee5c
commit 3af7d23a46
Signed by: SebastianStork
SSH key fingerprint: SHA256:tRrGdjYOwgHxpSc/wTOZQZEjxcb15P0tyXRsbAfd+2Q
2 changed files with 32 additions and 12 deletions

View file

@ -38,11 +38,21 @@ in
};
assertions =
(
config.sops.secrets
|> lib.attrNames
|> lib.map (secretPath: {
assertion = cfg.secrets |> lib.hasAttrByPath (secretPath |> lib.splitString "/");
message = "Sops secret `${secretPath}` must be defined in secrets.json";
});
message = "Sops secret `${secretPath}` is used in a module but not defined in secrets.json";
})
)
++ (
lib.removeAttrs cfg.secrets [ "sops" ]
|> lib.mapAttrsToListRecursive (path: _: path |> lib.concatStringsSep "/")
|> lib.map (secretPath: {
assertion = config.sops.secrets |> lib.hasAttr secretPath;
message = "Sops secret `${secretPath}` is defined in secrets.json but not used in any module";
})
);
};
}

View file

@ -36,11 +36,21 @@ in
};
assertions =
(
config.sops.secrets
|> lib.attrNames
|> lib.map (secretPath: {
assertion = cfg.secrets |> lib.hasAttrByPath (secretPath |> lib.splitString "/");
message = "Sops secret `${secretPath}` must be defined in secrets.json";
});
message = "Sops secret `${secretPath}` is used in a module but not defined in secrets.json";
})
)
++ (
lib.removeAttrs cfg.secrets [ "sops" ]
|> lib.mapAttrsToListRecursive (path: _: path |> lib.concatStringsSep "/")
|> lib.map (secretPath: {
assertion = config.sops.secrets |> lib.hasAttr secretPath;
message = "Sops secret `${secretPath}` is defined in secrets.json but not used in any module";
})
);
};
}