ostrya 0.19.0

Pure-Rust async reimplementation of the ostree repository library
Documentation

ostrya

Ostrya [n. a botanical genus within the family Betulaceae, commonly known as ironwood tree] is a pure-Rust, async implementation of the ostree repository system, written from scratch.

An async, pure-Rust library that reads and writes ostree repositories.

A user opens a repository, writes commits in transactions, reads and checks out trees, and pulls, pushes, signs, and prunes. The bytes on disk are the bytes that the ostree command writes. Many Transactions can write to one repository at once in one process.

As an extension, the crate also has a push protocol over HTTP and over ssh. With the push feature, Repo::push sends commits to a remote, and Repo::push_onto asks a remote to commit the tree of a local commit. With the receive feature, the receive module takes a push on the server side. With the push and s3 features, Repo::push_to_bucket writes commits to a bucket repository in an S3 bucket, BucketRepo::push_tree writes a local directory to one as a new commit, and BucketRepo::init creates one.

API documentation: https://docs.rs/ostrya

Entry points

  • Repo::open and Repo::create give a Repo, the handle of a repository.
  • OpenOptions and CreateOptions give a Repo with options, such as a RemotesDir.
  • Repo::transaction begins a Transaction, which publishes objects and refs at commit.
  • StagingTree and MutableTree build the tree of a new commit.
  • Repo::checkout_at writes the tree of a commit into a directory.
  • Repo::pull copies commits from a remote, and Repo::pull_local from a local repository.
  • Repo::pull_with_report and Repo::pull_local_with_report also list the refs that the pull changed.
  • Repo::pull_with_session copies commits from a remote through a session of the caller.
  • Repo::pull_collection copies the refs of a collection from the remotes that serve it.
  • Repo::export_media copies the commits of collection refs onto removable media.
  • Repo::import_media pulls collection refs from removable media, under the trust of their remotes.
  • Error is the error of each fallible operation of Repo, Transaction, and the other handles.

Modules

  • Read: read, file, tree, refs, and traverse.
  • Write: transaction, mtree, staging_tree, commit, modifier, bootable.
  • Checkout and export: checkout, composefs, tar, and archive.
  • Pull: pull, summary, fetch, the HTTP client of ostrya-fetch, and remote, which holds the session of a pull over HTTP, over ssh, or over a pair of byte streams.
  • Removable media: media, the export of collection refs onto a mounted volume, and the import from it.
  • Push and receive: remote, the wire protocol of ostrya-remote, and receive.
  • Client access: access, the client groups and the server settings of the config, the claims of a client certificate, and the read rights of a client.
  • Remote resolution: endpoint, which reads the keys and files of a remote for a pull or a push.
  • Bucket repositories: bucket, a repository in an S3 bucket, with the init, the writer lock, the listing of the objects, the fsck, the prune, and the summary update.
  • Signing: sign, gpg, and spki.
  • Signature trust: verify, the trusted keys, the trust of one pull, and the verifiers of one remote.
  • Config: config, a type for each key of the repository config, and config_group!, which defines the keys of a group.
  • Maintenance: prune, fsck, diff, and update.
  • Static deltas: DeltaSuperblock, DeltaOptions, AdvertisedDelta, and Repo::generate_static_delta.

Features

  • smol (default): the smol backend of ostrya-rt.
  • tokio: the tokio backend of ostrya-rt.
  • sign-spki: the spki module, the spki signing engine with each of its key types: ECDSA P-256, ECDSA P-384, Ed25519, RSA, ML-DSA-44, ML-DSA-65, and ML-DSA-87, and the 12 parameter sets of SLH-DSA. It turns on the feature spki of ostrya-sign.
  • verify-gpg: the gpg module: the GPG verifier of ostrya-sign with the trait FromOstreeKeyrings, which reads the keyrings of a remote and the gpgkeys.gpg keyring of a repository through a repository handle, and the keyring management of a remote. It turns on the feature gpg of ostrya-sign.
  • sign-gpg: GpgSigner, which signs with the gpg command. It turns on verify-gpg.
  • sign-x509: X509Signer, the trait of a signer with an X.509 certificate chain for a CMS signature. With sign-spki, also X509SpkiSigner, SpkiSigner::with_certificates, SpkiVerifier::from_certificates, X509Chain, x509_crls, X509ChainSigner, and SigningKey::spki_x509, the X.509 chains and CRLs that an spki signature carries in the detached metadata, the keys certificate-chain-file and crl-file of a key group, the chain removal of Repo::delete_signatures, and the path check of the chains: X509Trust, x509_certificates, SpkiVerifier::with_x509, sign::load_x509_anchors, and the keys verification-spki-ca-file, verification-spki-intermediates-file, verification-spki-eku, and verification-spki-identity of a remote and of a trust group, and the revocation check: sign::load_x509_crls, the X.509 CRL cache of Repo::x509_crl_context and Repo::cache_x509_crls, and the keys verification-spki-crl-file and verification-spki-revocation of a remote and of a trust group. A build without the feature refuses these keys.
  • receive: the receive module, the receive side of a push.
  • push: Repo::push, Repo::push_onto, and Repo::export_stream, the push from a repository.
  • s3: the pull from a bucket repository at an s3:// address and the pull of collection refs from one, the bucket module with the fsck, the prune, and the summary update of a bucket repository, the s3 module of ostrya-remote, and with push, the push of commits and of a local directory to a bucket repository.
  • lzma-static: xz built from source and linked statically, with no runtime liblzma.

Examples

let repo = ostrya::Repo::open("/srv/repo".as_ref()).await?;
let tip = repo.resolve_rev("exampleos/stable", false).await?;

Design

The API is idiomatic Rust. The bytes on disk follow the format reference of the project.

  • Repo is cheap to clone. It holds its state in an Arc, so a handle moves between tasks. Repo::open does the descriptor and config work once, and each clone shares it.
  • The runtime backend is a feature of the internal ostrya-rt crate: smol by default, or tokio. ContentReader, ContentWriter, and the hashing streams implement the futures-io traits with each backend, and the tokio traits with the tokio feature. A caller needs no adapter for these types.
  • An AsyncRead or AsyncWrite bound in an argument, as in write_content, import_tar, and export_tar, is the futures-io trait. A caller on tokio adapts its stream with tokio_util::compat.
  • Each I/O entry point is an async fn. A filter callback and an xattr callback are synchronous.
  • Verifier::verify is synchronous. Each verification of the crate runs it on the blocking pool of ostrya-rt. DeltaSuperblock::verify and sign::verify_all run it in the calling thread.
  • rustix makes the namespace and metadata syscalls: the opens relative to a descriptor, stat, link, rename, the xattrs, reflink, O_TMPFILE with linkat, the record locks, and the syncs. These calls are synchronous. They run on the blocking pool of ostrya-rt in steps that each group several calls, and not one step for each call. The content of a file streams through the File and FileReader of ostrya-rt, over a descriptor that the rustix layer opened.
  • To cancel an operation, drop its future. To cancel on a signal, race the future against that signal.
  • Each fallible operation of Repo, Transaction, and the other handles returns ostrya::Error. The signing engines, the fetcher, and the typed reads and edits of config::Section, config::ConfigView, config::ConfigEdit, and config::SectionMut have their own error types. ? converts each of them into ostrya::Error.
  • File content is never whole in memory. Hashing, compression, storing, checkout, and transfer read and write async streams in chunks of bounded size. Only a metadata object is held whole, because the format caps its size.
  • Repo, Transaction, FileObject, and the file content readers and writers are Send + Sync. Compile-time assertions in the tests hold this.

Relation to the C API

The public documentation of libostree describes a C API with GLib types. This crate maps that API to Rust as follows:

  • Cancellation is the drop of a future. The crate has no GCancellable.
  • A result comes back in a Result. The crate has no out-parameters.
  • Options are builders and structs. The dynamic Value of ostrya-gvariant holds commit metadata, which is an arbitrary a{sv}.
  • A descriptor is a BorrowedFd or an OwnedFd. The crate has no raw dfd: i32.
  • The functions of the C repository object are split: Repo for the lifecycle, the reads, the checkout, and the maintenance, and Transaction for all writes. The Signer and Verifier traits make signing pluggable, and the progress handles give live counters.
  • RAII guards hold the scoped state: a transaction aborts when it drops without a commit, a lock releases when its guard drops, and Checksum is a typed value.
  • A key of config is a type. repo.config().get::<repo::Fsync>() reads [core] fsync and gives a bool, and a read of a key of another group does not compile. The C API reads a key by its group name and its key name.
  • The remotes directory of a repository comes from OpenOptions::remotes_dir, CreateOptions::remotes_dir, or the key [ex-ostrya] remotes-config-dir of config. The crate detects no system repository, so it reads /etc/ostree/remotes.d only when the caller or the key names that directory.
  • OpenOptions::force and OpenOptions::fallback set a key of config in memory on the handle, for example the fallback true of [core] add-remotes-config-dir, whose default false puts a new remote into config.