Skip to content

Commit bea9070

Browse files
aknot242alessfg
andauthored
NGINX 2.3 updates and new features (#50)
* initial commit * fix for buster broken minor version number missing * use more succint fact naming convention * Alpine functionality warning * removing alpine from molecule * adding support for specific sigs and tc package versions * move to platform specific package management modules * new downgrade syntax * changed downgrade options * create version specific test * allow downgrade * adding default package options * downgrades not working * check mode fix. remove latest designation * fix conditional * updating version detection logic. remove package facts in role itself. * missing var * updating apk key task * update signing keys for alpine * update cache * add alpine prereqs * remove dependencies and explicit repository for apk * do not modify service if no systemd * fix molecule tests * Various syntax updates Also consolidate dependency into a single tasks file * Update Molecule CICD * Fix typo * Update GitHub actions base images * remove nap version selection option Co-authored-by: alessfg <[email protected]>
1 parent 4866b6e commit bea9070

31 files changed

+609
-226
lines changed

.github/workflows/molecule.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
scenario:
2121
- advanced
2222
- default
23+
- specific-version
2324
steps:
2425
- name: Check out the codebase
2526
if: github.event.pull_request.head.repo.full_name == github.repository

CHANGELOG.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,34 @@
44

55
FEATURES:
66

7+
* Add support for Dependabot.
78
* Replace Ansible community distribution with Ansible base and add the necessary extra collections as a dependency requirement. For reference, these are:
89
* `community.general`
910
* `ansible.posix`
10-
* Add support for Dependabot.
11+
* You can now specify an `nginx_app_protect_repository` for NGINX App Protect.
12+
* You can now specify an `nginx_app_protect_security_updates_repository` for NGINX App Protect signatures and threat campaigns packages.
13+
* You can now specify NGINX App Protect signatures and threat campaigns package versions using the `nginx_app_protect_signatures_version` and `nginx_app_protect_threat_campaigns_version` variables.
1114

1215
ENHANCEMENTS:
1316

17+
* Support for App Protect 2.3 -- Adds support for Debian 10 (buster) and Alpine 3.10.x.
18+
* Add test coverage for new platforms and testing scenario.
19+
* Consolidate dependencies into a single tasks file.
20+
* Remove requirement for `package_facts` module when using this role.
21+
* Update Signatures repository URL.
1422
* Update Ansible base to `2.10.7`, Molecule to `3.2.4`, yamllint to `1.26.0` and Docker Python SDK to `4.4.4`.
1523
* Specify GitHub actions Ubuntu release.
1624
* Minor GitHub template tweaks, including the creation of a SECURITY doc.
1725
* Only run GitHub actions Galaxy CI/CD workflow when a new release is published.
1826

27+
BREAKING CHANGES:
28+
29+
The `nginx_app_protect_version` variable has been removed, as it cannot be implemented fully on all platforms.
30+
31+
KNOWN ISSUES:
32+
33+
Service manager support is not included in NGINX App Protect for Alpine. When using this role to install NGINX App Protect on Alpine, you will need to start the NGINX App Protect processes then reload NGINX Plus yourself in order for App Protect to function. You can use commands similar to what are contained in the `entrypoint.sh` script in the [NGINX App Protect Administration Guide](https://docs.nginx.com/nginx-app-protect/admin-guide/install/#docker-deployment-instructions) to accomplish this.
34+
1935
## 0.4.2 (January 11, 2021)
2036

2137
ENHANCEMENTS:

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,7 @@ Similarly, descriptions and defaults for preset variables can be found in the **
7979

8080
## Dependencies
8181

82-
* Since this role uses the [package_facts](https://docs.ansible.com/ansible/latest/modules/package_facts_module.html) module, on debian-based systems the `python-apt` package must be installed on targeted hosts.
83-
84-
* If NGINX Plus is *not* already installed on the system, this role will install the version of NGINX Plus that is dependent on the version of NGINX App Protect set with the `nginx_app_protect_version` variable. If none is specified, the latest version of NGINX Plus and NGINX App Protect will be installed.
85-
86-
* When using the `nginx_app_protect_version` variable, a specific version of NGINX Plus must already be installed on the target system.
82+
* If NGINX Plus is *not* already installed on the system, this role will install the version of NGINX Plus that is dependent on the version of NGINX App Protect that is being installed.
8783

8884
## Example Playbook
8985

defaults/main.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
---
22
# Specify whether you want to maintain your version of NGINX App Protect, upgrade to the latest version, or remove NGINX App Protect.
3-
# Can be used with `nginx_app_protect_version` to achieve fine grained control on which version of NGINX App Protect is installed/used on each playbook execution.
4-
# Using 'present' will install the latest version (or 'nginx_app_protect_version') of NGINX App Protect on a fresh install.
5-
# Using 'latest' will upgrade NGINX App Protect to the latest version (that matches your 'nginx_app_protect_version') of NGINX App Protect on every playbook execution.
3+
# Using 'present' will install the latest version of NGINX App Protect on a fresh install.
4+
# Using 'latest' will upgrade NGINX App Protect to the latest version on every playbook execution.
65
# Using 'absent' will remove NGINX App Protect from your system.
76
# Default is present.
87
nginx_app_protect_state: present
98

10-
# (Optional) Installs a specific version of NGINX App Protect
11-
# Default is to install the latest release.
12-
# nginx_app_protect_version: 22
13-
149
# If you have a RHEL subscription, NGINX App Protect's dependencies will use subscription repos.
1510
# Otherwise, it will source packages from CentOS' repositories.
1611
# Default is false.
@@ -21,17 +16,33 @@ nginx_app_protect_use_rhel_subscription_repos: false
2116
# Default is true.
2217
nginx_app_protect_install_signatures: true
2318

19+
# (Optional) Installs a specific version of the NGINX App Protect attack signatures package
20+
# Default is to install the latest release.
21+
# nginx_app_protect_signatures_version: "=2019.07.16-1" # <- Example value for Debian/Ubuntu
22+
2423
# The installation of NGINX App Protect can include a page of frequently-updated, high-accuracy signatures called "threat campaigns".
2524
# This option installs the latest NGINX App Protect threat campaigns signatures.
2625
# Default is true.
2726
nginx_app_protect_install_threat_campaigns: true
2827

28+
# (Optional) Installs a specific version of the NGINX App Protect threat campaigns package
29+
# Default is to install the latest release.
30+
# nginx_app_protect_threat_campaigns_version: "=2020.08.20-1" # <- Example value for Debian/Ubuntu
31+
2932
# (Optional) Choose where to fetch the NGINX App Protect and security updates signing keys from.
3033
# Default settings are the official NGINX signing key hosts.
3134
# nginx_app_protect_signing_key:
3235
# nginx_plus: https://cs.nginx.com/static/keys/nginx_signing.key
3336
# security_updates: https://cs.nginx.com/static/keys/app-protect-security-updates.key
3437

38+
# (Optional) Specify repository for NGINX App Protect.
39+
# Defaults are the official NGINX repositories.
40+
# nginx_app_protect_repository: deb [arch=amd64] https://plus-pkgs.nginx.com/debian buster nginx-plus
41+
42+
# (Optional) Specify repository for NGINX App Protect security updates.
43+
# Defaults are the official NGINX repositories.
44+
# nginx_app_protect_security_updates_repository: deb [arch=amd64] https://app-protect-security-updates.nginx.com/debian buster nginx-plus
45+
3546
# Location of your NGINX App Protect license in your local machine.
3647
# Default is the files folder within the NGINX Ansible role.
3748
nginx_app_protect_license:

handlers/main.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
when:
1212
- nginx_app_protect_start | bool
1313
- not ansible_check_mode | bool
14+
- ansible_os_family != "Alpine"
1415
listen: (Handler - NGINX App Protect) Run NGINX
1516

1617
- name: (Handler - NGINX App Protect) Check NGINX
@@ -24,5 +25,7 @@
2425
debug:
2526
var: config.stderr_lines
2627
failed_when: config.rc != 0
27-
when: config.rc != 0
28+
when:
29+
- config.rc is defined
30+
- config.rc != 0
2831
listen: (Handler - NGINX App Protect) Run NGINX

meta/main.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ galaxy_info:
1010
min_ansible_version: 2.10
1111

1212
platforms:
13+
- name: Alpine
14+
versions:
15+
- any
1316
- name: EL
1417
versions:
1518
- 7
1619
- name: Debian
1720
versions:
1821
- stretch
22+
- buster
1923
- name: Ubuntu
2024
versions:
2125
- bionic

molecule/Dockerfile.j2

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ ENV {{ var }} {{ value }}
1717
RUN \
1818
if [ $(command -v apt-get) ]; then \
1919
apt-get update \
20-
&& DEBIAN_FRONTEND=noninteractive apt-get install -y aptitude bash ca-certificates curl iproute2 python-apt python3 python3-apt procps sudo systemd systemd-sysv \
20+
&& DEBIAN_FRONTEND=noninteractive apt-get install -y aptitude bash ca-certificates curl iproute2 python-apt python3 python3-apt procps sudo systemd systemd-sysv vim \
2121
&& apt-get clean; \
2222
elif [ $(command -v dnf) ]; then \
2323
dnf makecache \
24-
&& dnf --assumeyes install bash iproute /usr/bin/dnf-3 /usr/bin/python3 /usr/bin/python3-config \
24+
&& dnf --assumeyes install bash iproute sudo /usr/bin/dnf-3 /usr/bin/python3 /usr/bin/python3-config vim \
2525
&& dnf clean all; \
2626
elif [ $(command -v yum) ]; then \
2727
yum makecache fast \
28-
&& yum install -y bash iproute /usr/bin/python /usr/bin/python2-config sudo yum-plugin-ovl \
28+
&& yum install -y bash iproute sudo /usr/bin/python /usr/bin/python2-config vim yum-plugin-ovl \
2929
&& sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf \
3030
&& yum clean all; \
3131
elif [ $(command -v zypper) ]; then \
3232
zypper refresh \
33-
&& zypper install -y bash iproute2 python3 sudo \
33+
&& zypper install -y bash iproute2 python3 sudo vim \
3434
&& zypper clean -a; \
3535
elif [ $(command -v apk) ]; then \
3636
apk update \
37-
&& apk add --no-cache bash ca-certificates curl openrc python3 sudo; \
37+
&& apk add --no-cache bash ca-certificates curl openrc python3 sudo vim; \
3838
echo 'rc_provide="loopback net"' >> /etc/rc.conf; \
3939
elif [ $(command -v xbps-install) ]; then \
4040
xbps-install -Syu \
41-
&& xbps-install -y bash ca-certificates iproute2 python3 sudo \
41+
&& xbps-install -y bash ca-certificates iproute2 python3 sudo vim \
4242
&& xbps-remove -O; \
4343
fi

molecule/advanced/molecule.yml

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,67 @@ lint: |
77
ansible-lint --force-color
88
platforms:
99
- name: test-workload
10-
groups:
11-
- workload
1210
image: nginxdemos/hello
1311
privileged: true
12+
groups:
13+
- workload
1414
networks:
1515
- name: molecule-test
16-
- name: centos-7
16+
- name: alpine-3.10
17+
image: alpine:3.10
18+
dockerfile: ../Dockerfile.j2
19+
privileged: true
20+
volumes:
21+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
22+
command: "/sbin/init"
1723
groups:
1824
- nap
25+
networks:
26+
- name: molecule-test
27+
- name: centos-7
1928
image: centos:7
2029
dockerfile: ../Dockerfile.j2
2130
privileged: true
22-
networks:
23-
- name: molecule-test
2431
volumes:
2532
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
2633
command: "/usr/sbin/init"
27-
- name: ubuntu-bionic
2834
groups:
2935
- nap
36+
networks:
37+
- name: molecule-test
38+
- name: ubuntu-bionic
3039
image: ubuntu:bionic
3140
dockerfile: ../Dockerfile.j2
3241
privileged: true
33-
networks:
34-
- name: molecule-test
3542
volumes:
3643
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
3744
command: "/sbin/init"
38-
- name: debian-stretch
3945
groups:
4046
- nap
47+
networks:
48+
- name: molecule-test
49+
- name: debian-stretch
4150
image: debian:stretch-slim
4251
dockerfile: ../Dockerfile.j2
4352
privileged: true
53+
volumes:
54+
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
55+
command: "/sbin/init"
56+
groups:
57+
- nap
4458
networks:
4559
- name: molecule-test
60+
- name: debian-buster
61+
image: debian:buster-slim
62+
dockerfile: ../Dockerfile.j2
63+
privileged: true
4664
volumes:
4765
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
4866
command: "/sbin/init"
67+
groups:
68+
- nap
69+
networks:
70+
- name: molecule-test
4971
provisioner:
5072
name: ansible
5173
config_options:

molecule/advanced/requirements.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
---
22
roles:
3-
- robertdebock.rsyslog
3+
- name: robertdebock.rsyslog
4+
version: 3.2.0

molecule/advanced/verify.yml

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,59 +2,67 @@
22
- name: Verify
33
hosts: nap
44
tasks:
5-
- name: Check if NGINX is installed
5+
- name: Check if NGINX Plus is installed
66
package:
77
name: nginx-plus
8+
state: present
89
check_mode: true
910
register: install
1011
failed_when: (install is changed) or (install is failed)
12+
when: ansible_os_family != "Alpine"
1113

1214
- name: Check if NGINX App Protect is installed
1315
package:
1416
name: app-protect
17+
state: present
1518
check_mode: true
1619
register: install
1720
failed_when: (install is changed) or (install is failed)
1821

19-
- name: Check if NGINX App Protect Signatures is installed
22+
- name: Check if NGINX App Protect signatures is installed
2023
package:
2124
name: app-protect-attack-signatures
25+
state: present
2226
check_mode: true
2327
register: install
2428
failed_when: (install is changed) or (install is failed)
2529

26-
- name: Check if NGINX App Protect Threat Campaigns is installed
30+
- name: Check if NGINX App Protect threat campaigns is installed
2731
package:
2832
name: app-protect-threat-campaigns
33+
state: present
2934
check_mode: true
3035
register: install
3136
failed_when: (install is changed) or (install is failed)
3237

33-
- name: Check if NGINX service is running
34-
service:
35-
name: nginx
36-
state: started
37-
enabled: true
38-
check_mode: true
39-
register: service
40-
failed_when: (service is changed) or (service is failed)
38+
- name: Functional tests
39+
block:
40+
- name: Check if NGINX service is running
41+
service:
42+
name: nginx
43+
state: started
44+
enabled: true
45+
check_mode: true
46+
register: service
47+
failed_when: (service is changed) or (service is failed)
4148

42-
- name: Check that a page returns a status 200 and fail if the words Hello World are not in the page contents
43-
uri:
44-
url: "http://localhost"
45-
return_content: true
46-
register: this
47-
failed_when: "'Hello World' not in this.content"
49+
- name: Check that a page returns a status 200 and fail if the words Hello World are not in the page contents
50+
uri:
51+
url: "http://localhost"
52+
return_content: true
53+
register: this
54+
failed_when: "'Hello World' not in this.content"
4855

49-
- name: Check that a page returns a status 200 and fail if the words Request Rejected are not in the page contents
50-
uri:
51-
url: "http://localhost/?v=<script>"
52-
return_content: true
53-
register: this
54-
failed_when: "'Request Rejected' not in this.content"
56+
- name: Check that a page returns a status 200 and fail if the words Request Rejected are not in the page contents
57+
uri:
58+
url: "http://localhost/?v=<script>"
59+
return_content: true
60+
register: this
61+
failed_when: "'Request Rejected' not in this.content"
5562

56-
- name: Ensure /var/log/messages contains block event from above test
57-
shell: grep -c "Non-browser Client,Abuse of Functionality,Cross Site Scripting (XSS)" /var/log/messages || true
58-
register: event
59-
changed_when: false
60-
failed_when: event.stdout == "0"
63+
- name: Ensure /var/log/messages contains block event from above test
64+
shell: grep -c "Non-browser Client,Abuse of Functionality,Cross Site Scripting (XSS)" /var/log/messages || true
65+
register: event
66+
changed_when: false
67+
failed_when: event.stdout == "0"
68+
when: ansible_os_family != "Alpine"

0 commit comments

Comments
 (0)