Skip to contentSkip to conversation

nfsd: Refine the firewall settings on the -nfsd target node

RFC PATCH Superseded [email protected] 3 participants 3 messages Oct 18, 2024 – Oct 19, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 nfsd: Refine the firewall settings on the -nfsd target node

From: Chuck Lever <[email protected]>

In preparation for testing NFSD in the cloud, where target nodes might be exposed to the public internet, leave the firewall enabled and permit NFS traffic.

The documentation for the ansible.posix.firewalld module states "Not tested on any Debian based system." For now, Debian-based target nodes still simply disable firewalld.

---
 .../roles/nfsd/tasks/firewall/debian/main.yml | 11 ++++
 .../roles/nfsd/tasks/firewall/redhat/main.yml | 65 +++++++++++++++++++
 .../roles/nfsd/tasks/firewall/suse/main.yml   | 65 +++++++++++++++++++
 playbooks/roles/nfsd/tasks/main.yml           | 20 +++---
 playbooks/roles/nfsd/templates/nfs.conf.j2    |  3 +
 playbooks/roles/nfsd/vars/RedHat.yml          |  2 +
 6 files changed, 156 insertions(+), 10 deletions(-)
 create mode 100644 playbooks/roles/nfsd/tasks/firewall/debian/main.yml
 create mode 100644 playbooks/roles/nfsd/tasks/firewall/redhat/main.yml
 create mode 100644 playbooks/roles/nfsd/tasks/firewall/suse/main.yml

I have tested this change with Fedora on libvirt, and RHEL 9.4 on AWS.

I haven't tested these changes with SuSE-based target nodes. It looks like the menu option to select SuSE on the target nodes has disappeared.

playbooks/roles/nfsd/tasks/firewall/debian/main.yml new file +11 -0
new file mode 100644
index 000000000000..0ba5272812a6
@@ -0,0 +1,11 @@
+---
+- name: Populate service facts
+  ansible.builtin.service_facts:
+
+- name: Turn off firewalld
+  become: true
+  ansible.builtin.systemd_service:
+    name: firewalld.service
+    enabled: false
+    state: stopped
+  when: '"firewalld.service" in ansible_facts.services'
playbooks/roles/nfsd/tasks/firewall/redhat/main.yml new file +65 -0

65 lines not on this page · raw message

playbooks/roles/nfsd/tasks/firewall/suse/main.yml new file +65 -0

65 lines not on this page · raw message

playbooks/roles/nfsd/tasks/main.yml +10 -10
index 63388f857627..5f944708b2ec 100644
@@ -106,17 +106,17 @@
     state: present
   when: selinux_status.rc == 0
 
-# FIXME: open ports instead
-- name: Populate service facts
-  service_facts:
+- name: Open ports in NFS server's firewall (Debian)
+  ansible.builtin.include_tasks: roles/nfsd/tasks/firewall/debian/main.yml
+  when: ansible_os_family == 'Debian'
 
-- name: Turn off firewalld
-  become: yes
-  ansible.builtin.systemd_service:
-    name: firewalld.service
-    enabled: false
-    state: stopped
-  when: '"firewalld.service" in ansible_facts.services'
+- name: Open ports in NFS server's firewall (Suse)
+  ansible.builtin.include_tasks: roles/nfsd/tasks/firewall/suse/main.yml
+  when: ansible_os_family == 'Suse'
+
+- name: Open ports in NFS server's firewall (Red Hat)
+  ansible.builtin.include_tasks: roles/nfsd/tasks/firewall/redhat/main.yml
+  when: ansible_os_family == 'RedHat'
 
 - name: Start up nfsd
   become: yes
playbooks/roles/nfsd/templates/nfs.conf.j2 +3 -0
index a5f4a714ec34..e319f9246904 100644
@@ -1,6 +1,9 @@
 [general]
 pipefs-directory={{ pipefs_directory }}
 
+[lockd]
+port=4045
+
 [nfsd]
 udp=y
 rdma=y
playbooks/roles/nfsd/vars/RedHat.yml +2 -0
index 091c827c777d..ccffdcc4fdd9 100644
@@ -1,9 +1,11 @@
 ---
 nfsd_packages:
   - checkpolicy
+  - firewalld
   - lvm2
   - nfs-utils
   - policycoreutils
+  - python3-firewall
   - python3-policycoreutils
 
 fstype_userspace_progs:
Signature · 1 line
2.46.1
#1 lore raw
Quoted 5 lines · On Fri, 18 Oct 2024, [email protected] wrote:

From: Chuck Lever <[email protected]>

In preparation for testing NFSD in the cloud, where target nodes might be exposed to the public internet, leave the firewall enabled and permit NFS traffic.

I'm assuming there's no need to open a port for statd because we're not doing any reboot testing with v3?

Quoted 251 lines

The documentation for the ansible.posix.firewalld module states "Not tested on any Debian based system." For now, Debian-based target nodes still simply disable firewalld.

---
 .../roles/nfsd/tasks/firewall/debian/main.yml | 11 ++++
 .../roles/nfsd/tasks/firewall/redhat/main.yml | 65 +++++++++++++++++++
 .../roles/nfsd/tasks/firewall/suse/main.yml   | 65 +++++++++++++++++++
 playbooks/roles/nfsd/tasks/main.yml           | 20 +++---
 playbooks/roles/nfsd/templates/nfs.conf.j2    |  3 +
 playbooks/roles/nfsd/vars/RedHat.yml          |  2 +
 6 files changed, 156 insertions(+), 10 deletions(-)
 create mode 100644 playbooks/roles/nfsd/tasks/firewall/debian/main.yml
 create mode 100644 playbooks/roles/nfsd/tasks/firewall/redhat/main.yml
 create mode 100644 playbooks/roles/nfsd/tasks/firewall/suse/main.yml

