feat(provenance): enforce trusted Ed25519 package signatures in publish, lockfile, and locked builds
This commit is contained in:
1 parent
21babb8c31
commit
85f2ae274f
21 files changed
+519
-15
No files matched your search
@@ -2,6 +2,7 @@
|
||||
#include <Void/Build/Package/Archive.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Provenance/Signing.hpp>
|
||||
#include <Void/Build/Registry/HttpServer.hpp>
|
||||
#include <Void/Build/Registry/RegistryService.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
@@ -140,6 +141,37 @@ VOID_TEST(RegistryTests, registry_rbac_immutability_csrf_xss_web_and_backup_rest
|
||||
*bytes1);
|
||||
Void::Testing::expect(pub_ok.has_value() && pub_ok->status == 201);
|
||||
|
||||
// Signature metadata is stored and served verbatim (the registry is not a trust authority).
|
||||
const std::string release_signature(128, 'a');
|
||||
const std::string release_public_key(64, 'b');
|
||||
auto signed_pub = send_loopback_http(port, "PUT", "/api/v1/packages/signed-pkg/1.0.0",
|
||||
{{"Authorization", "Bearer " + *alice_tok},
|
||||
{"X-Content-SHA256", *sha1},
|
||||
{"X-Package-Signature", release_signature},
|
||||
{"X-Package-Public-Key", release_public_key}},
|
||||
*bytes1);
|
||||
Void::Testing::expect(signed_pub.has_value() && signed_pub->status == 201);
|
||||
auto signed_detail = send_loopback_http(port, "GET", "/api/v1/packages/signed-pkg",
|
||||
{{"Authorization", "Bearer " + *alice_tok}});
|
||||
Void::Testing::expect(signed_detail.has_value() && signed_detail->status == 200);
|
||||
if (signed_detail) {
|
||||
Void::Testing::expect(signed_detail->body.find(release_signature) != std::string::npos);
|
||||
Void::Testing::expect(signed_detail->body.find(release_public_key) != std::string::npos);
|
||||
}
|
||||
auto bad_sig_pub = send_loopback_http(port, "PUT", "/api/v1/packages/bad-sig-pkg/1.0.0",
|
||||
{{"Authorization", "Bearer " + *alice_tok},
|
||||
{"X-Content-SHA256", *sha1},
|
||||
{"X-Package-Signature", std::string(127, 'a')},
|
||||
{"X-Package-Public-Key", release_public_key}},
|
||||
*bytes1);
|
||||
Void::Testing::expect(bad_sig_pub.has_value() && bad_sig_pub->status == 400);
|
||||
auto half_sig_pub = send_loopback_http(port, "PUT", "/api/v1/packages/half-sig-pkg/1.0.0",
|
||||
{{"Authorization", "Bearer " + *alice_tok},
|
||||
{"X-Content-SHA256", *sha1},
|
||||
{"X-Package-Signature", release_signature}},
|
||||
*bytes1);
|
||||
Void::Testing::expect(half_sig_pub.has_value() && half_sig_pub->status == 400);
|
||||
|
||||
// Unauthenticated access to private package MUST fail (401)!
|
||||
auto anon_priv = send_loopback_http(port, "GET", "/api/v1/packages/secret-pkg");
|
||||
Void::Testing::expect(anon_priv.has_value() && anon_priv->status == 401);
|
||||
@@ -471,5 +503,51 @@ target_include_directories(hello_pkg PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
auto run_res = Platform::run_supervised(run_req);
|
||||
Void::Testing::expect(run_res.has_value() && run_res->succeeded());
|
||||
|
||||
// 5. Requiring a trusted key must fail closed for the unsigned locked package.
|
||||
Platform::ProcessRequest trusted_req = bld_req;
|
||||
trusted_req.arguments.push_back("--trusted-public-key");
|
||||
trusted_req.arguments.push_back(std::string(64, 'a'));
|
||||
auto trusted_res = Platform::run_supervised(trusted_req);
|
||||
Void::Testing::expect(trusted_res.has_value() && !trusted_res->succeeded());
|
||||
if (trusted_res) {
|
||||
Void::Testing::expect(trusted_res->stderr_data.find("not signed by a trusted key") !=
|
||||
std::string::npos);
|
||||
}
|
||||
|
||||
// 6. With the OpenSSL backend, publish a signed release and require its trusted key.
|
||||
if (Provenance::signing_available()) {
|
||||
const auto seed_path = tmp / "publish.seed";
|
||||
Void::Testing::require(Provenance::generate_signing_seed(seed_path).has_value());
|
||||
auto public_key = Provenance::public_key_from_seed(seed_path);
|
||||
Void::Testing::require(public_key.has_value());
|
||||
|
||||
(void)Platform::atomic_write_file(
|
||||
pkg_dir / "src" / "hello.cpp",
|
||||
"#include \"hello_pkg.hpp\"\nint hello_pkg_value() { return 7; }\n", false);
|
||||
Platform::ProcessRequest pub3 = pub1;
|
||||
pub3.arguments[8] = "1.2.0";
|
||||
pub3.arguments.push_back("--signing-key");
|
||||
pub3.arguments.push_back(seed_path.string());
|
||||
auto r3 = Platform::run_supervised(pub3);
|
||||
Void::Testing::expect(r3.has_value() && r3->succeeded());
|
||||
|
||||
Platform::ProcessRequest update_req = deps_req;
|
||||
update_req.arguments[1] = "update";
|
||||
auto update_res = Platform::run_supervised(update_req);
|
||||
Void::Testing::expect(update_res.has_value() && update_res->succeeded());
|
||||
|
||||
Platform::ProcessRequest signed_build = bld_req;
|
||||
signed_build.arguments.push_back("--trusted-public-key");
|
||||
signed_build.arguments.push_back(*public_key);
|
||||
auto signed_res = Platform::run_supervised(signed_build);
|
||||
Void::Testing::expect(signed_res.has_value() && signed_res->succeeded());
|
||||
|
||||
Platform::ProcessRequest wrong_key_build = bld_req;
|
||||
wrong_key_build.arguments.push_back("--trusted-public-key");
|
||||
wrong_key_build.arguments.push_back(std::string(64, 'a'));
|
||||
auto wrong_key_res = Platform::run_supervised(wrong_key_build);
|
||||
Void::Testing::expect(wrong_key_res.has_value() && !wrong_key_res->succeeded());
|
||||
}
|
||||
|
||||
(*svc)->stop_http();
|
||||
}
|
||||
Reference in new issue
Block a user