codex/gate3-signed-year-scope-20261030
ARAM Gate 3 — signed company, fiscal-year and role authorization boundary
Status: Proposed in Draft PR #56, child of unmerged Draft #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.
Gap and policy
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.
- The verified access token may contain an optional signed
aram_scopesarray of EXACT grants, each a three-key object{"company_code": "FIN-OPERATIONS", "fiscal_year": 1404, "role": "mapping_proposer"}.company_codeis the reporting Company.code, not an arbitrary database year ID. The year is the fiscal-year business number fromFiscalYear.year. The role must be identical to the single already-validated signedaram_rolesrole. No wildcard, implicit company ownership, broad admin, header-based grant, cross-role or inherited authorization. - Backward-compatible authentication without authorization:
aram_scopesabsent means an empty set; the existing read-onlyGET /auth/mecan 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. - 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. - The
VerifiedPrincipalincludes a frozen tuple of parsedSignedYearScopeobjects; 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'sDepends(require_verified_principal)before asking a policy checker to authorize access. No client-providedX-User, company header or X-ARAM-Role changes authorization. require_year_access(session, principal, *, year_id, required_role)intersects signed grant and role with the actual current databaseFiscalYear(company_id, year, status)andCompany.code. Refresh ORM identity-map objects withpopulate_existing=Trueunderno_autoflushso 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.GET /api/v1/auth/year-access/{year_id}wires bothDepends(require_verified_principal)andDepends(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.- 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.
Synthetic verification and acceptance limits
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.
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.
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.