feat(provenance): enforce trusted Ed25519 package signatures in publish, lockfile, and locked builds
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 3s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 10s

This commit is contained in:
faumaray committed 2026-12-03 17:57:20 +03:00
1 parent 21babb8c31
commit 85f2ae274f
21 files changed
+519 -15

No files matched your search

+54 -6
View File
@@ -16,6 +16,7 @@
#include <Void/Build/Platform/FileOps.hpp>
#include <Void/Build/Platform/ProcessSupervisor.hpp>
#include <Void/Build/Provenance/Sbom.hpp>
#include <Void/Build/Provenance/Verification.hpp>
#include <Void/Build/Provider/Provider.hpp>
#include <Void/Build/Provider/Translator.hpp>
#include <Void/Build/SelfHost/TestRegistryGen.hpp>
@@ -269,7 +270,8 @@ struct ResolvedDepMaterialization {
Void::Result::Result<ResolvedDepMaterialization, Void::Result::Error> resolve_and_materialize_deps(
const ProfileContext &ctx, const std::vector<Package::NormalizedDependency> &merged_deps,
const std::filesystem::path &project_root, const std::filesystem::path &build_root,
const std::optional<Package::PinnedLock> &pinned_lock, bool offline, bool allow_upgrade) {
const std::optional<Package::PinnedLock> &pinned_lock, bool offline, bool allow_upgrade,
const std::vector<std::string> &trusted_public_keys) {
const std::string ctx_key = Package::make_lock_context_key(ctx, "target");
const std::string fp = Package::compute_declaration_fingerprint(ctx, "target", merged_deps);
@@ -413,6 +415,35 @@ Void::Result::Result<ResolvedDepMaterialization, Void::Result::Error> resolve_an
const auto tar_path = pkg_cache_root / (sp.source_sha256 + ".tar");
const auto extract_dir = pkg_cache_root / sp.source_sha256 / "src";
std::string package_signature;
std::string package_public_key;
if (const auto it = locked_pkg_entries.find(pid);
it != locked_pkg_entries.end() && it->second.sha256 == sp.source_sha256) {
package_signature = it->second.signature.value_or(std::string{});
package_public_key = it->second.public_key.value_or(std::string{});
} else {
package_signature = sp.signature.value_or(std::string{});
package_public_key = sp.public_key.value_or(std::string{});
}
if (!trusted_public_keys.empty()) {
auto decision = Provenance::verify_trusted_package_signature(
pid.name, sp.version.to_string(),
Provenance::PackageSignature{sp.source_sha256, package_signature,
package_public_key},
trusted_public_keys);
if (!decision) {
return std::unexpected{decision.error()};
}
if (*decision != Provenance::TrustDecision::Verified) {
return std::unexpected{Void::System::make_system_error(
Void::System::SystemErrorCode::permission_denied,
std::format("package {}@{} is not signed by a trusted key ({})", pid.name,
sp.version.to_string(),
Provenance::trust_decision_name(*decision)))};
}
}
if (!std::filesystem::is_directory(extract_dir, ec)) {
bool need_download = true;
if (std::filesystem::is_regular_file(tar_path, ec)) {
@@ -455,6 +486,12 @@ Void::Result::Result<ResolvedDepMaterialization, Void::Result::Error> resolve_an
le.builder = nd.record.builder;
le.features = nd.record.features;
le.build_dependency = nd.record.build_dependency;
if (!package_signature.empty()) {
le.signature = package_signature;
}
if (!package_public_key.empty()) {
le.public_key = package_public_key;
}
out.lock_context.entries.push_back(std::move(le));
} else {
Package::FetchOptions fopt{build_root / ".vbs" / "cache", project_root, offline, {}};
@@ -515,6 +552,7 @@ struct BuildCmdOptions {
std::optional<std::string> sbom_format_arg;
std::optional<std::filesystem::path> lock_root;
std::optional<std::filesystem::path> state_dir;
std::vector<std::string> trusted_public_keys;
bool publish_editor_selection{true};
bool no_cache{false};
bool locked{false};
@@ -707,8 +745,9 @@ int execute_build_or_test(BuildCmdOptions opts, bool run_tests) {
return 1;
}
auto resolved = resolve_and_materialize_deps(
ctx, *merged_deps, project_root, build_root, *pinned_lock, opts.offline, false);
auto resolved = resolve_and_materialize_deps(ctx, *merged_deps, project_root,
build_root, *pinned_lock, opts.offline,
false, opts.trusted_public_keys);
if (!resolved) {
std::cerr << "vbs: " << resolved.error().message() << '\n';
return 1;
@@ -1312,6 +1351,7 @@ struct PublishCmdOptions {
std::optional<std::string> version_arg;
std::string description;
std::string token_env{"VBS_REGISTRY_TOKEN"};
std::optional<std::string> signing_key_arg;
bool is_private{false};
};
@@ -1342,6 +1382,9 @@ int execute_publish_command(const PublishCmdOptions &opts) {
popts.description = opts.description;
popts.is_private = opts.is_private;
popts.auth.bearer_token = Void::Configuration::get_env_or(opts.token_env, "");
if (opts.signing_key_arg) {
popts.signing_seed_path = std::filesystem::path{*opts.signing_key_arg};
}
Void::Log::info("Publish", "Uploading {}@{} ({}) to {}...", *opts.name_arg, *opts.version_arg,
sha->substr(0, 12), registry_url);
@@ -1723,7 +1766,7 @@ int execute_deps_command(std::string_view sub, const DepsCmdOptions &opts) {
const std::string base_rev = existing->has_value() ? (*existing)->revision_hash : std::string{};
auto resolved = resolve_and_materialize_deps(ctx, *merged, project_root, build_root, *existing,
opts.offline, sub == "update");
opts.offline, sub == "update", {});
if (!resolved) {
std::cerr << "vbs deps: " << resolved.error().message() << '\n';
return 1;
@@ -2137,7 +2180,7 @@ int execute_ide_command(std::string_view sub, const IdeCmdOptions &opts) {
pinned_lock = *pl;
}
auto resolved = resolve_and_materialize_deps(ctx, *merged_deps, project_root, build_root,
pinned_lock, true, false);
pinned_lock, true, false, {});
if (resolved) {
for (const auto &[dep_rec, mat] : resolved->materialized) {
DependencyRecord effective_dep = dep_rec;
@@ -2339,7 +2382,10 @@ int main(int argc, char **argv) {
.flag("--no-cache", "", "Bypass action cache reads", build_opts.no_cache)
.flag("--native-foreign", "",
"Translate supported CMake/Meson dependencies to native VBS actions (Plan 20)",
build_opts.native_foreign);
build_opts.native_foreign)
.option_many("--trusted-public-key", "",
"Trusted Ed25519 package public key (hex; repeatable)",
build_opts.trusted_public_keys);
add_log_flags(p);
};
@@ -2448,6 +2494,8 @@ int main(int argc, char **argv) {
.option_default("--description", "-d", "Package description", publish_opts.description, "")
.option_default("--token-env", "", "Environment variable holding bearer token",
publish_opts.token_env, "VBS_REGISTRY_TOKEN")
.option("--signing-key", "", "Ed25519 signing seed file (64 hex characters)",
publish_opts.signing_key_arg)
.flag("--private", "", "Publish package as private", publish_opts.is_private);
add_log_flags(publish_cmd, false); // `-v` is `--version` on `publish`.
+8
View File
@@ -113,6 +113,8 @@ serialize_contexts_body(const std::map<std::string, LockContextRecord, std::less
",\"sha256\":" + json_quote(e.sha256) + ",\"builder\":" + json_quote(e.builder) +
",\"features\":" + json_array(e.features, json_quote) +
",\"build_dependency\":" + std::string{e.build_dependency ? "true" : "false"} +
(e.signature ? ",\"signature\":" + json_quote(*e.signature) : std::string{}) +
(e.public_key ? ",\"public_key\":" + json_quote(*e.public_key) : std::string{}) +
'}';
});
out += '}';
@@ -252,6 +254,12 @@ parse_lockfile(std::string_view json_text) {
e.builder = get_str(*eo, "builder");
e.features = get_str_array(*eo, "features");
e.build_dependency = get_bool(*eo, "build_dependency", false);
if (const auto sig = get_str(*eo, "signature"); !sig.empty()) {
e.signature = sig;
}
if (const auto key = get_str(*eo, "public_key"); !key.empty()) {
e.public_key = key;
}
rec.entries.push_back(std::move(e));
}
}
+20
View File
@@ -3,6 +3,7 @@
#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/Util/Sha256.hpp>
#include <Void/Core/Scope.hpp>
#include <Void/Data/StrictJson.hpp>
@@ -323,6 +324,12 @@ fetch_package_releases(std::string_view registry_url, std::string_view package_n
rec.version = *ver;
rec.yanked = get_bool(*ro, "yanked", false);
rec.source_sha256 = get_str(*ro, "sha256");
if (const auto sig = get_str(*ro, "signature"); !sig.empty()) {
rec.signature = sig;
}
if (const auto key = get_str(*ro, "public_key"); !key.empty()) {
rec.public_key = key;
}
rec.source_url = std::string{registry_url} + "/api/v1/packages/" +
Void::Encoding::Url::encode(package_name) + "/" +
Void::Encoding::Url::encode(ver_str) + "/download";
@@ -390,6 +397,19 @@ publish_package_archive(const PublishOptions &options) {
std::map<std::string, std::string, std::less<>> headers;
headers["X-Content-SHA256"] = sha;
if (options.signing_seed_path) {
auto signature = Provenance::sign_package(options.package_name, options.version, sha,
*options.signing_seed_path);
if (!signature) {
return std::unexpected{signature.error()};
}
auto public_key = Provenance::public_key_from_seed(*options.signing_seed_path);
if (!public_key) {
return std::unexpected{public_key.error()};
}
headers["X-Package-Signature"] = *signature;
headers["X-Package-Public-Key"] = *public_key;
}
if (!options.auth.bearer_token.empty()) {
headers["Authorization"] = "Bearer " + options.auth.bearer_token;
}
+2
View File
@@ -57,6 +57,8 @@ class PubGrubSolver {
sp.version = rel.version;
sp.source_sha256 = rel.source_sha256;
sp.source_url = rel.source_url;
sp.signature = rel.signature;
sp.public_key = rel.public_key;
sp.binaries = rel.binaries;
if (const auto cit = constraints.find(id); cit != constraints.end()) {
for (const auto &ac : cit->second) {
+65
View File
@@ -0,0 +1,65 @@
#include <Void/Build/Provenance/Verification.hpp>
#include <Void/Build/Provenance/Signing.hpp>
#include <algorithm>
#include <cctype>
#include <string>
#include <string_view>
#include <vector>
namespace Void::Build::Provenance {
namespace {
std::string normalize_hex(std::string_view hex) {
std::string normalized{hex};
std::ranges::transform(normalized, normalized.begin(), [](char c) {
return static_cast<char>(std::tolower(static_cast<unsigned char>(c)));
});
return normalized;
}
} // namespace
std::string_view trust_decision_name(TrustDecision decision) noexcept {
switch (decision) {
case TrustDecision::Verified:
return "verified";
case TrustDecision::Unsigned:
return "unsigned";
case TrustDecision::UntrustedKey:
return "untrusted_key";
case TrustDecision::InvalidSignature:
return "invalid_signature";
}
return "unknown";
}
Void::Result::Result<TrustDecision, Void::Result::Error>
verify_trusted_package_signature(std::string_view name, std::string_view version,
const PackageSignature &signature,
const std::vector<std::string> &trusted_public_keys_hex) {
if (trusted_public_keys_hex.empty()) {
return TrustDecision::Unsigned;
}
if (signature.signature.empty() || signature.public_key.empty()) {
return TrustDecision::Unsigned;
}
const std::string normalized_key = normalize_hex(signature.public_key);
const bool trusted = std::ranges::any_of(trusted_public_keys_hex, [&](const std::string &key) {
return normalize_hex(key) == normalized_key;
});
if (!trusted) {
return TrustDecision::UntrustedKey;
}
auto verified =
verify_package(name, version, signature.sha256, signature.signature, signature.public_key);
if (!verified) {
return std::unexpected{verified.error()};
}
return *verified ? TrustDecision::Verified : TrustDecision::InvalidSignature;
}
} // namespace Void::Build::Provenance