feat(package,daemon): revoke registry tokens; allow daemon deps updates
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 6s
VoidBuildSystem CI / signing-openssl-gcc16 (push) Failing after 14s

This commit is contained in:
faumaray committed 2026-12-04 07:20:06 +03:00
1 parent eb35bb6b6e
commit c7d2662cf2
11 files changed
+309 -13

No files matched your search

+13 -2
View File
@@ -578,7 +578,7 @@ make_resolve_options(const DaemonOptions &options) {
// Resolves and materializes declared dependencies without building, returning the lock context.
std::string deps_project(const DaemonOptions &options, std::string_view profile_name,
std::optional<CompilerFamily> compiler_override, std::string_view member,
bool offline) {
bool offline, bool allow_upgrade) {
auto effective_result = resolve_member_options(options, member);
if (!effective_result) {
return error_response(std::format("deps: {}", effective_result.error()));
@@ -606,6 +606,7 @@ std::string deps_project(const DaemonOptions &options, std::string_view profile_
return error_response(std::format("deps: {}", resolve_options.error()));
}
resolve_options->offline = offline;
resolve_options->allow_upgrade = allow_upgrade;
auto resolved = Package::resolve_and_materialize_dependencies(evaluated->context, *merged,
*resolve_options);
if (!resolved) {
@@ -2570,7 +2571,17 @@ DaemonServer::Impl::DispatchResult DaemonServer::Impl::dispatch(std::string_view
}
offline = *value;
}
return {deps_project(options, profile_name, compiler_override, member, offline), false};
bool allow_upgrade = false;
if (const auto entry = object->find("update"); entry != object->end()) {
const auto *value = std::get_if<bool>(&entry->second.value);
if (value == nullptr) {
return {error_response("\"update\" must be a boolean"), false};
}
allow_upgrade = *value;
}
return {deps_project(options, profile_name, compiler_override, member, offline,
allow_upgrade),
false};
}
if (*name == "install") {
InstallRequest install_request;
+31 -9
View File
@@ -1156,18 +1156,34 @@ int execute_publish_binary_command(const PublishBinaryCmdOptions &opts) {
struct TokensCmdOptions {
std::optional<std::string> registry_arg;
std::optional<std::string> token_id_arg;
std::string token_env{"VBS_REGISTRY_TOKEN"};
};
int execute_tokens_list_command(const TokensCmdOptions &opts) {
int execute_tokens_command(std::string_view sub, const TokensCmdOptions &opts) {
const std::string registry_url = opts.registry_arg
? *opts.registry_arg
: Void::Configuration::get_env_or("VBS_REGISTRY_URL", "");
if (registry_url.empty()) {
std::cerr << "vbs tokens list: --registry is required\n";
std::cerr << "vbs tokens: --registry is required\n";
return 2;
}
Package::RegistryAuth auth{Void::Configuration::get_env_or(opts.token_env, "")};
if (sub == "revoke") {
if (!opts.token_id_arg || opts.token_id_arg->empty()) {
std::cerr << "vbs tokens revoke: --token-id is required\n";
return 2;
}
auto revoked = Package::revoke_token(registry_url, *opts.token_id_arg, auth);
if (!revoked) {
std::cerr << "vbs tokens revoke: " << revoked.error().message() << '\n';
return 1;
}
std::cout << "revoked " << *opts.token_id_arg << '\n';
return 0;
}
auto tokens = Package::fetch_tokens(registry_url, auth);
if (!tokens) {
std::cerr << "vbs tokens: " << tokens.error().message() << '\n';
@@ -2582,13 +2598,19 @@ int main(int argc, char **argv) {
add_log_flags(publish_binary_cmd, false); // `-v` is `--version` on publish-binary.
auto &tokens_cmd = root.subcommand("tokens", "Inspect API tokens in a package registry");
auto configure_tokens = [&](Void::Argparse::Parser &parser) {
parser
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
tokens_opts.registry_arg)
.option_default("--token-env", "", "Environment variable holding bearer token",
tokens_opts.token_env, "VBS_REGISTRY_TOKEN");
add_log_flags(parser);
};
auto &tokens_list_cmd = tokens_cmd.subcommand("list", "List token metadata");
tokens_list_cmd
.option("--registry", "-r", "Registry base URL (or VBS_REGISTRY_URL)",
tokens_opts.registry_arg)
.option_default("--token-env", "", "Environment variable holding bearer token",
tokens_opts.token_env, "VBS_REGISTRY_TOKEN");
add_log_flags(tokens_list_cmd);
configure_tokens(tokens_list_cmd);
auto &tokens_revoke_cmd = tokens_cmd.subcommand("revoke", "Revoke an API token");
configure_tokens(tokens_revoke_cmd);
tokens_revoke_cmd.option("--token-id", "", "Token id to revoke", tokens_opts.token_id_arg);
auto &releases_cmd =
root.subcommand("releases", "List published releases in a package registry");
@@ -3008,7 +3030,7 @@ int main(int argc, char **argv) {
return execute_releases_list_command(releases_opts);
}
if (cmd == "tokens") {
return execute_tokens_list_command(tokens_opts);
return execute_tokens_command(parsed.matched_command_path.at(1), tokens_opts);
}
if (cmd == "bridge") {
return execute_bridge_command(bridge_opts);
+27
View File
@@ -742,6 +742,33 @@ fetch_tokens(std::string_view registry_url, const RegistryAuth &auth) {
return tokens;
}
Void::Result::Result<void, Void::Result::Error>
revoke_token(std::string_view registry_url, std::string_view token_id,
const RegistryAuth &auth) {
auto parsed_url = parse_registry_url(registry_url);
if (!parsed_url) {
return std::unexpected{parsed_url.error()};
}
std::map<std::string, std::string, std::less<>> headers;
if (!auth.bearer_token.empty()) {
headers["Authorization"] = "Bearer " + auth.bearer_token;
}
const std::string path = "/api/v1/tokens/" + Void::Encoding::Url::encode(token_id);
auto reply = send_http_request(*parsed_url, "DELETE", path, headers, {});
if (!reply) {
return std::unexpected{reply.error()};
}
if (reply->status != 200) {
return std::unexpected{make_error(
reply->status == 404 ? Void::System::SystemErrorCode::not_found
: reply->status == 401 || reply->status == 403
? Void::System::SystemErrorCode::permission_denied
: Void::System::SystemErrorCode::io_error,
std::format("registry DELETE {} failed with HTTP {}", path, reply->status))};
}
return {};
}
Void::Result::Result<std::filesystem::path, Void::Result::Error>
download_binary_artifact(std::string_view url, std::string_view expected_sha256,
const std::filesystem::path &dest_file, const RegistryAuth &auth) {