Skip to content
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

Add support for custom ports #38

Merged
merged 43 commits into from Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
050939f
Add support for custom ports
May 10, 2021
01bf854
typo
May 10, 2021
23c512f
changed exist to exists now it all works
May 10, 2021
59aa205
made the requested changes
Jun 9, 2021
eea9d5e
fix
Jun 9, 2021
99cd26d
type-o
Jun 9, 2021
f91df23
requested changes were implemented
Aug 23, 2021
42af42a
removed the rhel-system-roles
Aug 23, 2021
740d068
Merge branch 'linux-system-roles:master' into master
lessfoobar Aug 9, 2022
81d01c5
swapped firewalld module with the LSR.firewall
lessfoobar Aug 9, 2022
9d6defb
removed FQDN for import_role
lessfoobar Aug 9, 2022
b7b3c71
removed by requiest
lessfoobar Aug 9, 2022
bfa7193
fixed the FQDN for the selinux and firewall roles
lessfoobar Aug 9, 2022
1295970
add requirements for the fedora.linux_system_roles
lessfoobar Aug 9, 2022
2144329
update the readme with requirements section
lessfoobar Aug 9, 2022
bf8d525
address some of the linter issues
richm Aug 10, 2022
aa07654
fix more lint issues
richm Aug 10, 2022
05c94b7
fix lint issues
richm Aug 10, 2022
677c1f7
remove extra blank line
richm Aug 10, 2022
51b443a
swap blockinfile to template usage
lessfoobar Aug 11, 2022
9fac310
add template for custom port
lessfoobar Aug 11, 2022
1c81ed7
add when statement against the default values
lessfoobar Aug 11, 2022
91272a8
test firewall changes
lessfoobar Aug 11, 2022
208cf90
add TCP check on listening port
lessfoobar Aug 11, 2022
638c75a
Added comments for the tasks in the test
lessfoobar Aug 15, 2022
487f868
fix yamllint, style issues
richm Aug 19, 2022
80c4b01
fix yamlint issues
richm Aug 19, 2022
7530e3f
more yamllint issues
richm Aug 19, 2022
1327743
fix more yamllint issues
richm Aug 19, 2022
71644f7
fixed yamllint errors
Sep 7, 2022
a01a3bb
Merge branch 'master' of https://github.com/lessfoobar/nbde_server
Sep 7, 2022
a9aff14
Merge branch 'linux-system-roles:master' into master
lessfoobar Sep 7, 2022
2cd1a28
fixing merger errors
Sep 7, 2022
1a26448
Merge branch 'master' of https://github.com/lessfoobar/nbde_server
Sep 7, 2022
cd3fb90
fixed role name
Sep 8, 2022
efb96d3
add fixes suggested by nhosoi
lessfoobar Sep 14, 2022
6f22e1c
fix for port possibility as int
Sep 15, 2022
c112230
Merge branch 'master' of https://github.com/lessfoobar/nbde_server
Sep 15, 2022
344462b
implement the proposed changes from richm & nhosoi
Sep 27, 2022
b515a68
sorry I have word wrap and its hard to follow this 80 chars per line
lessfoobar Sep 27, 2022
ee98762
yeap forgot the empty space on the two lines. Fixed now
lessfoobar Sep 27, 2022
0b32b1e
remove the stat and moved the templates shortcut
lessfoobar Sep 28, 2022
0dbc506
added the int conversion
lessfoobar Sep 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .cache/roles/nbde_server
18 changes: 15 additions & 3 deletions README.md
Expand Up @@ -14,9 +14,6 @@ Supported Distributions
Limitations
-----------

It is not currently possible to specify a custom port for the NBDE servers configured by this role.


Role Variables
--------------

Expand All @@ -30,6 +27,9 @@ These are the variables that can be passed to the role:
|`nbde_server_fetch_keys`| `no` | indicates whether we should fetch keys to the control node, in which case they will be placed in `nbde_server_keys_dir`. You **must** set `nbde_server_keys_dir` to use `nbde_server_fetch_keys`.
|`nbde_server_deploy_keys`| `no` |indicates whether we should deploy the keys located in `nbde_server_keys_dir` directory to the remote hosts. You **must** set `nbde_server_keys_dir` to use `nbde_server_deploy_keys`.
|`nbde_server_keys_dir`| | specifies a directory in the control node that contains keys to be deployed to the remote hosts. Keys located in the top level directory will be deployed to every remote host, while keys located within subdirectories named after the remote hosts -- as per the inventory -- will be deployed only to these specific hosts. `nbde_server_keys_dir` **must** be an absolute path. You need to set this to use either `nbde_server_fetch_keys` and/or `nbde_server_deploy_keys`.
|`nbde_server_port`|`80`| setup custom port which will be enabled in SELinux and firewalld.
|`nbde_server_firewall_zone`|`public`| change the default zone where the port should be opened.



#### nbde_server_fetch_keys and nbde_server_deploy_keys
Expand Down Expand Up @@ -108,6 +108,18 @@ To redeploy keys, they must be placed into subdirectories named after the host t
- linux-system-roles.nbde_server
```

#### Example 5: deploy NBDE server with custom port and zone
```yaml
---
- hosts: all

