diff --git a/src/libstore/binary-cache-store.cc b/src/libstore/binary-cache-store.cc index 60bd68026..744bccef0 100644 --- a/src/libstore/binary-cache-store.cc +++ b/src/libstore/binary-cache-store.cc @@ -29,8 +29,17 @@ BinaryCacheStore::BinaryCacheStore(const Params & params) , Store(params) { if (secretKeyFile != "") - signer = std::make_unique( - SecretKey { readFile(secretKeyFile) }); + signers.push_back(std::make_unique( + SecretKey { readFile(secretKeyFile) })); + + if (secretKeyFiles != "") { + std::stringstream ss(secretKeyFiles); + Path keyPath; + while (std::getline(ss, keyPath, ',')) { + signers.push_back(std::make_unique( + SecretKey { readFile(keyPath) })); + } + } StringSink sink; sink << narVersionMagic1; @@ -270,9 +279,11 @@ ref BinaryCacheStore::addToStoreCommon( stats.narWriteCompressedBytes += fileSize; stats.narWriteCompressionTimeMs += duration; - /* Atomically write the NAR info file.*/ - if (signer) narInfo->sign(*this, *signer); + for (auto &signer: signers) { + narInfo->sign(*this, *signer); + } + /* Atomically write the NAR info file.*/ writeNarInfo(narInfo); stats.narInfoWrite++; diff --git a/src/libstore/include/nix/store/binary-cache-store.hh b/src/libstore/include/nix/store/binary-cache-store.hh index da4906d3f..445a10328 100644 --- a/src/libstore/include/nix/store/binary-cache-store.hh +++ b/src/libstore/include/nix/store/binary-cache-store.hh @@ -32,6 +32,9 @@ struct BinaryCacheStoreConfig : virtual StoreConfig const Setting secretKeyFile{this, "", "secret-key", "Path to the secret key used to sign the binary cache."}; + const Setting secretKeyFiles{this, "", "secret-keys", + "List of comma-separated paths to the secret keys used to sign the binary cache."}; + const Setting localNarCache{this, "", "local-nar-cache", "Path to a local cache of NARs fetched from this binary cache, used by commands such as `nix store cat`."}; @@ -57,7 +60,7 @@ class BinaryCacheStore : public virtual BinaryCacheStoreConfig, { private: - std::unique_ptr signer; + std::vector> signers; protected: diff --git a/tests/functional/signing.sh b/tests/functional/signing.sh index 8ec093a48..2893efec7 100755 --- a/tests/functional/signing.sh +++ b/tests/functional/signing.sh @@ -110,3 +110,13 @@ nix store verify --store "$TEST_ROOT"/store0 -r "$outPath2" --trusted-public-key # Content-addressed stuff can be copied without signatures. nix copy --to "$TEST_ROOT"/store0 "$outPathCA" + +# Test multiple signing keys +nix copy --to "file://$TEST_ROOT/storemultisig?secret-keys=$TEST_ROOT/sk1,$TEST_ROOT/sk2" "$outPath" +for file in "$TEST_ROOT/storemultisig/"*.narinfo; do + if [[ "$(grep -cE '^Sig: cache[1,2]\.example.org' "$file")" -ne 2 ]]; then + echo "ERROR: Cannot find cache1.example.org and cache2.example.org signatures in ${file}" + cat "${file}" + exit 1 + fi +done