feat(registry): store and serve signed binary variants
This commit is contained in:
1 parent
64116f6e0d
commit
663215f7f3
7 files changed
+378
-17
No files matched your search
@@ -488,6 +488,136 @@ VOID_TEST(RegistryTests, binary_variant_distribution_downloads_and_verifies) {
|
||||
Void::Testing::expect(!mismatched.has_value());
|
||||
}
|
||||
|
||||
VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materialize) {
|
||||
if (!Provenance::signing_available()) {
|
||||
return;
|
||||
}
|
||||
Void::FileSystem::TempDir tmp{"vbs_reg_binary_"};
|
||||
RegistryConfig cfg;
|
||||
cfg.data_dir = tmp / "reg_data";
|
||||
cfg.web_root = std::filesystem::path{Bootstrap::source_dir} / "registry" / "web";
|
||||
cfg.bind_address = "127.0.0.1";
|
||||
cfg.port = 0;
|
||||
cfg.bootstrap_admin_user = "admin";
|
||||
cfg.bootstrap_admin_password = "admin_pw";
|
||||
|
||||
auto svc = RegistryService::open(cfg);
|
||||
Void::Testing::expect(svc.has_value());
|
||||
if (!svc) {
|
||||
return;
|
||||
}
|
||||
Void::Testing::expect((*svc)->create_user("bin_pub", "bin_pass", Role::Publisher).has_value());
|
||||
auto tok = (*svc)->create_token("bin_pub", "publish", {"read", "publish"});
|
||||
Void::Testing::expect(tok.has_value());
|
||||
if (!tok) {
|
||||
return;
|
||||
}
|
||||
Void::Testing::expect((*svc)->start_http().has_value());
|
||||
const auto port = (*svc)->bound_port();
|
||||
const std::string reg_url = "http://127.0.0.1:" + std::to_string(port);
|
||||
|
||||
// The binary variant belongs to an existing source release.
|
||||
const auto pkg_src = tmp / "src_pkg";
|
||||
(void)Platform::atomic_write_file(pkg_src / "payload.txt", "SOURCE_PAYLOAD", false);
|
||||
const auto tar = tmp / "src.tar";
|
||||
auto source_sha = Package::create_source_package(pkg_src, tar, 0);
|
||||
Void::Testing::require(source_sha.has_value());
|
||||
auto source_bytes = Void::FileSystem::read_file(tar);
|
||||
Void::Testing::require(source_bytes.has_value());
|
||||
auto src_pub = send_loopback_http(
|
||||
port, "PUT", "/api/v1/packages/demo-bin/1.0.0",
|
||||
{{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", *source_sha}}, *source_bytes);
|
||||
Void::Testing::require(src_pub.has_value() && src_pub->status == 201);
|
||||
|
||||
const std::string artifact = "PREBUILT_BINARY_VARIANT_BYTES";
|
||||
const std::string artifact_sha = Util::sha256_hex(artifact);
|
||||
const std::string variant_id = "linux-x86_64-gcc16-static";
|
||||
const std::string binary_path = "/api/v1/packages/demo-bin/1.0.0/binaries/" + variant_id;
|
||||
|
||||
auto unauthorized = send_loopback_http(port, "PUT", binary_path,
|
||||
{{"X-Content-SHA256", artifact_sha}}, artifact);
|
||||
Void::Testing::expect(unauthorized.has_value() && unauthorized->status == 401);
|
||||
|
||||
const auto seed_path = tmp / "binary.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());
|
||||
const std::string message = Provenance::canonical_binary_message(variant_id, artifact_sha);
|
||||
auto signature = Provenance::sign_message(
|
||||
std::as_bytes(std::span<const char>{message.data(), message.size()}), seed_path);
|
||||
Void::Testing::require(signature.has_value());
|
||||
|
||||
auto bad_signature = send_loopback_http(port, "PUT", binary_path,
|
||||
{{"Authorization", "Bearer " + *tok},
|
||||
{"X-Content-SHA256", artifact_sha},
|
||||
{"X-Binary-Signature", std::string(127, 'a')},
|
||||
{"X-Binary-Public-Key", *public_key}},
|
||||
artifact);
|
||||
Void::Testing::expect(bad_signature.has_value() && bad_signature->status == 400);
|
||||
|
||||
auto published = send_loopback_http(port, "PUT", binary_path,
|
||||
{{"Authorization", "Bearer " + *tok},
|
||||
{"X-Content-SHA256", artifact_sha},
|
||||
{"X-Binary-Signature", *signature},
|
||||
{"X-Binary-Public-Key", *public_key}},
|
||||
artifact);
|
||||
Void::Testing::expect(published.has_value() && published->status == 201);
|
||||
|
||||
auto detail = send_loopback_http(port, "GET", "/api/v1/packages/demo-bin");
|
||||
Void::Testing::expect(detail.has_value() && detail->status == 200);
|
||||
if (detail) {
|
||||
Void::Testing::expect(detail->body.find(variant_id) != std::string::npos);
|
||||
Void::Testing::expect(detail->body.find(artifact_sha) != std::string::npos);
|
||||
}
|
||||
|
||||
auto downloaded = send_loopback_http(port, "GET", binary_path + "/download");
|
||||
Void::Testing::expect(downloaded.has_value() && downloaded->status == 200);
|
||||
if (downloaded) {
|
||||
Void::Testing::expect(downloaded->body == artifact);
|
||||
}
|
||||
|
||||
auto conflict = send_loopback_http(
|
||||
port, "PUT", binary_path,
|
||||
{{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", Util::sha256_hex("different")}},
|
||||
"different");
|
||||
Void::Testing::expect(conflict.has_value() && conflict->status == 409);
|
||||
|
||||
// The registry-served artifact materializes through the signed binary-variant path.
|
||||
Package::BinaryVariantMeta variant;
|
||||
variant.variant_id = variant_id;
|
||||
variant.os = "Linux";
|
||||
variant.architecture = "x86_64";
|
||||
variant.compiler_family = "gcc";
|
||||
variant.compiler_abi = "gcc-16";
|
||||
variant.stdlib_abi = "libstdc++";
|
||||
variant.linkage = "static";
|
||||
variant.lto_mode = "off";
|
||||
variant.dependency_closure_hash = "closure";
|
||||
variant.sha256 = artifact_sha;
|
||||
variant.download_url = reg_url + binary_path + "/download";
|
||||
variant.signature = *signature;
|
||||
variant.public_key = *public_key;
|
||||
|
||||
Package::BinaryCompatibilityKey key;
|
||||
key.os = variant.os;
|
||||
key.architecture = variant.architecture;
|
||||
key.compiler_family = variant.compiler_family;
|
||||
key.compiler_abi = variant.compiler_abi;
|
||||
key.stdlib_abi = variant.stdlib_abi;
|
||||
key.linkage = variant.linkage;
|
||||
key.lto_mode = variant.lto_mode;
|
||||
key.dependency_closure_hash = variant.dependency_closure_hash;
|
||||
|
||||
Package::BinaryFetchOptions options{tmp / "binary_cache", {*public_key}};
|
||||
auto materialized = Package::materialize_binary_variant(key, {variant}, options);
|
||||
Void::Testing::require(materialized.has_value());
|
||||
auto cached = Void::FileSystem::read_file(tmp / "binary_cache" / "binaries" / artifact_sha);
|
||||
Void::Testing::require(cached.has_value());
|
||||
Void::Testing::expect(*cached == artifact);
|
||||
|
||||
(*svc)->stop_http();
|
||||
}
|
||||
|
||||
// End-to-end live client <-> server test: `vbs publish` -> `vbs deps resolve` -> `vbs build
|
||||
// --locked`!
|
||||
VOID_TEST(RegistryTests, cli_publish_deps_resolve_and_locked_build_against_live_registry) {
|
||||
|
||||
Reference in new issue
Block a user