-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(libstore): add RequiredSignatures to nix-cache-info #14313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lovesegfault
wants to merge
4
commits into
NixOS:master
Choose a base branch
from
lovesegfault:nix-store-require-sigs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4d6393f
feat(libstore): add RequiredSignatures field to binary cache protocol
lovesegfault 626e7c0
feat(libstore): add RequireAllSignatures field for multi-party signing
lovesegfault 786871e
test(tests/nixos/s3-binary-cache-store): add RequiredSignatures tests
lovesegfault 2bb8334
docs: add release notes for RequiredSignatures feature
lovesegfault File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| --- | ||
| synopsis: "Binary caches can now soft-enforce signature requirements" | ||
| issues: [12491] | ||
| --- | ||
|
|
||
| Binary caches can now advertise signature requirements through their | ||
| `nix-cache-info` file, preventing accidental uploads of unsigned or | ||
| incorrectly-signed store paths. | ||
|
|
||
| Cache operators can add a `RequiredSignatures` field containing a | ||
| whitespace-separated list of public keys. When uploading paths to such caches, | ||
| Nix validates that each path has at least one valid signature from the required | ||
| keys: | ||
|
|
||
| ``` | ||
| StoreDir: /nix/store | ||
| RequiredSignatures: cache.example.org-1:abc123... cache.example.org-2:def456... | ||
| ``` | ||
|
|
||
| This helps catch common configuration errors, such as typos in store URLs | ||
| (`secret-key-file` vs `secret-key`), by failing fast with clear error messages | ||
| rather than silently uploading unsigned paths. | ||
|
|
||
| For multi-party approval workflows, the optional `RequireAllSignatures: 1` field | ||
| requires paths to be signed by *all* listed keys rather than just one: | ||
|
|
||
| ``` | ||
| StoreDir: /nix/store | ||
| RequiredSignatures: dev:key1... qa:key2... release:key3... | ||
| RequireAllSignatures: 1 | ||
| ``` | ||
|
|
||
| Content-addressed paths are automatically exempt from signature requirements as | ||
| they are self-validating. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
|
|
||
| #include <chrono> | ||
| #include <future> | ||
| #include <ranges> | ||
| #include <regex> | ||
| #include <fstream> | ||
| #include <sstream> | ||
|
|
@@ -66,6 +67,24 @@ void BinaryCacheStore::init() | |
| config.wantMassQuery.setDefault(value == "1"); | ||
| } else if (name == "Priority") { | ||
| config.priority.setDefault(std::stoi(value)); | ||
| } else if (name == "RequiredSignatures") { | ||
| // Parse whitespace-separated list of public keys | ||
| for (const auto & keyStr : tokenizeString<Strings>(value, " \t\n\r")) { | ||
| if (!keyStr.empty()) { | ||
| try { | ||
| PublicKey key(keyStr); | ||
| requiredSignatures.emplace(key.name, key); | ||
| } catch (Error & e) { | ||
| e.addTrace( | ||
| {}, | ||
| "while parsing RequiredSignatures field in binary cache '%s'", | ||
| config.getHumanReadableURI()); | ||
| throw; | ||
| } | ||
| } | ||
| } | ||
| } else if (name == "RequireAllSignatures") { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could also be |
||
| requireAllSignatures = (value == "1"); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -284,6 +303,50 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon( | |
|
|
||
| narInfo->sign(*this, signers); | ||
|
|
||
| /* Check if this binary cache requires signatures. Content-addressed paths don't need signatures. */ | ||
| if (!requiredSignatures.empty() && !info.ca) { | ||
| auto validSigs = info.checkSignatures(*this, requiredSignatures); | ||
| size_t requiredSigs = requireAllSignatures ? requiredSignatures.size() : 1; | ||
|
|
||
| if (validSigs < requiredSigs) { | ||
| auto keys = std::views::keys(requiredSignatures); | ||
| std::vector<std::string> keyNames(keys.begin(), keys.end()); | ||
| std::string requiredKeyNames = concatStringsSep(", ", keyNames); | ||
|
|
||
| if (info.sigs.empty()) { | ||
| throw Error( | ||
| "refusing to upload unsigned path '%s' to binary cache '%s'\n\n" | ||
| "The cache requires paths to be signed by %s:\n %s\n\n" | ||
| "You have not configured any signing keys. To fix this:\n" | ||
| " - Use: %s?secret-key=/path/to/key (not 'secret-key-file'!)\n" | ||
| " - Or set: secret-key-files = /path/to/key in nix.conf\n", | ||
| printStorePath(info.path), | ||
| config.getHumanReadableURI(), | ||
| requireAllSignatures ? "ALL of these keys" : "at least ONE of these keys", | ||
| requiredKeyNames, | ||
| config.getHumanReadableURI()); | ||
| } else { | ||
| // Has signatures, but insufficient or wrong keys | ||
| throw Error( | ||
| "refusing to upload path '%s' to binary cache '%s'\n\n" | ||
| "The cache requires paths to be signed by %s:\n %s\n\n" | ||
| "Current valid signatures: %d out of %d required\n" | ||
| "Current signatures on path:\n %s\n\n" | ||
| "The path %s.\n" | ||
| "Make sure you're using the correct signing key(s) for this cache.", | ||
| printStorePath(info.path), | ||
| config.getHumanReadableURI(), | ||
| requireAllSignatures ? "ALL of these keys" : "at least ONE of these keys", | ||
| requiredKeyNames, | ||
| validSigs, | ||
| requiredSigs, | ||
| concatStringsSep("\n ", info.sigs), | ||
| validSigs == 0 ? "is signed, but not by any of the keys this cache requires" | ||
| : "is signed by some required keys, but not all of them"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /* Atomically write the NAR info file.*/ | ||
| writeNarInfo(narInfo); | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be named
RequiredSigners(it's a list of public keys, not a list of signatures).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And actually the name
RequiredSignersis misleading ifRequireAllSignaturesis false. So it should probably beSignersorAllowedSigners.