# Configuración de Firewalls y accesos restringidos

Los firewalls y políticas de acceso restringido son componentes críticos para proteger infraestructuras industriales que utilizan InfluxDB 2.x en sistemas SCADA.

### Fundamentos de Firewalls en Entornos Industriales

**Firewalls como barrera primaria**:

* Implementan políticas **deny-by-default** (bloquear todo tráfico no explícitamente permitido).
* Segmentan redes en zonas lógicas (OT, IT, DMZ) para limitar el impacto de brechas.

**Arquitectura recomendada**:

{% code title="text" overflow="wrap" %}

```
[Red SCADA] ←→ [Firewall] ←→ [InfluxDB] ←→ [Firewall] ←→ [Red Corporativa]
```

{% endcode %}

* Aísla el servidor de InfluxDB con dos firewalls: uno frente a dispositivos SCADA y otro hacia redes empresariales.

## Configuración de Reglas para InfluxDB 2.x

**Reglas básicas de entrada/salida**:

| Puerto | Protocolo | Dirección | Acción | Uso               |
| ------ | --------- | --------- | ------ | ----------------- |
| 8086   | TCP       | SCADA     | ALLOW  | API HTTP InfluxDB |
| 8088   | TCP       | Interna   | ALLOW  | API gRPC          |
| \*     | ANY       | ANY       | DENY   | Regla final       |

**Mejores prácticas**:

* Limitar acceso a la API de escritura (POST /write) solo a dispositivos SCADA autorizados.
* Usar **listas de control de acceso (ACL)** para restringir consultas a buckets específicos.

## Integración Segura con Herramientas Externas

**Grafana y Postman**:

{% code title="bash" overflow="wrap" %}

```bash
# Ejemplo de regla UFW para Grafana
sudo ufw allow from 192.168.1.0/24 to any port 3000 proto tcp
```

{% endcode %}

* Autenticar todas las consultas mediante tokens de acceso de InfluxDB.
* Monitorizar logs de acceso para detectar consultas anómalas usando:

  <pre data-title="text" data-overflow="wrap"><code>from(bucket: "_monitoring")
    |> range(start: -1h)
    |> filter(fn: (r) => r._measurement == "httpd" and r._field == "authFail")
  </code></pre>

## Gestión de Usuarios y Roles en InfluxDB

**Estructura jerárquica**:

1. **Administradores**: Acceso completo (creación de buckets, DBRPs)
2. **Ingenieros SCADA**: Escritura en buckets específicos + lectura limitada
3. **Analistas**: Solo consultas de series temporales predefinidas

**Configuración mediante CLI**:

{% code title="bash" overflow="wrap" %}

```bash
influx v1 auth create \
  --username operador_scada \
  --password S3cur3P@ss \
  --read-bucket alarmas \
  --write-bucket metricas
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://darioaplicano.gitbook.io/influxdb2.x/sesion-4/guion-de-la-sesion/documentacion/seguridad-y-gestion-de-accesos/configuracion-de-firewalls-y-accesos-restringidos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
