feat(package): download and verify prebuilt binary variants
This commit is contained in:
1 parent
118c0dc860
commit
9b405ce772
9 files changed
+199
-3
No files matched your search
@@ -1,8 +1,10 @@
|
||||
#include <Void/Build/BootstrapConfig.hpp>
|
||||
#include <Void/Build/Package/Archive.hpp>
|
||||
#include <Void/Build/Package/Fetch.hpp>
|
||||
#include <Void/Build/Platform/FileOps.hpp>
|
||||
#include <Void/Build/Platform/ProcessSupervisor.hpp>
|
||||
#include <Void/Build/Provenance/Signing.hpp>
|
||||
#include <Void/Build/Provenance/Verification.hpp>
|
||||
#include <Void/Build/Registry/HttpServer.hpp>
|
||||
#include <Void/Build/Registry/RegistryService.hpp>
|
||||
#include <Void/Build/State/StateStore.hpp>
|
||||
@@ -15,6 +17,7 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <span>
|
||||
|
||||
using namespace Void::Build;
|
||||
using namespace Void::Build::Registry;
|
||||
@@ -389,6 +392,102 @@ void build(Void::Build::Project &p) {
|
||||
(*svc)->stop_http();
|
||||
}
|
||||
|
||||
VOID_TEST(RegistryTests, binary_variant_distribution_downloads_and_verifies) {
|
||||
if (!Provenance::signing_available()) {
|
||||
return;
|
||||
}
|
||||
Void::FileSystem::TempDir tmp{"vbs_bin_dist_"};
|
||||
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);
|
||||
|
||||
const auto pkg_src = tmp / "bin_pkg";
|
||||
(void)Platform::atomic_write_file(pkg_src / "payload.bin", "BINARY_VARIANT_PAYLOAD", false);
|
||||
const auto tar = tmp / "bin.tar";
|
||||
auto sha = Package::create_source_package(pkg_src, tar, 0);
|
||||
Void::Testing::require(sha.has_value());
|
||||
auto bytes = Void::FileSystem::read_file(tar);
|
||||
Void::Testing::require(bytes.has_value());
|
||||
auto published = send_loopback_http(
|
||||
port, "PUT", "/api/v1/packages/demo-bin/1.0.0",
|
||||
{{"Authorization", "Bearer " + *tok}, {"X-Content-SHA256", *sha}}, *bytes);
|
||||
Void::Testing::require(published.has_value() && published->status == 201);
|
||||
|
||||
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());
|
||||
|
||||
Package::BinaryVariantMeta variant;
|
||||
variant.variant_id = "demo-bin-1.0.0-linux-x86_64";
|
||||
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 = *sha;
|
||||
variant.download_url = reg_url + "/api/v1/packages/demo-bin/1.0.0/download";
|
||||
|
||||
const std::string message =
|
||||
Provenance::canonical_binary_message(variant.variant_id, variant.sha256);
|
||||
auto signature = Provenance::sign_message(
|
||||
std::as_bytes(std::span<const char>{message.data(), message.size()}), seed_path);
|
||||
Void::Testing::require(signature.has_value());
|
||||
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 fetched = Package::materialize_binary_variant(key, {variant}, options);
|
||||
Void::Testing::require(fetched.has_value());
|
||||
auto downloaded =
|
||||
Void::FileSystem::read_file(tmp / "binary_cache" / "binaries" / variant.sha256);
|
||||
Void::Testing::require(downloaded.has_value());
|
||||
Void::Testing::expect(*downloaded == *bytes);
|
||||
|
||||
// Cached artifacts are reused without contacting the registry.
|
||||
(*svc)->stop_http();
|
||||
auto cached = Package::materialize_binary_variant(key, {variant}, options);
|
||||
Void::Testing::expect(cached.has_value());
|
||||
|
||||
// A digest mismatch fails closed instead of materializing unverified bytes.
|
||||
auto tampered = variant;
|
||||
tampered.sha256 = std::string(64, '0');
|
||||
auto mismatched = Package::materialize_binary_variant(key, {tampered}, options);
|
||||
Void::Testing::expect(!mismatched.has_value());
|
||||
}
|
||||
|
||||
// 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