> Source: https://docs.cyberelements.io/bastion/4.7/pt/Security/LocalFirewall/

# Local firewall

The `iptables` package is installed by default with CyberElements Bastion. It allows **local** network filtering to be put in place on each server, in addition to (**never as a replacement for**) the perimeter filtering equipment already in place.

How the rules are implemented differs between **standalone mode**, where filtering is configured locally, and **cluster mode**, where CyberElements Bastion applies and manages a predefined rule base on the Mediation Controller ([R39](#r39)). On the Edge Gateway, standalone or cluster, the simplified profile of [R37](#r37) applies.

> **Information**
>
> The closest ANSSI reference on this subject is the technical note **DAT-NT-006/ANSSI/SDE/NP** "Recommandations pour la définition d'une politique de filtrage réseau d'un pare-feu". The principle adopted in this guide is the **positive security model**: inbound flows must be limited to the needs explicitly identified. For the Mediation Controller, outbound filtering is restricted as well. For the Edge Gateway, a simplified profile allowing outbound flows is offered in [R37](#r37) so as to cover published resources without maintaining a port list specific to each deployment; that trade-off is documented explicitly.

## Summary

| # | Recommendation | Mediation Controller | Edge Gateway |
|---|---|---|---|
| [**R35**](#r35) | Filtering principle and positive security model | ✅ | ✅ |
| [**R36**](#r36) | Base rules in Standalone mode (Mediation Controller) | ✅ | ❌ |
| [**R37**](#r37) | Simplified profile for the Edge Gateway | ❌ | ✅ |
| [**R38**](#r38) | Persistence of rules at startup | ✅ | ✅ |
| [**R39**](#r39) | Cluster mode: filtering script managed by the product | ✅ | ❌ |
| [**R40**](#r40) | Disabling IPv6 when it is not needed | ✅ | ✅ |
| [**R41**](#r41) | Verification, audit and monitoring of rules | ✅ | ✅ |

## R35. Filtering principle and positive security model

**Applies to**: Mediation Controller ✅ · Edge Gateway ✅

The local filtering policy must follow the principle of **least privilege**. Inbound, any flow not explicitly authorised must be rejected. The Mediation Controller also uses a restrictive policy **outbound**.

On the Edge Gateway, the simplified profile described in [R37](#r37) is a **deliberate exception**: outbound flows are allowed so as to permit access to published resources, while inbound connections remain blocked apart from SSH administration.

Filtering must be **stateful** (connection tracking) so as to allow packets belonging to a legitimately established or related connection, without opening a specific rule for each return flow.

> **Warning!**
>
> Configuring a local firewall can cause an **immediate loss of connectivity** if something goes wrong. Every change must be prepared from a **console access** or a fallback administration session, tested before being made persistent, then **checked after a reboot**.

## R36. Base rules in Standalone mode (Mediation Controller)

**Applies to**: Mediation Controller ✅ · Edge Gateway ❌

In standalone mode, create a dedicated working file. The rules below reflect the functional profile of the Mediation Controller; they must be **adapted** where additional flows are needed: monitoring, backup, remote logging, SMTP or other information system services.

```
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
```

Check the syntax of the file **before** applying it:

```
1
```

Where administration is carried out remotely, `iptables-apply` is recommended, so as to benefit from an **automatic rollback** to the previous rule set if the new policy cuts off the administration session:

```
1
```

Then check the active rules:

```
1
```

Port **TCP/25** should only be kept if the email notification function is used. In that case, the rule should, where possible, be **restricted to the address of the SMTP relay**. Access to the APT repositories and the other additional flows must remain consistent with the deployment's flow matrix.

## R37. Simplified profile for the Edge Gateway

**Applies to**: Mediation Controller ❌ · Edge Gateway ✅

The Edge Gateway must initiate connections towards the Mediation Controller and towards the **published resources** of the information system. As the nature and ports of those resources vary from one deployment to another, a simplified profile may be used: **all outbound flows are allowed**, while inbound connections are denied apart from SSH administration access from an explicitly authorised network.

> **Warning!**
>
> This profile is suitable only where the Edge Gateway needs no inbound flow other than SSH administration access. If **agent mode** is used, or if **direct access to resources** is enabled, additional inbound rules must be added **before the `COMMIT` line**. Those openings must be limited to the ports required and, where possible, to the authorised IP addresses or network ranges only. Otherwise, the features concerned will not work. Routed flows may also require the `FORWARD` chain to be adapted.

```
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
```

The value `<ADMIN_NETWORK/CIDR>` must be replaced with the administration address or subnet actually authorised. **Opening the SSH port to all networks is not recommended.**

Test then apply the policy with the same checks as for the Mediation Controller:

```
1
2
3
```

## R38. Persistence of rules at startup

**Applies to**: Mediation Controller ✅ · Edge Gateway ✅

Once the rule set has been validated, it must be **loaded automatically at every startup**. The recommended mechanism is `iptables-persistent`, which relies on `netfilter-persistent` to load and save the Netfilter configuration.

```
1
2
3
4
```

> **Warning!**
>
> Persistence must only be enabled **once the rule set has been functionally validated**. After a full reboot, check that the expected policy is indeed loaded and that the administration and production functions remain operational.

```
1
```

## R39. Cluster mode: filtering script managed by the product

**Applies to**: Mediation Controller ✅ · Edge Gateway ❌

In cluster mode, CyberElements Bastion applies predefined rules **by default**. Inbound flows are blocked apart from the services the product provides for, and the flows required between the mediation servers are managed by the cluster configuration. Additional rules can be added through `/etc/ipdiva/server/extraNetFilterRules`.

> **Warning!**
>
> This file is a **shell script using variables internal to the product**. The rules below match the intended operation of the cluster, but any adaptation must take into account the installed version, the real and virtual addresses, and the needs specific to the deployment. **The file must be backed up before modification.**

```
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
```

> **Information**
>
> If an external database, a logging server, an SMTP relay, a monitoring solution or another external service is used, the **corresponding outbound rules must be added**, with strictly the address and port required.

After modification, reload the configuration following the product procedure then check the active rules:

```
1
2
```

> **Warning!**
>
> This recommendation is classified as **reserved for support/project**: it manipulates variables internal to the product, liable to change from one version to the next (see [Classification of recommendations](https://docs.cyberelements.io/bastion/4.7/pt/Security/Classification/#reserved-or-to-be-validated)).

## R40. Disabling IPv6 when it is not needed

**Applies to**: Mediation Controller ✅ · Edge Gateway ✅

The `iptables` rules presented in this chapter cover **IPv4** traffic. To prevent a service from being reachable over IPv6 **without an equivalent filtering policy**, the reference profile recommends disabling IPv6 where that protocol is not used in the architecture.

Create a dedicated `sysctl` file:

```
1
2
3
4
```

Apply and check the configuration:

```
1
2
3
4
```

> **Warning!**
>
> If IPv6 is **explicitly required** by the architecture, it must not be disabled. In that case, an **equivalent IPv6 filtering policy** must be defined and tested: IPv4 filtering alone does not protect IPv6 flows.

> **Classification**
>
> **To be validated**: IPv6 coverage of the filtering (`ip6tables`). See the [Classification of recommendations](https://docs.cyberelements.io/bastion/4.7/pt/Security/Classification/#reserved-or-to-be-validated) appendix.

## R41. Verification, audit and monitoring of rules

**Applies to**: Mediation Controller ✅ · Edge Gateway ✅

The active rules and their counters can be consulted with:

```
1
2
```

It is recommended to check periodically that the counters of the `ACCEPT` rules **evolve as expected** and that the rules logging rejected packets do not report an abnormal volume. The active rules must be compared against the **expected flow matrix** for the server's role.

```
1
```

Every rule added, modified or removed must be **documented**: purpose, direction of the flow, protocol, port, source, destination, date and person behind the change. After any significant update of CyberElements Bastion or of the system, check that the persistent rules remain consistent with the services actually in use.

> **Information**
>
> [fail2ban](https://docs.cyberelements.io/bastion/4.7/pt/Security/Fail2ban/) can insert and remove IP banning rules **dynamically**. Those rules must be taken into account during audits so as to tell the firewall's **static policy** apart from the **temporary rules** generated by the protection mechanisms.
