Tema
Fintrixs Security Architecture
Overview
Este documento describe la arquitectura de seguridad implementada en la pasarela de pagos Fintrixs, diseñada para cumplir con los estándares PCI DSS y las mejores prácticas de seguridad en la industria de pagos.
Índice
- Principios de Seguridad
- Capas de Seguridad
- Autenticación y Autorización
- Tokenización
- Encriptación
- Auditoría y Logging
- Seguridad de Red
- Gestión de Secretos
Principios de Seguridad
Defense in Depth
Múltiples capas de seguridad para proteger los datos sensibles:
Least Privilege
- Cada microservicio tiene acceso solo a los datos que necesita
- Roles de base de datos específicos por servicio
- Row Level Security (RLS) para aislamiento multi-tenant
Zero Trust
- Autenticación en cada capa
- No confiar en la red interna
- Verificar siempre la identidad del servicio
Capas de Seguridad
1. API Gateway (Kong)
yaml
Funciones:
- Rate Limiting
- JWT/API Key Authentication
- IP Restriction
- Request/Response Transformation
- TLS Termination
- CORS ManagementConfiguración: infra/kong/kong.yaml
2. Service Mesh (Interno)
yaml
Funciones:
- mTLS entre servicios
- Service Discovery
- Circuit Breaker
- Load Balancing3. Application Layer
yaml
Funciones:
- Input Validation (DTOs)
- Output Sanitization
- Business Logic Authorization
- Structured Logging4. Database Layer
yaml
Funciones:
- Row Level Security (RLS)
- Column Encryption
- Audit Triggers
- Connection PoolingAutenticación y Autorización
API Authentication
| Método | Uso | Implementación |
|---|---|---|
| JWT | Dashboard, Apps | RS256 con rotación de keys |
| API Key | Servidor a Servidor | SHA256 hash almacenado |
| mTLS | Servicios Internos | Certificados PKI |
Flujo de Autenticación
Database Roles
sql
-- Roles definidos en db/payments_db/core/migrations/005_create_rls_roles.sql
api_user → Schema: payments_api (SELECT, INSERT)
core_user → Schema: payments_core (FULL)
vault_user → Schema: payments_vault (tokenize/detokenize only)Tokenización
Arquitectura
Componentes:
apps/tokenization-service/- Servicio de tokenizacióndb/payments_db/vault/- Schema de vault encriptado
Documentación detallada: TOKENIZATION_FLOW.md
Encriptación
En Tránsito
| Conexión | Protocolo | Versión Mínima |
|---|---|---|
| Cliente → API | TLS | 1.2 |
| Servicio → Servicio | mTLS | 1.2 |
| Servicio → Database | TLS | 1.2 |
En Reposo
| Dato | Algoritmo | Key Management |
|---|---|---|
| PAN Tokenizado | AES-256-GCM | HashiCorp Vault |
| Passwords | Argon2id | N/A |
| API Keys | SHA256 | N/A |
| Backups | AES-256 | AWS KMS |
Key Rotation
yaml
Frecuencia:
- Master Keys: Anual
- Data Keys: Mensual
- JWT Keys: Semanal
- Session Keys: Por sesiónAuditoría y Logging
Audit Log Schema
sql
-- db/payments_db/core/migrations/006_create_audit_triggers.sql
audit_log:
- event_id
- event_type (INSERT, UPDATE, DELETE, SELECT, LOGIN)
- schema_name, table_name, record_id
- old_values, new_values (masked)
- user_id, session_id
- client_ip, service_name
- timestamp (with timezone)
- sensitivity_levelLog Levels
| Level | Uso | Retención |
|---|---|---|
| DEBUG | Desarrollo | 1 día |
| INFO | Operacional | 7 días |
| WARN | Alertas | 30 días |
| ERROR | Incidentes | 90 días |
| AUDIT | Cumplimiento | 1 año |
Sensitive Data Masking
typescript
// packages/logging/src/logger.service.ts
const SENSITIVE_FIELDS = [
'card_number', 'pan', 'cvv', 'cvc',
'password', 'secret', 'token', 'key',
'ssn', 'tax_id', 'account_number'
];
// Auto-redacted: "card_number": "[REDACTED]"Seguridad de Red
Network Segmentation
Firewall Rules
yaml
DMZ:
- Inbound: 443 (HTTPS only)
- Outbound: App Zone ports
App Zone:
- Inbound: DMZ only
- Outbound: Data Zone, External APIs
Data Zone:
- Inbound: App Zone only
- Outbound: NoneGestión de Secretos
HashiCorp Vault (Recomendado)
yaml
Secretos Almacenados:
- Database credentials
- API keys
- Encryption keys
- JWT signing keys
- Third-party credentialsKubernetes Secrets (Alternativa)
yaml
# Encriptados con SOPS/Sealed Secrets
apiVersion: v1
kind: Secret
metadata:
name: fintrix-secrets
type: Opaque
data:
DATABASE_PASSWORD: <base64-encrypted>
ENCRYPTION_KEY: <base64-encrypted>Environment Variables
bash
# .env (desarrollo local)
# NUNCA en producción
DATABASE_URL=postgresql://...
ENCRYPTION_KEY=dev-only-key
JWT_SECRET=dev-secretCompliance Checklist
PCI DSS Requirements
| Req | Descripción | Estado | Implementación |
|---|---|---|---|
| 1 | Firewall | ✅ | Kong, Network Policies |
| 2 | No defaults | ✅ | Custom configs |
| 3 | Protect stored data | ✅ | Tokenization, Encryption |
| 4 | Encrypt transmission | ✅ | TLS 1.2+ |
| 5 | Anti-virus | ✅ | Container scanning |
| 6 | Secure systems | ✅ | Hardened images |
| 7 | Restrict access | ✅ | RBAC, RLS |
| 8 | Unique IDs | ✅ | JWT, API Keys |
| 9 | Physical access | ✅ | Cloud provider |
| 10 | Track access | ✅ | Audit logs |
| 11 | Test security | ⏳ | Penetration testing |
| 12 | Security policy | ✅ | This documentation |
Documentación detallada: PCI_DSS_CONTROLS.md
Incident Response
Severity Levels
| Level | Descripción | Response Time |
|---|---|---|
| P1 | Data breach | 15 min |
| P2 | Service down | 30 min |
| P3 | Security alert | 2 hours |
| P4 | Minor issue | 24 hours |
Response Procedure
- Detect - Alerting (Prometheus, PagerDuty)
- Contain - Isolate affected systems
- Investigate - Audit logs analysis
- Remediate - Fix and patch
- Report - Compliance notification if required
