youki Documentation
repository·main·Indexed 27 days ago
https://github.com/youki-dev/youkiyouki is a memory-safe, lightweight implementation of the OCI runtime-spec written in Rust, designed as an alternative to runc. It includes support for rootless mode, WebAssembly (WASM) modules, and integration as a Docker runtime. The project contains several crates, including liboci-cli for parsing OCI runtime command line arguments and libcgroups for managing cgroup statistics, PSI, and systemd CPU set restrictions.
What's inside youki
- youki is an implementation of the OCI runtime-spec written in Rust. It is designed to be a memory-safe alternative to runc, offering potential improvements in speed and memory usage, making it suitable for environments with tight resource constraints.
Overview of liboci-cli
mainTheliboci-clicrate is used to parse command line arguments for OCI (Open Container Initiative) container runtimes. It is designed to follow the OCI Runtime Command Line Interface specification.Use the libcontainer crate for container management
mainThe
libcontainercrate is a core component of theyoukiworkspace. It provides the fundamental functions and structs required to create and manage container processes by leveraging Linux kernel mechanisms such as control groups (cgroups), namespaces, andpivot_root.Key features include:
- Youki Config: A lightweight subset of the OCI specification containing only the essential data required for running containers, optimized for efficient parsing and passing.
- Socket Wrappers: Provides wrappers over basic Linux sockets used for communication between the main
youkiprocess, the container process, and intermediate processes. - AppArmor Interface: An interface to apply security profiles to programs via the AppArmor Linux Kernel module.
Use libcontainer for container management
mainThelibcontainercrate is the core library used by Youki to create and manage containers. It provides a modular API for handling various aspects of the container lifecycle, security, and isolation.Use the seccomp Rust FFI bindings
mainThe
seccompcrate provides Rust Foreign Function Interface (FFI) bindings for the Linux kernel'//seccomp feature. It allows processes to transition into a secure mode where syscalls and file descriptor interactions are restricted (e.g., limiting toexit,sigreturn, andread/writeon existing descriptors).These bindings are generated via
rust-bindgenfrom theseccompC headers and manually adjusted for correctness. This crate is a low-level binding layer and does not implement high-level seccomp features itself.Understand the youki container lifecycle
mainThe
youkicrate provides the main binary and user interface for container management. It orchestrates other crates to perform container creation and management through a multi-stage process involving an intermediate process and an init process.Container Creation Flow (
youki create)- Main Process: Loads specification, configuration, and sockets. Uses the
clonesyscall to create an intermediate process. - Intermediate Process: Sets cgroups and capabilities, then forks to create the init process. It handles the transition into the PID namespace (since
clonecannot enter an existing PID namespace directly). It also requests UID/GID mappings from the main process, applies them, and returns the init process PID to the main process before exiting. - Init Process:
- Transitions into the new namespace setup.
- Changes the root mountpoint using
pivot_root. - Sets up capabilities and
seccomp. - Sends a
seccompnotify FD to the main process. - Waits for a 'ready' signal from the host's seccomp agent.
- Sends a 'ready' notification to the main process and waits for a 'start' signal.
- Main Process: Receives 'ready' signals, updates the container's PID file, and exits.
Container Execution Flow (
youki start)- Main Process: Executed with the container ID. It sends a 'start' signal to the waiting init process and then exits.
- Init Process: Receives the 'start' signal,
execsthe target program inside the container, and exits.
- Main Process: Loads specification, configuration, and sockets. Uses the
Use liboci-cli to parse OCI-compliant command line arguments
mainTheliboci-clicrate provides a standalone implementation of the structures required to parse command-line arguments for an OCI-spec compliant runtime interface. While it is used byyoukito handle its own CLI, it can be integrated into any other project that needs to implement an OCI-compliant command-line interface. It is built on top of theclap-v4crate.Build libcontainer with musl
mainTo build
libcontainerusingmusl, you must disable the default features to remove thelibseccompdependency, aslibseccompreferences shared libraries that are incompatible withmuslbuilds.When building, use the
--no-default-featuresflag followed by-Fand the specific feature you wish to build (e.g.,-F v2). You must also use the+nightlyflag withrustupandcargo.Find beginner-friendly tasks in youki
mainTo start contributing to youki, you can look for specific entry points designed for beginners:
- GitHub Issues: Search the GitHub repository issues for labels
good first issueorhelp wanted. - Source Code Comments: Search the codebase for
TODOorFIXMEcomments to find pending tasks or known bugs. - Documentation: Improve the public-facing API and struct documentation. Adding doc comments and usage examples helps users of the
cargo docgenerated documentation. - Integration Tests: Contribute to the porting of OCI-runtime integration tests from Go to Rust. This is located in the
integration_testcrate and aims to provide a pure Rust implementation of OCI spec compliance tests.
- GitHub Issues: Search the GitHub repository issues for labels
Build youki with WebAssembly feature flags
mainTo run WebAssembly modules, you must buildyoukiwith one of the following feature flags enabled using thebuild.shscript. You can choose betweenwasm-wasmedge,wasm-wasmer, orwasm-wasmtime.Build youki from source
mainTo build youki locally on Linux, clone the repository and use the
justcommand to build the development or release version.git clone git@github.com:youki-dev/youki.git cd youki just youki-dev # or youki-release ./youki -h # view help informationgit clone git@github.com:youki-dev/youki.git cd youki just youki-dev # or youki-release ./youki -h # you can get information about youki commandUse liboci-cli to parse OCI runtime command line arguments
mainThe
liboci-climodule provides Rust structures that implement the OCI (Open Container Initiative) Runtime Command Line Interface specification. These structures deriveclap::Parser, allowing you to integrate OCI-compliant command-line argument parsing directly into your own Rust applications or CLI tools.Supported subcommands implemented in
liboci-cliinclude:createstartstatekilldeleteeventsexeclistpausepsresumerunspec