feat(cli): require trusted signatures when fetching binary variants
This commit is contained in:
1 parent
f60c2708e8
commit
2c6b60453a
6 files changed
+70
-3
No files matched your search
+33
-1
@@ -1189,6 +1189,8 @@ struct BinariesCmdOptions {
|
||||
std::optional<std::string> variant_arg;
|
||||
std::optional<std::string> output_arg;
|
||||
std::string token_env{"VBS_REGISTRY_TOKEN"};
|
||||
std::vector<std::string> trusted_public_keys;
|
||||
std::vector<std::string> trusted_key_files;
|
||||
};
|
||||
|
||||
int execute_binaries_command(std::string_view sub, const BinariesCmdOptions &opts) {
|
||||
@@ -1232,6 +1234,31 @@ int execute_binaries_command(std::string_view sub, const BinariesCmdOptions &opt
|
||||
std::cerr << "vbs binaries fetch: variant '" << *opts.variant_arg << "' not found\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// When trusted keys are configured, require a verified signature before downloading.
|
||||
auto trusted_keys = combine_trusted_keys(opts.trusted_public_keys, opts.trusted_key_files,
|
||||
std::filesystem::current_path());
|
||||
if (!trusted_keys) {
|
||||
std::cerr << "vbs binaries fetch: " << trusted_keys.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
if (!trusted_keys->empty()) {
|
||||
auto decision = Provenance::verify_trusted_binary_signature(
|
||||
Provenance::BinarySignature{match->variant_id, match->sha256,
|
||||
match->signature.value_or(std::string{}),
|
||||
match->public_key.value_or(std::string{})},
|
||||
*trusted_keys);
|
||||
if (!decision) {
|
||||
std::cerr << "vbs binaries fetch: " << decision.error().message() << '\n';
|
||||
return 1;
|
||||
}
|
||||
if (*decision != Provenance::TrustDecision::Verified) {
|
||||
std::cerr << "vbs binaries fetch: variant '" << match->variant_id
|
||||
<< "' is not signed by a trusted key ("
|
||||
<< Provenance::trust_decision_name(*decision) << ")\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
const std::string url = registry_url + "/api/v1/packages/" +
|
||||
Void::Encoding::Url::encode(*opts.name_arg) + "/" +
|
||||
Void::Encoding::Url::encode(*opts.version_arg) + "/binaries/" +
|
||||
@@ -2607,7 +2634,12 @@ int main(int argc, char **argv) {
|
||||
binaries_cmd.subcommand("fetch", "Download one binary variant artifact");
|
||||
configure_binaries(binaries_fetch_cmd);
|
||||
binaries_fetch_cmd.option("--variant", "", "Binary variant id", binaries_opts.variant_arg)
|
||||
.option("--output", "-o", "Destination artifact path", binaries_opts.output_arg);
|
||||
.option("--output", "-o", "Destination artifact path", binaries_opts.output_arg)
|
||||
.option_many("--trusted-public-key", "",
|
||||
"Required trusted Ed25519 signer key (hex; repeatable)",
|
||||
binaries_opts.trusted_public_keys)
|
||||
.option_many("--trusted-key-file", "", "File with trusted public keys (repeatable)",
|
||||
binaries_opts.trusted_key_files);
|
||||
|
||||
auto &pack_cmd = root.subcommand("pack", "Create a deterministic USTAR source archive (.tar)");
|
||||
pack_cmd.option_default("--project", "-C", "Project directory", pack_opts.project_arg, cwd)
|
||||
|
||||
Reference in new issue
Block a user