Skip to content

refactor(file): name the write surface mode, user and group; floor the encryption mode - #514

Merged
David-Noble-at-work merged 3 commits into
developfrom
write-surface-mode-user-group
Aug 18, 2026
Merged

David-Noble-at-work merged 3 commits into
developfrom
write-surface-mode-user-group

Conversation

@David-Noble-at-work

Copy link
Copy Markdown
Contributor

Summary

Three commits on the file and encryption write surface.

Closes #512
Closes #513

1. Append the run index before the latest link

WriteTrace linked latest.yaml and then appended the index entry, so any link failure discarded the
index entry for a trace already durable on disk — silently, because all nine callers warn rather than
fail.

That ordering is wrong on every platform. Windows is only where it fires for ordinary users, who have
neither Developer Mode nor SeCreateSymbolicLinkPrivilege and so cannot create a symlink at all.

The regression test forces a link failure portably — occupy latest.yaml with a non-empty directory, so the
best-effort Remove cannot unlink it — then asserts the trace is both on disk and in the index.

This advances #438 by one of its six exit criteria and does not close it. The latest disposition still
needs its ruling (and the fact that nothing reads it reframes the question), and the Windows proof must
deny the privilege rather than run where it happens to be granted.

2. mode, user, group

chmod is a verb. The Dockerfile-style chown string made every caller assemble a value the callee
immediately took apart with strings.Cut.

Python decides it, because Python is the surface Starlark projects into — os.chmod(path, mode),
os.mkdir(path, mode=…), pathlib.Path.chmod(mode), shutil.chown(path, user=…, group=…). Go is not
self-consistent here (perm when creating, mode in os.Chmod), so there was no single stdlib convention
to defer to.

  • applyChown / parseChown → applyOwnership / resolveOwnership, taking the two sides directly.
  • os/user aliased osuser, because the parameter now legitimately owns the name user.
  • 46 .star fixtures, the +devlore:defaults directives, and the generated announce lists all move.
    No .star file ever passed chown, so that side was a pure rename.
  • One test changed meaning, not shape: with two parameters there is no malformed spec left to reject,
    so RejectsMalformedChown became RejectsUnresolvableUser.
  • Incidental fix: default_func.go listed the deferred-default functions as (umask, chmod, env); the
    registry has had "mode" all along.

3. A floored mode on the encryption actions

They hardcoded 0o600 — the only writes in the catalog not taking a mode.

The parameter is floored on decrypt. Encrypting a file is the declaration that its contents are
sensitive, and tree/builder.go already derives 0o600 from the pipeline containing encryption.decrypt.
A free parameter would reopen that decision to a caller who can get it wrong, and a world-readable secret
fails silently. enforceSecretFloor refuses group or other access before decrypting, so a rejected call
never materializes plaintext — asserted by the test.

Encrypt is deliberately not floored: ciphertext is safe at rest and lands in a repository that stores it
0o644 regardless. Both default to 0o600, so behavior is unchanged unless asked.

Note on the codegen

AnnounceProvider panics at init when a generated parameter list disagrees with its signature, so the
generator could not run to fix its own output. The announce lists in the two gen/provider.gen.go files were
corrected by hand to break that cycle, then regenerated — the committed files are generator output.

Verified

make check and make lint-all both exit 0.

David Noble added 3 commits August 17, 2026 19:46
WriteTrace linked latest.yaml and then appended the index entry, so any link failure discarded the index
entry for a trace already durable on disk -- silently, because all nine callers warn rather than fail.

That ordering is wrong on every platform. Windows is only where it fires for ordinary users, who lack both
Developer Mode and SeCreateSymbolicLinkPrivilege and so cannot create a symlink at all.

The regression test forces a link failure portably by occupying latest.yaml with a non-empty directory, then
asserts the trace is both on disk and in the index.

Advances #438; the symlink disposition and the privilege-denying Windows proof remain open.
chmod is a verb -- you pass a mode, not a chmod -- and the Dockerfile-style chown string made every caller
assemble a value the callee immediately took apart with strings.Cut.

Python decides it, because Python is the surface Starlark projects into: os.chmod(path, mode),
os.mkdir(path, mode=...), pathlib.Path.chmod(mode), shutil.chown(path, user=..., group=...). Go is not
self-consistent here -- perm when creating, mode in os.Chmod -- so there was no single convention to defer
to.

applyChown/parseChown become applyOwnership/resolveOwnership taking the two sides directly. os/user is
aliased osuser, because the parameter now legitimately owns the name user.

Touches 46 .star fixtures, the +devlore:defaults directives and the generated announce lists. No .star file
ever passed chown, so that side was a pure rename. One test changed meaning rather than shape: with two
parameters there is no malformed spec left to reject, so RejectsMalformedChown became
RejectsUnresolvableUser -- the failure mode that remains.

Also corrects a stale doc comment in default_func.go, which listed the deferred-default functions as
(umask, chmod, env); the registry has had "mode" all along.
The encryption actions hardcoded 0o600, the only writes in the catalog not taking a mode.

The parameter is floored on decrypt: encrypting a file IS the declaration that its contents are sensitive,
so a free parameter would reopen that decision to a caller who can get it wrong -- and a world-readable
secret fails silently, since the file is written and the run succeeds. enforceSecretFloor refuses any mode
granting group or other access, BEFORE decrypting, so a rejected call never materializes plaintext.

Encrypt is deliberately not floored: ciphertext is safe at rest by construction, and lands in a repository
that stores it 0o644 regardless. Both default to 0o600, so behavior is unchanged unless asked.
@David-Noble-at-work David-Noble-at-work self-assigned this Aug 18, 2026
@David-Noble-at-work
David-Noble-at-work requested a lite review from Copilot August 18, 2026 02:53
@David-Noble-at-work
David-Noble-at-work merged commit 1e1bd5b into develop Aug 18, 2026
8 of 9 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the file write surface to use clearer parameter names (mode, user, group), improves trace-index durability by reordering operations in WriteTrace, and updates encryption actions to accept a mode argument with a safety floor applied on decrypt.

Changes:

  • Reorders WriteTrace to append the index entry before attempting the best-effort latest.yaml link, and adds a regression test for link-failure scenarios.
  • Renames file-provider write parameters from chmod/chown to mode/user/group, updating generators, planners, and Starlark fixtures accordingly.
  • Adds a mode parameter to encryption actions, enforcing a “no group/other bits” floor for decrypted plaintext.

Reviewed changes

Copilot reviewed 71 out of 71 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
star/extensions/com.noblefactor.devlore.Actions/commands/generate.star Updates generator writes to mode=
pkg/op/provider/plan/provider_units_test.go Updates planned kwargs to mode/user/group
pkg/op/provider/plan/provider_test.go Updates helper planning kwargs
pkg/op/provider/plan/lifecycle_starlark_test.go Updates Starlark lifecycle script kwargs
pkg/op/provider/plan/lifecycle_e2e_test.go Updates Starlark lifecycle script kwargs
pkg/op/provider/plan/lifecycle_api_test.go Updates public API tests to new kwargs
pkg/op/provider/plan/gather_api_test.go Updates write planning to mode
pkg/op/provider/plan/deferred_default_test.go Updates docs/comments around defaults
pkg/op/provider/file/provider.go Refactors provider signatures to mode/user/group
pkg/op/provider/file/provider_unix_test.go Updates ownership test to new signature
pkg/op/provider/file/provider_test.go Updates file provider tests to new signature
pkg/op/provider/file/helpers.go Refactors ownership parsing/apply helpers
pkg/op/provider/file/helpers_test.go Updates ownership helper tests
pkg/op/provider/file/gen/provider.gen.go Updates generated parameter lists
pkg/op/provider/encryption/provider.go Adds mode params + decrypt floor helper
pkg/op/provider/encryption/provider_test.go Adds/updates tests for mode floor + signatures
pkg/op/provider/encryption/gen/provider.gen.go Updates generated parameter lists
pkg/op/provider/archive/provider.go Updates mkdir call signature
pkg/op/default_func.go Updates docs to refer to mode
cmd/writ/writ/migrate/register.go Updates planning kwargs
cmd/writ/writ/migrate/receipt_integration_test.go Updates planning kwargs
cmd/writ/writ/migrate/plan_builder.go Updates planning kwargs
cmd/writ/writ/deploy/plan.go Updates planning kwargs
cmd/writ/writ/adopt/plan.go Updates planning kwargs
cmd/internal/cli/store.go Reorders index append vs symlink creation
cmd/internal/cli/store_test.go Adds regression test for link failure ordering
cmd/devlore-test/devloretest/data/test_write_text.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_write_bytes.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_write_and_read.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_writ_adopt.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_writ_adopt_type_mismatch.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_writ_adopt_subgraph.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_writ_adopt_precedence.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_writ_adopt_origin_namespace.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_writ_adopt_origin_full.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_writ_adopt_missing_required.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_walk_tree.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_walk_tree_gitignore.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_walk_tree_closure.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_wait_until.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_round_trip_writ_adopt.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_promise_type_mismatch.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_orphan_unattached.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_move.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_mkdir_and_remove_all.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_link.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_is_file.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_is_dir.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_imm_file.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_gather_projection.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_gather_projection_missing_field.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_gather_concurrency.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_gather_basic.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_gather_advanced.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_flow_fatal_template.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_flow_fatal_recovery.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_flow_degraded_template.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_file_unlink.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_file_lifecycle.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_file_glob.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_file_find.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_copy.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_compensation.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_choose_unchosen_branch.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_choose_predicates.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_choose_not_exists.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_choose_literals.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_choose_lambdas.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_choose_in_gather.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_choose_exists.star Renames chmod → mode
cmd/devlore-test/devloretest/data/test_backup.star Renames chmod → mode

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 39 to 41
script := fmt.Sprintf(`
node = plan.file.mkdir(path = %q, chmod = 0o755, chown = "")
node = plan.file.mkdir(path = %q, mode = 0o755, chown = "")
graph = plan.assemble_definition([node])
Comment on lines +209 to +210
a = plan.file.mkdir(path = %q, mode = 0o755, chown = "")
b = plan.file.mkdir(path = %q, mode = 0o755, chown = "")
Comment on lines +44 to 45
// mode and chown deliberately omitted: mode carries the deferred {{ umask 0o666 }} default, chown a
// literal "".
Comment on lines +70 to +76
func TestResolveOwnership_LooksUpNamedUser(t *testing.T) {

// Looking up the current user by name should always succeed and return the same uid as os.Getuid.
currentUID := os.Getuid()
currentName := strconv.Itoa(currentUID)

gotUID, gotGID, err := parseChown(currentName)
gotUID, gotGID, err := resolveOwnership(currentName, "")
Comment on lines +225 to +229
if beyondOwner := mode.Perm() & 0o077; beyondOwner != 0 {
return fmt.Errorf(
"encryption: mode %04o would leave decrypted plaintext readable beyond its owner (offending bits %04o); "+
"a decrypted secret must not grant group or other access", mode.Perm(), beyondOwner)
}
@David-Noble-at-work
David-Noble-at-work deleted the write-surface-mode-user-group branch August 18, 2026 02:59
David-Noble-at-work added a commit that referenced this pull request Aug 18, 2026
The burn-down describes its chown cluster as TestApplyChown_* / TestParseChown_*. PR #514 renamed those to
TestApplyOwnership_* / TestResolveOwnership_*, so the wildcards match nothing.

Same tests, same failures -- the windows leg held at 28 through that PR, and the only delta against develop
was those two names appearing under their new ones. Recorded so the next name-for-name comparison does not
read a rename as one regression and one fix.

Co-authored-by: David Noble <[email protected]>
David-Noble-at-work added a commit that referenced this pull request Aug 18, 2026
Three things were stale.

The exit gate still described a defect that PR #514 fixed: appendIndexEntry sat after the latest link, so
any link failure discarded the index entry for a trace already on disk. The plan now records that half as
met, and says which five of the six exit criteria remain.

It cited step numbers where issues now exist -- step 58 is #392, step 60 is #438 -- and step 54, which is
complete and has no issue, is cited by document filename instead. No step-number citation remains.

And it named none of its own tracked work: phases 3.4, 4, 5 and LAST are #433, #434, #435 and #436, so a
reader could not get from the plan to the issues that track it.

Co-authored-by: David Noble <[email protected]>
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.

Take a floored mode argument on the encryption actions Name the write surface mode, user and group

2 participants