Skip to content

feat: add detect_rootless_container helper for SQPOLL gate (SQP-LAND.3) - #5554

Merged
oferchen merged 3 commits into
masterfrom
feat/sqp-land-3-detect-rootless
Jun 10, 2026
Merged

oferchen merged 3 commits into
masterfrom
feat/sqp-land-3-detect-rootless

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Adds fast_io::detect_rootless_container() - a pure, side-effect-free helper that probes well-known markers (/proc/self/uid_map, /run/.containerenv, /.dockerenv) to detect rootless container / user-namespace environments where SQPOLL is structurally unavailable.
  • Result is cached in a OnceLock<bool>; probe runs at most once per process.
  • Linux-only logic with a compile-time false stub on every other target.
  • This PR ships the helper only - SQP-LAND.4 will wire it into IoUringConfig::build_ring to skip the doomed SQPOLL attempt and surface context-rich diagnostics.

Motivation and design rationale are documented in docs/audits/sqpoll-rootless-detection-status.md (SQP-LAND.1), which identified the rootless detection gap at crates/fast_io/src/io_uring/config.rs:357-386.

Test plan

  • Unit tests cover host-identity uid_map, rootless uid_map, multi-line maps, truncated range, Podman / Docker marker fall-through, signal priority (uid_map short-circuits before marker probes), single-read caching of the uid_map reader, empty uid_map fall-through, and the non-Linux constant-false stub.
  • No new public API beyond detect_rootless_container(). Helper enum types and detection logic stay private to the module.
  • No call sites changed - SQPOLL gating remains exactly as it is on master.
  • CI - fmt+clippy, nextest (stable), Windows, macOS, Linux musl.

Adds a pure, side-effect-free `detect_rootless_container()` helper to
`fast_io` that probes the well-known rootless-container markers in
priority order:

1. `/proc/self/uid_map` non-identity (user namespace)
2. `/run/.containerenv` (Podman)
3. `/.dockerenv` (Docker)

The outcome is cached in a `OnceLock<bool>` so the probe runs at most
once per process. On non-Linux targets the helper is a compile-time
constant `false` because SQPOLL has no analogue outside Linux io_uring.

Detection logic lives in an internal `probe_with_reader` taking
injectable readers so unit tests can exercise every signal path without
touching the real filesystem. Tests cover host identity, multi-line
maps, narrowed ranges, marker fall-through, signal priority, single-read
caching, and the non-Linux stub.

This PR ships the helper only - the call-site wiring into
`IoUringConfig::build_ring` is reserved for SQP-LAND.4. See
`docs/audits/sqpoll-rootless-detection-status.md` (SQP-LAND.1) for the
gap analysis that motivates the helper.
@github-actions github-actions Bot added the enhancement New feature or request label Jun 10, 2026
oferchen added 2 commits June 10, 2026 15:31
is_identity_uid_map was returning false for empty /proc/self/uid_map contents, which made probe_with_reader short-circuit to container detected before checking the marker-file probes. Empty contents carry no signal, so the probe must fall through to /run/.containerenv and /.dockerenv instead of falsely reporting a user namespace.

Aligns the helper with the empty_uid_map_falls_through unit test contract: an empty uid_map is not a positive container signal.
@oferchen
oferchen merged commit a933345 into master Jun 10, 2026
69 checks passed
oferchen added a commit that referenced this pull request Aug 24, 2026
…3) (#5554)

* feat: add detect_rootless_container helper for SQPOLL gate (SQP-LAND.3)

Adds a pure, side-effect-free `detect_rootless_container()` helper to
`fast_io` that probes the well-known rootless-container markers in
priority order:

1. `/proc/self/uid_map` non-identity (user namespace)
2. `/run/.containerenv` (Podman)
3. `/.dockerenv` (Docker)

The outcome is cached in a `OnceLock<bool>` so the probe runs at most
once per process. On non-Linux targets the helper is a compile-time
constant `false` because SQPOLL has no analogue outside Linux io_uring.

Detection logic lives in an internal `probe_with_reader` taking
injectable readers so unit tests can exercise every signal path without
touching the real filesystem. Tests cover host identity, multi-line
maps, narrowed ranges, marker fall-through, signal priority, single-read
caching, and the non-Linux stub.

This PR ships the helper only - the call-site wiring into
`IoUringConfig::build_ring` is reserved for SQP-LAND.4. See
`docs/audits/sqpoll-rootless-detection-status.md` (SQP-LAND.1) for the
gap analysis that motivates the helper.

* fix: treat empty uid_map as no-signal in rootless container probe

is_identity_uid_map was returning false for empty /proc/self/uid_map contents, which made probe_with_reader short-circuit to container detected before checking the marker-file probes. Empty contents carry no signal, so the probe must fall through to /run/.containerenv and /.dockerenv instead of falsely reporting a user namespace.

Aligns the helper with the empty_uid_map_falls_through unit test contract: an empty uid_map is not a positive container signal.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant