@davoodmehraban89 / Aram-1 / commits / 1c1455d
Fork 0

docs(mapping): specify authenticated author binding without approving financial Mapping

davoodmehraban89 committed Oct 30, 2026 at 23:07 UTC 1c1455db1e043bca0fe56d292f8d529f57d712d1
1 file changed +33
docs/superpowers/specs/2026-10-30-authored-mapping-draft-staging.md new
+33
@@ -0,0 +1,33 @@
1 +# ARAM Gate 3 — RSA-authenticated author attribution for new Unreviewed Mapping drafts
2 +
3 +**Status:** PROPOSED, [Draft PR #57](https://github.com/davoodmehraban89/Aram/pull/57), child of **unmerged** [Draft PR #56](https://github.com/davoodmehraban89/Aram/pull/56) at exact parent SHA `0fc0713bd9e0906954c16d7a6b25aad8bf793383`. Parents #55→#54→#53→#52→#51→#50→#26 remain Draft/unmerged; initial DDL PR #25 also unmerged. Accepted `source-data-cleanup@7dc864fd032f0c4ae4d650d89304a01286a6d914` unchanged.
4 +
5 +## Objective, precise security boundary
6 +
7 +The previous proposal persistence function `save_unreviewed_batch` records only a draft and a SYSTEM `DraftStaged` event, **not a known person**. Prior role preflight verified RSA-signed subject and company/year scope but did not bind it to a saved proposal. This PR creates a strictly **opt-in, new, authenticated POST path** that binds the subject of an *already verified access token* to the exact proposed Mapping batch and per-year idempotency request key, using one SQL transaction.
8 +
9 +A signed identity/role is **not evidence of actually connected corporate identity**. The default issuer/public-key configuration remains disabled; all proof is synthetic. The new system is NOT human review, an `Approved` transition, a signed financial decision, or MappingRule apply.
10 +
11 +## Design contract
12 +
13 +1. New `backend/src/aram_backend/authored_mapping_draft.py` defines `mapping_draft_authors` on the same **independent Core MetaData** as the prior `mapping_review_drafts` and `mapping_draft_events`; never add to `Base.metadata` because baseline Alembic migration uses `Base.metadata.create_all`.
14 +2. Each immutable candidate row references its draft ID by FK RESTRICT, with `UNIQUE(draft_id)` and a DB CHECK enforcing `role='mapping_proposer'`, plus `year_id`, verified `issuer`, `subject`, company code, fiscal-year business number, original draft payload hash, and an unsigned deterministic author-hash consistency check. Creation timestamp captured. This is an **independent record**, not retroactively appended to existing DraftStaged audit rows, whose event type and direct UPDATE/DELETE are intentionally frozen.
15 +3. New explicit SQLite-only Alembic `20261030_04` (down_revision `20261030_03`) creates `mapping_draft_authors` and SQLite BEFORE UPDATE/DELETE denial triggers. Other dialects **fail before DDL** until independently reviewed. Ordinary DML updates/deletions are blocked; a privileged database operator can still drop triggers, insert forged rows, replace the file, and recompute unsigned SHA hashes. **Not WORM, not a qualified financial audit trail.** A later downgrade is destructive and requires separately approved evidence retention/backups; never use against production data without authorization.
16 +4. New `POST /api/v1/mapping/unreviewed-drafts` is the *only newly exposed mutation*. FastAPI obtains `VerifiedPrincipal` via `Depends(require_verified_principal)` and exact signed `company_code/year/role` via `require_year_access`. This request must be an actual `mapping_proposer` grant to a **currently Draft** fiscal year. User-supplied author, role, extra JSON keys, Bool IDs or versions are forbidden by strict Pydantic request models. It first authorizes the year, then classifies source rows, validates review readiness and current snapshot, and stages draft + existing system event + new author evidence in a **single caller-owned transaction**. It returns only draft ID/year, Unreviewed status and idempotency request key; no subject/private token.
17 +5. An existing same-year request key with **different** issuer or subject is HTTP 409. An existing *legacy/unbound* draft with the same key is also rejected: **never manufacture retroactive identity**. Same actor+request key+identical proposal is idempotent with exactly one row in each of the three tables. If any insertion fails, the entire SQL transaction rolls back all three, and no MappingRule is written.
18 +6. `get_draft_author` verifies the original year's draft and staging event, exact original payload hash, record role and author digest and refuses missing/altered author evidence. It is an **internal** metadata reader, not an authenticated public read endpoint.
19 +7. `check_independent_mapping_reviewer` is a **read-only eligibility preflight**: it first requires a verified reviewer's *signed exact same-year role grant*, then verifies the original author and denies matching (`issuer`, `subject`) pairs, even if the same individual was issued a different role token. For a different eligible reviewer it returns without ANY DB mutation, review event, `Approved` status or authorization to skip concurrency checks. Do not describe this as two-person approval implementation. Never invoke it with client-created principal objects instead of verified FastAPI dependency.
20 +
21 +## Observed test coverage
22 +
23 +Synthetic SQLite and 2048-bit ephemeral RSA fixtures test: successful 3-record atomic staging, signed scope/role and default-off issuer, unauthorized cross-company and approved fiscal year, missing/forged signature and headers, strict request-body field validation, idempotent same-person retry, different-author request-key conflict, legacy unbound record cannot be attributed, SQLite author UPDATE/DELETE triggers, rollback of draft and SYSTEM event on induced attribution failure, non-self reviewer eligibility preflight with same actor denied and distinct role+scope allowed, no original `MappingRule` writes, full fresh migration up/down and compile.
24 +
25 +## Unfinished risk and explicit acceptance blockers
26 +
27 +- Existing **internal** `save_unreviewed_batch` remains usable by other application code without identity. It creates *unbound* drafts; the new authenticated endpoint rejects attaching an author to those later. Do not claim the old importer or all internal write paths are governed. `save_mapping_rule` and Excel import still bypass the proposed approval workflow.
28 +- No actual Iranian Gas Company or other enterprise IdP is configured, no verified production employee identity, no corporate entitlement provisioning, no issuer key rotation or revocation, no manager/finance-reviewer directory and no producer-vs-reviewer authorization at a real workplace.
29 +- No durable human review/accept/reject decision event, identity-signed approval audit, database CAS/locking of MappingRule at apply time, or real financial statement reconciliation. Issuer/subject equality presumes the IdP issues stable subjects and is **not** proof of human separation across different IdPs or duplicate accounts.
30 +- SQL Server/PostgreSQL provider-specific DDL and transactional isolation remain in [Issue #43](https://github.com/davoodmehraban89/Aram/issues/43); actual Gate 3 full financial approval and real-data evidence remain [Issue #49](https://github.com/davoodmehraban89/Aram/issues/49); 3 distinct non-author C1/C2/C3 reviewer attestations and branch protections remain [Issue #39](https://github.com/davoodmehraban89/Aram/issues/39).
31 +- No canonical XLSX/PDF, `data/`, actual customer/production SQL, dependencies, CI workflow, original migration or accepted branch touched. Keep Draft/unmerged, no formal Gate 3 acceptance, no real customer data migration.
32 +
33 +**Rollback:** close the Draft before merge. If future authorized merge requires revert, do not drop recorded author evidence without written retention and backup plan.