Repository navigation
fix(auth): refuse a namespace claim onto an occupied directory - #209
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 lintclean. New tests cover therefusal, the permitted paths, and that a refused claim leaves no partial
account. Verified by reverting the change and confirming the new tests fail.