Skip to content

Commit bdfb68c

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 bdfb68c

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/libstore/binary-cache-store.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "nix/util/archive.hh"
1616

1717
#include <chrono>
18+
#include <cstddef>
1819
#include <future>
1920
#include <regex>
2021
#include <fstream>
@@ -29,8 +30,17 @@ BinaryCacheStore::BinaryCacheStore(const Params & params)
2930
, Store(params)
3031
{
3132
if (secretKeyFile != "")
32-
signer = std::make_unique<LocalSigner>(
33-
SecretKey { readFile(secretKeyFile) });
33+
signers.push_back(std::make_unique<LocalSigner>(
34+
SecretKey { readFile(secretKeyFile) }));
35+
36+
if (secretKeyFiles != "") {
37+
std::stringstream ss(secretKeyFiles);
38+
Path keyPath;
39+
while (std::getline(ss, keyPath, ',')) {
40+
signers.push_back(std::make_unique<LocalSigner>(
41+
SecretKey { readFile(keyPath) }));
42+
}
43+
}
3444

3545
StringSink sink;
3646
sink << narVersionMagic1;
@@ -271,7 +281,9 @@ ref<const ValidPathInfo> BinaryCacheStore::addToStoreCommon(
271281
stats.narWriteCompressionTimeMs += duration;
272282

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

276288
writeNarInfo(narInfo);
277289

src/libstore/include/nix/store/binary-cache-store.hh

Lines changed: 4 additions & 1 deletion
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)