> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/fpp/latest/llms.txt) (all documentation: [llms.txt](https://docs.cennso.com/llms.txt)). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cennso.com/components/fpp/latest/operation-guides/firewall.md).

# Configure firewall

The firewall capability is available using the `VPPACL` Custom Resource since FPP 2.2.0.

## VPPACL Custom Resources

To define Access Control List (ACL) rules, use the VPPACL Custom Resource (CR) that has the same fields as objects defined directly in VPP.

VPPACL Custom Resource consists of two arrays:
  - **rules**
  - **bindings**

VPPACL also contains a **required** label `fpp-manager.cennso.com/plumbing-instance` that must point to an FPP pod instance.

The minimal VPPACL example looks as follows:

```yaml
# Apply this on the Core Cluster
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPACL
metadata:
  name: test
  namespace: fpp
  labels:
    fpp-manager.cennso.com/created-for: node-op
    fpp-manager.cennso.com/plumbing-instance: vpp-webserver
spec:
  bindings:
    - ifName: srv
      direction: "input"
  rules:
    - action: "deny"
      source: "198.19.1.0/24"
```

This rule denies all incoming traffic at the **srv** interface from IPs matching range `198.19.1.0/24` on an instance `vpp-webserver`.

The example iptables set:

```
-A INPUT  -p tcp -i gre1 -s 10.10.10.2/32 -d 10.10.10.10/32 --dport 179 -j ACCEPT
-A INPUT  -p tcp -i gre1 -s 10.10.10.2/32 -d 10.10.10.10/32 --sport 179 -j ACCEPT
-A OUTPUT -p tcp -o gre1 -d 10.10.10.2/32 -s 10.10.10.10/32 --dport 179 -j ACCEPT
-A OUTPUT -p tcp -o gre1 -d 10.10.10.2/32 -s 10.10.10.10/32 --sport 179 -j ACCEPT
```

The equivalent in VPPACL object:

```yaml
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPACL
metadata:
  name: input-firewall
  labels:
    fpp-manager.cennso.com/created-for: node-op
    fpp-manager.cennso.com/plumbing-instance: vpp-webserver
spec:
  bindings:
    - ifName: gre1
      direction: "input"
  rules:
    - action: "permit"
      source: "10.10.10.2/32"
      protocol: "tcp"
      dest: "10.10.10.10/32"
      dstPort: "179"
    - action: "permit"
      source: "10.10.10.2/32"
      protocol: "tcp"
      dest: "10.10.10.10/32"
      srcPort: "179"
---
apiVersion: fpp-manager.cennso.com/v1alpha1
kind: VPPACL
metadata:
  name: output-firewall
  labels:
    fpp-manager.cennso.com/created-for: node-op
    fpp-manager.cennso.com/plumbing-instance: vpp-webserver
spec:
  bindings:
    - ifName: gre1
      direction: "output"
  rules:
    - action: "permit"
      source: "10.10.10.10/32"
      protocol: "tcp"
      dest: "10.10.10.2/32"
      dstPort: "179"
    - action: "permit"
      source: "10.10.10.10/32"
      protocol: "tcp"
      dest: "10.10.10.2/32"
      srcPort: "179"
```

### Rules
Rules are used to match traffic with a certain pattern and perform a defined action.
Each rule consists of an action and one or more optional parameters:

- **action** - Action to perform. The possible values are `deny`, `permit`, and `reflect`.
- **addressFamily** (optional) - Specifies the address family if it can't be deduced from the source or dest address
- **dest** (optional) - Destination Classless Inter-Domain Routing (CIDR)
- **dstPort** (optional) - Destination port range
- **protocol** (optional) - Defines the protocol. The possible values are `tcp`, `udp`, `sctp`, `icmp`, and `icmp6`.
- **source** (optional) - Source CIDR
- **srcPort** (optional) - Source port range

Source and destination port ranges are defined in the format of `1234-1235`.

CIDR addresses are defined in the formats of `192.168.0.0/24` or `2001:4860:4860::8888/32`.

### Bindings
Before rules can start matching traffic, they must be bound to an interface.
Bindings are a list of interfaces to which all the above rules will be applied.

Each element consists of those parameters:

- **ifName** - Interface name as specified in the VPPInterface CR
- **direction** - Applies the rules to the incoming traffic (`input`) or outgoing traffic (`output`)

## CLI

> **CAUTION:** This approach does not allow strict control over ACL identification.

> **CAUTION:** Using VPPACL CR makes this section obsolete. However, it still may be used for debugging purposes on interfaces not managed by FPP.

> **CAUTION:** ACLs defined for VPPInterfaces are removed by FPP.

The vppcli creation command looks as follows:

````bash
set acl-plugin acl {PERMIT|DENY} src {PREFIX} dst {PREFIX} proto {TCP|UDP} sport {X-Y} dport {X-Y} [tag FOO]
````

ACL Index used for later assignment to the input or output traffic is returned in CLI.
Normally, ACLs are indexed as positive numbers, starting from `0`. So if there are no ACLs on the running VPP instance, the first created ACL will be indexed as `0`. If the next ACL is created, it most likely will have ACL Index `1`.

Attaching ACLs to a specific interface and detaching them is done through the following command:

````bash
set acl-plugin interface {INTERFACE} {INPUT|OUTPUT} {ACL_INDEX} [del]
````

## FPP VPPConfig

> **CAUTION:** Using VPPACL CR makes this section obsolete. However, it still may be used for debugging purposes on interfaces not managed by FPP.

> **CAUTION:** ACLs defined for VPPInterfaces are removed by FPP.

The following set of iptables commands is replicated by the VPPConfig spec:

```
-A INPUT  -i gre1 -j ACCEPT -p icmp
```

ICMP is currently not supported by CLI, please refer to the [Limitations](#limitations) section.

```
-A INPUT -i eth0 -j ACCEPT
```

If no ACLs are assigned to the interface, all traffic will be accepted. There is no need to put extra rules per interface.

```
-A INPUT  -p tcp -i gre1 -s 10.10.10.2/32 -d 10.10.10.10/32 --dport 179 -j ACCEPT
-A INPUT  -p tcp -i gre1 -s 10.10.10.2/32 -d 10.10.10.10/32 --sport 179 -j ACCEPT
-A OUTPUT -p tcp -o gre1 -d 10.10.10.2/32 -s 10.10.10.10/32 --dport 179 -j ACCEPT
-A OUTPUT -p tcp -o gre1 -d 10.10.10.2/32 -s 10.10.10.10/32 --sport 179 -j ACCEPT
```

The specific interface/proto/destination can be specified as:

```yaml
afterCommands:
  ...
  set acl-plugin acl permit src 10.10.10.2/32 dst 10.10.10.10/32 proto TCP sport 179 dport 179
  # ACL Index: 1 -- this is an example
  set acl-plugin acl permit src 10.10.10.10/32 dst 10.10.10.2/32 proto TCP sport 179 dport 179
  # ACL Index: 2 -- this is an example
  set acl-plugin interface gre1 input acl 1
  set acl-plugin interface gre1 output acl 2
```

VRRP ACL example
> **NOTE:** VPP does not support protocol identification such as IPTables, see the [Limitations](#limitations) section.)

```yaml
afterCommands:
  ...
  set acl-plugin acl permit dst 224.0.0.0/8 # we have to open entire mcast group w/o proto specification
  # ACL Index: 3 -- this is an example
  set acl-plugin interface vrrp1 input acl 3
```

Drop specific network

```yaml
afterCommands:
  ...
  set acl-plugin acl deny src 10.10.0.0/24
  #ACL Index: 4 -- this is an example
  set acl-plugin interface memif0/100 input acl 4
```

## Verification

After applying a `VPPACL` resource, you can verify the ACL configuration in the VPP container in the Core Cluster:

```bash
vppctl show acl-plugin acl
```

The output shows the configured firewall rules:

```txt
acl-index 0 count 2 tag {472a169c-1f18-4cf4-9edb-e28a716f5ab2}
          0: ipv4 permit src 10.10.10.10/32 dst 10.10.10.2/32 proto 6 sport 0-65535 dport 179
          1: ipv4 permit src 10.10.10.10/32 dst 10.10.10.2/32 proto 6 sport 179 dport 0-65535
  applied inbound on sw_if_index:
  applied outbound on sw_if_index: 3
  used in lookup context index: 0
acl-index 1 count 2 tag {53554547-4524-4d69-8b3d-afc72b684b5f}
          0: ipv4 permit src 10.10.10.2/32 dst 10.10.10.10/32 proto 6 sport 0-65535 dport 179
          1: ipv4 permit src 10.10.10.2/32 dst 10.10.10.10/32 proto 6 sport 179 dport 0-65535
  applied inbound on sw_if_index: 3
  used in lookup context index: 1
```

## Limitations

- VPP CLI does not give any control of ACL indexing.
- VPP ACLs cover only TCP/UDP/ICMP L4 protocols and only TCP/UDP through CLI.
