Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
name: Integration

# The two start-ups sys-lib is built for, on every environment it is meant
# for (dev/ROADMAP.md, 0.9): a service's boot phase 0 (examples/boot.rs) and a
# database start-up (examples/database.rs). Each example exits 1 when a
# reading breaks its own rules or differs from what the environment is known
# to give, which each job states with SYS_LIB_EXPECT_* variables.
on:
pull_request:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true"

jobs:
native:
name: ${{ matrix.name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- { name: "Linux server x86-64", os: ubuntu-24.04 }
- { name: "Linux server Arm64", os: ubuntu-24.04-arm }
- { name: "Windows Server", os: windows-latest }
- { name: "macOS Apple silicon", os: macos-latest }
- { name: "macOS Intel", os: macos-15-intel }
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release --example boot --example database
- name: Service boot
shell: bash
env:
SYS_LIB_EXPECT_CONTAINER: none
SYS_LIB_EXPECT_KUBERNETES: "false"
run: target/release/examples/boot
- name: Database start-up
shell: bash
run: target/release/examples/database "$RUNNER_TEMP/db"

docker:
name: Docker, 1 GiB and 2 CPUs
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release --example boot --example database
- name: Both start-ups in the container
run: |
docker run --rm --memory=1g --cpus=2 \
-e SYS_LIB_EXPECT_MEMORY=1073741824 -e SYS_LIB_EXPECT_CPUS=2 \
-e SYS_LIB_EXPECT_CONTAINER=docker -e SYS_LIB_EXPECT_KUBERNETES=false \
-v "$PWD/target/release/examples:/bin/sys-lib:ro" ubuntu:24.04 \
sh -c '/bin/sys-lib/boot && /bin/sys-lib/database /var/lib/exampledb'

kubernetes:
name: Kubernetes pod, 512 MiB and 1 CPU
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Build
run: cargo build --release --example boot --example database
- uses: helm/kind-action@v1
with:
cluster_name: sys-lib
- name: Image
run: |
mkdir -p image
cp target/release/examples/boot target/release/examples/database image/
printf 'FROM ubuntu:24.04\nCOPY boot database /usr/local/bin/\n' > image/Dockerfile
docker build -q -t sys-lib-integration:ci image
kind load docker-image sys-lib-integration:ci --name sys-lib
- name: Both start-ups in a pod with limits
run: |
cat > pod.yaml <<'EOF'
apiVersion: v1
kind: Pod
metadata:
name: sys-lib
spec:
restartPolicy: Never
containers:
- name: start-ups
image: sys-lib-integration:ci
imagePullPolicy: Never
command: ["sh", "-c", "boot && database /var/lib/exampledb"]
env:
- { name: SYS_LIB_EXPECT_MEMORY, value: "536870912" }
- { name: SYS_LIB_EXPECT_CPUS, value: "1" }
- { name: SYS_LIB_EXPECT_CONTAINER, value: containerd }
- { name: SYS_LIB_EXPECT_KUBERNETES, value: "true" }
resources:
requests: { memory: 512Mi, cpu: "1" }
limits: { memory: 512Mi, cpu: "1" }
EOF
kubectl apply -f pod.yaml
kubectl wait --for=jsonpath='{.status.phase}'=Succeeded pod/sys-lib --timeout=180s || true
kubectl logs pod/sys-lib
test "$(kubectl get pod sys-lib -o jsonpath='{.status.phase}')" = Succeeded

freebsd:
name: FreeBSD 14 VM
runs-on: ubuntu-latest
timeout-minutes: 45
steps:
- uses: actions/checkout@v5
- name: Both start-ups in FreeBSD
uses: vmactions/freebsd-vm@v1.5.9
with:
release: "14"
copyback: false
run: |
set -eu
pw useradd -n ci -m -s /bin/sh
chown -R ci .
cat > /tmp/ci.sh <<'EOS'
set -eu
fetch -q -o /tmp/rustup-init https://static.rust-lang.org/rustup/dist/x86_64-unknown-freebsd/rustup-init
chmod +x /tmp/rustup-init
/tmp/rustup-init -y -q --profile minimal --default-toolchain stable
. "$HOME/.cargo/env"
cd "$1"
cargo build --release --example boot --example database
SYS_LIB_EXPECT_CONTAINER=none SYS_LIB_EXPECT_KUBERNETES=false target/release/examples/boot
target/release/examples/database "$HOME/db"
EOS
su -l ci -c "sh /tmp/ci.sh '$PWD'"
42 changes: 41 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,45 @@

---

## [0.9.0] - 2026-12-02

Alpha: sys-lib now runs in the two start-ups it is built for, a service's boot
phase 0 and a database start-up, on every platform it supports, in a Docker
container with limits, and in a Kubernetes pod.

### Added

- `GuardBuilder::process_wide(false)`: the guard takes the lock and nothing
else. It leaves the umask and the open-file limit alone, for a library or a
component inside a larger program that should not change state the whole
process shares. Before, this took three calls (`keep_umask()`,
`open_files_target(0)`, `open_files_minimum(0)`), and the guard still read
the umask, which on Unix means setting it.
- `examples/database.rs`: a database start-up. The lock beside the data
directory, the cache sized from `mem::total()`, workers from
`cpu::available()`, the data directory's disk, and the Database readiness
report.
- `examples/boot.rs` is now a service's boot phase 0: the guard, build and
instance info, workers, and where it runs. Both examples exit 1 when a
reading breaks its own rules or differs from what the environment is known
to give.
- The `Integration` workflow runs both examples on Linux (x86-64 and Arm64),
Windows, macOS (Apple silicon and Intel), FreeBSD, in a Docker container
limited to 1 GiB and 2 CPUs, and in a Kubernetes pod limited to 512 MiB and
1 CPU, and checks that each one reads the limits it was given.

### Fixed

- `virt::detect()` names containerd in a Kubernetes pod on cgroup v2, where
`/proc/1/cgroup` says only `0::/` and no marker file exists: it now reads
the pod's mounts (the kubelet's hosts file, the overlay root's layers).
Before, such a pod read as `Container::Other`.
- The access-time check in the readiness report gave the Linux fix
(`/etc/fstab`) on Windows and macOS. Each platform now names its own tool:
`fsutil` on Windows, `mount -u` on macOS and FreeBSD.

---

## [0.8.0] - 2026-12-02

Hardening: every threat in the model has a named attack test, the process
Expand Down Expand Up @@ -460,7 +499,8 @@ The scaffold and the plan. No functional code yet.
`dev/ROADMAP.md`.
- `tests/fixtures/` and `fuzz/` skeletons.

[Unreleased]: https://github.com/jamesgober/sys-lib/compare/v0.8.0...HEAD
[Unreleased]: https://github.com/jamesgober/sys-lib/compare/v0.9.0...HEAD
[0.9.0]: https://github.com/jamesgober/sys-lib/compare/v0.8.0...v0.9.0
[0.8.0]: https://github.com/jamesgober/sys-lib/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/jamesgober/sys-lib/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/jamesgober/sys-lib/compare/v0.5.1...v0.6.0
Expand Down
6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# =============================================================================
[package]
name = "sys-lib"
version = "0.8.0"
version = "0.9.0"

# Minimum Supported Rust Version (MSRV)
# 1.89: `std::fs::File::lock` and `File::try_lock` are stable from 1.89.0, so
Expand Down Expand Up @@ -63,6 +63,10 @@ harness = false
name = "boot"
required-features = ["instance", "guard"]

[[example]]
name = "database"
required-features = ["guard"]

[[example]]
name = "device_id"
required-features = ["device-id"]
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<strong>MSRV is 1.89+</strong> (Rust 2024 edition). <code>unsafe</code> is denied at the crate root and allowed only in one OS module per platform.
</p>
<blockquote>
<strong>Status: <code>0.8.0</code>, feature complete, measured, and hardened.</strong> The boot kit, the live readings (memory, CPU, disks, network, pressure, this process), detection and identity (virtualization, form factor, topology, power, DNS, the time zone, firmware, launch context, <code>summary()</code>, an application-scoped device id), and now the server readiness, benchmark environment, and security posture reports, temperatures, graphics adapters, and explicit roots for monitoring agents. Linux (64-bit, and 32-bit glibc on x86 and Arm), macOS, Windows, and FreeBSD; Android and iOS best effort. 0.7 measured every reading against the crates people use for it (<a href="./docs/PERFORMANCE.md"><code>docs/PERFORMANCE.md</code></a>); 0.8 hardened it, with every threat and its test in <a href="./docs/SECURITY.md"><code>docs/SECURITY.md</code></a>; the API is in <a href="./docs/API.md"><code>docs/API.md</code></a>. Design: <a href="./dev/PLAN.md"><code>dev/PLAN.md</code></a>; schedule: <a href="./dev/ROADMAP.md"><code>dev/ROADMAP.md</code></a>.
<strong>Status: <code>0.9.0</code>, alpha: feature complete, measured, hardened, and run in real start-ups.</strong> The boot kit, the live readings (memory, CPU, disks, network, pressure, this process), detection and identity (virtualization, form factor, topology, power, DNS, the time zone, firmware, launch context, <code>summary()</code>, an application-scoped device id), and now the server readiness, benchmark environment, and security posture reports, temperatures, graphics adapters, and explicit roots for monitoring agents. Linux (64-bit, and 32-bit glibc on x86 and Arm), macOS, Windows, and FreeBSD; Android and iOS best effort. 0.7 measured every reading against the crates people use for it (<a href="./docs/PERFORMANCE.md"><code>docs/PERFORMANCE.md</code></a>); 0.8 hardened it, with every threat and its test in <a href="./docs/SECURITY.md"><code>docs/SECURITY.md</code></a>; 0.9 runs it in a service's boot and a database start-up (<a href="./examples/boot.rs"><code>examples/boot.rs</code></a>, <a href="./examples/database.rs"><code>examples/database.rs</code></a>) on Linux, macOS, Windows, FreeBSD, in a Docker container with limits, and in a Kubernetes pod; the API is in <a href="./docs/API.md"><code>docs/API.md</code></a>. Design: <a href="./dev/PLAN.md"><code>dev/PLAN.md</code></a>; schedule: <a href="./dev/ROADMAP.md"><code>dev/ROADMAP.md</code></a>.
</blockquote>
</div>

Expand All @@ -47,10 +47,10 @@ Cargo's rename makes the crate `sys` in your code:

```toml
[dependencies]
sys = { package = "sys-lib", version = "0.8" }
sys = { package = "sys-lib", version = "0.9" }

# The application-scoped device id (brings crypt-io's BLAKE3 stack):
sys = { package = "sys-lib", version = "0.8", features = ["device-id"] }
sys = { package = "sys-lib", version = "0.9", features = ["device-id"] }
```

The default features are `instance` (instance info) and `guard` (the process guard). `default-features = false` keeps every reading and report and brings no dependency at all.
Expand Down
4 changes: 4 additions & 0 deletions dev/PLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1285,3 +1285,7 @@ Other ideas:
| D-118 | 2026-11-29 | The owners of CoreFoundation, IOKit, and Mach objects (`Cf::new`, `Cf::lent`, `Io::new`, `Io::matching`, `SendRight::from_raw`, `ProcessorInfo::from_raw`) are `unsafe fn` with a `# Safety` section | they release or read whatever they are given; a Get-rule reference passed to `Cf::new` would compile without `unsafe` and be released twice |
| D-119 | 2026-11-29 | The 24-hour fuzz run is five chained rounds on GitHub's runners (`fuzz.yml`, `long`), eight targets at a time, each round starting from the corpus the last saved | a hosted job stops at 6 hours; eight at a time (about 60 hours for the whole run) leaves runners for every other repository's CI |
| D-120 | 2026-11-29 | macOS keeps the host name port for the life of the process (fetched again in a child after `fork`), and reads the device anchors from the service plane's root by path, matching by class only when that fails | `mach_host_self` and the `mach_port_deallocate` that returns its reference were two traps in every memory and CPU reading; `IOServiceGetMatchingService` searches the registry where a path lookup goes straight to the platform device, which is the gap to machine-uid in `docs/PERFORMANCE.md` |
| D-121 | 2026-12-02 | `GuardBuilder::process_wide(false)` takes the lock and touches no state the process shares: no umask read or change, no open-file limit change or check, no thread warning | the database example's second guard, the tests, and any library that holds a lock inside a larger program needed three calls to get there, and still had the umask read, which on Unix sets it and races other threads |
| D-122 | 2026-12-02 | The 0.9 environments run in the `Integration` workflow on every pull request: hosted runners for Linux, Windows, and macOS, a VM for FreeBSD, `docker run --memory --cpus`, and a kind cluster for the Kubernetes pod. Windows 11 and WSL 2 run by hand on the workstation before each release | each environment states what it is known to give (`SYS_LIB_EXPECT_*`), so a wrong limit or a missed container fails the pull request instead of a user's start-up; no hosted runner is Windows 11 or WSL 2 |
| D-123 | 2026-12-02 | API review against real use, 0.9.0: kept as they are, a default lock directory that another account can change (an old folder with a capability-SID entry inherited from `AppData`) is refused with `RunDirUnavailable`, as on Unix; the readiness report's value names (`noatime`, `relatime`) stay the same words on every platform, with the fix naming each platform's tool | refusing is the guard's purpose and the message says which directory; one set of value names keeps reports comparable across a fleet |
| D-124 | 2026-12-02 | On Linux, `/proc/self/mountinfo` names the container runtime when nothing stronger does: a `/etc/hosts` or `/etc/hostname` bound from a `kubelet/pods/` directory is containerd (the CRI runtime), and the overlay root's layers under `/var/lib/docker/` are Docker, under a containerd snapshotter are containerd. Strong evidence, after the marker files and `/proc/1/cgroup` | a pod on cgroup v2 with a cgroup namespace shows `0::/` in `/proc/1/cgroup` and containerd writes no marker, so the 0.9 Kubernetes run would have read `Container::Other`; the paths are the runtime's own, set before the process starts |
4 changes: 2 additions & 2 deletions dev/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ Exit: no open finding; every threat has a passing attack test.

## v0.9.0 - Alpha and beta
Exit: both integrations run on every listed environment; two weeks without an API change; every document checked against the build.
- [ ] 0.9.0 (alpha): integrated in a service's boot phase 0 and in a database start-up (guard beside the data directory, cache sizing from `mem::total()`, the Database readiness report) on Windows 11, WSL 2 Ubuntu, a Linux server, macOS on Apple silicon, FreeBSD, a Docker container with limits, and a Kubernetes pod if available.
- [ ] API review against real use; changes made in 0.9.0, not later.
- [x] 0.9.0 (alpha): integrated in a service's boot phase 0 and in a database start-up (guard beside the data directory, cache sizing from `mem::total()`, the Database readiness report) on Windows 11, WSL 2 Ubuntu, a Linux server, macOS on Apple silicon, FreeBSD, a Docker container with limits, and a Kubernetes pod if available. `examples/boot.rs` and `examples/database.rs`, run by the `Integration` workflow on Linux x86-64 and Arm64, Windows Server, macOS Apple silicon and Intel, FreeBSD 14, Docker (1 GiB, 2 CPUs), and a kind pod (512 MiB, 1 CPU); by hand on Windows 11 and WSL 2 Ubuntu (D-122).
- [x] API review against real use; changes made in 0.9.0, not later. `GuardBuilder::process_wide` (D-121), containerd named in a cgroup v2 pod (D-124), the access-time fix per platform; what was kept and why in D-123.
- [ ] 0.9.x (beta): API frozen; only fixes. Documentation complete; `docs/STABILITY-1.0.md` drafted with the requirement-to-test map.
- [ ] Release candidates `1.0.0-rc.N` as needed.

Expand Down
Loading
Loading