Skip to content

Use name space mount for code simplicity#174

Draft
say-paul wants to merge 2 commits into
fedora-iot:mainfrom
say-paul:issue-120-code-agent-test
Draft

Use name space mount for code simplicity#174
say-paul wants to merge 2 commits into
fedora-iot:mainfrom
say-paul:issue-120-code-agent-test

Conversation

@say-paul

Copy link
Copy Markdown
Member

POC-e2e agentic workflow

Problem
greenboot currently manages /boot remounts by parsing /proc/mounts to detect mount state, remounting /boot read-write before GRUB operations, and then restoring it to read-only afterward. This creates several issues:

Race conditions: Another process could modify /boot between the RW operation and the RO restore, or the restore could fail leaving /boot permanently writable.
Complex error handling: Every code path that touches /boot must track the original mount state and ensure cleanup, even on failure.
Fragile detection: Parsing /proc/mounts for mount state is brittle and doesn't account for bind mounts or overlay configurations.

Solution
Use Linux mount namespaces to isolate /boot remounts to the greenboot process. When the process exits, the namespace is destroyed and the global mount state is untouched — no restore step needed.

Systemd path: Add PrivateMounts=yes and RequiresMountsFor=/boot to the service unit, so systemd creates the namespace automatically.
CLI path: Call unshare(CLONE_NEWNS) via the nix crate early in main() when not running in a container.
Writable detection: Replace /proc/mounts parsing with access(2) using W_OK, which correctly detects read-only mounts (not just inode permission bits).
Simplify with_boot_rw: Remove the was_rw tracking and remount_boot_ro() call entirely — the namespace handles cleanup.

Resolves #120

Leverage Linux mount namespaces to simplify /boot remount logic:
- Add PrivateMounts=yes and RequiresMountsFor=/boot to systemd service
- Create private mount namespace via unshare(CLONE_NEWNS) for CLI path
- Replace /proc/mounts parsing with access(W_OK) writable check
- Expose is_boot_writable_at as public API for testability
- Remove remount_boot_ro and post-operation read-only restore
- Skip read-only permission test when running as root (access(2) lets
  root bypass permission bits by design)

Ref: fedora-iot#120
Made-with: Cursor
Functional tests covering greenboot's own API with mock temp dirs:
- ensure_mount_namespace succeeds under test-remount feature
- is_boot_writable_at detects writable, read-only, and missing paths
- remount_boot_rw succeeds under test-remount feature
- Public API surface compile-time validation
- Skip read-only permission test when running as root

All sensitive paths mocked — no real /boot or mount operations.

Ref: fedora-iot#120
Made-with: Cursor
@say-paul

Copy link
Copy Markdown
Member Author

/test

@say-paul
say-paul marked this pull request as draft April 14, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use name space mount for code simplicity

1 participant