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 and sensitive connection options, repository-source secrets, discovery host passwords, MFA secrets, identity-provider secrets (batched via encryptJsonFields()), AI provider API keys, AWS keys and session tokens, and AI extra header values. The AI settings API never returns these: it says whether a key is stored, and shows header values as [stored]. Values stored in the clear by an older release are encrypted when the server starts.

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: ENCRYPTION_KEY is required (32+ characters); without it the server refuses to start and names the missing value. There is no plaintext mode. Values stored before encryption was applied still read, and changing the key makes existing ciphertext unrecoverable.

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. Credential-bearing fields are redacted before any record is written, including the before/after values routes record: any field whose name refers to a password, passphrase, secret, token, API or access key, private key, credential, connection string or license key, in any casing and at any depth (for example new_password, sshPrivateKey, clientSecret, bindCredentials, awsSecretAccessKey), the value of any setting whose name refers to a secret, credentials embedded in connection URLs, and PEM private keys. The audit log is append-only, so live secrets never reach it.

{
  "id": "3f2a1b4c-…",
  "seq": 10432,
  "created_at": "2026-10-15T14:30:00.000Z",
  "user_email": "developer@company.com",
  "action": "UPDATE_SCRIPT",
  "entity_type": "script",
  "entity_id": "9b1e07d2-…",
  "old_values": { ... },
  "new_values": { ... },
  "ip_address": "192.168.1.100",
  "prev_hash": "…",
  "row_hash": "…"
}

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. The image carries only the license public key; the signing key never leaves Simcha.

Container & Datastore

Compliance Framework Mapping

SOC 2 (Type II)

CriterionSupporting control
CC6.1, Logical accessJWT authn, 4-role RBAC plus custom roles, license gating, optional TOTP MFA
CC6.2, ProvisioningAdmin-managed user creation and role assignment, recorded in the audit log; SSO provisioning
CC6.3, Access removalDeactivation, deletion and role changes apply on the user's next request; a password reset ends older sessions; JWT_SECRET rotation ends all sessions.
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, session lifetime set by JWT_EXPIRES_IN, 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, and per-user data export and erasure (/api/data-protection). Erasure removes the account and its sign-in details in one transaction; Audit Log entries stay sealed, as records kept for a legal obligation, until the audit retention period removes them
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.