Node Hardening & Firewall (UFW)

Overview

A fundamental prerequisite of the Dark K3s philosophy is defense-in-depth at the host operating system level. Before K3s or container runtimes are even installed, the host node must be locked down to prevent unintentional port exposure to the public internet.

The xnok.infra_bootstrap_tools.k3s_os_hardening Ansible role manages this process declaratively using UFW (Uncomplicated Firewall).


Firewall Policy Design

The firewall follows a strict default-deny ingress security posture:

Default Incoming: DENY  โ”‚  Default Outgoing: ALLOW  โ”‚  Default Routed: DENY

Port Matrix

PortProtocolPurposeAccess Scope
8441TCPOpenZiti Controller APIPublic / Edge Clients
8442TCPOpenZiti Edge Router ListenerPublic / Mesh Routers & Tunnels
22TCPSSH AdministrationRestricted to Admin CIDR (or temporary)
6443TCPK3s Kubernetes API ServerInternal Only (k3s_os_hardening_k3s_api_cidr)
8472UDPFlannel CNI VXLAN OverlayInternal Only (k3s_os_hardening_k3s_api_cidr)
10250TCPKubelet Node APIInternal Only (k3s_os_hardening_k3s_api_cidr)

By isolating port 6443 strictly to internal network interfaces (or localhost), internet scanners cannot detect or brute-force the Kubernetes API server.


Role Variables & Configuration

The k3s_os_hardening role provides variables in ansible/roles/k3s_os_hardening/defaults/main.yml:

# Default firewall policies
k3s_os_hardening_default_input: "deny"
k3s_os_hardening_default_output: "allow"

# Internal CIDR permitted to communicate directly with K3s API and CNI
# IMPORTANT: Override this with your cloud private VPC or wireguard CIDR
k3s_os_hardening_k3s_api_cidr: "10.0.0.0/24"

# OpenZiti Ingress Ports
k3s_os_hardening_openziti_controller_port: 8441
k3s_os_hardening_openziti_router_port: 8442

# Management Access
k3s_os_hardening_ssh_port: 22
k3s_os_hardening_ssh_cidr: "0.0.0.0/0" # Strongly recommended to restrict to your IP

Playbook Execution

The hardening role runs as the first step in the ansible/playbooks/k3s.yml playbook:

- name: Setup K3s Server
  hosts: k3s_servers
  become: true
  roles:
    - role: xnok.infra_bootstrap_tools.k3s_os_hardening
      vars:
        k3s_os_hardening_k3s_api_cidr: "10.136.0.0/16"
        k3s_os_hardening_ssh_cidr: "198.51.100.24/32"
    - role: xnok.infra_bootstrap_tools.k3s_server
    - role: xnok.infra_bootstrap_tools.k3s_flux_bootstrap

Verifying Firewall Status

Once the playbook completes, you can verify active rules on the target host:

sudo ufw status verbose

Expected output:

Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22/tcp                     ALLOW IN    198.51.100.24
8441/tcp                   ALLOW IN    Anywhere
8442/tcp                   ALLOW IN    Anywhere
6443/tcp                   ALLOW IN    10.136.0.0/16
8472/udp                   ALLOW IN    10.136.0.0/16
10250/tcp                  ALLOW IN    10.136.0.0/16

Future Roadmap: “Zitified” SSH

While SSH is currently allowed through port 22 from restricted admin CIDRs, the ultimate security goal for the Dark K3s stack is Zitifying SSH:

  1. Run ziti-edge-tunnel directly on the host or in an administrative sidecar.
  2. Intercept SSH traffic over an authenticated OpenZiti service (e.g. ssh.host.ziti).
  3. Fully close port 22 on UFW, leaving zero administrative ports open to the public internet.