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
+54
-6
@@ -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`.
|
||||
|
||||
|
||||
Reference in new issue
Block a user