-
Notifications
You must be signed in to change notification settings - Fork 32
docs: add a howto for configuring UFW #1642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f929763
965ea21
2e9f8ab
8d40fab
1c71504
bdf9a6b
3f4d29c
a25a9f6
828cb49
61f6da0
c81bdc1
3aa5ed1
c05f83c
4c92fc6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -530,6 +530,7 @@ ubuntu | |
Ubuntu Core | ||
Ubuntu Pro | ||
Ubuntu Server | ||
UFW | ||
uid | ||
UIDs | ||
unix | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,180 @@ | ||||||||||||||||||||||||||||||||
# How to configure Uncomplicated Firewall (UFW) | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
In this how-to we present a set of firewall rules/guidelines | ||||||||||||||||||||||||||||||||
you should consider when setting up {{product}}. | ||||||||||||||||||||||||||||||||
Be aware that these rules may be incompatible with your network setup | ||||||||||||||||||||||||||||||||
and we recommend you review and tune them to match your needs. | ||||||||||||||||||||||||||||||||
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like a note can we format it accordingly please?
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(active voice + causal conjunction) |
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Also, be aware that for each service hosted in Kubernetes, | ||||||||||||||||||||||||||||||||
the firewall rules need to be reviewed as there might be | ||||||||||||||||||||||||||||||||
special requirements for each. | ||||||||||||||||||||||||||||||||
Comment on lines
+8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
## Prerequisites | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
This guide assumes the following: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
- A machine with Ubuntu where you have installed | ||||||||||||||||||||||||||||||||
or you plan to install {{product}}. | ||||||||||||||||||||||||||||||||
- You have root or sudo access to the machine. | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should you already have a Canonical K8s cluster or is this done before the cluster is deployed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. Have a look at the updated version of this section.
Comment on lines
+17
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(active voice) |
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
## Install and enable UFW | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Uncomplicated Firewall needs to be configured on all nodes of {{product}}. | ||||||||||||||||||||||||||||||||
To do so try: | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo apt update | ||||||||||||||||||||||||||||||||
sudo apt install ufw | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
To verify UFW is installed try: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw status verbose | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
If you need to maintain ssh access to the machine, make sure you configure | ||||||||||||||||||||||||||||||||
UFW to allow `OpenSSH` before enabling it: | ||||||||||||||||||||||||||||||||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw allow OpenSSH | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Now you are ready to enable UFW: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw enable | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
## Allow forwarding | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Forwarding is needed because containers typically live in isolated networks | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
and expect the host-to-route traffic between their internal network and the | ||||||||||||||||||||||||||||||||
outside world to be allowed. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
First edit `/etc/default/ufw` and allow UFW to route/forward packets: | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
DEFAULT_FORWARD_POLICY="ACCEPT" | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Enable IP forwarding by editing `/etc/sysctl.conf` so it persists through | ||||||||||||||||||||||||||||||||
system reboots: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
net.ipv4.ip_forward=1 | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Or use `sysctl` directly so forwarding is applied immediately, | ||||||||||||||||||||||||||||||||
without rebooting the system: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Comment on lines
+61
to
+71
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Otherwise, use
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you edit the /etc/sysctl then you don't need to run this command correct? I think this is slightly unclear There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've clarified the need for this command in the revised version of this PR. |
||||||||||||||||||||||||||||||||
sudo sysctl -w net.ipv4.ip_forward=1 | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Reload UFW: | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw reload | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could optionally add a verification step here using ufw status. Wdyt? |
||||||||||||||||||||||||||||||||
## Allow access to the Kubernetes services | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Services such as CoreDNS require access to the Kubernetes API | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add a link to CoreDNS docs here. |
||||||||||||||||||||||||||||||||
server listening on port 6443. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Allow traffic on port 6443 with: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
``` sh | ||||||||||||||||||||||||||||||||
sudo ufw allow 6443/tcp | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Services such as the metrics-server need access to the kubelet, | ||||||||||||||||||||||||||||||||
controller manager and kube scheduler to query for metrics. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Kubelet runs on all nodes, so allow traffic on port 10250 on all nodes: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw allow 10250/tcp | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
The kube-controller-manager and kube-scheduler run only on | ||||||||||||||||||||||||||||||||
the control plane so allow traffic on ports 10257 and 10259 | ||||||||||||||||||||||||||||||||
on control plane nodes: | ||||||||||||||||||||||||||||||||
Comment on lines
+102
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw allow 10257/tcp | ||||||||||||||||||||||||||||||||
sudo ufw allow 10259/tcp | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
## Allow cluster formation | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
To form a High Availability (HA) cluster the datastore used by Kubernetes | ||||||||||||||||||||||||||||||||
(dqlite/etcd) needs to establish a direct connection among its peers. | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nhennigan We capitalize Dqlite in the rest of the docs but keep etcd lower-case. I think we should be uniform in out capitalization with etcd/dqlite. Wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch. Yes Dqlite should be capitalized according to their docs. I think the confusion stems from the fact on github it is listed with a lower case. etcd is the name of the product and they do not capitalize |
||||||||||||||||||||||||||||||||
In dqlite this is done through port 9000 while on etcd port 2380 is used. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Allow traffic on port 9000 on control plane nodes with dqlite: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw allow 9000/tcp | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Allow traffic on port 2380 on control plane nodes with etcd: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw allow 2380/tcp | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
Comment on lines
+123
to
+127
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about port 2379 for client communication? |
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Cluster formation is overseen by a Kubernetes daemon running on all nodes | ||||||||||||||||||||||||||||||||
on port 6400. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Allow traffic on port 6400: | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw allow 6400/tcp | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
## Allow CNI specific communication | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
(we've repeated allow a lot) |
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
If you are using the default network plugin (Cilium), | ||||||||||||||||||||||||||||||||
you should consider the following firewall rules. | ||||||||||||||||||||||||||||||||
Comment on lines
+140
to
+141
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Allow cluster-wide Cilium agent health checks and VXLAN traffic: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw allow 4240/tcp | ||||||||||||||||||||||||||||||||
sudo ufw allow 8472/udp | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
## UFW troubleshooting | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
The [ports-and-services] page has a list of all ports {{product}} uses. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
To inspect a failing service you can enable logging: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw logging on | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
Monitor the firewall logs with: | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
tail -f /var/log/ufw.log | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What can you learn form these logs? Which ports are trying to be accessed? Maybe we should add a comment here along the lines of "you should be able to see where the traffic is being dropped" or "this may help you identify any other ports or services you need to enable with UTW" |
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
The logs will show you which packets are dropped, their destination | ||||||||||||||||||||||||||||||||
and source as well as the protocol used and the destination port. | ||||||||||||||||||||||||||||||||
This information may help you identify any other ports or services | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
you need to enable within UFW. | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
To keep the resources used by UFW to a minimum you can disable logging: | ||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
```sh | ||||||||||||||||||||||||||||||||
sudo ufw logging off | ||||||||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
<!-- LINKS --> | ||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||
[ports-and-services]: ../../reference/ports-and-services |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(let's use an active voice)