Bootstrap EDEN: Fase 0 (arquitetura) e Fase 1 (monorepo + infra)
Fase 0 — descoberta e arquitetura:
- Inventário do projeto, glossário de domínio, arquitetura com bounded
contexts e topologia de containers, threat model inicial.
- 12 ADRs cobrindo modular monolith, topologia de containers (Postgres
isolado + eden-core/parceiros/assinante em containers e portas
distintos), auth/sessões, modelo de permissões, criptografia/segredos,
contrato first-class, stock ledger, separação billing/finance/fiscal,
outbox transacional, adapters SaperX e Focus NFe, e identidade
compartilhada entre as 3 apps.
- 14 subagentes e 7 skills especializados por domínio em .claude/.
- Hooks de segurança (PreToolUse/PostToolUse/Stop) testados via pipe.
Fase 1 — plataforma (em andamento):
- Monorepo pnpm workspaces + Turborepo: apps/{api,worker,core-web,
reseller-web,subscriber-web} + 9 packages compartilhados.
- apps/api: NestJS mínimo com /health/live e /health/ready (checando
Postgres real via @eden/database).
- 3 frontends Vite + React + TypeScript + Tailwind, com o favicon
oficial do EDEN.
- packages/database: migration baseline (node-pg-migrate) criando
roles/role_permissions/applications/users/user_applications/sessions/
audit_log — audit log append-only com hash-chain, testado ao vivo
(UPDATE/DELETE bloqueados pelo trigger).
- compose.yaml implementando a topologia da ADR-0002, validada de ponta
a ponta: os 6 containers sobem e ficam saudáveis com um único
`docker compose up`.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
10
.claude/skills/eden-security/references/audit.md
Normal file
10
.claude/skills/eden-security/references/audit.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# Audit conventions — EDEN
|
||||
|
||||
Minimum audited actions (Master Prompt §5.6): login/logout/MFA, user/role/permission changes, discount approval, contract changes, price changes, stock movement, serial/MAC/asset link-unlink, fiscal document issue/cancel, financial write-off/reversal, boleto/billing changes, timeclock period reopening, subscription actions, integration secret/config changes.
|
||||
|
||||
Rules:
|
||||
- Append-only, enforced at the database level (trigger rejecting UPDATE/DELETE outside an explicit, itself-audited escape hatch) — never rely on "the application just never calls UPDATE."
|
||||
- Order of events defined by a monotonic sequence (serial/bigserial), never by timestamp alone (timestamps can collide within a transaction — see the legacy signature audit chain's `seq` column).
|
||||
- Never write a raw secret into audit metadata, ever.
|
||||
- `super_admin`-equivalent bypasses authorization but never bypasses audit.
|
||||
- For hash-chained audit trails (e.g., signature envelopes): version the canonicalization algorithm explicitly (`hash_algorithm_version`) so a future bug fix doesn't retroactively invalidate old, correctly-recorded events — treat linkage failures as always-real tampering, content failures on outdated algorithm versions as a legacy warning, not a failure.
|
||||
@@ -0,0 +1,8 @@
|
||||
# Data classification — decide before writing a new column
|
||||
|
||||
Per Master Prompt §5.4. Three buckets, decide explicitly, never default to "encrypt everything":
|
||||
|
||||
1. **One-way hash**: passwords, refresh tokens, public tokens that never need recovery. Argon2id for passwords (ADR-0005); SHA-256/HMAC-SHA256 for tokens depending on entropy (see `encryption.md`).
|
||||
2. **Reversible field encryption (AES-256-GCM)**: anything the application must recover in plaintext to function — integration API keys/tokens (SaperX, Focus NFe, AI providers), device credentials (Control iD), gateway secrets. Root key never in the database; versioned.
|
||||
3. **Personal data (LGPD)**: minimize collection, access-control + audit + TLS + storage encryption by default; field-level encryption only for items the threat model flags as high-risk (not blanket).
|
||||
4. **Credit card**: never store CVV; tokenize via PSP; store only token/brand/last-4/non-sensitive metadata. No homegrown card vault.
|
||||
8
.claude/skills/eden-security/references/encryption.md
Normal file
8
.claude/skills/eden-security/references/encryption.md
Normal file
@@ -0,0 +1,8 @@
|
||||
# Encryption patterns — EDEN
|
||||
|
||||
See ADR-0005 for the full decision. Quick reference:
|
||||
|
||||
- **Reversible field encryption**: AES-256-GCM, random 96-bit IV per operation, auth tag verified on decrypt. Storage format: `{iv_b64}:{authTag_b64}:{ciphertext_b64}` in a single TEXT column (legacy-proven pattern from Control iD credential storage). Root key derived via SHA-256 of an env-provided secret, normalizing any-length input to 32 bytes. Every encrypted value also stores a `key_version` for rotation.
|
||||
- **OTP**: HMAC-SHA256 with a server secret (never plain SHA-256 — OTP space is only 10^6, needs secret-based rainbow-table resistance). 6 digits, 5-minute TTL, single use, max attempts with lockout, invalidate-on-new-request.
|
||||
- **Public link tokens** (client/reseller registration, signature invite): CSPRNG, ≥96 bits for registration tokens, 256 bits for signature invite tokens. Stored as SHA-256 hash only (plain hash sufficient given the token's own entropy — no HMAC needed here, unlike OTP).
|
||||
- **Passwords**: Argon2id, versioned parameters (see ADR-0005), re-hash on next successful login when parameters change.
|
||||
13
.claude/skills/eden-security/references/security-baseline.md
Normal file
13
.claude/skills/eden-security/references/security-baseline.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# Security baseline — every EDEN endpoint
|
||||
|
||||
Checklist (Master Prompt §12):
|
||||
- Security headers (helmet-equivalent) + adequate CSP.
|
||||
- CORS by allowlist per environment (legacy had none configured — deliberate improvement).
|
||||
- Server-side input validation, output encoding, parameterized queries only (never string-concat SQL).
|
||||
- File upload: real MIME validation, size limits, stored outside webroot, malware-scan hook point.
|
||||
- Rate limiting: by IP AND by identity/token for sensitive routes (never just one dimension — legacy pattern, keep it).
|
||||
- Anti-enumeration on auth flows (forgot-password always returns success regardless of whether the email exists).
|
||||
- Authorization resolved server-side from session — never trust `role`/`customer_id`/`reseller_id`/`legal_entity_id` from the client.
|
||||
- Mass-assignment protection (explicit field allowlist on every PATCH, mirroring the legacy pattern of CPF/CNPJ never being in the admin-PATCH allowlist).
|
||||
- SSRF prevention on anything that renders external content (PDF renderer must never navigate the network — `setContent` only, block all outgoing requests).
|
||||
- Request size limits, secure cookie/token handling, dependency scanning, secret scanning in CI.
|
||||
Reference in New Issue
Block a user