From 4e5bdab8cd54a0cc5f921be34cf13a61450f0a41 Mon Sep 17 00:00:00 2001 From: "Aleksei (Faumaray) Selikhov" Date: Thu, 3 Dec 2026 23:03:38 +0300 Subject: [PATCH] feat(package): authenticate private binary-variant downloads --- docs/agent-workflow/STATE.md | 2 +- docs/agent-workflow/TASKS.md | 1 + docs/agent-workflow/VERIFICATION.md | 15 +++ docs/roadmap/21-expansion-roadmap.md | 2 +- include/Void/Build/Package/Fetch.hpp | 1 + include/Void/Build/Package/RegistryClient.hpp | 2 +- src/Main.cpp | 3 +- src/Package/Fetch.cpp | 4 +- src/Package/RegistryClient.cpp | 8 +- tests/RegistryTests.cpp | 110 ++++++++++++++++++ 10 files changed, 140 insertions(+), 8 deletions(-) diff --git a/docs/agent-workflow/STATE.md b/docs/agent-workflow/STATE.md index dce7138..fe77a34 100644 --- a/docs/agent-workflow/STATE.md +++ b/docs/agent-workflow/STATE.md @@ -173,7 +173,7 @@ Stage: VERIFIED — Plans 01–19 + Plan 20 Slices 1–2C + Track A + Track B (B - Added the `compdb_entries` daemon request (`vbs daemon compdb entries [--file SUFFIX] [--limit N]`): reads the active published compilation database (selection state or root alias), returns bounded projected entries (`file`, `directory`, `output`, `command`, bounded `arguments`), reports `total`/`returned`, and errors explicitly when nothing is published. - Added `Daemon.compdb_entries_queries_published_database` (unpublished → error, then all entries, a `main.cpp` filter with `limit:1`, and an invalid limit) and a CLI help contract; Daemon suite is now 18 cases. -## Remaining future scope +- **Wave 40 (Authenticated Binary-Variant Downloads)**:\n - `download_binary_artifact` now accepts `RegistryAuth` and sends the bearer token, so private registry binary artifacts can be fetched; `BinaryFetchOptions` gained `bearer_token` and `materialize_binary_variant` forwards it; `vbs binaries fetch` passes the configured token.\n - Added `RegistryTests.private_binary_variant_download_requires_auth`: anonymous download of a private binary → 401, authenticated client download and signed materialization succeed.\n\n## Remaining future scope - **Post-v1 Expansion Roadmap ([21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md) & [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md))**: Live `conan` CLI verification (Track B3), Track C (macOS/Windows ports + dual-profile cross-compilation), Track D3 signing (SBOM, Ed25519 primitives, trusted-key enforcement and distribution, binary-variant signing and distribution materialization, the #52 built-in-backend capability probe, and the VoidLibrary pin bump to `0002e74` done), Track E3 (daemon core, bounded `describe`, build-serving, dependency materialization, daemon-backed IDE metadata, compdb export, IDE config generation, editor watch poll and bounded long-poll done; dedicated external editor plugins remain), and Track E4 (`Void::Net`/`Void::Sqlite` alignment) remain planned scope. diff --git a/docs/agent-workflow/TASKS.md b/docs/agent-workflow/TASKS.md index 394a941..b3d384d 100644 --- a/docs/agent-workflow/TASKS.md +++ b/docs/agent-workflow/TASKS.md @@ -46,4 +46,5 @@ Base HEAD: `fe0d1a6` | Wave 37 (Daemon graph export) | `graph` daemon request + `vbs daemon graph --format dot|json --member`: target dependency graph in a JSON envelope | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 16/16, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | | Wave 38 (Daemon test request) | `test` daemon request + `vbs daemon test`: builds, runs declared test targets with bounded output, reports pass/fail counts | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 17/17, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | | Wave 39 (Compdb entries query) | `compdb_entries` daemon request + `vbs daemon compdb entries --file --limit`: bounded projected entries from the active compdb | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Daemon 18/18, full CTest 8/8) | `src/Daemon/Daemon.cpp`, `src/Main.cpp`, `tests/DaemonTests.cpp`, `tests/CliContracts.cmake`, docs | +| Wave 40 (Authenticated binary downloads) | `download_binary_artifact` bearer auth, `BinaryFetchOptions::bearer_token`, `vbs binaries fetch` token | COMPLETE & VERIFIED (GCC 16.2, pin `0002e74`; Registry 7/7, full CTest 8/8) | `include/Void/Build/Package/{RegistryClient,Fetch}.hpp`, `src/Package/{RegistryClient,Fetch}.cpp`, `src/Main.cpp`, `tests/RegistryTests.cpp`, docs | | Future (Plan 20 Slice 3 / Tracks C, E3 editor extensions, E4, live `conan`) | Live `conan` CLI verification; macOS/Windows/cross-compile; binary-variant signing and key distribution; daemon-side dependency materialization and editor plugins; `Void::Net`/`Void::Sqlite` alignment | PLANNED (unimplemented) | [21-expansion-roadmap.md](../roadmap/21-expansion-roadmap.md), [20-future-translation-platforms.md](../roadmap/20-future-translation-platforms.md) | diff --git a/docs/agent-workflow/VERIFICATION.md b/docs/agent-workflow/VERIFICATION.md index 9a62865..d77ca26 100644 --- a/docs/agent-workflow/VERIFICATION.md +++ b/docs/agent-workflow/VERIFICATION.md @@ -687,6 +687,21 @@ dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure - Full CTest: **8 / 8 passed** in 218.84 s. - `clang-format --dry-run --Werror` passes on the changed C++ files. +## Authenticated Binary-Variant Downloads (GCC 16.2, pin `0002e74`) + +```sh +dev cpp-gcc -c cmake --build build/pinned --parallel 8 +dev cpp-gcc -c build/pinned/bin/vbs_registry_tests --no-color +dev cpp-gcc -c ctest --test-dir build/pinned --output-on-failure +``` + +- Build: exit 0. Registry suite: **7 / 7 passed** in 12.41 s, including + `private_binary_variant_download_requires_auth`: a private package's binary artifact returns 401 + anonymously, while `download_binary_artifact(..., RegistryAuth{token})` and + `materialize_binary_variant` with `BinaryFetchOptions::bearer_token` download and verify it. +- Full CTest: **8 / 8 passed** in 219.68 s. +- `clang-format --dry-run --Werror` passes on the changed C++ files. + ## Limits and Unrun Checks 1. **HTTPS git fetch**: the host shell is proxy-restricted, but the Docker container could clone `https://git.faumaray.com/Void/VoidLibrary.git`; the pinned commit `3e254055e081a104f08df68dde39711bc7813518` was fetched directly for the verification above. A separate configure against the local `/home/faumaray/Projects/Library` checkout via `VBS_VOID_SOURCE_DIR` also succeeded (development-only override, checkout unmodified). diff --git a/docs/roadmap/21-expansion-roadmap.md b/docs/roadmap/21-expansion-roadmap.md index 65ef1bb..7456dbb 100644 --- a/docs/roadmap/21-expansion-roadmap.md +++ b/docs/roadmap/21-expansion-roadmap.md @@ -61,7 +61,7 @@ flowchart LR | --- | --- | --- | | **D1 — Shared HTTP Content-Addressed Action Cache (CAS)** *(verified: cross-build-directory 100% cache hit)* | Push/pull action records and output blobs (`PUT/GET /api/v1/cas/blobs/{sha256}`, `/api/v1/cas/actions/{action_key}`) against `vbs-registry` or any compatible HTTP CAS server with bearer auth and digest verification on every read. Action keys are normalized to be build-directory independent; `vbs build/test --remote-cache URL [--remote-cache-token-env VAR]` (or `VBS_REMOTE_CACHE` / `VBS_REMOTE_CACHE_TOKEN`). | Cold CI build populates remote CAS; second clean machine achieves 100% cache hit with verified SHA-256 outputs. | | **D2 — Fast Hashing & Parallel Snapshot Pipeline** *(verified: 5,001-file warm no-op 374 ms)* | Adopt `Void::Crypto` BLAKE2b / hardware-accelerated SHA-256 (when available) + parallel snapshot hashing across `Void::Concurrency::ThreadPool` + optional `Void::Sqlite` indexed state store for >10k-file monorepos. Snapshot capture revalidation now hashes on a bounded thread pool for trees of 32+ files. | Sub-second warm no-op on 5,000-file synthetic benchmark fixture (`vbs_benchmarks`). | -| **D3 — Supply-Chain Provenance & Signed Packages** *(SBOM, Ed25519 signing primitives, and trusted-key enforcement implemented; OpenSSL or the built-in Ed25519 backend)* | Emit SPDX/CycloneDX SBOM JSON from `vbs.lock` + `BuildGraph` (`vbs build/test --sbom FILE --sbom-format spdx\|cyclonedx`, `src/Provenance/Sbom.cpp`); Ed25519 detached-signature primitives in `Void::Build::Provenance::Signing` (`include/Void/Build/Provenance/Signing.hpp`, `src/Provenance/Signing.cpp`): 0600 seed generation, public-key derivation, canonical `vbs-package-v1` package message, and sign/verify; package signature/public-key metadata persisted in `vbs.lock` and registry releases; `vbs publish --signing-key FILE`; `vbs build\|test --trusted-public-key HEX` enforced before extraction via `Provenance::verify_trusted_package_signature` (`include/Void/Build/Provenance/Verification.hpp`); trusted keys can also come from `--trusted-key-file`, a project `vbs.keys` ring, or `VBS_TRUSTED_PUBLIC_KEYS` (`Provenance::load_trusted_keys`); prebuilt binary variants carry optional signatures verified by `select_compatible_signed_binary` over the canonical `vbs-binary-v1` message, `materialize_binary_variant` downloads digest-verified artifacts with cached-digest revalidation, `vbs-registry` stores/serves per-release binary variants with optional signature metadata and CSRF-protected yank (the client never selects yanked variants), `vbs publish-binary` publishes signed variants through `RegistryClient`, and `vbs binaries list|fetch` inspects and downloads them. | SBOM is deterministic and valid JSON; signing primitives pass round-trip/tamper/malformed tests (`tests/SigningTests.cpp`); trusted-key policy tests pass with and without OpenSSL (`tests/SignatureEnforcementTests.cpp`); a signed publish -> deps update -> `--locked` trusted build succeeds and an untrusted/unsigned package fails closed before extraction (`RegistryTests.cpp`). | +| **D3 — Supply-Chain Provenance & Signed Packages** *(SBOM, Ed25519 signing primitives, and trusted-key enforcement implemented; OpenSSL or the built-in Ed25519 backend)* | Emit SPDX/CycloneDX SBOM JSON from `vbs.lock` + `BuildGraph` (`vbs build/test --sbom FILE --sbom-format spdx\|cyclonedx`, `src/Provenance/Sbom.cpp`); Ed25519 detached-signature primitives in `Void::Build::Provenance::Signing` (`include/Void/Build/Provenance/Signing.hpp`, `src/Provenance/Signing.cpp`): 0600 seed generation, public-key derivation, canonical `vbs-package-v1` package message, and sign/verify; package signature/public-key metadata persisted in `vbs.lock` and registry releases; `vbs publish --signing-key FILE`; `vbs build\|test --trusted-public-key HEX` enforced before extraction via `Provenance::verify_trusted_package_signature` (`include/Void/Build/Provenance/Verification.hpp`); trusted keys can also come from `--trusted-key-file`, a project `vbs.keys` ring, or `VBS_TRUSTED_PUBLIC_KEYS` (`Provenance::load_trusted_keys`); prebuilt binary variants carry optional signatures verified by `select_compatible_signed_binary` over the canonical `vbs-binary-v1` message, `materialize_binary_variant` downloads digest-verified artifacts with cached-digest revalidation, `vbs-registry` stores/serves per-release binary variants with optional signature metadata and CSRF-protected yank (the client never selects yanked variants), `vbs publish-binary` publishes signed variants through `RegistryClient`, `vbs binaries list|fetch` inspects and downloads them (with bearer auth for private artifacts). | SBOM is deterministic and valid JSON; signing primitives pass round-trip/tamper/malformed tests (`tests/SigningTests.cpp`); trusted-key policy tests pass with and without OpenSSL (`tests/SignatureEnforcementTests.cpp`); a signed publish -> deps update -> `--locked` trusted build succeeds and an untrusted/unsigned package fails closed before extraction (`RegistryTests.cpp`). | --- diff --git a/include/Void/Build/Package/Fetch.hpp b/include/Void/Build/Package/Fetch.hpp index f023435..a37b8df 100644 --- a/include/Void/Build/Package/Fetch.hpp +++ b/include/Void/Build/Package/Fetch.hpp @@ -70,6 +70,7 @@ select_compatible_signed_binary(const BinaryCompatibilityKey &key, struct BinaryFetchOptions { std::filesystem::path cache_dir; std::vector trusted_public_keys; + std::string bearer_token; // Optional registry token for private binary artifacts. }; // Selects a compatible binary variant (verifying its trusted signature when keys are supplied), diff --git a/include/Void/Build/Package/RegistryClient.hpp b/include/Void/Build/Package/RegistryClient.hpp index d24a9e5..207cdd1 100644 --- a/include/Void/Build/Package/RegistryClient.hpp +++ b/include/Void/Build/Package/RegistryClient.hpp @@ -80,7 +80,7 @@ fetch_binary_variants(std::string_view registry_url, std::string_view package_na // rejecting any content whose SHA-256 differs from `expected_sha256` (verified before writing). [[nodiscard]] Void::Result::Result download_binary_artifact(std::string_view url, std::string_view expected_sha256, - const std::filesystem::path &dest_file); + const std::filesystem::path &dest_file, const RegistryAuth &auth = {}); // Publishes a verified deterministic archive via PUT /api/v1/packages//. [[nodiscard]] Void::Result::Result diff --git a/src/Main.cpp b/src/Main.cpp index 2055b07..e01ced9 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -1203,7 +1203,8 @@ int execute_binaries_command(std::string_view sub, const BinariesCmdOptions &opt Void::Encoding::Url::encode(*opts.version_arg) + "/binaries/" + Void::Encoding::Url::encode(match->variant_id) + "/download"; auto downloaded = Package::download_binary_artifact(url, match->sha256, - std::filesystem::path{*opts.output_arg}); + std::filesystem::path{*opts.output_arg}, + Package::RegistryAuth{auth.bearer_token}); if (!downloaded) { std::cerr << "vbs binaries fetch: " << downloaded.error().message() << '\n'; return 1; diff --git a/src/Package/Fetch.cpp b/src/Package/Fetch.cpp index 36691df..f942ddc 100644 --- a/src/Package/Fetch.cpp +++ b/src/Package/Fetch.cpp @@ -191,8 +191,8 @@ materialize_binary_variant(const BinaryCompatibilityKey &key, } } std::filesystem::create_directories(destination.parent_path(), ec); - auto downloaded = - download_binary_artifact(selected->download_url, selected->sha256, destination); + auto downloaded = download_binary_artifact(selected->download_url, selected->sha256, + destination, RegistryAuth{options.bearer_token}); if (!downloaded) { return std::unexpected{downloaded.error()}; } diff --git a/src/Package/RegistryClient.cpp b/src/Package/RegistryClient.cpp index 8311bfe..4a9da9c 100644 --- a/src/Package/RegistryClient.cpp +++ b/src/Package/RegistryClient.cpp @@ -530,12 +530,16 @@ fetch_binary_variants(std::string_view registry_url, std::string_view package_na Void::Result::Result download_binary_artifact(std::string_view url, std::string_view expected_sha256, - const std::filesystem::path &dest_file) { + const std::filesystem::path &dest_file, const RegistryAuth &auth) { auto parsed_url = parse_registry_url(url); if (!parsed_url) { return std::unexpected{parsed_url.error()}; } - auto reply = send_http_request(*parsed_url, "GET", "", {}, {}); + std::map> headers; + if (!auth.bearer_token.empty()) { + headers["Authorization"] = "Bearer " + auth.bearer_token; + } + auto reply = send_http_request(*parsed_url, "GET", "", headers, {}); if (!reply) { return std::unexpected{reply.error()}; } diff --git a/tests/RegistryTests.cpp b/tests/RegistryTests.cpp index 372645d..67b16df 100644 --- a/tests/RegistryTests.cpp +++ b/tests/RegistryTests.cpp @@ -681,6 +681,116 @@ VOID_TEST(RegistryTests, registry_binary_variant_publish_download_and_materializ (*svc)->stop_http(); } +VOID_TEST(RegistryTests, private_binary_variant_download_requires_auth) { + if (!Provenance::signing_available()) { + return; + } + Void::FileSystem::TempDir tmp{"vbs_priv_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("priv_pub", "priv_pass", Role::Publisher).has_value()); + auto tok = (*svc)->create_token("priv_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 / "priv_pkg"; + (void)Platform::atomic_write_file(pkg_src / "payload.txt", "PRIVATE_SOURCE", false); + const auto tar = tmp / "priv.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/priv-bin/1.0.0", + {{"Authorization", "Bearer " + *tok}, + {"X-Content-SHA256", *source_sha}, + {"X-Package-Private", "true"}}, + *source_bytes); + Void::Testing::require(src_pub.has_value() && src_pub->status == 201); + + const std::string artifact = "PRIVATE_BINARY_BYTES"; + const std::string artifact_sha = Util::sha256_hex(artifact); + const std::string variant_id = "private-variant"; + const std::string binary_path = "/api/v1/packages/priv-bin/1.0.0/binaries/" + variant_id; + const auto seed_path = tmp / "private.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{message.data(), message.size()}), seed_path); + Void::Testing::require(signature.has_value()); + auto bin_pub = 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::require(bin_pub.has_value() && bin_pub->status == 201); + + const std::string download_url = reg_url + binary_path + "/download"; + auto anonymous = send_loopback_http(port, "GET", binary_path + "/download"); + Void::Testing::expect(anonymous.has_value() && anonymous->status == 401); + + const auto dest = tmp / "private-binary.bin"; + auto downloaded = Package::download_binary_artifact(download_url, artifact_sha, dest, + Package::RegistryAuth{*tok}); + Void::Testing::require(downloaded.has_value()); + auto bytes = Void::FileSystem::read_file(dest); + Void::Testing::require(bytes.has_value()); + Void::Testing::expect(*bytes == artifact); + + 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 = download_url; + 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 / "private_cache", {*public_key}, *tok}; + auto materialized = Package::materialize_binary_variant(key, {variant}, options); + Void::Testing::require(materialized.has_value()); + auto cached = Void::FileSystem::read_file(tmp / "private_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) {