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)
| Parameter | Value |
|---|---|
| Cipher | AES-256-GCM (authenticated encryption, confidentiality + integrity) |
| Key derivation | PBKDF2(ENCRYPTION_KEY, random 32-byte salt, 100,000 iterations, SHA-512) |
| Wire format | enc: + base64(salt[32] ‖ iv[16] ‖ tag[16] ‖ ciphertext) |
| Applied to | Connection 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.
- Append-only enforcement: triggers reject
UPDATEandDELETEon the audit table unless the transaction sets the maintenance flag (app.audit_maintenance), which the app sets only in the retention purge. The application cannot mutate a sealed record; the only sanctioned deletion is the controlled retention purge. - Sealing occurs in the database, not the application layer, a compromised or malicious app process cannot forge, reorder, or backdate the chain.
- Verification:
GET /api/db-devops/audit/integritywalks the whole chain and returns{ valid, brokenSeq, total }.valid: falseplusbrokenSeqpinpoints the first record whose hash no longer reconciles, including tampering performed by a database superuser editing the table directly.
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.
- Kept until purged: an administrator removes the entries older than N days with
DELETE /api/db-devops/audit/cleanup?days=N; nothing is removed on a schedule. - Purge mechanism: a privileged, itself-audited database function removes only the oldest records, the tail of the chain, so the surviving chain stays internally verifiable end-to-end. Ad-hoc
DELETEis refused by the append-only triggers. - Archival: export the tail to S3 / Azure Blob / a log platform before purge for long-horizon retention.
Production Hardening
Network
- TLS 1.2+ at the edge; TLS 1.0/1.1 disabled; trusted-CA certs; the proxy forwards
X-Forwarded-Proto: httpsso the app sends HSTS. - App and datastore in private subnets; egress via NAT only to what the app reaches: the databases you manage, repo sources, the AI provider, the identity provider, the mail relay or SES, alert webhooks, audit stream receivers and the license service, as configured.
- Security groups: inbound 80/443 to the edge only; app→Postgres on 5432; deny-all otherwise.
- Prefer VPN / private-link for internal-only deployments to remove public exposure entirely.
Secrets
| Secret | Store | Rotation |
|---|---|---|
JWT_SECRET | Secrets Manager / Key Vault / K8s Secret | Annually or on suspicion |
ENCRYPTION_KEY | Same | Requires re-encryption tooling; treat rotation as a migration, not a swap |
| DevOps DB password | Same | Quarterly |
| Repo/cloud tokens | Encrypted 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
- Non-root runtime user; minimal (Alpine) base; scan and block critical/high CVEs; pin immutable tags;
readOnlyRootFilesystemwith writable mounts scoped to/tmpand logs. - Dedicated least-privilege Postgres role that owns the metadata database (the migrations create tables, functions, triggers and the
pgcryptoextension; no SUPERUSER/CREATEDB/CREATEROLE);sslmode=require|verify-full; storage encryption on; aCONNECTION LIMITto bound pool exhaustion.
Compliance Framework Mapping
SOC 2 (Type II)
| Criterion | Supporting control |
|---|---|
| CC6.1, Logical access | JWT authn, 4-role RBAC plus custom roles, license gating, optional TOTP MFA |
| CC6.2, Provisioning | Admin-managed user creation and role assignment, recorded in the audit log; SSO provisioning |
| CC6.3, Access removal | Deactivation, 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, Monitoring | Health endpoints, structured Pino logging, sealed audit chain |
| CC7.2, Anomaly detection | Rate limiting, failed-login capture, SecurityAlertService |
| CC8.1, Change management | Approval workflows, script versioning, immutable execution records |
HIPAA (164.312)
| Safeguard | Supporting control |
|---|---|
| (a) Access control | Unique identities, RBAC, session lifetime set by JWT_EXPIRES_IN, MFA |
| (b) Audit controls | Tamper-evident hash-chained trail with cryptographic integrity verification |
| (c) Integrity | Two-person approval gate; GCM-authenticated at-rest storage |
| (e) Transmission security | TLS in transit end-to-end |
PCI DSS
| Requirement | Supporting control |
|---|---|
| Req 2, No defaults | Fail-loud on unset JWT_SECRET/ENCRYPTION_KEY; no shipped credentials |
| Req 7, Restrict access | Least-privilege RBAC |
| Req 8, Identify users | Unique accounts, bcrypt(12) + JWT + MFA |
| Req 10, Track access | Sealed, integrity-verifiable audit chain with redaction |
| Req 11, Test security | Rate limiting, CORS allowlist, health probes |
GDPR
| Principle | Supporting control |
|---|---|
| Data minimization | Local accounts store only email, name, role |
| Accountability | Full who/what/when audit trail |
| Right to erasure | Admin 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 design | bcrypt 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.