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
| Port | Protocol | Purpose | Access Scope |
|---|---|---|---|
| 8441 | TCP | OpenZiti Controller API | Public / Edge Clients |
| 8442 | TCP | OpenZiti Edge Router Listener | Public / Mesh Routers & Tunnels |
| 22 | TCP | SSH Administration | Restricted to Admin CIDR (or temporary) |
| 6443 | TCP | K3s Kubernetes API Server | Internal Only (k3s_os_hardening_k3s_api_cidr) |
| 8472 | UDP | Flannel CNI VXLAN Overlay | Internal Only (k3s_os_hardening_k3s_api_cidr) |
| 10250 | TCP | Kubelet Node API | Internal 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:
- Run
ziti-edge-tunneldirectly on the host or in an administrative sidecar. - Intercept SSH traffic over an authenticated OpenZiti service (e.g.
ssh.host.ziti). - Fully close port 22 on UFW, leaving zero administrative ports open to the public internet.