@davoodmehraban89 / Aram-2 Mirror · read-only
Fork 0

Mirrored from https://github.com/davoodmehraban89/Aram.git

Synced Dec 4, 11:45 UTC

codex/gate3-signed-year-scope-20261030
add-index-html-10623938925177053894 arena/094f314c-aram arena/2d4eda07-aram chatgpt-phase1b2-autopilot codex/adr-future-connectors-pi-v1 codex/aram-account-note-source-trace-20261031 codex/aram-actions-node24-maintenance-20261031 codex/aram-analyst-review-workbook-20261031 codex/aram-bs-candidate-statement-20261031 codex/aram-cash-flow-direct-candidate-20261031 codex/aram-clean-reference-year-integrity-20261030 codex/aram-cross-statement-controls-20261031 codex/aram-equity-changes-candidate-20261031 codex/aram-five-statement-cli-20261031 codex/aram-five-statement-integration-20261031 codex/aram-five-statement-orchestrator-20261031 codex/aram-gate3-coverage-target-guard-20261030 codex/aram-gate3-hidden-xlsx-guard-20261030 codex/aram-gate3-integration-validation-20261030 codex/aram-gate3-mapping-change-preview-20261030 codex/aram-gate3-stale-note-guard-20261030 codex/aram-income-statement-candidate-20261031 codex/aram-manifest-referential-integrity-20261031 codex/aram-mapping-source-parser-20261101 codex/aram-multidimensional-mapping-20261101 codex/aram-multistatement-mapping-20261031 codex/aram-pipeline-manifest-schema-20261031 codex/aram-readonly-mapping-coverage-20261031 codex/aram-reconciliation-review-gate-20261031 codex/aram-same-flush-fiscal-lock-20261030 codex/aram-synthetic-windows-demo-20261031 codex/aram-trial-balance-diagnostic-20261031 codex/aram-windows-background-detail-search-20261031 codex/aram-windows-detail-review-20261031 codex/aram-windows-five-statement-pilot-20261031 codex/aram-windows-statement-figures-20261031 codex/gate-2a-pilot-workbook codex/gate-2a-pilot-workbook-6864754244772568979 codex/gate3-authenticated-principal-boundary-20261030 codex/gate3-authored-draft-staging-20261030 codex/gate3-carry-forward-preview-20261023 codex/gate3-draft-staging-audit-20261030 codex/gate3-mapping-batch-freshness-20261030 codex/gate3-mapping-batch-review-20261030 codex/gate3-mapping-core codex/gate3-mapping-coverage-20261023 codex/gate3-mapping-excel-20261023 codex/gate3-note-mapping-review-20261023 codex/gate3-signed-year-scope-20261030 codex/gate3-unapproved-proposal-storage-20261030 codex/payvast-mapping-discovery-20261023 codex/phase-2a-backend-foundation codex/phase-2b-post-merge-record codex/phase-2b-source-registration codex/phase-2b-source-registration-12955190277775369594 codex/post-gate2a-control-reconciliation codex/post-pr18-acceptance-record codex/project-control-foundation codex/t1-repo-hygiene-20261023 codex/t2-ci-hardening-20261023 codex/t3-explicit-migrations-20261023 codex/t6a-readonly-diagnostics-20261023 codex/v1-01-safety-gate-hardening codex/v1-year-isolation-followup-20261023 codex/windows-native-pilot-shell-20261030 docs/aram-master-control-plan-20261111 docs/aram-roadmap-dashboard-20261030 docs/financial-statement-reconciliation-1402-1404-20261110 feat/gate3-governed-mapping-20261101 feat/gate3-package9-1-security-20261103 feat/gate3-package9-isolated-20261103 fix/password-unicode-validation-20261111 governance/aram-5-1-3-controls-20261030 governance/role-based-operating-model jules-1168663913887856558-73b8a885 jules-gate-2b-mapping-workflow-foundation-4137724387867065330 phase-1b1-audit-report-7365389436990903239 phase-2a-backend-foundation-10237597358138521261 phase1b2-postmerge-metadata-fix refactor/drg-parent-year-id-15088443704684163304 source-data-cleanup
md 23 lines 5.57 KB
Rendered Raw
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.