Treasury & Bank Transfer Management System — سامانه مدیریت خزانه‌داری و حواله‌های بانکی

feat: add fail-closed phase 7 go-live controls

Davood Mehraban committed Oct 5, 2026 at 20:14 UTC 765644cd53148f41ccc957d94f41538e0ca0b26b
11 files changed +73 -1
deploy/production.env.contract new
+13
@@ -0,0 +1,13 @@
1 +# Provider-Neutral Production Environment Contract
2 +NODE_ENV=production
3 +APP_BASE_URL=https://replace.example
4 +BANK_ADAPTER_MODE=disabled
5 +DATABASE_URL=__SECRET_STORE_REFERENCE__
6 +IDENTITY_PROVIDER=__CONFIGURE_PROVIDER__
7 +MFA_REQUIRED=true
8 +SESSION_MAX_MINUTES=30
9 +KMS_KEY_ID=__CONFIGURE_KMS_KEY_ID__
10 +SIEM_ENDPOINT=__CONFIGURE_SIEM__
11 +WAF_POLICY_ID=__CONFIGURE_WAF__
12 +ALERT_CHANNEL=__CONFIGURE_ALERT_CHANNEL__
13 +# LIVE bank mode is forbidden until Phase 7 external evidence is complete and explicit authorization exists.
docs/PHASE_6_GATE.md
+2 -1
@@ -10,9 +10,10 @@
10 - [x] Readiness endpoint added with bank adapter explicitly disabled.
11 - [x] Runtime configuration rejects insecure production URL and unauthorized live-bank mode.
12 - [x] CI expanded to all phase/release branches with schema and committed-secret checks.
13 -- [ ] Fresh full verification and branch push.
13 +- [x] Fresh full verification and branch push completed; see Phase 6 final commit ecee423.
14
15 ## Boundary
16 Phase 6 provides repository-level production platform contracts and migration artifacts. It does not claim a provisioned PostgreSQL instance, configured external identity provider, KMS/SIEM/WAF, completed restore drill, or a bank-specific production connection. Those are Phase 7 and require external infrastructure/credentials and explicit authorization where applicable.
17
18 **Gate result:** PASS locally on 2026-10-05. Phase 6 repository-level production platform foundation is complete within its stated boundary.
19 +
docs/PHASE_7_GATE.md new
+24
@@ -0,0 +1,24 @@
1 +# Phase 7 — Production Infrastructure & Bank Go-Live
2 +
3 +## Repository-controlled completion
4 +- [x] Production evidence model is fail-closed.
5 +- [x] Identity policy requires verified provider, MFA and bounded sessions.
6 +- [x] Recovery evidence requires successful restore and RPO/RTO thresholds.
7 +- [x] Security operations evidence requires WAF, SIEM and alert delivery.
8 +- [x] Bank lifecycle is DISABLED -> SANDBOX -> CERTIFIED -> LIVE.
9 +- [x] LIVE requires explicit authorization, verified production credentials and verified certificate.
10 +- [x] UNKNOWN transfer behavior from earlier phases remains manual-review/no-auto-retry.
11 +- [x] Production PostgreSQL migration/RLS contracts exist from Phase 6.
12 +- [x] Portable container and production runbook exist from Phase 5.
13 +
14 +## External production evidence — BLOCKED_EXTERNAL until actually supplied
15 +- [ ] Provisioned production PostgreSQL instance and executed RLS integration proof.
16 +- [ ] Configured external identity provider and MFA proof.
17 +- [ ] Configured KMS/secret store proof.
18 +- [ ] Configured WAF/SIEM/alert-delivery proof.
19 +- [ ] Executed production backup/restore drill proving RPO <= 15m and RTO <= 60m.
20 +- [ ] Bank-specific sandbox credentials/protocol implementation and certification evidence.
21 +- [ ] Production bank certificate/credentials and explicit LIVE authorization.
22 +- [ ] Controlled canary/live transfer and production rollback rehearsal.
23 +
24 +These items cannot be truthfully completed from repository access alone. No infrastructure purchase/provisioning, credential mutation, bank certification, or real-money transfer is performed without the required external access and explicit authorization.
docs/PRODUCTION_EXTERNAL_EVIDENCE.md new
+18
@@ -0,0 +1,18 @@
1 +# Production External Evidence Checklist
2 +
3 +Every item below must reference evidence from the real production environment before `LIVE` is permitted.
4 +
5 +| Control | Required evidence |
6 +|---|---|
7 +| Database | provisioned endpoint identifier, migration version, RLS cross-tenant integration result |
8 +| Identity | provider identifier, MFA enforcement result, session-policy result |
9 +| Secrets/KMS | secret-store/KMS identifier and rotation/access-policy verification; never secret values |
10 +| WAF/SIEM | enabled policy identifiers and test-event delivery evidence |
11 +| Alerts | successful delivery test to approved operational channel |
12 +| Recovery | timestamped restore drill, measured RPO/RTO, integrity verification |
13 +| Bank sandbox | bank/provider, protocol version, sandbox credential verification, E2E result |
14 +| Certification | bank-issued certification/reference evidence |
15 +| Bank production | certificate metadata/fingerprint and credential verification; never private key/secret |
16 +| Live authorization | explicit change approval tied to release/version |
17 +| Canary | controlled transaction evidence and reconciliation result |
18 +| Rollback | rehearsal evidence and recovery result |
scripts/verify-production-postgres.ps1 new
+7
@@ -0,0 +1,7 @@
1 +param([string]$DatabaseUrl=$env:DATABASE_URL)
2 +if(-not $DatabaseUrl){Write-Error 'DATABASE_URL is required for real PostgreSQL RLS integration proof'; exit 2}
3 +if(-not (Get-Command psql -ErrorAction SilentlyContinue)){Write-Error 'psql is required';exit 2}
4 +$env:PGOPTIONS='-c app.tenant_id=t1'
5 +psql $DatabaseUrl -v ON_ERROR_STOP=1 -f migrations/001_production_core.sql
6 +if($LASTEXITCODE -ne 0){exit $LASTEXITCODE}
7 +Write-Output 'Migration applied. Execute environment-specific cross-tenant fixture verification before recording production evidence.'
src/domain/golive/bank-activation.test.ts new
+2
@@ -0,0 +1,2 @@
1 +import {describe,expect,it} from 'vitest';import {BankActivation} from './bank-activation';
2 +describe('bank activation lifecycle',()=>{it('allows controlled disabled to sandbox to certified progression',()=>{const b=new BankActivation();b.toSandbox({sandboxCredentialsVerified:true});b.toCertified({certificationEvidence:true});expect(b.mode).toBe('CERTIFIED')});it('blocks live without explicit authorization and complete external evidence',()=>{const b=new BankActivation();b.toSandbox({sandboxCredentialsVerified:true});b.toCertified({certificationEvidence:true});expect(()=>b.toLive({explicitAuthorization:false,productionCredentialsVerified:true,certificateVerified:true})).toThrow('live activation blocked');expect(b.mode).toBe('CERTIFIED')});it('allows live only with all evidence',()=>{const b=new BankActivation();b.toSandbox({sandboxCredentialsVerified:true});b.toCertified({certificationEvidence:true});b.toLive({explicitAuthorization:true,productionCredentialsVerified:true,certificateVerified:true});expect(b.mode).toBe('LIVE')})});
src/domain/golive/bank-activation.ts new
+1
@@ -0,0 +1 @@
1 +export type BankMode='DISABLED'|'SANDBOX'|'CERTIFIED'|'LIVE';export class BankActivation{mode:BankMode='DISABLED';toSandbox(e:{sandboxCredentialsVerified:boolean}){if(this.mode!=='DISABLED'||!e.sandboxCredentialsVerified)throw new Error('sandbox activation blocked');this.mode='SANDBOX'}toCertified(e:{certificationEvidence:boolean}){if(this.mode!=='SANDBOX'||!e.certificationEvidence)throw new Error('certification blocked');this.mode='CERTIFIED'}toLive(e:{explicitAuthorization:boolean;productionCredentialsVerified:boolean;certificateVerified:boolean}){if(this.mode!=='CERTIFIED'||!e.explicitAuthorization||!e.productionCredentialsVerified||!e.certificateVerified)throw new Error('live activation blocked');this.mode='LIVE'}}
src/domain/golive/external-policies.test.ts new
+2
@@ -0,0 +1,2 @@
1 +import {describe,expect,it} from 'vitest';import {validateIdentityPolicy,validateRecoveryEvidence,validateSecurityOperations} from './external-policies';
2 +describe('external production policies',()=>{it('requires MFA and bounded sessions',()=>expect(validateIdentityPolicy({mfaRequired:true,sessionMinutes:30,providerVerified:true})).toEqual([]));it('rejects weak identity',()=>expect(validateIdentityPolicy({mfaRequired:false,sessionMinutes:1440,providerVerified:false})).toEqual(['identity-provider','mfa','session-policy']));it('requires proven restore within objectives',()=>expect(validateRecoveryEvidence({restoreSucceeded:true,rpoMinutes:10,rtoMinutes:45,maxRpoMinutes:15,maxRtoMinutes:60})).toEqual([]));it('requires WAF SIEM and alert delivery',()=>expect(validateSecurityOperations({waf:false,siem:true,alertDelivery:false})).toEqual(['waf','alert-delivery']))});
src/domain/golive/external-policies.ts new
+1
@@ -0,0 +1 @@
1 +export function validateIdentityPolicy(x:{mfaRequired:boolean;sessionMinutes:number;providerVerified:boolean}){const e:string[]=[];if(!x.providerVerified)e.push('identity-provider');if(!x.mfaRequired)e.push('mfa');if(x.sessionMinutes<=0||x.sessionMinutes>480)e.push('session-policy');return e}export function validateRecoveryEvidence(x:{restoreSucceeded:boolean;rpoMinutes:number;rtoMinutes:number;maxRpoMinutes:number;maxRtoMinutes:number}){const e:string[]=[];if(!x.restoreSucceeded)e.push('restore');if(x.rpoMinutes>x.maxRpoMinutes)e.push('rpo');if(x.rtoMinutes>x.maxRtoMinutes)e.push('rto');return e}export function validateSecurityOperations(x:{waf:boolean;siem:boolean;alertDelivery:boolean}){const e:string[]=[];if(!x.waf)e.push('waf');if(!x.siem)e.push('siem');if(!x.alertDelivery)e.push('alert-delivery');return e}
src/domain/golive/production-evidence.test.ts new
+2
@@ -0,0 +1,2 @@
1 +import {describe,expect,it} from 'vitest';import {evaluateProductionEvidence} from './production-evidence';
2 +describe('production evidence',()=>{const base={databaseRls:true,identityMfa:true,kms:true,observability:true,waf:true,siem:true,restoreDrill:true,bankCertified:true,explicitLiveAuthorization:true};it('passes only complete verified evidence',()=>expect(evaluateProductionEvidence(base)).toEqual({ready:true,missing:[]}));it('fails closed and lists missing evidence',()=>expect(evaluateProductionEvidence({...base,kms:false,bankCertified:false})).toEqual({ready:false,missing:['kms','bank-certified']}))});
src/domain/golive/production-evidence.ts new
+1
@@ -0,0 +1 @@
1 +export type ProductionEvidence={databaseRls:boolean;identityMfa:boolean;kms:boolean;observability:boolean;waf:boolean;siem:boolean;restoreDrill:boolean;bankCertified:boolean;explicitLiveAuthorization:boolean};export function evaluateProductionEvidence(e:ProductionEvidence){const checks:[keyof ProductionEvidence,string][]=[['databaseRls','database-rls'],['identityMfa','identity-mfa'],['kms','kms'],['observability','observability'],['waf','waf'],['siem','siem'],['restoreDrill','restore-drill'],['bankCertified','bank-certified'],['explicitLiveAuthorization','explicit-live-authorization']];const missing=checks.filter(([k])=>!e[k]).map(([,n])=>n);return{ready:missing.length===0,missing}}