Skip to content

Collapse fsroot to one confinement behaviour and two types #568

Closed

Description

@David-Noble-at-work

Design: 4.5-fsroot-variants.md

Filed as a three-variant rename; rewritten 2026-08-19 after the design collapsed to two types. The original
ordering constraint no longer applies -- it existed to stop one name silently acquiring a wider meaning, and the
wider meanings are now deleted rather than renamed.

Target

Opener Type Lifetime
OpenConfined(dir) confinedDir the caller's
OpenScratch(pattern) confinedScratchDir removes its tree on Close

Both confine reads and writes through *os.Root. Nothing else.

Why the other variants go

The write-confined variant has no real consumers -- two production references, both internal plumbing --
and the requirement it was meant to meet was never implemented: fourteen mutators return errReadOnly because
its name was read as "this root cannot write" rather than "unconfined for reads only".

The unconfined variant's ~20 callers all anchor at a tree they own. The one recorded reason is
bootstrapping: "the prefix need not exist yet ... a confined root requires its anchor to exist." With open
ruled a query
and a missing root ruled an error, such a caller opens a confined root at an existing
ancestor, creates the chain through it, then opens the target. / always exists, so an ancestor always does.

The work, in order

  1. Verify the premise. Trace every OpenWritableUnconfined call site and confirm none writes outside its
    anchor. Sampled, not exhaustively traced. This is the only thing that can invalidate the design, so it
    goes first.
  2. Migrate the call sites. Tests against t.TempDir() become OpenConfined directly, since the directory
    already exists. The bootstrapping cases -- prefix, ConfigHome, StateHome, CacheHome, installPath --
    create through an ancestor root, then open.
  3. Delete unconfinedRootReader, unconfinedRootReaderWriter, rootBase, errReadOnly, Mode and its
    constants, Open, OpenUnconfined, OpenWritableUnconfined.
  4. Rename confinedRoot -> confinedDir, scratchRoot -> confinedScratchDir.
  5. WithRoot(path, mode) -> WithRoot(path), and WithRootMode with it. Two production call sites plus
    tests.

Five types become two. The Dir interface stops being a substitution point for confinement policy and survives
as the seam every provider already programs against.

Also in scope

TestIsPrivateMode and TestNewPath are exported from non-test files, so they sit in the public API. They
belong in _test.go files, or unexported.

Not in scope

Symlink target validation. The kernel restricts following rather than making, deliberately, and fsroot matches
it -- see 4.5 section 4, which also inverts
#556 from "fix the guard" to "delete it".

Activity

  1. changed the title [-]Rename fsroot's variants to say which operations they confine[/-] [+]Collapse fsroot to one confinement behaviour and two types[/+] on Aug 19, 2026
  2. David-Noble-at-work commented on Aug 19, 2026

    @David-Noble-at-work
    ContributorAuthor

    Step 1 is done: the premise holds

    Traced every OpenWritableUnconfined call site. No production or fixture caller writes outside its anchor.
    Every path handed to one of these roots is relative to it: prefixRoot addresses bin and share/man/man1,
    configRoot addresses config.yaml and config.d, stateRoot addresses GraphsDir() and latest.yaml, and
    so on.

    Two candidates examined and dismissed

    store.go hands a root anchored at ~/.config/devlore a path at ~/.ssh/id_ed25519. Not a breach: the
    path goes to loadSSHKeyfile directly, bypassing the root, and signing.DefaultSigner carries the
    justification the Dir doc requires -- "the publisher's own SSH directory is not ours to confine ... a root
    anchored at our config tree cannot address it."

    devlore-test/runner.go claimed a confined root "refuses by design" because scripts under test address
    absolute paths.
    False, and it was the last thing making the variant look necessary. An absolute path inside
    the anchor is fine, since fsroot.Path derives its root-relative half from it. The fixture paths that genuinely
    sit outside -- "/some/dir/file.txt" for file.name and file.parent, and the "/tmp/fake.*" arguments to
    archive and encryption -- are pure string operations or plan-shape fixtures that never execute against a real
    file. Corrected in step 2.

    Step 2 is up, and it found eight fixtures reaching across trees

    Confining the test roots failed eight tests, all for the same underlying reason: fixtures reached across trees
    because nothing stopped them. testFileResource called t.TempDir() itself so a copy's source sat in a second
    tree; the archive fixtures wrote their tarball one level above the root they extracted into; and two tests used
    "/nonexistent/path" as a convenient absent value.

    Worth recording because production has been confined all along -- plan/provider.go:488 and
    deploy/plan.go:387 -- so these tests were exercising a path production never takes. All eight are fixed
    in step 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions