8000 fix(auth): refuse a namespace claim onto an occupied directory by jasonmadigan · Pull Request #209 · tracefinity/tracefinity · GitHub
[go: up one dir, main page]

Skip to content

fix(auth): refuse a namespace claim onto an occupied directory - #209

Merged
jasonmadigan merged 2 commits into
mainfrom
fix/namespace-claim-occupied-directory
Aug 30, 2026
Merged

jasonmadigan merged 2 commits into
mainfrom
fix/namespace-claim-occupied-directory

Conversation

@jasonmadigan
@jasonmadigan jasonmadigan commented Aug 30, 2026 •
Copy link
Copy Markdown
Collaborator

Summary

Hardens namespace claiming so a claim is refused when the target storage
directory already exists and holds files. An empty or absent namespace stays
claimable, which is the ordinary case.

Taking over data already on the volume remains possible where that is the
caller's explicit purpose, and is no longer the default.

Test evidence

Backend and frontend suites pass, make lint clean. New tests cover the
refusal, the permitted paths, and that a refused claim leaves no partial
account. Verified by reverting the change and confirming the new tests fail.

claim() returned early for any namespace without a deletion marker, so the
refusal that protects a namespace still holding files only covered namespaces
something had explicitly marked. an unmarked directory holding files was
claimed silently.

POST /api/admin/users takes a caller-supplied id, makes it the account's
storage namespace, and ensure_user_dirs adopts an existing tree without
touching it, so an account created on a colliding id opened onto another
account's files. a marker is the wrong condition: an account creation
interrupted before its record landed, or a volume restored without its
users.json, leaves occupied directories and no marker at all.

refuse on the state of the directory instead. an empty or absent namespace
stays claimable, which is the ordinary case. adoption survives only where it
is the caller's purpose: first-run setup taking a single-user library into
authenticated use, create-admin, and an import that passes
adopt_existing_storage. a marked namespace is refused even then, because those
files' owner was already destroyed here.

the claim still runs before the account is written, so a refusal leaves no
account and no directories behind.

Closes #208

Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
review feedback: the adopt_existing_storage field added on this branch was
ungated by principal type. get_admin_principal accepts an admin API token,
and create_user's only token-specific check covered the admin bit, so a
tfadm_ token holder could set one boolean, name any unmarked namespace
holding another party's files, create an account onto it and log in as that
account to read and write them. reproduced end to end before fixing.

extend the invariant the module already holds. a token neither creates an
administrator nor writes to an account that is one; now it also cannot open
an account onto storage that already holds files. 403 with the same shape as
the existing refusal.

adoption stays available to an administrator session rather than moving to
the CLI. the CLI creates the first administrator only, so this endpoint is
the only way to put the second and later accounts back on storage carried
over with them, and removing it would push operators to edit users.json by
hand. the risk was never that adoption exists, it is that an unattended
credential with no password step and no second factor could perform it.

checked on the request field rather than on whether the namespace turns out
to be occupied, so the answer does not leak which namespaces hold data and
there is no window between the check and files arriving.

add is_token to AdminPrincipal as the single discriminator both token rules
test. token_id is set only by the token branch of get_admin_principal, from
a record whose field is a str, so the default None means a session and
nothing else; the named property stops a future guard picking the truthiness
form instead.

Signed-off-by: Jason Madigan <jason@jasonmadigan.com>
@jasonmadigan
jasonmadigan merged commit b72bc0f into main Aug 30, 2026
6 checks passed
@jasonmadigan
jasonmadigan deleted the fix/namespace-claim-occupied-directory branch August 30, 2026 22:38
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.

1 participant

0