c_agri_trade/project_code/docs/runbooks/OPERATIONAL_RUNBOOK.md

6.0 KiB

Agriculture Trading Backoffice (ATB) — Operational Maintenance Runbook

Field Value
Product Agriculture Trading Backoffice (ATB)
Release Version v1.0.0 (Production / UAT Release)
Governed Standard SEI-CMMI Level 3 (UP-AI v1.5 Standard Enterprise Tier)
Document Path 04_generated_documentation/08_review_ready_baselines/02_handover_package/OPERATIONAL_RUNBOOK.md
Audience Platform Operations, Security Officers, Database Administrators

1. Tenant Lifecycle Administration

ATB enforces a strict multi-tenant control plane. Tenants represent autonomous trading firms with segregated data boundaries enforced at the PostgreSQL engine layer via Row-Level Security.

1.1 Tenant Provisioning Procedure

Tenants are provisioned via the Platform Administration API (/api/tenants):

  1. Submit Provisioning Request:
    curl -X POST http://localhost:8000/api/tenants \
      -H "Authorization: Bearer $PLATFORM_ADMIN_TOKEN" \
      -H "Content-Type: application/json" \
      -d '{
        "name": "Kisan Agri Corp",
        "slug": "kisan-agri",
        "gstin": "27AABCK1234F1Z5",
        "pan": "AABCK1234F",
        "admin_email": "admin@kisanagri.com"
      }'
    
  2. Post-Provisioning Verification: The system creates the tenant in state ACTIVE, assigns a unique UUID, initializes tenant operating policy defaults, and registers the initial Tenant Administrator user membership.

1.2 Tenant Suspension & Reactivation

When a tenant firm is suspended (e.g. non-payment, compliance freeze), access is immediately cut off at the middleware layer:

  • Suspend Tenant: PATCH /api/tenants/{tenant_id}/status with {"status": "SUSPENDED", "reason": "Audit freeze"}.
  • Immediate Effect: All subsequent requests carrying this tenant_id receive 403 TENANT_SUSPENDED.
  • Reactivate Tenant: PATCH /api/tenants/{tenant_id}/status with {"status": "ACTIVE"} restores immediate operational capabilities.

2. User & RBAC Membership Management

Users authenticate via Keycloak OIDC, and their permissions within an active tenant are governed by the tenant membership registry.

2.1 Role Matrix & Segregation of Duties

The platform enforces 11 distinct operational roles:

  1. Tenant Administrator: Tenant settings, user invitations, role assignments.
  2. Mandi Buyer: Live mandi auction arrivals, bidding, sauda purchase contract creation.
  3. Purchase Manager: Sauda contract approval, supplier limits, rate verification.
  4. Yard Supervisor: Weighbridge tare/gross weighment, vehicle gate-in/gate-out passes.
  5. Quality Officer: Lab assay moisture/admixture testing, lot grading, lab rejection slips.
  6. Sales Executive: Customer inquiry, sales order creation, dispatch requests.
  7. Sales Manager: Customer credit approvals, price band approvals, bilty release.
  8. Logistics Coordinator: Transporter fleet registry, truck assignment, bilty tracking.
  9. Accounts Executive: Invoicing, payments, supplier bills, mandi cess expense ledgers.
  10. Partner / MD: Executive snapshot dashboard, high-value overrides, financial audits.
  11. System Administrator: Platform health, break-glass security logs, tenant onboarding.

3. Privileged Support Access & Break-Glass Protocol (UC-020)

To protect confidential customer trading margins and farmer payment records, platform engineers have zero standing access to tenant business ledgers.

3.1 Standard Support Access (Dual-Authorization)

  1. Tenant Request: Tenant Administrator creates a support ticket: POST /api/support/tickets.
  2. Support Claim: Support engineer requests read-only session: POST /api/support/sessions/request.
  3. Dual Approval Rule: The requester cannot self-approve. A designated Tenant Administrator or Security Officer must approve: POST /api/support/sessions/{id}/approve.
  4. Time Bounds: Session token expires automatically after 60 minutes.

3.2 Emergency Break-Glass Procedure

In high-severity production outage scenarios (P1 incidents):

  1. Platform Security Officer issues emergency bypass:
    POST /api/support/break-glass
    {
      "tenant_id": "<UUID>",
      "incident_ticket": "INC-88910",
      "justification": "Database index corruption affecting mandi yard auction",
      "duration_minutes": 45
    }
    
  2. System Enforcement:
    • Duration is strictly capped at 120 minutes.
    • Emits high-severity SECURITY_ALERT to all tenant administrators within 15 minutes.
    • Records an immutable audit log entry in audit_logs with before/after state captures.

4. Routine Database Maintenance & Backups

4.1 Daily Automated Backup Script

Run daily at 02:00 UTC via cron:

#!/bin/bash
BACKUP_DIR="/var/backups/atb"
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
mkdir -p "$BACKUP_DIR"

docker exec atb-prod-postgres pg_dump -U atb -d atb -F c -b -v -f "/tmp/atb_backup_${TIMESTAMP}.dump"
docker cp atb-prod-postgres:/tmp/atb_backup_${TIMESTAMP}.dump "${BACKUP_DIR}/"
docker exec atb-prod-postgres rm "/tmp/atb_backup_${TIMESTAMP}.dump"

# Retain backups for 35 days
find "$BACKUP_DIR" -type f -name "atb_backup_*.dump" -mtime +35 -delete

4.2 Database Health & VACUUM Maintenance

Execute weekly to maintain PostgreSQL query performance:

docker exec -it atb-prod-postgres psql -U atb -d atb -c "VACUUM (ANALYZE, VERBOSE);"

5. Transactional Outbox & Poison-Queue Handling (AMB-011)

The platform implements an asynchronous Outbox Pattern (event_outbox table) for alerts and downstream notifications.

5.1 Poison Event Triage

If an external webhook or SMS gateway fails repeatedly:

  1. After 5 retries with exponential backoff, event status transitions to POISON.
  2. View poisoned events:
    SELECT event_id, event_type, tenant_id, retry_count, last_error 
    FROM event_outbox 
    WHERE status = 'POISON';
    
  3. Manual Replay: After resolving the underlying gateway failure, reset the event:
    UPDATE event_outbox 
    SET status = 'PENDING', retry_count = 0, next_retry_at = NOW() 
    WHERE event_id = '<EVENT_UUID>';