Best Practices, Audit & Compliance

Production hardening guidance, the at-rest encryption scheme, the tamper-evident audit trail, and framework mappings for teams under SOC 2 / HIPAA / PCI / GDPR obligations.

Encryption at Rest (EncryptionService)

ParameterValue
CipherAES-256-GCM (authenticated encryption, confidentiality + integrity)
Key derivationPBKDF2(ENCRYPTION_KEY, random 32-byte salt, 100,000 iterations, SHA-512)
Wire formatenc: + base64(salt[32] ‖ iv[16] ‖ tag[16] ‖ ciphertext)
Applied toConnection passwords, MFA seeds, sensitive settings (batched via encryptJsonFields())

Per-record salt means every ciphertext derives an independent subkey, a single leaked derived key does not generalize. The GCM tag authenticates each record; tampering fails decryption rather than yielding garbage plaintext. The prefix makes encrypted values self-identifying, enabling transparent migration and mixed-state reads. Fail-loud invariant: with ENCRYPTION_KEY unset the service silently degrades to plaintext with only a warning, CI aside, an unset key in any real environment is a critical misconfiguration.

Audit Middleware & Redaction

auditMiddleware is mounted globally and records every state-changing verb (POST/PUT/PATCH/DELETE) plus login, approval, and execution events; read-only queries are not logged. Entity IDs are derived from the URL path UUID or the response body. Sensitive fields, password, token, secret, apiKey, mfaToken, and peers, are redacted before the record is written, so before/after diffs never persist live secrets.

{
  "id": 12345,
  "timestamp": "2025-01-15T14:30:00.000Z",
  "userEmail": "developer@company.com",
  "action": "script.execute",
  "entityType": "script",
  "entityId": 42,
  "oldValues": { ... },
  "newValues": { ... },
  "ipAddress": "192.168.1.100",
  "success": true
}

Immutable, Tamper-Evident Audit Trail

The trail is append-only and cryptographically sealed by the database. On insert, a trigger assigns a monotonic sequence number, links the row to the hash of its predecessor, and stores a SHA-256 over the record contents concatenated with that prior hash. Each hash therefore depends on the entire prefix of the chain: any modification, deletion, reorder, or back-dated insertion of a historical record invalidates every subsequent hash and is detectable.

Honest caveat: stock PostgreSQL cannot make a table physically unwritable to a superuser. This design does not claim to prevent superuser writes; it makes any such write cryptographically detectable and blocks every ordinary mutation path. Where hardware-enforced immutability is mandated, target a ledger-backed or WORM store (append-only object storage, or a managed ledger database) behind the same interface.

Retention

Records live in the DevOps Postgres database; retention is the only sanctioned removal path.

Production Hardening

Network

Secrets

SecretStoreRotation
JWT_SECRETSecrets Manager / Key Vault / K8s SecretAnnually or on suspicion
ENCRYPTION_KEYSameRequires re-encryption tooling; treat rotation as a migration, not a swap
DevOps DB passwordSameQuarterly
Repo/cloud tokensEncrypted in-DB (automatic)Per provider policy

Never place secrets in source, committed .env, image layers, or logs. Note that keys/license-private.pem is currently committed to the repo, a tracked debt item; inject it from a secrets manager for real signing.

Container & Datastore

Compliance Framework Mapping

SOC 2 (Type II)

CriterionSupporting control
CC6.1, Logical accessJWT authn, 5-role RBAC, license-tier gating, optional TOTP MFA
CC6.2, ProvisioningAdmin-managed user creation and role assignment; SSO provisioning (Enterprise)
CC6.3, Access removalDeactivation blocks new logins; JWT_SECRET rotation forces global revocation. Per-token revocation is eventual, bounded by the 8h lifetime.
CC7.1, MonitoringHealth endpoints, structured Pino logging, sealed audit chain
CC7.2, Anomaly detectionRate limiting, failed-login capture, SecurityAlertService
CC8.1, Change managementApproval workflows, script versioning, immutable execution records

HIPAA (164.312)

SafeguardSupporting control
(a) Access controlUnique identities, RBAC, 8h token expiry, MFA
(b) Audit controlsTamper-evident hash-chained trail with cryptographic integrity verification
(c) IntegrityTwo-person approval gate; GCM-authenticated at-rest storage
(e) Transmission securityTLS in transit end-to-end

PCI DSS

RequirementSupporting control
Req 2, No defaultsFail-loud on unset JWT_SECRET/ENCRYPTION_KEY; no shipped credentials
Req 7, Restrict accessLeast-privilege RBAC
Req 8, Identify usersUnique accounts, bcrypt(12) + JWT + MFA
Req 10, Track accessSealed, integrity-verifiable audit chain with redaction
Req 11, Test securityRate limiting, CORS allowlist, health probes

GDPR

PrincipleSupporting control
Data minimizationLocal accounts store only email, name, role
AccountabilityFull who/what/when audit trail
Right to erasureAdmin deactivation/deletion of accounts
Protection by designbcrypt hashing, AES-256-GCM at rest, TLS in transit

Scope note: these controls support compliance; they do not constitute it. Certification depends on your full stack, organizational policy, physical and vendor controls, and evidence collection beyond this application. Engage your auditor for an authoritative assessment.