commit ff1e74781dbae1d58741552e23dc198cd4d7b8b7 Author: Pavel Isaev Date: Thu Nov 5 21:27:25 2026 +0300 Initialize registry experimental implementation and documentation diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b83d222 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target/ diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..2b5d8d1 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "archipelago-registry" +version = "0.0.0" +edition = "2024" +rust-version = "1.90" +publish = false diff --git a/README.md b/README.md new file mode 100644 index 0000000..e772943 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Archipelago registry storage + +Rust module linked into the single `archipelago` binary. Initial commands: + +``` +archipelago registry init /storage/ostree/layers +archipelago registry init /storage/ostree/images +archipelago registry verify /storage/ostree/layers +``` + +Initialization creates native archive-mode repositories with an empty summary. +It is idempotent for an existing healthy archive repository and rejects nonempty +unrecognized directories, symlink destinations and incompatible repository modes. +Administrative operations share a nonblocking OS file lock outside the repository. +Use trusted parent directories and the same lock for future publisher operations. +`verify` runs native OSTree integrity checks; it does not certify signatures, +Archipelago metadata, reproducibility or release eligibility. + +This storage primitive can initialize public empty stores or private staging stores. +It does not import artifacts, expose staging, create channels or sign releases. +The signed publisher requires the release/trust contracts tracked in RFC-0010. diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..aa39198 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,73 @@ +//! Native OSTree storage administration. This is not a release publisher. +use std::{fs::{self, File, OpenOptions}, path::{Path, PathBuf}, process::Command}; + +type Result = std::result::Result; + +fn ostree(repo: &Path, args: &[&str]) -> Result { + let output = Command::new("ostree").arg(format!("--repo={}", repo.display())) + .args(args).env("LC_ALL", "C").output().map_err(|e| e.to_string())?; + if !output.status.success() { + return Err(format!("ostree {}: {}", args[0], String::from_utf8_lossy(&output.stderr))); + } + Ok(String::from_utf8_lossy(&output.stdout).trim().to_string()) +} + +// Lock outside the repository so initialization and subsequent checks serialize. +// Administrative paths must be in a trusted directory; no package scripts run here. +fn location(path: &str) -> Result<(PathBuf, File)> { + let path = Path::new(path); + let name = path.file_name().and_then(|s| s.to_str()).ok_or("Repository needs a directory name")?; + let parent = path.parent().filter(|p| !p.as_os_str().is_empty()).unwrap_or(Path::new(".")); + fs::create_dir_all(parent).map_err(|e| e.to_string())?; + let parent = fs::canonicalize(parent).map_err(|e| e.to_string())?; + let repo = parent.join(name); + if fs::symlink_metadata(&repo).is_ok_and(|m| m.file_type().is_symlink()) { + return Err("Repository path must not be a symlink".into()); + } + let lock = OpenOptions::new().create(true).truncate(false).read(true).write(true) + .open(parent.join(format!(".{name}.archipelago.lock"))).map_err(|e| e.to_string())?; + lock.try_lock().map_err(|e| format!("Repository is busy: {e}"))?; + Ok((repo, lock)) +} + +fn archive(repo: &Path) -> Result<()> { + let mode = ostree(repo, &["config", "get", "core.mode"])?; + if mode != "archive-z2" && mode != "archive" { + return Err(format!("HTTP registry requires archive mode, found {mode}")); + } + Ok(()) +} + +pub fn init(path: &str) -> Result<()> { + let (repo, _lock) = location(path)?; + if repo.join("config").exists() { + archive(&repo)?; + ostree(&repo, &["fsck"])?; + println!("Existing archive repository verified: {}", repo.display()); + return Ok(()); + } + if repo.exists() && fs::read_dir(&repo).map_err(|e| e.to_string())?.next().is_some() { + return Err("Refusing to initialize a nonempty non-repository directory".into()); + } + let temporary = repo.with_file_name(format!(".{}.init-{}", repo.file_name().unwrap().to_string_lossy(), std::process::id())); + fs::create_dir(&temporary).map_err(|e| e.to_string())?; + let result = (|| { + ostree(&temporary, &["init", "--mode=archive"])?; + ostree(&temporary, &["summary", "--update"])?; + ostree(&temporary, &["fsck"])?; + fs::rename(&temporary, &repo).map_err(|e| e.to_string())?; + File::open(repo.parent().unwrap()).and_then(|f| f.sync_all()).map_err(|e| e.to_string())?; + println!("Initialized empty archive repository: {}", repo.display()); + Ok(()) + })(); + if temporary.exists() { let _ = fs::remove_dir_all(&temporary); } + result +} + +pub fn verify(path: &str) -> Result<()> { + let (repo, _lock) = location(path)?; + archive(&repo)?; + let result = ostree(&repo, &["fsck"])?; + println!("{}\nVerified archive repository: {}", result, repo.display()); + Ok(()) +}