Skip to content

Commit 960818f

Browse files
committed
store URI: introduce multiple signatures support
Add a `secretKeyFiles` URI parameter in the store URIs receiving a coma-separated list of Nix signing keyfiles. For instance: nix copy --to "file:///tmp/store?secret-keys=/tmp/key1,/tmp/key2" \ "$(nix build --print-out-paths nixpkgs#hello)" The keys passed through this new store URI parameter are merged with the key specified in the `secretKeyFile` parameter, if any. We'd like to rotate the signing key for cache.nixos.org. To simplify the transition, we'd like to sign the new paths with two keys: the new one and the current one. With this, the cache can support nix configurations only trusting the new key and legacy configurations only trusting the current key. See NixOS/rfcs#149 for more informations behind the motivation.
1 parent e76bbe4 commit 960818f

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Diff for: src/libstore/binary-cache-store.cc

+14-3
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,17 @@ BinaryCacheStore::BinaryCacheStore(const Params & params)
2929
, Store(params)
3030
{
3131
if (secretKeyFile != "")
32-
signer = std::make_unique<LocalSigner>(
33-
SecretKey { readFile(secretKeyFile) });
32+
signers.push_back(std::make_unique<LocalSigner>(
33+
SecretKey { readFile(secretKeyFile) }));
34+
35+
if (secretKeyFiles != "") {
36+
std::stringstream ss(secretKeyFiles);
37+
Path keyPath;
38+
while (std::getline(ss, keyPath, ',')) {
39+
signers.push_back(std::make_unique<LocalSigner>(
40+
SecretKey { readFile(keyPath) }));
41+
}
42+
}
3443

3544
StringSink sink;
3645
sink << narVersionMagic1;
@@ -271,7 +280,9 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
271280
stats.narWriteCompressionTimeMs += duration;
272281

273282
/* Atomically write the NAR info file.*/
274-
if (signer) narInfo->sign(*this, *signer);
283+
for(auto &signer: signers) {
284+
narInfo->sign(*this, *signer);
285+
}
275286

276287
writeNarInfo(narInfo);
277288

Diff for: src/libstore/include/nix/store/binary-cache-store.hh

+4-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ struct BinaryCacheStoreConfig : virtual StoreConfig
3232
const Setting<Path> secretKeyFile{this, "", "secret-key",
3333
"Path to the secret key used to sign the binary cache."};
3434

35+
const Setting<std::string> secretKeyFiles{this, "", "secret-keys",
36+
"List of coma separated paths to the secret keys used to sign the binary cache."};
37+
3538
const Setting<Path> localNarCache{this, "", "local-nar-cache",
3639
"Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."};
3740

@@ -57,7 +60,7 @@ class BinaryCacheStore : public virtual BinaryCacheStoreConfig,
5760
{
5861

5962
private:
60-
std::unique_ptr<Signer> signer;
63+
std::vector<std::unique_ptr<Signer>> signers;
6164

6265
protected:
6366

0 commit comments

Comments
 (0)