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
@@ -297,6 +297,8 @@ Void::Result::Result<void, Void::Result::Error> RegistryService::load_locked() {
|
||||
rm.yanked = get_bool(*ro, "yanked", false);
|
||||
rm.publisher = get_str(*ro, "publisher");
|
||||
rm.published_epoch = get_i64(*ro, "published_epoch", 0);
|
||||
rm.signature = get_str(*ro, "signature");
|
||||
rm.public_key = get_str(*ro, "public_key");
|
||||
p.releases[rm.version] = std::move(rm);
|
||||
}
|
||||
}
|
||||
@@ -374,6 +376,12 @@ Void::Result::Result<void, Void::Result::Error> RegistryService::save_locked() {
|
||||
",\"yanked\":" + std::string{r->yanked ? "true" : "false"} +
|
||||
",\"publisher\":" + json_quote(r->publisher) +
|
||||
",\"published_epoch\":" + std::to_string(r->published_epoch) +
|
||||
(r->signature.empty()
|
||||
? std::string{}
|
||||
: ",\"signature\":" + json_quote(r->signature)) +
|
||||
(r->public_key.empty()
|
||||
? std::string{}
|
||||
: ",\"public_key\":" + json_quote(r->public_key)) +
|
||||
'}';
|
||||
}) +
|
||||
'}';
|
||||
@@ -791,7 +799,14 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
",\"size_bytes\":" + std::to_string(r->size_bytes) +
|
||||
",\"yanked\":" +
|
||||
std::string{r->yanked ? "true" : "false"} +
|
||||
",\"publisher\":" + json_quote(r->publisher) + '}';
|
||||
",\"publisher\":" + json_quote(r->publisher) +
|
||||
(r->signature.empty()
|
||||
? std::string{}
|
||||
: ",\"signature\":" + json_quote(r->signature)) +
|
||||
(r->public_key.empty()
|
||||
? std::string{}
|
||||
: ",\"public_key\":" + json_quote(r->public_key)) +
|
||||
'}';
|
||||
}) +
|
||||
"}\n");
|
||||
}
|
||||
@@ -827,6 +842,38 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
"X-Content-SHA256 does not match uploaded bytes");
|
||||
}
|
||||
|
||||
// Optional detached Ed25519 signature metadata. The registry stores and serves it;
|
||||
// trust evaluation belongs to the consumer. Both fields must be present together.
|
||||
std::string release_signature;
|
||||
std::string release_public_key;
|
||||
if (const auto sig = req.header("x-package-signature"); sig) {
|
||||
release_signature = std::string{*sig};
|
||||
}
|
||||
if (const auto key = req.header("x-package-public-key"); key) {
|
||||
release_public_key = std::string{*key};
|
||||
}
|
||||
if (release_signature.empty() != release_public_key.empty()) {
|
||||
return HttpResponse::error_json(
|
||||
400, "invalid_signature",
|
||||
"X-Package-Signature and X-Package-Public-Key must be provided together");
|
||||
}
|
||||
auto is_hex = [](std::string_view text) {
|
||||
return std::ranges::all_of(text, [](char c) {
|
||||
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
|
||||
(c >= 'A' && c <= 'F');
|
||||
});
|
||||
};
|
||||
if (!release_signature.empty() &&
|
||||
(release_signature.size() != 128 || !is_hex(release_signature))) {
|
||||
return HttpResponse::error_json(400, "invalid_signature",
|
||||
"X-Package-Signature must be 128 hex characters");
|
||||
}
|
||||
if (!release_public_key.empty() &&
|
||||
(release_public_key.size() != 64 || !is_hex(release_public_key))) {
|
||||
return HttpResponse::error_json(400, "invalid_signature",
|
||||
"X-Package-Public-Key must be 64 hex characters");
|
||||
}
|
||||
|
||||
// Immutability check: idempotent on exact bytes, 409 Conflict on different bytes!
|
||||
if (existing_pkg) {
|
||||
if (const auto rit = existing_pkg->releases.find(ver_str);
|
||||
@@ -891,8 +938,9 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
if (const auto priv = req.header("x-package-private")) {
|
||||
pkg.is_private = (*priv == "true" || *priv == "1");
|
||||
}
|
||||
pkg.releases[ver_str] = ReleaseMeta{ver_str, actual_sha, req.body.size(),
|
||||
false, principal->username, now_epoch()};
|
||||
pkg.releases[ver_str] = ReleaseMeta{
|
||||
ver_str, actual_sha, req.body.size(), false, principal->username,
|
||||
now_epoch(), release_signature, release_public_key};
|
||||
append_audit_locked(principal->username, "package.publish", pkg_name + "@" + ver_str,
|
||||
"ok", "sha256=" + actual_sha);
|
||||
if (auto s = save_locked(); !s) {
|
||||
|
||||
Reference in new issue
Block a user