🔐 Security hardening: auth, rate limiting, brute force protection
- Add comprehensive security package with: - API Key generation and validation (SHA256 hash) - Password policy enforcement (min 12 chars, complexity) - Rate limiting with presets (auth, api, ingest, export) - Brute force protection (5 attempts, 15min lockout) - Security headers middleware - IP whitelisting - Audit logging structure - Secure token generation - Enhanced auth middleware: - JWT + API Key dual authentication - Token revocation via Redis - Scope-based authorization - Role-based access control - Updated installer with: - Interactive setup for client customization - Auto-generated secure credentials - Docker all-in-one image - Agent installer script - Added documentation: - SECURITY.md - Complete security guide - INSTALL.md - Installation guide - .env.example - Configuration reference
This commit is contained in:
485
docs/INSTALL.md
485
docs/INSTALL.md
@@ -1,436 +1,231 @@
|
||||
# 🐍 OPHION - Manual de Instalação e Configuração
|
||||
# 🐍 OPHION - Guia de Instalação
|
||||
|
||||
## Índice
|
||||
1. [Instalação do Servidor](#instalação-do-servidor)
|
||||
2. [Instalação do Agent](#instalação-do-agent)
|
||||
3. [Monitoramento de Docker](#monitoramento-de-docker)
|
||||
4. [Monitoramento de Aplicações](#monitoramento-de-aplicações)
|
||||
5. [Configuração de Alertas](#configuração-de-alertas)
|
||||
## Instalação Rápida (1 comando)
|
||||
|
||||
```bash
|
||||
curl -fsSL https://get.ophion.io | bash
|
||||
```
|
||||
|
||||
O instalador vai:
|
||||
1. ✅ Verificar requisitos (Docker, Docker Compose)
|
||||
2. 📋 Coletar informações da sua empresa
|
||||
3. 🔐 Gerar credenciais seguras
|
||||
4. 📦 Configurar todos os serviços
|
||||
5. 🚀 Iniciar a plataforma
|
||||
|
||||
---
|
||||
|
||||
## 1. Instalação do Servidor
|
||||
## Instalação Manual (Passo a Passo)
|
||||
|
||||
### Requisitos Mínimos
|
||||
- CPU: 2 cores
|
||||
- RAM: 4GB (8GB recomendado)
|
||||
- Disco: 50GB SSD
|
||||
- OS: Ubuntu 22.04+ / Debian 12+
|
||||
- Docker 24+
|
||||
|
||||
### Instalação Rápida (1 comando)
|
||||
### 1. Requisitos
|
||||
|
||||
```bash
|
||||
curl -fsSL https://ophion.com.br/install.sh | bash
|
||||
# Ubuntu/Debian
|
||||
sudo apt update
|
||||
sudo apt install -y curl git
|
||||
|
||||
# Instalar Docker
|
||||
curl -fsSL https://get.docker.com | sh
|
||||
sudo usermod -aG docker $USER
|
||||
|
||||
# Logout e login para aplicar grupo docker
|
||||
```
|
||||
|
||||
### Instalação Manual
|
||||
### 2. Baixar Ophion
|
||||
|
||||
```bash
|
||||
# Clonar repositório
|
||||
git clone https://github.com/bigtux/ophion.git
|
||||
cd ophion/deploy/docker
|
||||
|
||||
# Configurar variáveis de ambiente
|
||||
cp .env.example .env
|
||||
nano .env # Editar conforme necessário
|
||||
|
||||
# Iniciar serviços
|
||||
docker compose up -d
|
||||
|
||||
# Verificar status
|
||||
docker compose ps
|
||||
cd ophion
|
||||
```
|
||||
|
||||
### Variáveis de Ambiente (.env)
|
||||
### 3. Configurar
|
||||
|
||||
Copie e edite o arquivo de configuração:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
nano .env
|
||||
```
|
||||
|
||||
Configurações importantes:
|
||||
|
||||
```env
|
||||
# Segurança (OBRIGATÓRIO - gere valores únicos!)
|
||||
JWT_SECRET=sua-chave-secreta-aqui-min-32-chars
|
||||
# Sua empresa
|
||||
ORG_NAME="Minha Empresa"
|
||||
ADMIN_EMAIL=admin@empresa.com
|
||||
ADMIN_PASSWORD=senha-segura-aqui
|
||||
|
||||
# Banco de Dados
|
||||
POSTGRES_USER=ophion
|
||||
POSTGRES_PASSWORD=senha-forte-aqui
|
||||
POSTGRES_DB=ophion
|
||||
# Domínio (ou localhost para testes)
|
||||
DOMAIN=ophion.empresa.com
|
||||
|
||||
# ClickHouse (métricas/logs)
|
||||
CLICKHOUSE_USER=default
|
||||
CLICKHOUSE_PASSWORD=senha-clickhouse
|
||||
# Portas
|
||||
SERVER_PORT=8080
|
||||
DASHBOARD_PORT=3000
|
||||
|
||||
# Redis
|
||||
REDIS_PASSWORD=senha-redis
|
||||
|
||||
# Configurações do Servidor
|
||||
OPHION_PORT=8080
|
||||
OPHION_HOST=0.0.0.0
|
||||
|
||||
# Retenção de dados (dias)
|
||||
METRICS_RETENTION_DAYS=30
|
||||
LOGS_RETENTION_DAYS=14
|
||||
# Segurança (gere valores únicos!)
|
||||
JWT_SECRET=seu-jwt-secret-aqui
|
||||
```
|
||||
|
||||
### Verificar Instalação
|
||||
### 4. Iniciar
|
||||
|
||||
```bash
|
||||
# Health check
|
||||
curl http://localhost:8080/health
|
||||
|
||||
# Resposta esperada:
|
||||
# {"status":"healthy","service":"ophion","version":"0.1.0"}
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### Acessar Dashboard
|
||||
### 5. Acessar
|
||||
|
||||
Abra no navegador: `http://seu-servidor:3000`
|
||||
|
||||
1. Crie sua conta de administrador
|
||||
2. Configure sua organização
|
||||
3. Gere API Keys para os agents
|
||||
- **Dashboard:** http://localhost:3000
|
||||
- **API:** http://localhost:8080
|
||||
|
||||
---
|
||||
|
||||
## 2. Instalação do Agent
|
||||
## Instalação do Agent (Servidores Monitorados)
|
||||
|
||||
O Agent coleta métricas do servidor e envia para o OPHION.
|
||||
|
||||
### Instalação Rápida
|
||||
Em cada servidor que você quer monitorar:
|
||||
|
||||
```bash
|
||||
# Substitua YOUR_API_KEY pela chave gerada no dashboard
|
||||
curl -fsSL https://ophion.com.br/agent.sh | OPHION_API_KEY=YOUR_API_KEY bash
|
||||
curl -fsSL http://SEU-SERVIDOR-OPHION:8080/install-agent.sh | sudo bash
|
||||
```
|
||||
|
||||
### Instalação Manual
|
||||
Ou manualmente:
|
||||
|
||||
```bash
|
||||
# Baixar binário
|
||||
wget https://github.com/bigtux/ophion/releases/latest/download/ophion-agent-linux-amd64
|
||||
chmod +x ophion-agent-linux-amd64
|
||||
sudo mv ophion-agent-linux-amd64 /usr/local/bin/ophion-agent
|
||||
# Baixar
|
||||
curl -o /usr/local/bin/ophion-agent \
|
||||
http://SEU-SERVIDOR-OPHION:8080/downloads/agent/linux/amd64/ophion-agent
|
||||
chmod +x /usr/local/bin/ophion-agent
|
||||
|
||||
# Criar arquivo de configuração
|
||||
sudo mkdir -p /etc/ophion
|
||||
sudo tee /etc/ophion/agent.yaml << EOF
|
||||
server: https://api.ophion.com.br
|
||||
api_key: YOUR_API_KEY
|
||||
hostname: $(hostname)
|
||||
interval: 30s
|
||||
# Configurar
|
||||
mkdir -p /etc/ophion
|
||||
cat > /etc/ophion/agent.yaml << EOF
|
||||
server:
|
||||
url: http://SEU-SERVIDOR-OPHION:8080
|
||||
api_key: SUA-API-KEY
|
||||
|
||||
collectors:
|
||||
cpu: true
|
||||
memory: true
|
||||
disk: true
|
||||
network: true
|
||||
processes: true
|
||||
collection:
|
||||
interval: 30s
|
||||
|
||||
metrics:
|
||||
enabled: true
|
||||
|
||||
logs:
|
||||
enabled: true
|
||||
paths:
|
||||
- /var/log/syslog
|
||||
EOF
|
||||
|
||||
# Criar serviço systemd
|
||||
sudo tee /etc/systemd/system/ophion-agent.service << EOF
|
||||
# Criar serviço
|
||||
cat > /etc/systemd/system/ophion-agent.service << EOF
|
||||
[Unit]
|
||||
Description=OPHION Monitoring Agent
|
||||
Description=OPHION Agent
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/local/bin/ophion-agent --config /etc/ophion/agent.yaml
|
||||
ExecStart=/usr/local/bin/ophion-agent -config /etc/ophion/agent.yaml
|
||||
Restart=always
|
||||
RestartSec=10
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# Iniciar serviço
|
||||
sudo systemctl daemon-reload
|
||||
sudo systemctl enable ophion-agent
|
||||
sudo systemctl start ophion-agent
|
||||
|
||||
# Verificar status
|
||||
sudo systemctl status ophion-agent
|
||||
```
|
||||
|
||||
### Variáveis de Ambiente do Agent
|
||||
|
||||
```bash
|
||||
export OPHION_SERVER="https://api.ophion.com.br"
|
||||
export OPHION_API_KEY="ophion_xxxxxxxxxxxxxxxx"
|
||||
export OPHION_HOSTNAME="meu-servidor"
|
||||
export OPHION_INTERVAL="30s"
|
||||
# Iniciar
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now ophion-agent
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. Monitoramento de Docker
|
||||
|
||||
### Opção A: Agent com Acesso ao Docker Socket
|
||||
## Comandos Úteis
|
||||
|
||||
```bash
|
||||
# Adicionar ao agent.yaml
|
||||
collectors:
|
||||
docker:
|
||||
enabled: true
|
||||
socket: /var/run/docker.sock
|
||||
collect_container_stats: true
|
||||
collect_container_logs: true
|
||||
```
|
||||
# Status
|
||||
ophion status
|
||||
|
||||
### Opção B: Container Dedicado
|
||||
# Logs
|
||||
ophion logs # Logs do server
|
||||
ophion logs ophion-web # Logs do dashboard
|
||||
|
||||
```yaml
|
||||
# docker-compose.yml do seu projeto
|
||||
services:
|
||||
ophion-agent:
|
||||
image: ophion/agent:latest
|
||||
container_name: ophion-agent
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
- OPHION_SERVER=https://api.ophion.com.br
|
||||
- OPHION_API_KEY=YOUR_API_KEY
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
- /proc:/host/proc:ro
|
||||
- /sys:/host/sys:ro
|
||||
network_mode: host
|
||||
pid: host
|
||||
```
|
||||
# Gerenciamento
|
||||
ophion start
|
||||
ophion stop
|
||||
ophion restart
|
||||
ophion update
|
||||
|
||||
### Métricas Coletadas do Docker
|
||||
# Backup
|
||||
ophion backup
|
||||
|
||||
| Métrica | Descrição |
|
||||
|---------|-----------|
|
||||
| `container.cpu.usage` | Uso de CPU por container |
|
||||
| `container.memory.usage` | Uso de memória |
|
||||
| `container.memory.limit` | Limite de memória |
|
||||
| `container.network.rx_bytes` | Bytes recebidos |
|
||||
| `container.network.tx_bytes` | Bytes enviados |
|
||||
| `container.disk.read_bytes` | Leitura de disco |
|
||||
| `container.disk.write_bytes` | Escrita de disco |
|
||||
| `container.status` | Status (running/stopped) |
|
||||
| `container.restarts` | Contagem de restarts |
|
||||
|
||||
### Labels para Identificação
|
||||
|
||||
Adicione labels aos seus containers para melhor organização:
|
||||
|
||||
```yaml
|
||||
services:
|
||||
minha-app:
|
||||
labels:
|
||||
ophion.monitor: "true"
|
||||
ophion.service: "api"
|
||||
ophion.environment: "production"
|
||||
ophion.team: "backend"
|
||||
# Gerar nova API Key
|
||||
ophion api-key
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. Monitoramento de Aplicações (APM)
|
||||
## Estrutura de Diretórios
|
||||
|
||||
### Node.js
|
||||
|
||||
```bash
|
||||
npm install @ophion/apm
|
||||
```
|
||||
|
||||
```javascript
|
||||
// No início do seu app (antes de outros imports)
|
||||
const ophion = require('@ophion/apm');
|
||||
|
||||
ophion.init({
|
||||
serverUrl: 'https://api.ophion.com.br',
|
||||
apiKey: 'YOUR_API_KEY',
|
||||
serviceName: 'minha-api',
|
||||
environment: 'production'
|
||||
});
|
||||
|
||||
// Seu código normal...
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
```
|
||||
|
||||
### Python
|
||||
|
||||
```bash
|
||||
pip install ophion-apm
|
||||
```
|
||||
|
||||
```python
|
||||
# No início do seu app
|
||||
import ophion_apm
|
||||
|
||||
ophion_apm.init(
|
||||
server_url='https://api.ophion.com.br',
|
||||
api_key='YOUR_API_KEY',
|
||||
service_name='minha-api',
|
||||
environment='production'
|
||||
)
|
||||
|
||||
# Seu código normal...
|
||||
from flask import Flask
|
||||
app = Flask(__name__)
|
||||
```
|
||||
|
||||
### Go
|
||||
|
||||
```go
|
||||
import "github.com/bigtux/ophion/sdk/go/apm"
|
||||
|
||||
func main() {
|
||||
// Inicializar APM
|
||||
apm.Init(apm.Config{
|
||||
ServerURL: "https://api.ophion.com.br",
|
||||
APIKey: "YOUR_API_KEY",
|
||||
ServiceName: "minha-api",
|
||||
Environment: "production",
|
||||
})
|
||||
defer apm.Close()
|
||||
|
||||
// Seu código normal...
|
||||
}
|
||||
```
|
||||
|
||||
### Java (Spring Boot)
|
||||
|
||||
```xml
|
||||
<!-- pom.xml -->
|
||||
<dependency>
|
||||
<groupId>com.ophion</groupId>
|
||||
<artifactId>ophion-apm</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
```yaml
|
||||
# application.yml
|
||||
ophion:
|
||||
apm:
|
||||
server-url: https://api.ophion.com.br
|
||||
api-key: YOUR_API_KEY
|
||||
service-name: minha-api
|
||||
environment: production
|
||||
```
|
||||
|
||||
### OpenTelemetry (Universal)
|
||||
|
||||
OPHION é compatível com OpenTelemetry. Use qualquer SDK OTel:
|
||||
|
||||
```bash
|
||||
# Variáveis de ambiente
|
||||
export OTEL_EXPORTER_OTLP_ENDPOINT="https://api.ophion.com.br/v1/traces"
|
||||
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer YOUR_API_KEY"
|
||||
export OTEL_SERVICE_NAME="minha-api"
|
||||
/opt/ophion/
|
||||
├── docker-compose.yml # Configuração dos containers
|
||||
├── .env # Variáveis de ambiente (SECRETO!)
|
||||
├── data/
|
||||
│ ├── postgres/ # Dados do PostgreSQL
|
||||
│ ├── clickhouse/ # Métricas e logs
|
||||
│ └── redis/ # Cache
|
||||
├── configs/ # Configurações customizadas
|
||||
├── logs/ # Logs da aplicação
|
||||
├── scripts/
|
||||
│ └── install-agent.sh # Instalador do agent
|
||||
└── backups/ # Backups automáticos
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. Configuração de Alertas
|
||||
## Portas
|
||||
|
||||
### Via Dashboard
|
||||
|
||||
1. Acesse **Alertas** → **Novo Alerta**
|
||||
2. Defina a condição:
|
||||
- Métrica: `cpu.usage`
|
||||
- Operador: `>`
|
||||
- Valor: `80`
|
||||
- Duração: `5 minutos`
|
||||
3. Configure notificações:
|
||||
- Telegram
|
||||
- Slack
|
||||
- Email
|
||||
- Webhook
|
||||
|
||||
### Via API
|
||||
|
||||
```bash
|
||||
curl -X POST "https://api.ophion.com.br/api/v1/alerts" \
|
||||
-H "Authorization: Bearer YOUR_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"name": "CPU Alta",
|
||||
"description": "Alerta quando CPU > 80%",
|
||||
"condition": {
|
||||
"metric": "cpu.usage",
|
||||
"operator": ">",
|
||||
"threshold": 80,
|
||||
"duration": "5m"
|
||||
},
|
||||
"notifications": [
|
||||
{
|
||||
"type": "telegram",
|
||||
"chat_id": "123456789"
|
||||
},
|
||||
{
|
||||
"type": "email",
|
||||
"to": "admin@empresa.com"
|
||||
}
|
||||
],
|
||||
"severity": "warning"
|
||||
}'
|
||||
```
|
||||
|
||||
### Integrações Disponíveis
|
||||
|
||||
| Canal | Configuração |
|
||||
|-------|-------------|
|
||||
| **Telegram** | Bot token + Chat ID |
|
||||
| **Slack** | Webhook URL |
|
||||
| **Discord** | Webhook URL |
|
||||
| **Email** | SMTP ou API (SendGrid, Resend) |
|
||||
| **PagerDuty** | Integration Key |
|
||||
| **Webhook** | URL customizada |
|
||||
|
||||
### Configurar Telegram
|
||||
|
||||
1. Crie um bot com [@BotFather](https://t.me/BotFather)
|
||||
2. Obtenha o token do bot
|
||||
3. Inicie conversa com o bot
|
||||
4. No dashboard OPHION: **Configurações** → **Integrações** → **Telegram**
|
||||
5. Cole o token e configure
|
||||
| Serviço | Porta | Descrição |
|
||||
|---------|-------|-----------|
|
||||
| Dashboard | 3000 | Interface web |
|
||||
| API | 8080 | REST API |
|
||||
| PostgreSQL | 5432 | Banco de dados (interno) |
|
||||
| ClickHouse | 9000 | Métricas/Logs (interno) |
|
||||
| Redis | 6379 | Cache (interno) |
|
||||
|
||||
---
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Containers não iniciam
|
||||
|
||||
```bash
|
||||
# Ver logs
|
||||
docker compose logs
|
||||
|
||||
# Verificar recursos
|
||||
docker system df
|
||||
df -h
|
||||
```
|
||||
|
||||
### Agent não conecta
|
||||
|
||||
```bash
|
||||
# Verificar conectividade
|
||||
curl -v https://api.ophion.com.br/health
|
||||
# Testar conectividade
|
||||
curl http://SEU-SERVIDOR:8080/health
|
||||
|
||||
# Verificar logs do agent
|
||||
# Ver logs do agent
|
||||
journalctl -u ophion-agent -f
|
||||
|
||||
# Testar API key
|
||||
curl -H "Authorization: Bearer YOUR_API_KEY" \
|
||||
https://api.ophion.com.br/api/v1/status
|
||||
```
|
||||
|
||||
### Métricas não aparecem
|
||||
|
||||
1. Verifique se o agent está rodando: `systemctl status ophion-agent`
|
||||
2. Verifique a API key no dashboard
|
||||
3. Confira o hostname no dashboard
|
||||
4. Aguarde até 60 segundos para primeira coleta
|
||||
|
||||
### Docker metrics não coletam
|
||||
### Resetar senha admin
|
||||
|
||||
```bash
|
||||
# Verificar permissões do socket
|
||||
ls -la /var/run/docker.sock
|
||||
|
||||
# Agent precisa estar no grupo docker
|
||||
sudo usermod -aG docker ophion-agent
|
||||
docker compose exec postgres psql -U ophion -c \
|
||||
"UPDATE users SET password_hash = crypt('nova-senha', gen_salt('bf')) WHERE email = 'admin@email.com';"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Suporte
|
||||
|
||||
- 📧 Email: suporte@ophion.com.br
|
||||
- 💬 Telegram: [@ophion_suporte](https://t.me/ophion_suporte)
|
||||
- 📖 Docs: https://docs.ophion.com.br
|
||||
- 🐙 GitHub: https://github.com/bigtux/ophion
|
||||
|
||||
---
|
||||
|
||||
*Made with 🖤 in Brazil*
|
||||
- 📖 Docs: https://docs.ophion.io
|
||||
- 💬 Discord: https://discord.gg/ophion
|
||||
- 🐛 Issues: https://github.com/bigtux/ophion/issues
|
||||
- 📧 Email: support@ophion.io
|
||||
|
||||
Reference in New Issue
Block a user