release: v0.6.1
This commit is contained in:
commit
877eef7f07
118 files changed
+46315
No files matched your search
@@ -0,0 +1,814 @@
|
||||
# Deploy com Docker
|
||||
|
||||
Guia de deploy do Evolution GO usando Docker, Docker Compose, Swarm e Kubernetes.
|
||||
|
||||
## Índice
|
||||
|
||||
- [Visão Geral](#visão-geral)
|
||||
- [Deploy com Docker Compose](#deploy-com-docker-compose)
|
||||
- [Deploy com Docker Swarm](#deploy-com-docker-swarm)
|
||||
- [Deploy com Kubernetes](#deploy-com-kubernetes)
|
||||
- [Otimização e Gestão](#otimização-e-gestão)
|
||||
- [Troubleshooting](#troubleshooting)
|
||||
|
||||
---
|
||||
|
||||
## Visão Geral
|
||||
|
||||
### Estratégias de Deploy
|
||||
|
||||
| Estratégia | Uso Recomendado | Complexidade | Escalabilidade |
|
||||
|------------|-----------------|--------------|----------------|
|
||||
| **Docker Compose** | Desenvolvimento, testes, deploys pequenos | Baixa | Limitada (single-host) |
|
||||
| **Docker Swarm** | Produção pequena/média, HA | Média | Boa (multi-host) |
|
||||
| **Kubernetes** | Produção enterprise, orquestração avançada | Alta | Excelente |
|
||||
|
||||
### Arquitetura de Componentes
|
||||
|
||||
```
|
||||
┌─────────────────────────────────────────────────────────────────┐
|
||||
│ EVOLUTION GO STACK │
|
||||
├─────────────────────────────────────────────────────────────────┤
|
||||
│ │
|
||||
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │
|
||||
│ │ Evolution GO │◄────►│ PostgreSQL │ │ RabbitMQ │ │
|
||||
│ │ (API) │ │ (Auth DB) │ │ (Events) │ │
|
||||
│ │ Port: 4000 │ │ (Users DB) │ │ Port: 5672 │ │
|
||||
│ └──────┬───────┘ └──────────────┘ └──────────────┘ │
|
||||
│ │ │
|
||||
│ │ ┌──────────────┐ ┌──────────────┐ │
|
||||
│ └─────────────►│ MinIO │ │ NATS │ │
|
||||
│ │ (Media) │ │ (Optional) │ │
|
||||
│ │ Port: 9000 │ │ Port: 4222 │ │
|
||||
│ └──────────────┘ └──────────────┘ │
|
||||
│ │
|
||||
└─────────────────────────────────────────────────────────────────┘
|
||||
```
|
||||
|
||||
### Imagem Docker
|
||||
|
||||
- **Registry**: `evoapicloud/evolution-go`
|
||||
- **Tags**: `latest`, `v1.x.x`
|
||||
- **Base**: Alpine Linux 3.19.1
|
||||
- **Tamanho**: ~50MB (compactada)
|
||||
- **Arquiteturas**: amd64, arm64
|
||||
|
||||
---
|
||||
|
||||
## Deploy com Docker Compose
|
||||
|
||||
### Setup Básico
|
||||
|
||||
Configuração mínima com Evolution GO + PostgreSQL.
|
||||
|
||||
#### docker-compose.yml
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
evolution-go:
|
||||
image: evoapicloud/evolution-go:latest
|
||||
container_name: evolution-go
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "4000:4000"
|
||||
environment:
|
||||
SERVER_PORT: 4000
|
||||
CLIENT_NAME: "evolution"
|
||||
GLOBAL_API_KEY: "SUBSTITUA-POR-UUID-FORTE"
|
||||
|
||||
POSTGRES_AUTH_DB: "postgresql://postgres:postgres@postgres:5432/evogo_auth?sslmode=disable"
|
||||
POSTGRES_USERS_DB: "postgresql://postgres:postgres@postgres:5432/evogo_users?sslmode=disable"
|
||||
DATABASE_SAVE_MESSAGES: "false"
|
||||
|
||||
WADEBUG: "INFO"
|
||||
LOGTYPE: "console"
|
||||
CONNECT_ON_STARTUP: "false"
|
||||
WEBHOOKFILES: "true"
|
||||
|
||||
volumes:
|
||||
- evolution_data:/app/dbdata
|
||||
- evolution_logs:/app/logs
|
||||
networks:
|
||||
- evolution_network
|
||||
depends_on:
|
||||
- postgres
|
||||
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
container_name: postgres
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: postgres
|
||||
ports:
|
||||
- "5432:5432"
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
|
||||
networks:
|
||||
- evolution_network
|
||||
|
||||
volumes:
|
||||
evolution_data:
|
||||
evolution_logs:
|
||||
postgres_data:
|
||||
|
||||
networks:
|
||||
evolution_network:
|
||||
driver: bridge
|
||||
```
|
||||
|
||||
#### init-db.sql
|
||||
|
||||
```sql
|
||||
CREATE DATABASE evogo_auth;
|
||||
CREATE DATABASE evogo_users;
|
||||
SELECT 'Databases criados com sucesso!' as message;
|
||||
```
|
||||
|
||||
#### Deploy
|
||||
|
||||
```bash
|
||||
# Gerar API Key
|
||||
uuidgen
|
||||
|
||||
# Editar docker-compose.yml e inserir API Key
|
||||
|
||||
# Iniciar
|
||||
docker-compose up -d
|
||||
|
||||
# Verificar
|
||||
docker-compose logs -f evolution-go
|
||||
curl http://localhost:4000/server/ok
|
||||
```
|
||||
|
||||
### Setup Completo
|
||||
|
||||
Incluindo RabbitMQ, MinIO e NATS.
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
evolution-go:
|
||||
image: evoapicloud/evolution-go:latest
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "4000:4000"
|
||||
environment:
|
||||
SERVER_PORT: 4000
|
||||
GLOBAL_API_KEY: "SUA-CHAVE-AQUI"
|
||||
|
||||
POSTGRES_AUTH_DB: "postgresql://postgres:senha@postgres:5432/evogo_auth?sslmode=disable"
|
||||
POSTGRES_USERS_DB: "postgresql://postgres:senha@postgres:5432/evogo_users?sslmode=disable"
|
||||
DATABASE_SAVE_MESSAGES: "true"
|
||||
|
||||
AMQP_URL: "amqp://admin:admin@rabbitmq:5672/default"
|
||||
AMQP_GLOBAL_ENABLED: "true"
|
||||
AMQP_GLOBAL_EVENTS: "messages.upsert,messages.update,connection.update"
|
||||
|
||||
MINIO_ENABLED: "true"
|
||||
MINIO_ENDPOINT: "minio:9000"
|
||||
MINIO_ACCESS_KEY: "minioadmin"
|
||||
MINIO_SECRET_KEY: "minioadmin"
|
||||
MINIO_BUCKET: "evolution-media"
|
||||
MINIO_USE_SSL: "false"
|
||||
|
||||
volumes:
|
||||
- evolution_data:/app/dbdata
|
||||
- evolution_logs:/app/logs
|
||||
depends_on:
|
||||
- postgres
|
||||
- rabbitmq
|
||||
- minio
|
||||
|
||||
postgres:
|
||||
image: postgres:15-alpine
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: senha
|
||||
POSTGRES_DB: postgres
|
||||
volumes:
|
||||
- postgres_data:/var/lib/postgresql/data
|
||||
- ./init-db.sql:/docker-entrypoint-initdb.d/init-db.sql
|
||||
|
||||
rabbitmq:
|
||||
image: rabbitmq:3-management-alpine
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
RABBITMQ_DEFAULT_USER: admin
|
||||
RABBITMQ_DEFAULT_PASS: admin
|
||||
RABBITMQ_DEFAULT_VHOST: default
|
||||
ports:
|
||||
- "5672:5672"
|
||||
- "15672:15672"
|
||||
volumes:
|
||||
- rabbitmq_data:/var/lib/rabbitmq
|
||||
|
||||
minio:
|
||||
image: minio/minio:latest
|
||||
restart: unless-stopped
|
||||
command: server /data --console-address ":9001"
|
||||
environment:
|
||||
MINIO_ROOT_USER: minioadmin
|
||||
MINIO_ROOT_PASSWORD: minioadmin
|
||||
ports:
|
||||
- "9000:9000"
|
||||
- "9001:9001"
|
||||
volumes:
|
||||
- minio_data:/data
|
||||
|
||||
nats:
|
||||
image: nats:2-alpine
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "4222:4222"
|
||||
- "8222:8222"
|
||||
|
||||
volumes:
|
||||
evolution_data:
|
||||
evolution_logs:
|
||||
postgres_data:
|
||||
rabbitmq_data:
|
||||
minio_data:
|
||||
```
|
||||
|
||||
**Acessos:**
|
||||
- Evolution GO: http://localhost:4000
|
||||
- Swagger: http://localhost:4000/swagger/index.html
|
||||
- RabbitMQ: http://localhost:15672 (admin/admin)
|
||||
- MinIO: http://localhost:9001 (minioadmin/minioadmin)
|
||||
|
||||
### Configurações Avançadas
|
||||
|
||||
#### Arquivo .env
|
||||
|
||||
```bash
|
||||
# .env
|
||||
EVOLUTION_VERSION=latest
|
||||
POSTGRES_VERSION=15-alpine
|
||||
|
||||
# Portas
|
||||
EVOLUTION_PORT=4000
|
||||
POSTGRES_PORT=5432
|
||||
|
||||
# Credenciais
|
||||
POSTGRES_USER=postgres
|
||||
POSTGRES_PASSWORD=senha_forte
|
||||
RABBITMQ_USER=admin
|
||||
RABBITMQ_PASS=senha_forte
|
||||
|
||||
# Evolution GO
|
||||
GLOBAL_API_KEY=df16caad-d0d2-41b2-bec5-75b90048a0db
|
||||
CLIENT_NAME=evolution-prod
|
||||
```
|
||||
|
||||
Referência no compose:
|
||||
```yaml
|
||||
services:
|
||||
evolution-go:
|
||||
image: evoapicloud/evolution-go:${EVOLUTION_VERSION:-latest}
|
||||
ports:
|
||||
- "${EVOLUTION_PORT:-4000}:4000"
|
||||
environment:
|
||||
GLOBAL_API_KEY: "${GLOBAL_API_KEY}"
|
||||
```
|
||||
|
||||
#### Health Checks
|
||||
|
||||
```yaml
|
||||
services:
|
||||
evolution-go:
|
||||
healthcheck:
|
||||
test: ["CMD", "wget", "-q", "--spider", "http://localhost:4000/server/ok"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
start_period: 40s
|
||||
|
||||
postgres:
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
||||
interval: 10s
|
||||
timeout: 5s
|
||||
retries: 5
|
||||
|
||||
rabbitmq:
|
||||
healthcheck:
|
||||
test: ["CMD", "rabbitmq-diagnostics", "ping"]
|
||||
interval: 30s
|
||||
timeout: 10s
|
||||
retries: 3
|
||||
```
|
||||
|
||||
#### Resource Limits
|
||||
|
||||
```yaml
|
||||
services:
|
||||
evolution-go:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '2.0'
|
||||
memory: 2G
|
||||
reservations:
|
||||
cpus: '0.5'
|
||||
memory: 512M
|
||||
|
||||
postgres:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '1.0'
|
||||
memory: 1G
|
||||
reservations:
|
||||
cpus: '0.25'
|
||||
memory: 256M
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Deploy com Docker Swarm
|
||||
|
||||
### Inicialização
|
||||
|
||||
```bash
|
||||
# Manager node
|
||||
docker swarm init --advertise-addr 192.168.1.10
|
||||
|
||||
# Worker nodes
|
||||
docker swarm join --token SWMTKN-1-xxxxx 192.168.1.10:2377
|
||||
|
||||
# Verificar cluster
|
||||
docker node ls
|
||||
```
|
||||
|
||||
### Preparação
|
||||
|
||||
```bash
|
||||
# Volumes
|
||||
docker volume create evolution_go_data
|
||||
docker volume create evolution_go_logs
|
||||
|
||||
# Rede
|
||||
docker network create --driver overlay network_public
|
||||
```
|
||||
|
||||
### docker-compose.swarm.yml
|
||||
|
||||
```yaml
|
||||
version: '3.8'
|
||||
|
||||
services:
|
||||
evolution_go:
|
||||
image: evoapicloud/evolution-go:latest
|
||||
networks:
|
||||
- network_public
|
||||
environment:
|
||||
SERVER_PORT: 4000
|
||||
GLOBAL_API_KEY: "sua-chave-api"
|
||||
POSTGRES_AUTH_DB: "postgresql://user:pass@postgres:5432/evogo_auth"
|
||||
POSTGRES_USERS_DB: "postgresql://user:pass@postgres:5432/evogo_users"
|
||||
|
||||
volumes:
|
||||
- evolution_go_data:/app/dbdata
|
||||
- evolution_go_logs:/app/logs
|
||||
|
||||
deploy:
|
||||
replicas: 3
|
||||
placement:
|
||||
constraints:
|
||||
- node.role == worker
|
||||
restart_policy:
|
||||
condition: on-failure
|
||||
delay: 5s
|
||||
max_attempts: 3
|
||||
window: 120s
|
||||
update_config:
|
||||
parallelism: 1
|
||||
delay: 10s
|
||||
failure_action: rollback
|
||||
order: start-first
|
||||
rollback_config:
|
||||
parallelism: 1
|
||||
delay: 5s
|
||||
labels:
|
||||
- traefik.enable=true
|
||||
- traefik.http.routers.evolution.rule=Host(`evolution.domain.com`)
|
||||
- traefik.http.routers.evolution.entrypoints=websecure
|
||||
- traefik.http.routers.evolution.tls.certresolver=letsencrypt
|
||||
- traefik.http.services.evolution.loadbalancer.server.port=4000
|
||||
|
||||
volumes:
|
||||
evolution_go_data:
|
||||
external: true
|
||||
evolution_go_logs:
|
||||
external: true
|
||||
|
||||
networks:
|
||||
network_public:
|
||||
external: true
|
||||
```
|
||||
|
||||
### Deploy e Gerenciamento
|
||||
|
||||
```bash
|
||||
# Deploy
|
||||
docker stack deploy -c docker-compose.swarm.yml evolution
|
||||
|
||||
# Status
|
||||
docker stack ls
|
||||
docker service ls
|
||||
docker service ps evolution_evolution_go
|
||||
|
||||
# Logs
|
||||
docker service logs evolution_evolution_go -f
|
||||
|
||||
# Escalar
|
||||
docker service scale evolution_evolution_go=5
|
||||
|
||||
# Atualizar (rolling update)
|
||||
docker service update --image evoapicloud/evolution-go:v1.2.0 evolution_evolution_go
|
||||
|
||||
# Remover
|
||||
docker stack rm evolution
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Deploy com Kubernetes
|
||||
|
||||
### Manifests Básicos
|
||||
|
||||
#### Namespace
|
||||
|
||||
```yaml
|
||||
# namespace.yaml
|
||||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: evolution-go
|
||||
```
|
||||
|
||||
#### ConfigMap
|
||||
|
||||
```yaml
|
||||
# configmap.yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: evolution-config
|
||||
namespace: evolution-go
|
||||
data:
|
||||
SERVER_PORT: "4000"
|
||||
CLIENT_NAME: "evolution"
|
||||
WADEBUG: "INFO"
|
||||
LOGTYPE: "console"
|
||||
CONNECT_ON_STARTUP: "false"
|
||||
WEBHOOKFILES: "true"
|
||||
DATABASE_SAVE_MESSAGES: "false"
|
||||
```
|
||||
|
||||
#### Secrets
|
||||
|
||||
```bash
|
||||
kubectl create secret generic evolution-secrets \
|
||||
--from-literal=GLOBAL_API_KEY=$(uuidgen) \
|
||||
--from-literal=POSTGRES_PASSWORD=$(openssl rand -base64 32) \
|
||||
--namespace=evolution-go
|
||||
```
|
||||
|
||||
#### Deployment
|
||||
|
||||
```yaml
|
||||
# deployment.yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: evolution-go
|
||||
namespace: evolution-go
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: evolution-go
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: evolution-go
|
||||
spec:
|
||||
containers:
|
||||
- name: evolution-go
|
||||
image: evoapicloud/evolution-go:latest
|
||||
ports:
|
||||
- containerPort: 4000
|
||||
env:
|
||||
- name: SERVER_PORT
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: evolution-config
|
||||
key: SERVER_PORT
|
||||
- name: GLOBAL_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: evolution-secrets
|
||||
key: GLOBAL_API_KEY
|
||||
resources:
|
||||
requests:
|
||||
memory: "512Mi"
|
||||
cpu: "500m"
|
||||
limits:
|
||||
memory: "2Gi"
|
||||
cpu: "2000m"
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /server/ok
|
||||
port: 4000
|
||||
initialDelaySeconds: 30
|
||||
periodSeconds: 10
|
||||
readinessProbe:
|
||||
httpGet:
|
||||
path: /server/ok
|
||||
port: 4000
|
||||
initialDelaySeconds: 10
|
||||
periodSeconds: 5
|
||||
volumeMounts:
|
||||
- name: evolution-data
|
||||
mountPath: /app/dbdata
|
||||
- name: evolution-logs
|
||||
mountPath: /app/logs
|
||||
volumes:
|
||||
- name: evolution-data
|
||||
persistentVolumeClaim:
|
||||
claimName: evolution-data-pvc
|
||||
- name: evolution-logs
|
||||
persistentVolumeClaim:
|
||||
claimName: evolution-logs-pvc
|
||||
```
|
||||
|
||||
#### Service
|
||||
|
||||
```yaml
|
||||
# service.yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: evolution-go-service
|
||||
namespace: evolution-go
|
||||
spec:
|
||||
type: LoadBalancer
|
||||
selector:
|
||||
app: evolution-go
|
||||
ports:
|
||||
- port: 4000
|
||||
targetPort: 4000
|
||||
```
|
||||
|
||||
#### Ingress
|
||||
|
||||
```yaml
|
||||
# ingress.yaml
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: evolution-ingress
|
||||
namespace: evolution-go
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "nginx"
|
||||
cert-manager.io/cluster-issuer: "letsencrypt-prod"
|
||||
spec:
|
||||
tls:
|
||||
- hosts:
|
||||
- evolution.domain.com
|
||||
secretName: evolution-tls
|
||||
rules:
|
||||
- host: evolution.domain.com
|
||||
http:
|
||||
paths:
|
||||
- path: /
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: evolution-go-service
|
||||
port:
|
||||
number: 4000
|
||||
```
|
||||
|
||||
#### HorizontalPodAutoscaler
|
||||
|
||||
```yaml
|
||||
# hpa.yaml
|
||||
apiVersion: autoscaling/v2
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: evolution-hpa
|
||||
namespace: evolution-go
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
name: evolution-go
|
||||
minReplicas: 3
|
||||
maxReplicas: 10
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 70
|
||||
- type: Resource
|
||||
resource:
|
||||
name: memory
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 80
|
||||
```
|
||||
|
||||
### Deploy Kubernetes
|
||||
|
||||
```bash
|
||||
# Aplicar manifests
|
||||
kubectl apply -f namespace.yaml
|
||||
kubectl apply -f configmap.yaml
|
||||
kubectl apply -f secrets.yaml
|
||||
kubectl apply -f deployment.yaml
|
||||
kubectl apply -f service.yaml
|
||||
kubectl apply -f ingress.yaml
|
||||
kubectl apply -f hpa.yaml
|
||||
|
||||
# Verificar
|
||||
kubectl get all -n evolution-go
|
||||
kubectl get pods -n evolution-go
|
||||
|
||||
# Logs
|
||||
kubectl logs -f deployment/evolution-go -n evolution-go
|
||||
|
||||
# Escalar
|
||||
kubectl scale deployment evolution-go --replicas=5 -n evolution-go
|
||||
|
||||
# Atualizar
|
||||
kubectl set image deployment/evolution-go \
|
||||
evolution-go=evoapicloud/evolution-go:v1.2.0 \
|
||||
-n evolution-go
|
||||
|
||||
# Rollback
|
||||
kubectl rollout undo deployment/evolution-go -n evolution-go
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Otimização e Gestão
|
||||
|
||||
### Gestão de Volumes
|
||||
|
||||
#### Backup
|
||||
|
||||
```bash
|
||||
# Backup volume
|
||||
docker run --rm \
|
||||
-v evolution_data:/data \
|
||||
-v $(pwd):/backup \
|
||||
alpine tar czf /backup/backup-$(date +%Y%m%d).tar.gz -C /data .
|
||||
|
||||
# Restaurar
|
||||
docker run --rm \
|
||||
-v evolution_data:/data \
|
||||
-v $(pwd):/backup \
|
||||
alpine tar xzf /backup/backup-20250111.tar.gz -C /data
|
||||
```
|
||||
|
||||
### Logging
|
||||
|
||||
```yaml
|
||||
services:
|
||||
evolution-go:
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "3"
|
||||
```
|
||||
|
||||
### Boas Práticas
|
||||
|
||||
**Segurança:**
|
||||
- Não executar containers como root
|
||||
- Usar secrets para credenciais
|
||||
- Habilitar HTTPS em produção
|
||||
- Configurar resource limits
|
||||
- Implementar health checks
|
||||
|
||||
**Performance:**
|
||||
- Definir resource requests/limits
|
||||
- Usar health checks
|
||||
- Implementar HPA (Kubernetes)
|
||||
- Configurar connection pooling
|
||||
|
||||
**Monitoramento:**
|
||||
- Coletar logs centralizados
|
||||
- Implementar métricas (Prometheus)
|
||||
- Configurar alertas
|
||||
- Dashboard de visualização (Grafana)
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Container Reiniciando
|
||||
|
||||
```bash
|
||||
# Ver logs
|
||||
docker-compose logs evolution-go
|
||||
|
||||
# Verificar variáveis obrigatórias
|
||||
# - GLOBAL_API_KEY
|
||||
# - POSTGRES_*_DB
|
||||
```
|
||||
|
||||
### Conectividade PostgreSQL
|
||||
|
||||
```bash
|
||||
# Testar conexão
|
||||
docker-compose exec evolution-go ping postgres
|
||||
|
||||
# Verificar porta
|
||||
docker-compose exec evolution-go nc -zv postgres 5432
|
||||
|
||||
# Inspecionar rede
|
||||
docker network inspect evolution_network
|
||||
```
|
||||
|
||||
### Sem Espaço em Disco
|
||||
|
||||
```bash
|
||||
# Ver uso
|
||||
docker system df
|
||||
|
||||
# Limpar
|
||||
docker container prune
|
||||
docker image prune
|
||||
docker volume prune # CUIDADO: apaga volumes não utilizados
|
||||
docker system prune -a
|
||||
```
|
||||
|
||||
### OOM (Out of Memory)
|
||||
|
||||
```bash
|
||||
# Ver eventos OOM
|
||||
docker events --filter 'event=oom'
|
||||
|
||||
# Ver uso de memória
|
||||
docker stats evolution-go
|
||||
|
||||
# Aumentar limite
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
memory: 4G
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Comandos Úteis
|
||||
|
||||
### Docker Compose
|
||||
|
||||
```bash
|
||||
docker-compose up -d # Iniciar
|
||||
docker-compose ps # Status
|
||||
docker-compose logs -f # Logs
|
||||
docker-compose stop # Parar
|
||||
docker-compose restart # Reiniciar
|
||||
docker-compose down # Remover
|
||||
docker-compose pull # Atualizar imagens
|
||||
```
|
||||
|
||||
### Docker Swarm
|
||||
|
||||
```bash
|
||||
docker stack deploy -c file.yml name # Deploy
|
||||
docker stack ls # Listar stacks
|
||||
docker service ls # Listar serviços
|
||||
docker service logs name -f # Logs
|
||||
docker service scale name=N # Escalar
|
||||
docker stack rm name # Remover
|
||||
```
|
||||
|
||||
### Kubernetes
|
||||
|
||||
```bash
|
||||
kubectl apply -f file.yaml # Aplicar
|
||||
kubectl get all -n namespace # Listar recursos
|
||||
kubectl logs -f deployment/name # Logs
|
||||
kubectl scale deployment name --replicas=N # Escalar
|
||||
kubectl delete -f file.yaml # Deletar
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
**Documentação Evolution GO v1.0**
|
||||
@@ -0,0 +1,732 @@
|
||||
# Segurança e Hardening
|
||||
|
||||
Guia de práticas de segurança para ambientes de produção do Evolution GO.
|
||||
|
||||
## Índice
|
||||
|
||||
- [Princípios de Segurança](#princípios-de-segurança)
|
||||
- [Autenticação e API Keys](#autenticação-e-api-keys)
|
||||
- [Gestão de Secrets](#gestão-de-secrets)
|
||||
- [Segurança de Rede](#segurança-de-rede)
|
||||
- [Hardening de Containers](#hardening-de-containers)
|
||||
- [SSL/TLS](#ssltls)
|
||||
- [Segurança do Banco de Dados](#segurança-do-banco-de-dados)
|
||||
- [Backup Seguro](#backup-seguro)
|
||||
- [Proteção contra Ataques](#proteção-contra-ataques)
|
||||
- [Auditoria e Compliance](#auditoria-e-compliance)
|
||||
- [Resposta a Incidentes](#resposta-a-incidentes)
|
||||
|
||||
---
|
||||
|
||||
## Princípios de Segurança
|
||||
|
||||
### Defense in Depth
|
||||
|
||||
Implementar múltiplas camadas de proteção:
|
||||
- Autenticação forte
|
||||
- Firewall e isolamento de rede
|
||||
- Criptografia em trânsito e repouso
|
||||
- Monitoramento e auditoria
|
||||
- Backup e disaster recovery
|
||||
|
||||
### Least Privilege
|
||||
|
||||
Conceder apenas permissões mínimas necessárias:
|
||||
- Containers não executam como root
|
||||
- Credenciais com escopo limitado
|
||||
- Acesso à rede restrito
|
||||
- Segregação de ambientes
|
||||
|
||||
### Security by Default
|
||||
|
||||
- Configurações seguras desde a instalação
|
||||
- HTTPS obrigatório em produção
|
||||
- Logs de auditoria habilitados
|
||||
- Credenciais fortes exigidas
|
||||
|
||||
### Requisitos por Ambiente
|
||||
|
||||
| Ambiente | Segurança Mínima |
|
||||
|----------|------------------|
|
||||
| **Desenvolvimento** | API Key forte, senhas não-padrão |
|
||||
| **Staging** | + Firewall, backup, logs |
|
||||
| **Produção** | + HTTPS, monitoramento, auditoria, secrets management |
|
||||
|
||||
---
|
||||
|
||||
## Autenticação e API Keys
|
||||
|
||||
### Geração de API Keys
|
||||
|
||||
Utilize chaves criptograficamente seguras:
|
||||
|
||||
```bash
|
||||
# UUID v4 (recomendado)
|
||||
uuidgen
|
||||
|
||||
# 64 caracteres hexadecimais
|
||||
openssl rand -hex 32
|
||||
|
||||
# URL-safe base64
|
||||
python3 -c "import secrets; print(secrets.token_urlsafe(32))"
|
||||
```
|
||||
|
||||
**Exemplo de chave forte:**
|
||||
```
|
||||
df16caad-d0d2-41b2-bec5-75b90048a0db
|
||||
```
|
||||
|
||||
**Evitar:**
|
||||
- Valores padrão ou previsíveis
|
||||
- Senhas comuns ou sequências
|
||||
- Reutilização de chaves entre ambientes
|
||||
|
||||
### Rotação de Chaves
|
||||
|
||||
**Política recomendada:**
|
||||
- Rotação periódica (90 dias)
|
||||
- Rotação imediata em caso de comprometimento
|
||||
- Manter período de transição para atualização de clientes
|
||||
|
||||
**Processo de rotação:**
|
||||
|
||||
1. Gerar nova chave
|
||||
2. Atualizar configuração do servidor
|
||||
3. Notificar clientes integradores
|
||||
4. Estabelecer deadline para migração
|
||||
5. Desabilitar chave antiga
|
||||
|
||||
### Rate Limiting
|
||||
|
||||
Implementar limitação de requisições por API Key via NGINX:
|
||||
|
||||
```nginx
|
||||
http {
|
||||
map $http_apikey $limit_key {
|
||||
default $http_apikey;
|
||||
"" $binary_remote_addr;
|
||||
}
|
||||
|
||||
limit_req_zone $limit_key zone=api_limit:10m rate=100r/s;
|
||||
|
||||
server {
|
||||
location / {
|
||||
limit_req zone=api_limit burst=200 nodelay;
|
||||
limit_req_status 429;
|
||||
proxy_pass http://evolution-go:4000;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Gestão de Secrets
|
||||
|
||||
### Docker Secrets (Swarm)
|
||||
|
||||
```bash
|
||||
# Criar secrets
|
||||
echo "senha_postgres" | docker secret create postgres_password -
|
||||
echo "$(uuidgen)" | docker secret create evolution_api_key -
|
||||
|
||||
# docker-compose.swarm.yml
|
||||
services:
|
||||
evolution-go:
|
||||
secrets:
|
||||
- evolution_api_key
|
||||
- postgres_password
|
||||
environment:
|
||||
GLOBAL_API_KEY_FILE: /run/secrets/evolution_api_key
|
||||
POSTGRES_PASSWORD_FILE: /run/secrets/postgres_password
|
||||
|
||||
secrets:
|
||||
evolution_api_key:
|
||||
external: true
|
||||
postgres_password:
|
||||
external: true
|
||||
```
|
||||
|
||||
### Kubernetes Secrets
|
||||
|
||||
```bash
|
||||
# Criar secrets
|
||||
kubectl create secret generic evolution-secrets \
|
||||
--from-literal=GLOBAL_API_KEY=$(uuidgen) \
|
||||
--from-literal=POSTGRES_PASSWORD=$(openssl rand -base64 32) \
|
||||
--namespace=evolution-go
|
||||
|
||||
# Habilitar encryption at rest
|
||||
# https://kubernetes.io/docs/tasks/administer-cluster/encrypt-data/
|
||||
```
|
||||
|
||||
```yaml
|
||||
# deployment.yaml
|
||||
env:
|
||||
- name: GLOBAL_API_KEY
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: evolution-secrets
|
||||
key: GLOBAL_API_KEY
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: evolution-secrets
|
||||
key: POSTGRES_PASSWORD
|
||||
```
|
||||
|
||||
### HashiCorp Vault
|
||||
|
||||
```yaml
|
||||
# vault-agent-config.hcl
|
||||
vault {
|
||||
address = "https://vault.seudominio.com:8200"
|
||||
}
|
||||
|
||||
auto_auth {
|
||||
method {
|
||||
type = "kubernetes"
|
||||
config = {
|
||||
role = "evolution-go"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template {
|
||||
source = "/vault/configs/.env.tpl"
|
||||
destination = "/app/.env"
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Segurança de Rede
|
||||
|
||||
### Firewall (iptables)
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# firewall-setup.sh
|
||||
|
||||
# Políticas padrão
|
||||
iptables -P INPUT DROP
|
||||
iptables -P FORWARD DROP
|
||||
iptables -P OUTPUT ACCEPT
|
||||
|
||||
# Loopback
|
||||
iptables -A INPUT -i lo -j ACCEPT
|
||||
|
||||
# Conexões estabelecidas
|
||||
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
|
||||
|
||||
# SSH com rate limiting
|
||||
iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -m recent --set
|
||||
iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 4 -j DROP
|
||||
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
|
||||
|
||||
# HTTP/HTTPS restrito à rede interna
|
||||
iptables -A INPUT -p tcp --dport 80 -s 10.0.1.0/24 -j ACCEPT
|
||||
iptables -A INPUT -p tcp --dport 443 -s 10.0.1.0/24 -j ACCEPT
|
||||
|
||||
# Docker network
|
||||
iptables -A INPUT -s 172.16.0.0/12 -j ACCEPT
|
||||
|
||||
# Drop inválidos
|
||||
iptables -A INPUT -m conntrack --ctstate INVALID -j DROP
|
||||
|
||||
# Salvar regras
|
||||
iptables-save > /etc/iptables/rules.v4
|
||||
```
|
||||
|
||||
### UFW (Alternativa Simplificada)
|
||||
|
||||
```bash
|
||||
sudo apt-get install ufw
|
||||
|
||||
# Configurar padrões
|
||||
sudo ufw default deny incoming
|
||||
sudo ufw default allow outgoing
|
||||
|
||||
# Permitir serviços
|
||||
sudo ufw allow 22/tcp # SSH
|
||||
sudo ufw allow 80/tcp # HTTP
|
||||
sudo ufw allow 443/tcp # HTTPS
|
||||
|
||||
# Ativar
|
||||
sudo ufw enable
|
||||
|
||||
# Status
|
||||
sudo ufw status
|
||||
```
|
||||
|
||||
### Isolamento de Redes Docker
|
||||
|
||||
```yaml
|
||||
networks:
|
||||
frontend:
|
||||
driver: overlay
|
||||
driver_opts:
|
||||
encrypted: "true"
|
||||
|
||||
backend:
|
||||
driver: overlay
|
||||
driver_opts:
|
||||
encrypted: "true"
|
||||
internal: true # Sem acesso externo
|
||||
|
||||
services:
|
||||
evolution-go:
|
||||
networks:
|
||||
- frontend
|
||||
- backend
|
||||
|
||||
postgres:
|
||||
networks:
|
||||
- backend # Apenas rede interna
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Hardening de Containers
|
||||
|
||||
### Não Executar como Root
|
||||
|
||||
```dockerfile
|
||||
FROM alpine:3.19.1
|
||||
|
||||
RUN addgroup -g 1000 evolution && \
|
||||
adduser -D -u 1000 -G evolution evolution
|
||||
|
||||
WORKDIR /app
|
||||
COPY --chown=evolution:evolution server .
|
||||
|
||||
USER evolution
|
||||
|
||||
ENTRYPOINT ["/app/server"]
|
||||
```
|
||||
|
||||
### Filesystem Read-Only
|
||||
|
||||
```yaml
|
||||
services:
|
||||
evolution-go:
|
||||
read_only: true
|
||||
tmpfs:
|
||||
- /tmp
|
||||
volumes:
|
||||
- evolution_data:/app/dbdata
|
||||
- evolution_logs:/app/logs
|
||||
```
|
||||
|
||||
### Security Options
|
||||
|
||||
```yaml
|
||||
services:
|
||||
evolution-go:
|
||||
security_opt:
|
||||
- no-new-privileges:true
|
||||
- apparmor:docker-default
|
||||
- seccomp:default.json
|
||||
cap_drop:
|
||||
- ALL
|
||||
cap_add:
|
||||
- NET_BIND_SERVICE # Apenas se necessário
|
||||
```
|
||||
|
||||
### Limites de Recursos
|
||||
|
||||
```yaml
|
||||
services:
|
||||
evolution-go:
|
||||
deploy:
|
||||
resources:
|
||||
limits:
|
||||
cpus: '2.0'
|
||||
memory: 2G
|
||||
pids: 100
|
||||
reservations:
|
||||
cpus: '1.0'
|
||||
memory: 1G
|
||||
ulimits:
|
||||
nofile:
|
||||
soft: 1024
|
||||
hard: 2048
|
||||
nproc: 64
|
||||
```
|
||||
|
||||
### Scan de Vulnerabilidades
|
||||
|
||||
```bash
|
||||
# Trivy
|
||||
trivy image evoapicloud/evolution-go:latest
|
||||
|
||||
# Apenas críticas
|
||||
trivy image --severity CRITICAL evoapicloud/evolution-go:latest
|
||||
|
||||
# Docker Scout
|
||||
docker scout cves evoapicloud/evolution-go:latest
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## SSL/TLS
|
||||
|
||||
### Obtenção de Certificados (Let's Encrypt)
|
||||
|
||||
```bash
|
||||
# Instalar Certbot
|
||||
sudo apt-get install certbot
|
||||
|
||||
# Gerar certificado
|
||||
sudo certbot certonly --standalone -d evolution.seudominio.com
|
||||
|
||||
# Certificados em:
|
||||
# /etc/letsencrypt/live/evolution.seudominio.com/
|
||||
```
|
||||
|
||||
### Configuração NGINX
|
||||
|
||||
```nginx
|
||||
# Redirecionar HTTP → HTTPS
|
||||
server {
|
||||
listen 80;
|
||||
server_name evolution.seudominio.com;
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
# HTTPS
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
server_name evolution.seudominio.com;
|
||||
|
||||
# Certificados
|
||||
ssl_certificate /etc/letsencrypt/live/evolution.seudominio.com/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/evolution.seudominio.com/privkey.pem;
|
||||
|
||||
# Protocolos e ciphers
|
||||
ssl_protocols TLSv1.2 TLSv1.3;
|
||||
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
|
||||
ssl_prefer_server_ciphers off;
|
||||
|
||||
# HSTS
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
|
||||
|
||||
# OCSP Stapling
|
||||
ssl_stapling on;
|
||||
ssl_stapling_verify on;
|
||||
ssl_trusted_certificate /etc/letsencrypt/live/evolution.seudominio.com/chain.pem;
|
||||
|
||||
# Security Headers
|
||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-XSS-Protection "1; mode=block" always;
|
||||
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||
|
||||
# Ocultar server tokens
|
||||
server_tokens off;
|
||||
|
||||
location / {
|
||||
proxy_pass http://evolution-go:4000;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
proxy_hide_header X-Powered-By;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Renovação Automática
|
||||
|
||||
```bash
|
||||
# Testar renovação
|
||||
sudo certbot renew --dry-run
|
||||
|
||||
# Agendar via cron
|
||||
sudo crontab -e
|
||||
|
||||
# Adicionar (renovação diária às 3h)
|
||||
0 3 * * * certbot renew --quiet && systemctl reload nginx
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Segurança do Banco de Dados
|
||||
|
||||
### PostgreSQL Hardening
|
||||
|
||||
```ini
|
||||
# postgresql.conf
|
||||
|
||||
# SSL obrigatório
|
||||
ssl = on
|
||||
ssl_cert_file = '/etc/ssl/certs/server.crt'
|
||||
ssl_key_file = '/etc/ssl/private/server.key'
|
||||
|
||||
# Auditoria
|
||||
log_connections = on
|
||||
log_disconnections = on
|
||||
log_duration = on
|
||||
log_statement = 'mod' # INSERT, UPDATE, DELETE
|
||||
|
||||
# Senha forte obrigatória
|
||||
password_encryption = scram-sha-256
|
||||
```
|
||||
|
||||
```ini
|
||||
# pg_hba.conf
|
||||
|
||||
# Apenas SSL
|
||||
hostssl evogo_auth evolution 10.0.0.0/8 scram-sha-256
|
||||
hostssl evogo_users evolution 10.0.0.0/8 scram-sha-256
|
||||
|
||||
# Rejeitar sem SSL
|
||||
hostnossl all all 0.0.0.0/0 reject
|
||||
```
|
||||
|
||||
### Backup Criptografado
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# backup-encrypted.sh
|
||||
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
BACKUP_FILE="postgres_${TIMESTAMP}.sql.gz.gpg"
|
||||
|
||||
# Dump e criptografar
|
||||
docker exec postgres pg_dumpall -U postgres | \
|
||||
gzip | \
|
||||
gpg --symmetric --cipher-algo AES256 --output "/backups/${BACKUP_FILE}"
|
||||
|
||||
# Upload S3 com SSE
|
||||
aws s3 cp "/backups/${BACKUP_FILE}" \
|
||||
"s3://bucket-backup/postgres/${BACKUP_FILE}" \
|
||||
--server-side-encryption AES256
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Backup Seguro
|
||||
|
||||
### Estratégia 3-2-1
|
||||
|
||||
- 3 cópias dos dados
|
||||
- 2 mídias diferentes
|
||||
- 1 cópia offsite
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# backup-secure.sh
|
||||
|
||||
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
|
||||
BACKUP_DIR="/backups"
|
||||
S3_BUCKET="s3://backup-bucket"
|
||||
GPG_KEY="[email protected]"
|
||||
|
||||
# PostgreSQL
|
||||
docker exec postgres pg_dumpall -U postgres | \
|
||||
gzip | \
|
||||
gpg --encrypt --recipient $GPG_KEY --output "${BACKUP_DIR}/postgres_${TIMESTAMP}.sql.gz.gpg"
|
||||
|
||||
# Volumes
|
||||
docker run --rm \
|
||||
-v evolution_data:/data \
|
||||
-v ${BACKUP_DIR}:/backup \
|
||||
alpine tar czf - -C /data . | \
|
||||
gpg --encrypt --recipient $GPG_KEY --output "${BACKUP_DIR}/evolution_data_${TIMESTAMP}.tar.gz.gpg"
|
||||
|
||||
# Upload S3 com KMS
|
||||
aws s3 cp "${BACKUP_DIR}/postgres_${TIMESTAMP}.sql.gz.gpg" \
|
||||
"${S3_BUCKET}/postgres/" \
|
||||
--server-side-encryption aws:kms \
|
||||
--ssekms-key-id alias/backup-key
|
||||
|
||||
# Limpeza (30 dias)
|
||||
find ${BACKUP_DIR} -name "*.gpg" -mtime +30 -delete
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Proteção contra Ataques
|
||||
|
||||
### DDoS Protection
|
||||
|
||||
**NGINX Rate Limiting:**
|
||||
|
||||
```nginx
|
||||
http {
|
||||
limit_conn_zone $binary_remote_addr zone=conn_limit:10m;
|
||||
limit_conn conn_limit 10;
|
||||
|
||||
limit_req_zone $binary_remote_addr zone=req_limit:10m rate=10r/s;
|
||||
|
||||
server {
|
||||
location / {
|
||||
limit_req zone=req_limit burst=20 nodelay;
|
||||
proxy_pass http://evolution-go:4000;
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
**Cloudflare:** Habilitar proteção DDoS no painel.
|
||||
|
||||
### SQL Injection
|
||||
|
||||
Evolution GO usa GORM (ORM) que previne SQL injection por padrão através de prepared statements.
|
||||
|
||||
### Brute-Force Protection (Fail2ban)
|
||||
|
||||
```bash
|
||||
sudo apt-get install fail2ban
|
||||
```
|
||||
|
||||
```ini
|
||||
# /etc/fail2ban/jail.local
|
||||
[nginx-req-limit]
|
||||
enabled = true
|
||||
filter = nginx-req-limit
|
||||
logpath = /var/log/nginx/error.log
|
||||
maxretry = 5
|
||||
findtime = 600
|
||||
bantime = 3600
|
||||
```
|
||||
|
||||
```ini
|
||||
# /etc/fail2ban/filter.d/nginx-req-limit.conf
|
||||
[Definition]
|
||||
failregex = limiting requests, excess:.* by zone.*client: <HOST>
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Auditoria e Compliance
|
||||
|
||||
### LGPD/GDPR
|
||||
|
||||
**Direito ao esquecimento:**
|
||||
|
||||
```sql
|
||||
CREATE PROCEDURE delete_user_data(user_phone VARCHAR)
|
||||
LANGUAGE plpgsql
|
||||
AS $$
|
||||
BEGIN
|
||||
DELETE FROM messages WHERE phone = user_phone;
|
||||
DELETE FROM contacts WHERE phone = user_phone;
|
||||
DELETE FROM instances WHERE owner_phone = user_phone;
|
||||
|
||||
INSERT INTO audit_log (action, details, timestamp)
|
||||
VALUES ('user_data_deleted', user_phone, NOW());
|
||||
|
||||
COMMIT;
|
||||
END;
|
||||
$$;
|
||||
```
|
||||
|
||||
**Retenção de dados:**
|
||||
|
||||
```sql
|
||||
-- Deletar mensagens antigas (30 dias)
|
||||
DELETE FROM messages WHERE timestamp < NOW() - INTERVAL '30 days';
|
||||
```
|
||||
|
||||
### Logging de Auditoria
|
||||
|
||||
```yaml
|
||||
services:
|
||||
evolution-go:
|
||||
logging:
|
||||
driver: "json-file"
|
||||
options:
|
||||
max-size: "10m"
|
||||
max-file: "5"
|
||||
labels: "service,environment"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Resposta a Incidentes
|
||||
|
||||
### Plano de Resposta
|
||||
|
||||
**1. Detecção**
|
||||
- Alertas automatizados
|
||||
- Monitoramento de logs
|
||||
- Relatórios de usuários
|
||||
|
||||
**2. Contenção**
|
||||
- Isolar sistemas afetados
|
||||
- Revogar credenciais comprometidas
|
||||
- Bloquear IPs maliciosos
|
||||
- Capturar evidências
|
||||
|
||||
**3. Erradicação**
|
||||
- Aplicar patches
|
||||
- Atualizar imagens
|
||||
- Revisar logs de auditoria
|
||||
- Remover backdoors
|
||||
|
||||
**4. Recuperação**
|
||||
- Restaurar de backup
|
||||
- Validar integridade
|
||||
- Monitorar por 48h
|
||||
|
||||
**5. Pós-Incidente**
|
||||
- Documentar lições aprendidas
|
||||
- Atualizar runbooks
|
||||
- Treinar equipe
|
||||
|
||||
### Forensics
|
||||
|
||||
```bash
|
||||
# Capturar estado do container
|
||||
docker commit container_suspeito forensics-image
|
||||
docker save forensics-image > forensics-image.tar
|
||||
|
||||
# Coletar logs
|
||||
docker logs container_suspeito > logs_suspeito.txt
|
||||
|
||||
# Inspecionar
|
||||
docker inspect container_suspeito > inspect_suspeito.json
|
||||
|
||||
# Exportar filesystem
|
||||
docker export container_suspeito > filesystem_suspeito.tar
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Checklist de Segurança
|
||||
|
||||
### Crítico
|
||||
- [ ] API Keys fortes (UUID)
|
||||
- [ ] HTTPS habilitado
|
||||
- [ ] Secrets em vault/secrets manager
|
||||
- [ ] Firewall configurado
|
||||
- [ ] Backups automáticos funcionando
|
||||
|
||||
### Importante
|
||||
- [ ] Containers não executam como root
|
||||
- [ ] Isolamento de redes Docker
|
||||
- [ ] Limites de recursos definidos
|
||||
- [ ] Logs de auditoria ativos
|
||||
- [ ] Monitoramento configurado
|
||||
|
||||
### Recomendado
|
||||
- [ ] Scan de vulnerabilidades regular
|
||||
- [ ] Plano de resposta a incidentes
|
||||
- [ ] Testes de restauração de backup
|
||||
- [ ] Documentação de segurança
|
||||
- [ ] Treinamento da equipe
|
||||
|
||||
---
|
||||
|
||||
## Recursos Adicionais
|
||||
|
||||
- [OWASP Top 10](https://owasp.org/www-project-top-ten/)
|
||||
- [CIS Docker Benchmark](https://www.cisecurity.org/benchmark/docker)
|
||||
- [Kubernetes Security Best Practices](https://kubernetes.io/docs/concepts/security/)
|
||||
- [NIST Cybersecurity Framework](https://www.nist.gov/cyberframework)
|
||||
|
||||
---
|
||||
|
||||
**Documentação Evolution GO v1.0**
|
||||
Reference in new issue
Block a user