Firewall

O Studio Next permite configurar regras de firewall (security groups) para controlar o tráfego de entrada e saída das suas VMs.

Conceitos básicos

Regras de firewall

Cada regra define:
  • Direction: inbound (entrada) ou outbound (saída)
  • Protocol: TCP, UDP, ICMP
  • Port: porta ou range (ex: 80, 443, 3000-4000)
  • Source/Destination: IP, CIDR, ou security group
  • Action: allow ou deny
Regras são stateful. Se você permite inbound na porta 80, o retorno é automaticamente permitido.

Ordem de aplicação

Regras são aplicadas em ordem:
  1. Regras específicas primeiro
  2. Regras gerais depois
  3. Default: deny all
Ordem importa. Uma regra “deny all” no topo bloqueará todas as conexões, mesmo se houver regras allow depois.

Templates de firewall

O Studio Next oferece templates pré-configurados:

Web Server

Para apps web:
DirectionPortProtocolSourceDescription
Inbound22TCPAnywhereSSH
Inbound80TCPAnywhereHTTP
Inbound443TCPAnywhereHTTPS
OutboundAllAllAnywhereAll outbound
Ideal para Next.js, React, APIs REST. Ajuste a porta SSH para IPs específicos em produção.

Database

Para bancos de dados:
DirectionPortProtocolSourceDescription
Inbound22TCPYour IPSSH
Inbound5432TCPApp VM IPPostgreSQL
OutboundAllAllAnywhereAll outbound
Nunca exponha databases na internet (0.0.0.0/0). Restrinja ao IP da app.

Custom

Crie suas próprias regras:
DirectionPortProtocolSourceDescription
Inbound22TCP192.168.1.0/24SSH from office
Inbound3000TCPAnywhereApp port
Inbound5432TCP10.0.0.5/32Database from app

Aplicando template

1

Acessar Firewall

Vá em Firewall no sidebar.
2

Selecionar VM

Escolha a VM para aplicar o firewall.
3

Escolher template

Selecione Web Server, Database ou Custom.
4

Customizar (opcional)

Ajuste regras conforme necessário: - Adicione regras custom - Edite source IPs - Reordene regras
5

Aplicar

Clique em Apply Template. As regras são aplicadas em 10-30 segundos.

Criando regras custom

1

Nova regra

Em Firewall → clique na VM → Add Rule.
2

Configurar

  • Direction: Inbound ou Outbound - Protocol: TCP, UDP, ICMP - Port: ex: 22, 80, 443, 3000-4000 - Source: IP, CIDR, ou 0.0.0.0/0 (anywhere) - Description: ex: “SSH from office”
3

Salvar

Clique em Save. A regra é aplicada imediatamente.
Para múltiplas portas, crie uma regra por porta ou use range (ex: 3000-4000).

Whitelist de IPs

Para restringir acesso a IPs específicos:
1

Identificar IPs

Liste os IPs que devem ter acesso: - Seu IP: whatismyip.com - Office IP: pergunte ao IT - CI/CD IP: documentação do provider
2

Criar regra

Em vez de 0.0.0.0/0, use: - Single IP: 192.168.1.100/32 - CIDR range: 192.168.1.0/24 (256 IPs)
Use /32 para um IP único. Isso evita expor IPs vizinhos.
3

Testar

Tente conectar de um IP não autorizado. A conexão deve falhar.

Regras comuns

SSH (porta 22)

Opção 1: Anywhere (não recomendado para produção)
Direction: Inbound
Port: 22
Protocol: TCP
Source: 0.0.0.0/0
Opção 2: IP específico (recomendado)
Direction: Inbound
Port: 22
Protocol: TCP
Source: 192.168.1.100/32
Expor SSH para 0.0.0.0/0 atrai brute force attacks. Use passkeys e/ou fail2ban.

HTTP/HTTPS (portas 80, 443)

# HTTP
Direction: Inbound
Port: 80
Protocol: TCP
Source: 0.0.0.0/0

# HTTPS
Direction: Inbound
Port: 443
Protocol: TCP
Source: 0.0.0.0/0

App port (3000, 8080, etc)

Opção 1: Expôr diretamente (dev only)
Direction: Inbound
Port: 3000
Protocol: TCP
Source: 0.0.0.0/0
Opção 2: Via reverse proxy (recomendado) Não exponha a porta da app. Use Nginx/Caddy na porta 80/443 e proxy_pass para localhost:3000.
Apps Node.js, Python, etc não devem ser expostas diretamente. Use reverse proxy para SSL, caching, rate limiting.

Database ports

PostgreSQL (5432)
Direction: Inbound
Port: 5432
Protocol: TCP
Source: 10.0.0.5/32 # IP da app
MongoDB (27017)
Direction: Inbound
Port: 27017
Protocol: TCP
Source: 10.0.0.5/32
MySQL (3306)
Direction: Inbound
Port: 3306
Protocol: TCP
Source: 10.0.0.5/32
Redis (6379)
Direction: Inbound
Port: 6379
Protocol: TCP
Source: 10.0.0.5/32

Debugging de firewall

Se a conexão falhar:

Próximos passos