A fresh two-lens end-to-end review (security + correctness) of the committed M5/M3 diff surfaced four real defects; all fixed here with regressions. - HIGH (M5 authz bypass) — `enforce_env_approval` resolved a group node with a bare `get_by_slug` and SKIPPED the GroupAdmin gate on miss. A node addressed by the group's UUID (which the apply still resolves) let a group EDITOR apply to a confirm-required env without admin. Now resolves UUID-or-slug and fails closed, mirroring authz_tree / prepare_tree. Raw-wire regression added. - FIX-FIRST (M3 correctness) — the legacy `project_key=None` path was not inert: the conflict loop pushed a conflict for any owned group (`Some(oid) != None`), so a keyless/direct-API tree apply touching an already-claimed group was spuriously 409'd. Ownership classification is now gated on a key being present (the discriminator is key-present, not project-persisted, so a first-ever keyed apply still sees an already-owned group as a conflict). Regression added. - FIX-FIRST (M3 data-loss) — the structural-prune guard checked collection MARKERS (`group_collections`) but data outlives its marker: un-declaring a `collections=[...]` entry drops the marker while the kv/docs/files/queue rows survive until group delete. A dropped-then-pruned group would silently CASCADE that orphaned data. The guard now EXISTS-checks the actual data tables (group_kv_entries/docs/files/queue_messages) plus secrets + markers. - MEDIUM (audit) — group ownership takeover (and claim) now emit a tracing::info! audit line with the actor + ousted owner, matching the M5 gated-env audit. Previously only a report counter. Also: documented WHY `pic plan --dir` mints the project key (a rare write for a read-only command) — plan and apply must present the same key or the ownership token folds diverge and trip a spurious StateMoved. Re-verified: 411 manager-core lib tests; 28 CLI journeys (incl. 2 new regressions: uuid-slug admin gate, keyless legacy apply); workspace clippy -D warnings + fmt clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
12 KiB
12 KiB