Mirrored from https://github.com/davoodmehraban89/Aram.git
Synced Dec 3, 18:15 UTC
docs(auth): specify company/year/role grants and strict read-only boundary
davoodmehraban89 committed
Oct 30, 2026 at 22:27 UTC
e8dff5ab9f75a5134bc88d175bc7c77a93670af2
1 file changed
+23
docs/superpowers/specs/2026-10-30-signed-year-scope.md
new
+23
@@ -0,0 +1,23 @@
1
+# ARAM Gate 3 — signed company, fiscal-year and role authorization boundary
2
+
3
+**Status:** Proposed in [Draft PR #56](https://github.com/davoodmehraban89/Aram/pull/56), child of **unmerged** [Draft #55](https://github.com/davoodmehraban89/Aram/pull/55), exact parent SHA `8d82f1e7be9653bac467101234a62029bdfa3178`. Upstream #54→#53→#52→#51→#50→#26, plus unrelated original migration PR #25, remain unmerged. Accepted `source-data-cleanup@7dc864fd032f0c4ae4d650d89304a01286a6d914` unchanged.
4
+
5
+## Gap and policy
6
+
7
+An RS256-verified issuer/user/role alone does not prove that a user may work with **a particular company's fiscal year**. Granting every user with `mapping_proposer` or `mapping_reviewer` access to every `year_id` is a cross-entity financial security flaw. Until trusted company/year/role provisioning exists in a real authorized IdP, every Mapping year operation must **fail closed**.
8
+
9
+- The verified access token may contain an optional signed `aram_scopes` array of EXACT grants, each a three-key object `{"company_code": "FIN-OPERATIONS", "fiscal_year": 1404, "role": "mapping_proposer"}`. `company_code` is the reporting Company.code, not an arbitrary database year ID. The year is the fiscal-year business number from `FiscalYear.year`. The role must be identical to the single already-validated signed `aram_roles` role. No wildcard, implicit company ownership, broad admin, header-based grant, cross-role or inherited authorization.
10
+- **Backward-compatible authentication without authorization:** `aram_scopes` absent means an empty set; the existing read-only `GET /auth/me` can still verify a role-only JWT but that token **cannot** pass a year-scoped authorization check. A malformed *present* grant is invalid credential (HTTP 401), not silently discarded.
11
+- Check grant collection is strictly a list, length at most 32, including zero grants; reject duplicate grants, non-dict entries, missing or surplus keys, whitespace/control/format/surrogate characters in company code, `*` or `?` wildcard characters, non-int/Boolean year, year outside 1–9999, unsupported/mismatched role. Signed JWT body modifications invalidate the RS256 signature.
12
+- The `VerifiedPrincipal` includes a frozen tuple of parsed `SignedYearScope` objects; the role and scopes are derived exclusively from the previously verified RSA token. **Caller-generated Python dataclass objects are not authentication.** Sensitive APIs must obtain principal with FastAPI's `Depends(require_verified_principal)` before asking a policy checker to authorize access. No client-provided `X-User`, company header or X-ARAM-Role changes authorization.
13
+- `require_year_access(session, principal, *, year_id, required_role)` intersects signed grant and role with the actual current database `FiscalYear(company_id, year, status)` and `Company.code`. Refresh ORM identity-map objects with `populate_existing=True` under `no_autoflush` so external SQL changes to year status are not hidden by cached objects. Only **Draft** years pass this preflight, and valid signer, positive int year ID, unexpired principal and exactly required role must match. Pending ORM edits touching Company/FiscalYear fail closed. An unrelated pending account change may exist without being auto-flushed by this read-only operation.
14
+- `GET /api/v1/auth/year-access/{year_id}` wires both `Depends(require_verified_principal)` and `Depends(get_session)` into this read-only preflight and returns exact matching company/year/role. Deny nonexistent year and wrong company/year/role with HTTP 403 and the **same generic** error body, without disclosing the requested company's metadata; malformed signed claims return HTTP 401, missing IdP config HTTP 503. No created MappingRule, stored proposal, Reviewed/Approved state, financial audit decision or apply operation.
15
+- A 200 response is **only current read-time policy eligibility**, not a stored permission, explicit reviewer decision, dual-control proof, transactional authorization, or permission to skip rechecking before eventual apply. Do not silently grant year access to existing unbound proposal rows.
16
+
17
+## Synthetic verification and acceptance limits
18
+
19
+Tests exercise valid proposer and reviewer signed grants on a configured synthetic 2048-bit RSA issuer, role-only tokens without company/year grants denied, company/year differences denied, same-company different-year denied, signed-role mismatch rejected as invalid token, malformed/oversized/duplicate grants denied, forged company or role headers ignored, cached year turning Approved via independent SQLAlchemy Session denied, nonexistent and zero year ID denied, unrelated uncommitted AccountVersion never auto-flushed, and no `POST approve` route. All DB checks are on ephemeral SQLite test files, not production SQL Server.
20
+
21
+**Still not done:** a real enterprise IdP/grant provisioning, stable approved company/year entitlement directory, key rotation/revocation, author→reviewer non-self-approval with persisted actor identity, signed immutable financial decisions, atomic compare-and-set MappingRule apply, legacy Excel import bypass closure, note/subnote hierarchy, production-provider concurrency and actual 1402–1404 account/statement reconciliation (Issues #49/#43). Real non-author C1/C2/C3 approval/branch protection remains Issue #39. The accepted branch, canonical XLSX/PDF, `data/`, production/client DB, migration files, dependencies and workflows are unaffected.
22
+
23
+A signed-scope token from a **synthetic test key** is not proof an actual employee has that permission. No such identity configuration was made. Keep PR #56 Draft and unmerged until all parents and actual financial/security reviewers are accepted.