> For the complete documentation index, see [llms.txt](https://docs.cennso.com/components/cgw/1.12/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/cgw/1.12/configuration/sysctls.md).

# Kernel parameters

CGW deployments have long configured network parameters through CNI plugins or
init containers. The chart's `sysctls` value is another option: it sets them in
the Pod specification before containers start. This page compares the available
mechanisms and their constraints.

## What a gateway needs

| Parameter | Effect | Safe? |
| --- | --- | --- |
| `net.ipv4.ip_forward` | Enable IPv4 forwarding in the Pod's network namespace. Changing it resets that namespace's IPv4 configuration to host or router defaults. | no |
| `net.ipv4.conf.all.forwarding` | Enable forwarding on existing IPv4 interfaces. | no |
| `net.ipv6.conf.all.forwarding` | Forward IPv6. Also turns off autoconfiguration and router advertisement acceptance. | no |
| `net.ipv6.conf.default.forwarding` | The value an interface created later starts with. | no |
| `net.ipv4.conf.all.rp_filter` | Reverse path filtering: `0` off, `1` strict, `2` loose. Asymmetric routing needs `2`. | no |
| `net.ipv4.conf.default.disable_policy` | Default to skipping IPsec policy lookup on newly created interfaces. Needed on a VTI, see [below](#interfaces-the-cgw-creates-itself). | no |
| `net.ipv4.ping_group_range` | Which groups may open an ICMP socket. Only relevant without `NET_RAW`. | yes |

`Safe?` is Kubernetes' isolation classification, not a recommendation. A
gateway normally needs forwarding, reverse-path-filtering, and VTI settings,
but Kubernetes classifies them as unsafe and requires kubelet configuration.
`ping_group_range` is optional.

## Setting them through the chart

`sysctls` is a list of `name`/`value` entries and lands in the pod's
`securityContext`:

```yaml
sysctls:
  - name: net.ipv4.conf.all.forwarding
    value: "1"
  - name: net.ipv4.conf.all.rp_filter
    value: "2"
```

Kubernetes applies them before containers, including init containers, start.

Two details:

* **`value` is a string in the Kubernetes API.**
* **`additionalPodSpec.securityContext` is retained.** If both the root-level
  `sysctls` value and `additionalPodSpec.securityContext.sysctls` are set, the
  root-level `sysctls` list replaces the latter. Other fields in
  `additionalPodSpec.securityContext`, such as `runAsUser`, are unchanged.

### Enable IPv6 routing

```yaml
sysctls:
  - name: net.ipv6.conf.all.forwarding
    value: "1"
  - name: net.ipv6.conf.default.forwarding
    value: "1"
```

`all` covers existing interfaces; `default` covers those created later. IPv6
forwarding disables autoconfiguration and router-advertisement acceptance. Set
`net.ipv6.conf.<interface>.accept_ra` to `2` when the gateway needs an RA.

## The node has to allow it

Kubernetes permits a small, release-specific safe set. Most router settings
fall outside it because they change network behavior, not because they are
wrong for CGW. They need node-level enablement; check [the upstream
list](https://kubernetes.io/docs/tasks/administer-cluster/sysctl-cluster/#safe-and-unsafe-sysctls)
for the Kubernetes version in use.

Everything else is unsafe and has to be allowed per node, by starting the
kubelet with the parameter listed:

```
--allowed-unsafe-sysctls=net.ipv4.ip_forward,net.ipv4.conf.all.rp_filter
```

Allow unsafe parameters on every node where CGW may run, preferably through the
node-pool definition. For managed clusters where kubelet flags are unavailable,
see [other ways](#other-ways).

A Pod requesting a disallowed parameter is scheduled but does not start:

```console
$ kubectl get pod cgw-0
NAME    READY   STATUS            RESTARTS   AGE
cgw-0   0/3     SysctlForbidden   0          12s

$ kubectl describe pod cgw-0
  Status:  Failed
  Reason:  SysctlForbidden
  Message: forbidden sysctl: "net.ipv4.ip_forward" not allowlisted
```

Older kubelets use `not whitelisted`.

Other limits:

* **Only namespaced parameters** can be set from a pod. Anything else belongs in
  the node's own configuration.
* **`net.*` is rejected outright when the pod uses host networking**, which
  `additionalPodSpec.hostNetwork` turns on. There is no pod-level way to set a
  network parameter on a pod that shares the host's network namespace - it would
  be changing the node.

A cluster running Pod Security Admission at `baseline` or `restricted` forbids
unsafe parameters in a pod spec regardless of what the kubelet allows.

## Interfaces the CGW creates itself

Per-interface parameters live under `net.ipv4.conf.<interface>.*`:

| Prefix | Meaning |
| --- | --- |
| `conf.<interface>.<param>` | The value on one interface. |
| `conf.all.<param>` | A setting across existing interfaces; the exact effect is parameter-specific. |
| `conf.default.<param>` | The value an interface gets **when it is created**. |

Chart-managed VTI mode and GRE create their interfaces after Kubernetes applies
`sysctls`. Use `conf.default.*` for these later interfaces; `conf.all.*` is
parameter-specific.

The chart-managed VTI path (`ipsec.enabled: true`,
`ipsec.manualConfig: false`, and `ipsec.vti_key` set) needs:

```yaml
sysctls:
  - name: net.ipv4.conf.default.disable_policy
    value: "1"
```

rather than naming the VTI. Manual IPsec configuration owns its interface setup
and sysctls. Writing `/proc/sys` after interface creation needs `privileged:
true`; see [Container privileges](https://docs.cennso.com/components/cgw/1.12/configuration/container-privileges.md).

## Other ways

| Way | Reaches | Needs |
| --- | --- | --- |
| `sysctls` in the release | the whole pod network namespace, before any container | the parameter allowed in the kubelet of every candidate node |
| CNI `tuning` plugin through a `NetworkAttachmentDefinition` | the Pod network namespace; `IFNAME` resolves to the attachment interface when present | Multus, a NAD, and node-side plugin policy |
| a `privileged` container writing `/proc/sys` | anything in the pod network namespace, at any time | `privileged: true` on that container |
| node configuration (`/etc/sysctl.d`) | the host network namespace; some values may be inherited by new namespaces | node access |

Node configuration cannot enable Pod `net.ipv4.ip_forward`. Some IPv4
`conf.{all,default}.*` values may be inherited, depending on
`net.core.devconf_inherit_init_net`; configure the Pod explicitly instead.

The CNI `tuning` plugin can write namespace-wide sysctls after `loopback`.
For interface-specific keys, `IFNAME` names the attachment interface, not one
CGW creates later. CNI configuration, the NetworkAttachmentDefinition (NAD),
and Multus are cluster-owned:

```json
{
  "cniVersion": "0.4.0",
  "name": "cgw-wan",
  "plugins": [
    { "type": "macvlan", "master": "eth1", "ipam": { "type": "static" } },
    { "type": "tuning", "sysctl": { "net.ipv4.conf.IFNAME.rp_filter": "2" } }
  ]
}
```

`IFNAME` is replaced with the attachment interface name. Select the attachment
through the chart's passthrough annotation:

```yaml
additionalAnnotations:
  k8s.v1.cni.cncf.io/networks: cgw-wan
```

Limits:

* `IFNAME` cannot select CGW-created `vti*` or `gre-cgw` interfaces.
* Namespace-wide and `conf.default.*` settings affect the entire Pod namespace.
* Validate the node-side allowlist and CNI chain against installed versions.

## Troubleshooting

**The Pod is `SysctlForbidden`.** Allow the parameter through
`--allowed-unsafe-sysctls` or use [another mechanism](#other-ways). The message
names only the first rejected parameter.

**The Pod runs but does not forward.** Check its namespace, not the node:

```console
$ kubectl exec -it cgw-0 -c debug -- sysctl net.ipv4.ip_forward net.ipv6.conf.all.forwarding
```

An annotation of the form
`security.alpha.kubernetes.io/unsafe-sysctls: net.ipv6.conf.default.forwarding=1`
uses Kubernetes' retired alpha interface. Move the entries to `sysctls`.

**The value is right on `eth0` but wrong on a tunnel.** Use `conf.default.*`;
the tunnel was created later. See [interfaces the CGW creates
itself](#interfaces-the-cgw-creates-itself).
