VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
- D1: RemoteCasClient + registry /api/v1/cas endpoints with bearer auth and digest verification, StateStore remote action/blob APIs, build-path-independent action keys, --remote-cache CLI - D2: parallel snapshot revalidation hashing via Void::Concurrency::ThreadPool - Verified in Docker GCC 16: 8/8 CTest suites, cross-build-dir 100% cache hit, 5001-file warm no-op 374 ms - Fix self-host recipe source list for RemoteCache.cpp and accept GCC 16 -lgcc_s_asneeded
153 lines
5.4 KiB
C++
153 lines
5.4 KiB
C++
#pragma once
|
|
|
|
#include <Void/Build/Registry/HttpServer.hpp>
|
|
#include <Void/Functional/Error.hpp>
|
|
#include <Void/Functional/Result.hpp>
|
|
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <map>
|
|
#include <mutex>
|
|
#include <optional>
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Void::Build::Registry {
|
|
|
|
enum class Role { Reader, Publisher, Admin };
|
|
|
|
struct UserRecord {
|
|
std::string username;
|
|
Role role{Role::Reader};
|
|
std::string password_salt_hex;
|
|
std::string password_hash_hex;
|
|
bool active{true};
|
|
};
|
|
|
|
struct ApiTokenRecord {
|
|
std::string token_id;
|
|
std::string username;
|
|
std::string label;
|
|
std::string token_sha256; // Never stores plaintext bearer secret!
|
|
std::set<std::string> scopes; // "read", "publish", "admin"
|
|
std::int64_t expires_epoch{0}; // 0 = no expiry
|
|
bool revoked{false};
|
|
};
|
|
|
|
struct SessionRecord {
|
|
std::string session_id_hash;
|
|
std::string username;
|
|
std::string csrf_token;
|
|
std::int64_t expires_epoch{0};
|
|
};
|
|
|
|
struct ReleaseMeta {
|
|
std::string version;
|
|
std::string sha256;
|
|
std::uint64_t size_bytes{0};
|
|
bool yanked{false};
|
|
std::string publisher;
|
|
std::int64_t published_epoch{0};
|
|
};
|
|
|
|
struct PackageMeta {
|
|
std::string name;
|
|
std::string description;
|
|
bool is_private{false};
|
|
std::set<std::string> owners;
|
|
std::map<std::string, ReleaseMeta, std::less<>> releases; // version -> ReleaseMeta
|
|
};
|
|
|
|
struct AuditEntry {
|
|
std::int64_t timestamp{0};
|
|
std::string actor;
|
|
std::string action;
|
|
std::string target;
|
|
std::string outcome;
|
|
std::string detail; // Always secret-redacted!
|
|
};
|
|
|
|
struct RegistryConfig {
|
|
std::filesystem::path data_dir;
|
|
std::filesystem::path web_root;
|
|
std::string bind_address{"127.0.0.1"};
|
|
std::uint16_t port{0};
|
|
std::uint64_t max_upload_bytes{32ULL * 1024ULL * 1024ULL};
|
|
std::uint64_t max_storage_bytes{2ULL * 1024ULL * 1024ULL * 1024ULL};
|
|
std::string bootstrap_admin_user{"admin"};
|
|
std::string bootstrap_admin_password; // Required on initial empty DB creation.
|
|
};
|
|
|
|
// Hosted C++ Package Registry Service (Plan 16 + Plan 17 API/UI backend):
|
|
// - Filesystem CAS blobs + transactional durable metadata
|
|
// - Immutable source/binary releases (idempotent same bytes, 409 Conflict on overwrite)
|
|
// - Archive traversal/symlink validation (never executes uploaded recipes!)
|
|
// - Reader/Publisher/Admin roles, package ownership, private/public isolation
|
|
// - Hashed scoped bearer tokens + HttpOnly SameSite=Strict sessions with CSRF protection
|
|
// - Secret-redacted audit log, orphan GC, storage quotas, consistent backup/restore.
|
|
class RegistryService {
|
|
public:
|
|
[[nodiscard]] static Void::Result::Result<std::unique_ptr<RegistryService>, Void::Result::Error>
|
|
open(RegistryConfig config);
|
|
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error> start_http();
|
|
void stop_http() noexcept;
|
|
[[nodiscard]] std::uint16_t bound_port() const noexcept { return server_.bound_port(); }
|
|
|
|
// Handles a single HTTP request (directly testable without sockets too!).
|
|
[[nodiscard]] HttpResponse handle_request(const HttpRequest &req);
|
|
|
|
// Consistent metadata + CAS blob backup and restore (Plan 16 acceptance #4).
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
backup_to(const std::filesystem::path &backup_dir);
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
restore_from(const std::filesystem::path &backup_dir);
|
|
|
|
// Direct user/token helpers for bootstrap and test fixtures.
|
|
[[nodiscard]] Void::Result::Result<void, Void::Result::Error>
|
|
create_user(std::string username, std::string password, Role role);
|
|
[[nodiscard]] Void::Result::Result<std::string, Void::Result::Error>
|
|
create_token(std::string username, std::string label, std::set<std::string> scopes,
|
|
std::int64_t expires_epoch = 0);
|
|
|
|
private:
|
|
explicit RegistryService(RegistryConfig config);
|
|
|
|
struct Principal {
|
|
std::string username;
|
|
Role role{Role::Reader};
|
|
std::set<std::string> scopes;
|
|
bool via_session_cookie{false};
|
|
std::string csrf_token;
|
|
};
|
|
|
|
Void::Result::Result<void, Void::Result::Error> load_locked();
|
|
Void::Result::Result<void, Void::Result::Error> save_locked();
|
|
std::optional<Principal> authenticate_locked(const HttpRequest &req,
|
|
std::string &auth_err) const;
|
|
bool check_csrf_locked(const HttpRequest &req, const Principal &p) const;
|
|
void append_audit_locked(std::string actor, std::string action, std::string target,
|
|
std::string outcome, std::string detail);
|
|
std::uint64_t total_storage_bytes_locked() const;
|
|
std::filesystem::path blob_path(std::string_view sha256) const;
|
|
HttpResponse serve_static_web_asset(std::string_view req_path) const;
|
|
|
|
RegistryConfig config_;
|
|
std::filesystem::path blobs_dir_;
|
|
std::filesystem::path action_blobs_dir_;
|
|
std::filesystem::path action_records_dir_;
|
|
std::filesystem::path meta_file_;
|
|
std::filesystem::path lock_file_;
|
|
mutable std::mutex mu_;
|
|
|
|
std::map<std::string, UserRecord, std::less<>> users_;
|
|
std::map<std::string, ApiTokenRecord, std::less<>> tokens_;
|
|
std::map<std::string, SessionRecord, std::less<>> sessions_;
|
|
std::map<std::string, PackageMeta, std::less<>> packages_;
|
|
std::vector<AuditEntry> audits_;
|
|
HttpServer server_;
|
|
};
|
|
|
|
} // namespace Void::Build::Registry
|