vars:
nbde_server_port: 7500
nbde_server_firewall_zone: dmz
roles:
- linux-system-roles.nbde_server
```

License
-------

Expand Down
10 changes: 10 additions & 0 deletions defaults/main.yml
Expand Up @@ -34,4 +34,14 @@ nbde_server_deploy_keys: no
# to use either nbde_server_fetch_keys and/or nbde_server_deploy_keys.
nbde_server_keys_dir: ""

# nbde_server_port indicate the port that nbde_server's firewall should open.
# The default port is 80. Tang uses the TCP protocol. Thus the specified port
# will listen on the nbde_server_port/TCP
nbde_server_port: 80

# nbde_server_firewall_zone indicate the zone that nbde_server's firewall should
# write into. The default zone is public. If that is not the case you can change
# that here. Usually it should be left like that.
nbde_server_firewall_zone: public

# vim:set ts=2 sw=2 et:
3 changes: 3 additions & 0 deletions tasks/main-tang.yml
Expand Up @@ -26,6 +26,9 @@
when: (nbde_server_fetch_keys | bool) or (nbde_server_deploy_keys | bool)
include_tasks: tang-key-management.yml

- name: Open port in firewalld
include_tasks: tangd-custom-port.yml

- name: Ensure required services are enabled and at the right state
service:
name: "{{ item }}"
Expand Down
55 changes: 55 additions & 0 deletions tasks/tangd-custom-port.yml
@@ -0,0 +1,55 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are changing the way we use system roles from other system roles - https://linux-system-roles.github.io/documentation/role-requirements.html

The short answer is

  • you'll need a meta/collection-requirements.yml like this
collections:
  - fedora.linux_system_roles
  • refer to the selinux and firewall system roles by the collection FQCN
- name: Allow the custom port for tangd_port_t in SELinux
  import_role:
    name: fedora.linux_system_roles.selinux
  vars:
...

# This task tells SELinux for the port that we want the tangd service to use when distribution Fedora
- name: Allow the custom port for tangd_port_t in SELinux
import_role:
name: linux-system-roles.selinux
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name: fedora.linux_system_roles.selinux

vars:
selinux_ports:
- { ports: '{{ nbde_server_port }}', proto: 'tcp', setype: 'tangd_port_t', state: 'present' }

# This block creates the override file for systemd with the new port that we have requested
- name: Create override file
block:
# This task checks if the directory /etc/systemd/system/tangd.socket.d exist and registers the value in systemd__system__tangd_socket
- name: Check if directory /etc/systemd/system/tangd.socket.d exist
stat:
path: /etc/systemd/system/tangd.socket.d
register: systemd_system_tangd_socket

# This tasks Create the /etc/systemd/system/tangd.socket.d directory if it does not exist
- name: Create a directory if it does not exist
file:
path: /etc/systemd/system/tangd.socket.d
state: directory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will already create the directory if it does not exist, no? There is no need to check/register in the previous task and run this conditionally here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

mode: '0755'
when: systemd_system_tangd_socket.stat.exists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We want to create the directory when it does not exist?

      when: not systemd_system_tangd_socket.stat.exists

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ops ... you are correct. I've fixed the problems and I'm pushing it right now.


# This tasks creates the file with the port entry that we want tangd to listen to
- name: Creates the file with the port entry that we want tangd to listen to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a blockinfile here instead of template?
We'll also need a proper ansible_managed header here - many of our users require a custom multi-line value for ansible_managed - so our roles have standardized on using
{{ ansible_managed | comment }} in files managed by the roles. If you use template it will be easy - if you use blockinfile then you'll need to have some additional code in order to ensure a proper ansible managed header.

blockinfile:
path: /etc/systemd/system/tangd.socket.d/override.conf
block: |
[Socket]
ListenStream=
ListenStream={{ nbde_server_port }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ListenStream is a list, so if you just specify a port here, it will be like you are adding this new port to the list. You should first clear this list with an empty ListenStream= line prior to setting the new port. Check out https://www.freedesktop.org/software/systemd/man/systemd.socket.html#Options for more info.

Also, it would be great if you could add a test to make sure the server is using the new port (and ideally make also sure we are not using in the old one)

state: present
create: yes
mode: '0644'
marker: "# {mark} ANSIBLE MANAGED BLOCK NBDE"
register: __nbde_server_daemon_reload

# This tasks reload the daemons so the new changes take effect
- name: Reload the daemons so the new changes take effect
systemd:
daemon_reload: yes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be conditional i.e. when: __nbde_server_daemon_reload - then one of the tasks above should set __nbde_server_daemon_reload if the daemon needs to be reloaded

when: __nbde_server_daemon_reload.changed

# This task makes sure that we add the new port to firewalld
- name: Ensure the desired port is added to firewalld
firewalld:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use the https://github.com/linux-system-roles/firewall role for this instead of the firewalld module, similar to how you used the selinux role for the selinux settings.

port: "{{ nbde_server_port }}/tcp"
zone: "{{ nbde_server_firewall_zone }}"
state: enabled
immediate: yes
permanent: yes