Gå til indholdet

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). On the Edge Gateway, standalone or cluster, the simplified profile of 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 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 Filtering principle and positive security model
R36 Base rules in Standalone mode (Mediation Controller)
R37 Simplified profile for the Edge Gateway
R38 Persistence of rules at startup
R39 Cluster mode: filtering script managed by the product
R40 Disabling IPv6 when it is not needed
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 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
mkdir -p /etc/iptables
cat > /etc/iptables/bastion-mediation.rules << 'EOF'
*filter
-P INPUT DROP
-P OUTPUT DROP
-P FORWARD DROP
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 3 -j ACCEPT
-A OUTPUT -p tcp -m state --state NEW --dport 25 -j ACCEPT
-A OUTPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
-A OUTPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT
-A OUTPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT
-A OUTPUT -p udp -m state --state NEW --dport 53 -j ACCEPT
-A OUTPUT -p udp -m state --state NEW --dport 123 -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT
-A OUTPUT ! -o lo -d 127.0.0.0/8 -j REJECT
-A INPUT -m limit --limit 5/min --limit-burst 10 -j LOG --log-prefix "iptables-input-dropped: " --log-level 4
-A OUTPUT -m limit --limit 5/min --limit-burst 10 -j LOG --log-prefix "iptables-output-dropped: " --log-level 4
COMMIT
EOF

Check the syntax of the file before applying it:

1
iptables-restore --test /etc/iptables/bastion-mediation.rules

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
iptables-apply -t 30 /etc/iptables/bastion-mediation.rules

Then check the active rules:

1
iptables -L -v -n

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
cat > /etc/iptables/bastion-edge.rules << 'EOF'
*filter
-P INPUT DROP
-P OUTPUT ACCEPT
-P FORWARD DROP
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -s 127.0.0.0/8 -j DROP
-A INPUT -m state --state INVALID -j DROP
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# SSH administration from the authorized network only
-A INPUT -p tcp -s <ADMIN_NETWORK/CIDR> -m state --state NEW --dport 22 -j ACCEPT
# Rate-limited logging of rejected inbound connections
-A INPUT -m limit --limit 5/min --limit-burst 10 -j LOG --log-prefix "iptables-edge-dropped: " --log-level 4
COMMIT
EOF

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
iptables-restore --test /etc/iptables/bastion-edge.rules
iptables-apply -t 30 /etc/iptables/bastion-edge.rules
iptables -L -v -n

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
apt install iptables-persistent
iptables-save > /etc/iptables/rules.v4
netfilter-persistent save
systemctl status netfilter-persistent

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
iptables -L -v -n

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
cp -a /etc/ipdiva/server/extraNetFilterRules /etc/ipdiva/server/extraNetFilterRules.bak
cat > /etc/ipdiva/server/extraNetFilterRules << 'EOF'
iptables -F OUTPUT
iptables -P OUTPUT DROP
iptables -A OUTPUT -o lo -j ACCEPT
iptables -A OUTPUT ! -o lo -d 127.0.0.0/8 -j REJECT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -p tcp -m state --state NEW --dport 25 -j ACCEPT
iptables -A OUTPUT -p tcp -m state --state NEW --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp -m state --state NEW --dport 443 -j ACCEPT
iptables -A OUTPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT
iptables -A OUTPUT -p udp -m state --state NEW --dport 53 -j ACCEPT
iptables -A OUTPUT -p udp -m state --state NEW --dport 123 -j ACCEPT
if [ "$loadBalancingMode" = "lbSlave" ]; then
iptables -A OUTPUT -d $loadBalancingMasterRip -j ACCEPT
iptables -A OUTPUT -d $loadBalancingMasterRipSsl -j ACCEPT
else
iptables -A OUTPUT -d $loadBalancingSlaveRip -j ACCEPT
iptables -A OUTPUT -d $loadBalancingSlaveRipSsl -j ACCEPT
fi
iptables -A OUTPUT -d $loadBalancingVip -j ACCEPT
iptables -A OUTPUT -d $loadBalancingVipSsl -j ACCEPT
if [ "x$clusterMode" = "xloadbalancing" -a -n "$zeoVip" ]; then
iptables -A OUTPUT -d $zeoVip -j ACCEPT
fi
iptables -A OUTPUT -s $loadBalancingVip -p tcp --sport 443 --tcp-flags SYN,ACK ACK -j ACCEPT
iptables -A OUTPUT -s $loadBalancingVip -p tcp --sport 443 --tcp-flags SYN,ACK SYN,ACK -j ACCEPT
iptables -A OUTPUT -s $loadBalancingVipSsl -p tcp --sport 443 --tcp-flags SYN,ACK ACK -j ACCEPT
iptables -A OUTPUT -s $loadBalancingVipSsl -p tcp --sport 443 --tcp-flags SYN,ACK SYN,ACK -j ACCEPT
EOF

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
systemctl restart ipdiva-server.service
iptables -L -v -n

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).

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
cat > /etc/sysctl.d/99-cyberelements-bastion-ipv6.conf << 'EOF'
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
EOF

Apply and check the configuration:

1
2
3
4
sysctl --system
sysctl net.ipv6.conf.all.disable_ipv6
sysctl net.ipv6.conf.default.disable_ipv6
ip -6 addr

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 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
iptables -L -v -n
iptables-save

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
conntrack -L 2>/dev/null | wc -l

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 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.