I have tested this change with Fedora on libvirt, and RHEL 9.4 on AWS.

I haven't tested these changes with SuSE-based target nodes. It looks like the menu option to select SuSE on the target nodes has disappeared.

playbooks/roles/nfsd/tasks/firewall/debian/main.yml new file +11 -0
new file mode 100644
index 000000000000..0ba5272812a6
@@ -0,0 +1,11 @@
+---
+- name: Populate service facts
+  ansible.builtin.service_facts:
+
+- name: Turn off firewalld
+  become: true
+  ansible.builtin.systemd_service:
+    name: firewalld.service
+    enabled: false
+    state: stopped
+  when: '"firewalld.service" in ansible_facts.services'
playbooks/roles/nfsd/tasks/firewall/redhat/main.yml new file +65 -0
new file mode 100644
index 000000000000..39fab7773d09
@@ -0,0 +1,65 @@
+---
+- name: Populate service facts
+  ansible.builtin.service_facts:
+
+- name: Turn on firewalld
+  become: true
+  ansible.builtin.systemd_service:
+    name: firewalld.service
+    enabled: true
+    state: started
+  when: '"firewalld.service" in ansible_facts.services'
+
+- name: Open the rpcbind service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    service: rpc-bind
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the NFS service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    service: nfs
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the NLM TCP service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    port: 4045/tcp
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the NLM UDP service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    port: 4045/udp
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the MNT TCP service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    port: 20048/tcp
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the MNT UDP service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    port: 20048/udp
+    permanent: true
+    immediate: true
+    state: enabled
playbooks/roles/nfsd/tasks/firewall/suse/main.yml new file +65 -0
new file mode 100644
index 000000000000..39fab7773d09
@@ -0,0 +1,65 @@
+---
+- name: Populate service facts
+  ansible.builtin.service_facts:
+
+- name: Turn on firewalld
+  become: true
+  ansible.builtin.systemd_service:
+    name: firewalld.service
+    enabled: true
+    state: started
+  when: '"firewalld.service" in ansible_facts.services'
+
+- name: Open the rpcbind service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    service: rpc-bind
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the NFS service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    service: nfs
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the NLM TCP service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    port: 4045/tcp
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the NLM UDP service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    port: 4045/udp
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the MNT TCP service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    port: 20048/tcp
+    permanent: true
+    immediate: true
+    state: enabled
+
+- name: Open the MNT UDP service port in firewalld
+  become: true
+  become_method: ansible.builtin.sudo
+  ansible.posix.firewalld:
+    port: 20048/udp
+    permanent: true
+    immediate: true
+    state: enabled
playbooks/roles/nfsd/tasks/main.yml +10 -10
index 63388f857627..5f944708b2ec 100644
@@ -106,17 +106,17 @@
     state: present
   when: selinux_status.rc == 0
 
-# FIXME: open ports instead
-- name: Populate service facts
-  service_facts:
+- name: Open ports in NFS server's firewall (Debian)
+  ansible.builtin.include_tasks: roles/nfsd/tasks/firewall/debian/main.yml
+  when: ansible_os_family == 'Debian'
 
-- name: Turn off firewalld
-  become: yes
-  ansible.builtin.systemd_service:
-    name: firewalld.service
-    enabled: false
-    state: stopped
-  when: '"firewalld.service" in ansible_facts.services'
+- name: Open ports in NFS server's firewall (Suse)
+  ansible.builtin.include_tasks: roles/nfsd/tasks/firewall/suse/main.yml
+  when: ansible_os_family == 'Suse'
+
+- name: Open ports in NFS server's firewall (Red Hat)
+  ansible.builtin.include_tasks: roles/nfsd/tasks/firewall/redhat/main.yml
+  when: ansible_os_family == 'RedHat'
 
 - name: Start up nfsd
   become: yes
playbooks/roles/nfsd/templates/nfs.conf.j2 +3 -0
index a5f4a714ec34..e319f9246904 100644
@@ -1,6 +1,9 @@
 [general]
 pipefs-directory={{ pipefs_directory }}
 
+[lockd]
+port=4045
+
 [nfsd]
 udp=y
 rdma=y
playbooks/roles/nfsd/vars/RedHat.yml +2 -0
index 091c827c777d..ccffdcc4fdd9 100644
@@ -1,9 +1,11 @@
 ---
 nfsd_packages:
   - checkpolicy
+  - firewalld
   - lvm2
   - nfs-utils
   - policycoreutils
+  - python3-firewall
   - python3-policycoreutils
 
 fstype_userspace_progs:
Signature · 1 line
2.46.1
#2 lore raw
Quoted 14 lines · Scott Mayhew
Quoted 5 lines · On Fri, 18 Oct 2024, [email protected] wrote:

From: Chuck Lever <[email protected]>

In preparation for testing NFSD in the cloud, where target nodes might be exposed to the public internet, leave the firewall enabled and permit NFS traffic.

I'm assuming there's no need to open a port for statd because we're not doing any reboot testing with v3?

Actually I didn't realize there was a "[statd]" section in nfs.conf, so I didn't think it would be easy to set a fixed port value for statd. Let me see if it can be added.

--
Chuck Lever