Skip to content

Commit e9c3cc6

Browse files
authored
Add support for new NAP DoS distros (#209)
1 parent a97ac6d commit e9c3cc6

File tree

9 files changed

+183
-25
lines changed

9 files changed

+183
-25
lines changed
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
---
22
collections:
3-
- name: community.general
4-
version: 5.5.0
53
- name: ansible.posix
64
version: 1.4.0
5+
- name: community.crypto
6+
version: 2.5.0
77
- name: community.docker
88
version: 3.1.0
9+
- name: community.general
10+
version: 5.5.0

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## 0.8.1 (Unreleased)
44

5+
FEATURES:
6+
7+
* Add support for Alpine Linux for NGINX App Protect DoS.
8+
* Add support for Debian bullseye for NGINX App Protect DoS.
9+
* Check NGINX App Protect license is valid before trying to install NGINX App Protect (this means the role now requires the `community.crypto` collection).
10+
511
ENHANCEMENTS:
612

713
Bump the Ansible `community.general` collection to `5.501`, `ansible.posix` collection to `1.4.0` and `community.docker` collection to `3.1.0`.
@@ -33,8 +39,8 @@ FEATURES:
3339

3440
ENHANCEMENTS:
3541

36-
* Add support of RHEL 8.1+ for NGINX App Protect WAF 3.8.
37-
* Add support of RHEL 7.4+ and 8.x for NGINX App Protect DoS 2.1.
42+
* Add support for RHEL 8.1+ for NGINX App Protect WAF 3.8.
43+
* Add support for RHEL 7.4+ and 8.x for NGINX App Protect DoS 2.1.
3844
* New molecule tests for RHEL 7/8 and for NGINX App Protect WAF/DoS removal scenarios.
3945
* Bump the Ansible `community.general` collection to `4.7.0` and `community.docker` collection to `2.3.0`.
4046
* Update Dependabot to trigger updates at the same time across all NGINX core roles at the same time and to avoid triggering release drafter on GitHub actions dependency updates.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ If you wish to install NGINX App Protect WAF or NGINX App Protect DoS using this
2626
```yaml
2727
---
2828
collections:
29-
- name: community.general
30-
version: 5.5.0
3129
- name: ansible.posix
3230
version: 1.4.0
31+
- name: community.crypto
32+
version: 2.5.0
33+
- name: community.general
34+
version: 5.5.0
3335
- name: community.docker # Only required if you plan to use Molecule (see below)
3436
version: 3.1.0
3537
```

molecule/dos/molecule.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ lint: |
55
set -e
66
ansible-lint --force-color
77
platforms:
8+
- name: alpine-3.15
9+
image: alpine:3.15
10+
dockerfile: ../common/Dockerfile.j2
11+
privileged: true
12+
volumes:
13+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
14+
command: /sbin/init
815
- name: centos-7
916
image: centos:7
1017
dockerfile: ../common/Dockerfile.j2
@@ -33,6 +40,13 @@ platforms:
3340
volumes:
3441
- /sys/fs/cgroup:/sys/fs/cgroup:rw
3542
command: /sbin/init
43+
- name: debian-bullseye
44+
image: debian:bullseye-slim
45+
dockerfile: ../common/Dockerfile.j2
46+
privileged: true
47+
volumes:
48+
- /sys/fs/cgroup:/sys/fs/cgroup:rw
49+
command: /sbin/init
3650
- name: ubuntu-bionic
3751
image: ubuntu:bionic
3852
dockerfile: ../common/Dockerfile.j2
Lines changed: 85 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,86 @@
11
---
2-
- name: (Debian/Red Hat OSs) Create SSL directory
3-
ansible.builtin.file:
4-
path: /etc/ssl/nginx
5-
state: directory
6-
mode: 0755
7-
8-
- name: (Debian/Red Hat OSs) Copy NGINX App Protect certificate and license key
9-
ansible.builtin.copy:
10-
src: "{{ item }}"
11-
dest: /etc/ssl/nginx
12-
decrypt: true
13-
mode: 0444
14-
loop:
15-
- "{{ nginx_app_protect_license.certificate }}"
16-
- "{{ nginx_app_protect_license.key }}"
2+
- name: (Alpine Linux) Set up NGINX App Protect WAF/DoS license
3+
block:
4+
- name: Install cryptography package
5+
ansible.builtin.package:
6+
name: py3-cryptography
7+
8+
- name: (Alpine Linux) Create APK directory
9+
ansible.builtin.file:
10+
path: /etc/apk
11+
state: directory
12+
mode: 0755
13+
14+
- name: (Alpine Linux) Copy NGINX App Protect WAF/DoS certificate
15+
ansible.builtin.copy:
16+
src: "{{ nginx_app_protect_license.certificate }}"
17+
dest: /etc/apk/cert.pem
18+
decrypt: true
19+
mode: 0444
20+
21+
- name: (Alpine Linux) Copy NGINX App Protect WAF/DoS key
22+
ansible.builtin.copy:
23+
src: "{{ nginx_app_protect_license.key }}"
24+
dest: /etc/apk/cert.key
25+
decrypt: true
26+
mode: 0444
27+
28+
- name: (Alpine Linux) Check that NGINX App Protect WAF/DoS certificate is valid
29+
community.crypto.x509_certificate_info:
30+
path: /etc/apk/cert.pem
31+
register: cert
32+
33+
- name: (Alpine Linux) Check that NGINX App Protect WAF/DoS key is valid
34+
community.crypto.openssl_privatekey_info:
35+
path: /etc/apk/cert.key
36+
register: key
37+
38+
- name: (Alpine Linux) Check that NGINX App Protect WAF/DoS license is valid
39+
ansible.builtin.assert:
40+
that:
41+
- cert.expired == false
42+
- cert.public_key == key.public_key
43+
success_msg: Your NGINX App Protect WAF/DoS license is valid!
44+
fail_msg: Something went wrong! Make sure your App Protect WAF/DoS license is valid!
45+
when: ansible_os_family == "Alpine"
46+
47+
- name: (Debian/Red Hat OSs) Set up NGINX App Protect WAF/DoS license
48+
block:
49+
- name: (Debian/Red Hat OSs) Create SSL directory
50+
ansible.builtin.file:
51+
path: /etc/ssl/nginx
52+
state: directory
53+
mode: 0755
54+
55+
- name: (Debian/Red Hat OSs) Copy NGINX App Protect WAF/DoS certificate and license key
56+
ansible.builtin.copy:
57+
src: "{{ item }}"
58+
dest: /etc/ssl/nginx
59+
decrypt: true
60+
mode: 0444
61+
loop:
62+
- "{{ nginx_app_protect_license.certificate }}"
63+
- "{{ nginx_app_protect_license.key }}"
64+
65+
- name: (Debian/Red Hat OSs) Install cryptography package
66+
ansible.builtin.package:
67+
name: "{{ (ansible_python.version.major == 3) | ternary('python3-cryptography', 'python2-cryptography') }}"
68+
69+
- name: (Debian/Red Hat OSs) Check that NGINX App Protect WAF/DoS certificate is valid
70+
community.crypto.x509_certificate_info:
71+
path: /etc/ssl/nginx/nginx-repo.crt
72+
register: cert
73+
74+
- name: (Debian/Red Hat OSs) Check that NGINX App Protect WAF/DoS key is valid
75+
community.crypto.openssl_privatekey_info:
76+
path: /etc/ssl/nginx/nginx-repo.key
77+
register: key
78+
79+
- name: (Debian/Red Hat OSs) Check that NGINX App Protect WAF/DoS license is valid
80+
ansible.builtin.assert:
81+
that:
82+
- cert.expired == false
83+
- cert.public_key == key.public_key
84+
success_msg: Your NGINX App Protect WAF/DoS license is valid!
85+
fail_msg: Something went wrong! Make sure your NGINX App Protect WAF/DoS license is valid!
86+
when: ansible_os_family != "Alpine"

tasks/common/keys/setup-keys.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
---
2+
- name: (Alpine Linux) Set up NGINX App Protect DoS signing key
3+
block:
4+
- name: (Alpine Linux) Set up NGINX App Protect DoS signing key URL
5+
ansible.builtin.set_fact:
6+
keysite: "{{ nginx_app_protect_signing_key.nginx_plus | default(nginx_app_protect_default_signing_key_rsa_pub) }}"
7+
8+
- name: (Alpine Linux) Download NGINX App Protect DoS signing key
9+
ansible.builtin.get_url:
10+
url: "{{ keysite }}"
11+
dest: /etc/apk/keys/nginx_signing.rsa.pub
12+
mode: 0400
13+
when: ansible_os_family == "Alpine"
14+
215
- name: (Debian/Ubuntu) Set up NGINX App Protect and security updates signing key
316
block:
417
- name: (Debian/Ubuntu) Add NGINX Plus signing key

tasks/common/prerequisites/install-dependencies.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
---
2+
- name: (Alpine Linux) Install package dependencies
3+
community.general.apk:
4+
name: "{{ nginx_app_protect_alpine_dependencies }}"
5+
update_cache: true
6+
state: latest # noqa package-latest
7+
when: ansible_os_family == "Alpine"
8+
29
- name: (Debian/Ubuntu) Install package dependencies
310
ansible.builtin.apt:
411
name: "{{ nginx_app_protect_debian_dependencies }}"

tasks/dos/install-alpine.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
- name: (Alpine Linux) {{ nginx_app_protect_license_status is defined | ternary('Remove', 'Configure') }} NGINX Plus repository
3+
ansible.builtin.lineinfile:
4+
path: /etc/apk/repositories
5+
insertafter: EOF
6+
line: "{{ nginx_plus_repository | default(nginx_plus_default_repository_alpine) }}"
7+
state: "{{ nginx_app_protect_license_status | default((nginx_app_protect_dos_setup == 'uninstall') | ternary('absent', 'present')) }}"
8+
when: nginx_app_protect_dos_manage_repo | bool
9+
10+
- name: (Alpine Linux) {{ nginx_app_protect_license_status is defined | ternary('Remove', 'Configure') }} NGINX App Protect DoS repository
11+
ansible.builtin.lineinfile:
12+
path: /etc/apk/repositories
13+
insertafter: EOF
14+
line: "{{ nginx_app_protect_dos_repository | default(nginx_app_protect_dos_default_repository_alpine) }}"
15+
state: "{{ nginx_app_protect_license_status | default((nginx_app_protect_dos_setup == 'uninstall') | ternary('absent', 'present')) }}"
16+
when: nginx_app_protect_dos_manage_repo | bool
17+
18+
- name: (Alpine Linux) {{ nginx_app_protect_dos_setup | capitalize }} NGINX Plus
19+
community.general.apk:
20+
name: nginx-plus
21+
repository: "{{ nginx_plus_repository | default(nginx_plus_default_repository_alpine) }}"
22+
state: "{{ nginx_app_protect_dos_state }}"
23+
ignore_errors: "{{ ansible_check_mode }}"
24+
when: nginx_app_protect_license_status is not defined
25+
notify: (Handler - NGINX App Protect) Run NGINX
26+
27+
- name: (Alpine Linux) {{ nginx_app_protect_dos_setup | capitalize }} NGINX App Protect DoS
28+
community.general.apk:
29+
name: app-protect-dos{{ (nginx_app_protect_dos_state == 'absent') | ternary(',nginx-plus-module-appprotectdos', '') }}
30+
repository: "{{ nginx_app_protect_dos_repository | default(nginx_app_protect_dos_default_repository_alpine) }}"
31+
state: "{{ nginx_app_protect_dos_state }}"
32+
ignore_errors: "{{ ansible_check_mode }}"
33+
when: nginx_app_protect_license_status is not defined
34+
notify: (Handler - NGINX App Protect) Run NGINX

vars/main.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ nginx_app_protect_waf_linux_families:
1919

2020
# NGINX App Protect DoS platform matrix. Populate this dictionary of lists with appropriate values from ansible_distribution and ansible_distribution_version facts
2121
nginx_app_protect_dos_linux_families:
22+
alpine: [
23+
"3.15",
24+
]
2225
centos: [
2326
"7.4", "7.5", "7.6", "7.7", "7.8", "7.9",
2427
]
2528
debian: [
26-
"10",
29+
"10", "11",
2730
]
2831
redhat: [
2932
"7.4", "7.5", "7.6", "7.7", "7.8", "7.9", "8.0", "8.1", "8.2", "8.3", "8.4", "8.5",
@@ -47,6 +50,11 @@ nginx_app_protect_waf_state: "{{ nginx_app_protect_state_vals[nginx_app_protect_
4750
nginx_app_protect_dos_default_setup: install
4851
nginx_app_protect_dos_state: "{{ nginx_app_protect_state_vals[nginx_app_protect_dos_setup] | default(nginx_app_protect_state_vals[nginx_app_protect_dos_default_setup]) }}"
4952

53+
# Alpine Linux dependencies
54+
nginx_app_protect_alpine_dependencies: [
55+
boost, ca-certificates, coreutils, openssl, pcre2, zeromq,
56+
]
57+
5058
# Amazon Linux 2 extras
5159
nginx_app_protect_amazon_extras: [
5260
selinux-ng,
@@ -71,20 +79,22 @@ nginx_app_protect_waf_security_updates_default_signing_key_pgp: https://cs.nginx
7179
nginx_app_protect_waf_security_updates_default_signing_key_rsa_pub: https://cs.nginx.com/static/keys/app-protect-security-updates.rsa.pub
7280

7381
# Default NGINX Plus repositories
82+
nginx_plus_default_repository_alpine: https://pkgs.nginx.com/plus/alpine/v{{ ansible_distribution_version | regex_search('^[0-9]+\.[0-9]+') }}/main
83+
nginx_plus_default_repository_amazon: https://pkgs.nginx.com/plus/amzn{{ (ansible_facts['distribution_major_version'] is version('2', '==')) | ternary('2', '') }}/$releasever/$basearch
7484
nginx_plus_default_repository_debian: deb [arch=amd64 signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] https://pkgs.nginx.com/plus/{{ ansible_facts['distribution'] | lower }} {{ ansible_facts['distribution_release'] }} nginx-plus
7585
nginx_plus_default_repository_redhat: https://pkgs.nginx.com/plus/centos/{{ ansible_distribution_major_version }}/$basearch/
76-
nginx_plus_default_repository_amazon: https://pkgs.nginx.com/plus/amzn{{ (ansible_facts['distribution_major_version'] is version('2', '==')) | ternary('2', '') }}/$releasever/$basearch
7786

7887
# Default NGINX App Protect WAF repositories
88+
nginx_app_protect_waf_default_repository_amazon: https://pkgs.nginx.com/app-protect/centos/7/$basearch/
7989
nginx_app_protect_waf_default_repository_debian: deb [arch=amd64 signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] https://pkgs.nginx.com/app-protect/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} nginx-plus
8090
nginx_app_protect_waf_default_repository_redhat: https://pkgs.nginx.com/app-protect/centos/{{ ansible_distribution_major_version }}/$basearch/
81-
nginx_app_protect_waf_default_repository_amazon: https://pkgs.nginx.com/app-protect/centos/7/$basearch/
8291

8392
# Default NGINX App Protect WAF Security Updates repositories
93+
nginx_app_protect_waf_security_updates_default_repository_amazon: https://pkgs.nginx.com/app-protect-security-updates/centos/7/$basearch/
8494
nginx_app_protect_waf_security_updates_default_repository_debian: deb [arch=amd64 signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] https://pkgs.nginx.com/app-protect-security-updates/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} nginx-plus
8595
nginx_app_protect_waf_security_updates_default_repository_redhat: https://pkgs.nginx.com/app-protect-security-updates/centos/{{ ansible_distribution_major_version }}/$basearch/
86-
nginx_app_protect_waf_security_updates_default_repository_amazon: https://pkgs.nginx.com/app-protect-security-updates/centos/7/$basearch/
8796

8897
# Default NGINX App Protect DoS repositories
98+
nginx_app_protect_dos_default_repository_alpine: https://pkgs.nginx.com/app-protect-dos/alpine/v{{ ansible_distribution_version | regex_search('^[0-9]+\.[0-9]+') }}/main
8999
nginx_app_protect_dos_default_repository_debian: deb [arch=amd64 signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] https://pkgs.nginx.com/app-protect-dos/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} nginx-plus
90100
nginx_app_protect_dos_default_repository_redhat: https://pkgs.nginx.com/app-protect-dos/centos/{{ ansible_distribution_major_version }}/$basearch/

0 commit comments

Comments
 (0)