Skip to content

Commit adbf1ad

Browse files
authored
Multiple optimizations (#26)
1 parent fd42f4b commit adbf1ad

26 files changed

+296
-336
lines changed

.travis.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
---
2-
# safelist - build only on the following branches
2+
language: python
3+
services: docker
34
branches:
45
only:
56
- main
6-
language: python
7-
services: docker
87
jobs:
98
include:
10-
- name: "Lint role"
9+
- name: Deploy NGINX App Protect
1110
env:
1211
scenario: default
1312
before_install:
@@ -17,11 +16,11 @@ before_install:
1716
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
1817
install:
1918
- pip install ansible==2.9.13
20-
- pip install ansible-lint==4.3.4
19+
- pip install ansible-lint==4.3.5
2120
- pip install yamllint==1.24.2
2221
- pip install molecule==3.0.8
2322
- pip install docker==4.3.1
2423
script:
25-
- molecule test -s $scenario
24+
- travis_wait 50 molecule test -s $scenario
2625
notifications:
2726
webhooks: https://galaxy.ansible.com/api/v1/notifications/

CHANGELOG.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Changelog
22

3+
## 0.3.0 (September 21, 2020)
4+
5+
DEPRECATION WARNING:
6+
7+
* The ability to create an NGINX config including some basic App Protect directives has migrated to the NGINX config role available [here](https://github.com/nginxinc/ansible-role-nginx-config). Any new issues or PRs related to configuring NGINX App Protect directives should be submitted in the new NGINX Config repository. New issues or PRs related to configuring NGINX App Protect directives submitted in this repository will not be worked on. The NGINX App Protect directives configuration functionalities included in this role will be removed in an upcoming release.
8+
9+
FEATURES:
10+
11+
* A new variable has been introduced:
12+
* `nginx_app_protect_setup_license` -- Determine whether you want to use this role to upload your NGINX App Protect license to your target host.
13+
14+
ENHANCEMENTS:
15+
16+
* Switch to using `ansible_facts` wherever possible.
17+
* Simplified overall role structure by:
18+
* Reducing signing key setup tasks to a single file.
19+
* Merging all install steps to a single file.
20+
* Added handlers to check for NGINX syntax validity and fail if any errors are detected.
21+
* Update Ansible Lint to `4.3.5`.
22+
323
## 0.2.2 (September 15, 2020)
424

525
ENHANCEMENTS:
@@ -24,17 +44,17 @@ BREAKING CHANGES:
2444
* All of the variables have been updated to prevent naming collisions when using other roles. Please see README.MD for new variable names.
2545
* Example playbook has been removed by collection authors in favor of using the Molecule configuration as a 'known-working' implementation.
2646

47+
FEATURES:
48+
49+
* Molecule 3 testing foundation is in the project, and linting is being performed by TravisCI. Now time to write tests!
50+
2751
ENHANCEMENTS:
2852

2953
* Huge refactoring by @alessfg to better unify this role with the structures present in the other nginxinc Ansible roles.
30-
* Update Ansible to 2.9.13 and Ansible Lint to 4.3.4.
54+
* Update Ansible to `2.9.13` and Ansible Lint to `4.3.4`.
3155
* Explicitly defined mode in relevant tasks for breaking changes in Ansible.
3256
* Role refactored to separate install and configure operations in preparation for an upcoming role split.
3357

34-
FEATURES:
35-
36-
* Molecule 3 testing foundation is in the project, and linting is being performed by TravisCI. Now time to write tests!
37-
3858
BUG FIXES:
3959

4060
* The CentOS, RHEL, Debian and Ubuntu repositories have slightly changed to respond to a NAP repository deprecation activity. You may run into some duplication issues when running the role on a preexisting target that already has had NGINX installed using the role. To fix this, manually remove the old repository source.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ Molecule is used to test the various functionalities of the role. Instructions o
2626
To run the Molecule tests, you must first add your NGINX repository certificate and key to the local environment. Run the following commands to export these files as base64-encoded variables and execute the Molecule tests:
2727

2828
``` bash
29-
export NGINX_CRT=$( cat <path to your certificate file> | base64)
30-
export NGINX_KEY=$( cat <path to your key file> | base64)
29+
export NGINX_CRT=$( cat <path to your certificate file> | base64 )
30+
export NGINX_KEY=$( cat <path to your key file> | base64 )
3131
molecule test
3232
```
3333

@@ -83,7 +83,7 @@ Example Playbook
8383

8484
A working functional playbook example can be found in the **`molecule/default`** directory in the following file:
8585

86-
- **[molecule/default/converge.yml](https://github.com/nginxinc/ansible-role-nginx-app_protect/blob/main/molecule/default/converge.yml):** Install and configure NGINX App Protect
86+
- **[molecule/default/converge.yml](https://github.com/nginxinc/ansible-role-nginx-app-protect/blob/main/molecule/default/converge.yml):** Install and configure NGINX App Protect
8787

8888
Other NGINX Roles
8989
-----------------

defaults/main.yml

Lines changed: 37 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,75 @@
77
# Default is present.
88
nginx_app_protect_state: present
99

10-
# # OPTIONAL: Installs a specific version of NGINX App Protect
10+
# (Optional) Installs a specific version of NGINX App Protect
11+
# Default is to install the latest release.
1112
# nginx_app_protect_version: 22
1213

14+
# If you have a RHEL subscription, NGINX App Protect's dependencies will use subscription repos.
15+
# Otherwise, it will source packages from CentOS' repositories.
16+
# Default is false.
17+
nginx_app_protect_use_rhel_subscription_repos: false
18+
1319
# The installation of NGINX App Protect includes a base signature set, which may be out of date.
1420
# This option installs the latest NGINX App Protect signatures.
21+
# Default is true.
1522
nginx_app_protect_install_signatures: true
1623

17-
# The installation of NGINX App Protect can include a page of frequently-updated, high-accuracy signatures called Threat Campaigns.
18-
# This option installs the latest NGINX App Protect Threat Campaigns signatures.
19-
nginx_app_protect_install_threat_campaigns: false
20-
21-
# Creates basic configuration files and enables NGINX App Protect on the target host
22-
nginx_app_protect_configure: false
24+
# The installation of NGINX App Protect can include a page of frequently-updated, high-accuracy signatures called "threat campaigns".
25+
# This option installs the latest NGINX App Protect threat campaigns signatures.
26+
# Default is true.
27+
nginx_app_protect_install_threat_campaigns: true
2328

24-
# Removes the license (certificate and key) for the NGINX App Protect repositories on the target host(s) when playbook run is complete.
25-
nginx_app_protect_delete_license: true
29+
# (Optional) Choose where to fetch the NGINX App Protect and security updates signing keys from.
30+
# Default settings are the official NGINX signing key hosts.
31+
# nginx_app_protect_signing_key:
32+
# nginx_plus: https://cs.nginx.com/static/keys/nginx_signing.key
33+
# security_updates: https://cs.nginx.com/static/keys/app-protect-security-updates.key
2634

27-
# If you have a RHEL subscription, NGINX App Protect's dependencies will use subscription repos.
28-
# Otherwise, it will source packages from CentOS' repositories.
29-
nginx_app_protect_use_rhel_subscription_repos: false
35+
# Set up NGINX App Protect license (cert/key) before installation.
36+
# Default is true.
37+
nginx_app_protect_setup_license: true
3038

31-
# Choose where to fetch the NGINX App Protect and Security Updates signing keys from.
32-
# Default settings are the official NGINX signing key hosts.
33-
nginx_app_protect_signing_keys:
34-
nginx_plus: https://cs.nginx.com/static/keys/nginx_signing.key
35-
app_protect: https://cs.nginx.com/static/keys/app-protect.key
36-
security_updates: https://cs.nginx.com/static/keys/app-protect-security-updates.key
39+
# Removes NGINX App Protect license (cert/key) after installation for security purposes.
40+
# Default is true.
41+
nginx_app_protect_remove_license: true
3742

3843
# Start/Restart NGINX service when App Protect related changes are complete.
3944
# Default is true.
4045
nginx_app_protect_start: true
4146

42-
# Increase NGINX service timeout to accommodate ruleset loading from default 90s
43-
nginx_app_protect_timeout: 180
47+
# Increase NGINX service timeout to accommodate ruleset loading from default 90s.
48+
# Default is commented out.
49+
# nginx_app_protect_timeout: 180
4450

45-
# App Protect Temporary Directory to use (Default: /tmp)
46-
nginx_app_protect_tempdir: /tmp
51+
# Creates basic configuration files and enables NGINX App Protect on the target host
52+
nginx_app_protect_configure: false
4753

54+
# Create a basic NGINX App Protect security policy file
4855
nginx_app_protect_security_policy_template_enable: true
4956
nginx_app_protect_security_policy_template:
5057
template_file: app-protect-security-policy.j2
5158
out_file_name: app-protect-security-policy.json
5259
out_file_location: /etc/nginx/
60+
# possible values: transparent, blocking
61+
nginx_app_protect_security_policy_enforcement_mode: transparent
5362

63+
# Create a basic NGINX App Protect log policy file
5464
nginx_app_protect_log_policy_template_enable: true
5565
nginx_app_protect_log_policy_template:
5666
template_file: app-protect-log-policy.j2
5767
out_file_name: app-protect-log-policy.json
5868
out_file_location: /etc/nginx/
69+
# possible values: all, illegal, blocked
70+
nginx_app_protect_log_policy_filter_request_type: all
5971

72+
## DEPRECATED -- Use nginxinc.nginx_config role instead (https://github.com/nginxinc/ansible-role-nginx-config)
73+
# Create a basic NGINX App Protect config file
6074
nginx_app_protect_conf_template_enable: false
6175
nginx_app_protect_conf_template:
6276
template_file: nginx.conf.j2
6377
out_file_name: nginx.conf
6478
out_file_location: /etc/nginx/
65-
66-
# possible values: transparent, blocking
67-
nginx_app_protect_security_policy_enforcement_mode: transparent
68-
69-
# possible values: all, illegal, blocked
70-
nginx_app_protect_log_policy_filter_request_type: all
71-
72-
nginx_app_protect_log_policy_syslog_target: 127.0.0.1:514
73-
7479
nginx_app_protect_demo_workload_protocol: http://
7580
nginx_app_protect_demo_workload_host: 10.1.1.1:8080
81+
nginx_app_protect_log_policy_syslog_target: 127.0.0.1:514

handlers/main.yml

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
---
2+
- name: (Handler) Systemd daemon-reload
3+
systemd:
4+
daemon_reload: true
5+
26
- name: (Handler) Check NGINX
3-
command: "nginx -t"
4-
changed_when: false
7+
command: nginx -t
8+
register: config
9+
ignore_errors: true
10+
listen: (Handler) Run NGINX
511

6-
- name: (Handler) Run NGINX
7-
block:
8-
- name: (Handler) Start NGINX
9-
service:
10-
name: nginx
11-
state: started
12-
enabled: true
13-
notify: (Handler) Check NGINX
12+
- name: (Handler) Print NGINX error if syntax check fails
13+
debug:
14+
var: config.stderr_lines
15+
failed_when: config.rc != 0
16+
when: config.rc != 0
17+
listen: (Handler) Run NGINX
1418

15-
- name: (Handler) Restart NGINX
16-
service:
17-
name: nginx
18-
state: restarted
19-
changed_when: false
19+
- name: (Handler) Start/Reload NGINX
20+
service:
21+
name: nginx
22+
state: reloaded
23+
enabled: true
2024
when:
2125
- nginx_app_protect_start | bool
22-
- not ansible_check_mode
26+
- not ansible_check_mode | bool
27+
listen: (Handler) Run NGINX

molecule/default/converge.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
name: ansible-role-nginx-app-protect
88
vars:
99
nginx_app_protect_enable: true
10+
nginx_app_protect_remove_license: false
1011
nginx_app_protect_install_signatures: true
1112
nginx_app_protect_install_threat_campaigns: true
1213
nginx_app_protect_configure: true
1314
nginx_app_protect_security_policy_template_enable: true
1415
nginx_app_protect_security_policy_enforcement_mode: blocking
1516
nginx_app_protect_log_policy_template_enable: true
1617
nginx_app_protect_log_policy_filter_request_type: all
17-
nginx_app_protect_conf_template_enable: true
1818
nginx_app_protect_log_policy_syslog_target: localhost:514
19+
nginx_app_protect_conf_template_enable: true
1920
nginx_app_protect_demo_workload_protocol: http://
2021
nginx_app_protect_demo_workload_host: test-workload:80
2122
nginx_app_protect_license:
22-
certificate: "license/nginx-repo.crt"
23-
key: "license/nginx-repo.key"
24-
nginx_app_protect_delete_license: false
25-
nginx_app_protect_timeout: 600
23+
certificate: license/nginx-repo.crt
24+
key: license/nginx-repo.key
25+
nginx_app_protect_timeout: 180

molecule/default/prepare.yml

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,30 @@
11
---
22
- name: Prepare
33
hosts: localhost
4-
connection: local
54
gather_facts: false
6-
vars:
7-
nginx_license:
8-
certificate: "./license/nginx-repo.crt"
9-
key: "./license/nginx-repo.key"
10-
115
tasks:
12-
- name: Create license directory
13-
file:
14-
path: "./license"
15-
state: directory
16-
mode: 0755
17-
186
- name: Create ephemeral license certificate file from b64 decoded env var
197
copy:
208
content: "{{ lookup('env','NGINX_CRT') | b64decode }}"
21-
dest: "{{ nginx_license.certificate }}"
9+
dest: ../../files/license/nginx-repo.crt
10+
force: false
2211
mode: 0444
2312

2413
- name: Create ephemeral license key file from b64 decoded env var
2514
copy:
2615
content: "{{ lookup('env','NGINX_KEY') | b64decode }}"
27-
dest: "{{ nginx_license.key }}"
16+
dest: ../../files/license/nginx-repo.key
17+
force: false
2818
mode: 0444
2919

3020
- name: Set up rsyslog server for verifying NAP syslog events
3121
hosts: nap
22+
roles:
23+
- role: robertdebock.rsyslog
3224
vars:
3325
rsyslog_receiver: true
3426
rsyslog_remote_tcp: true
3527
rsyslog_remote_port: 514
36-
roles:
37-
- role: robertdebock.rsyslog
3828

3929
- name: Prepare workload for tests
4030
hosts: workload

tasks/config/configure-app-protect.yml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
backup: true
2525
when: nginx_app_protect_log_policy_template_enable | bool
2626

27-
- name: Backup existing nginx.conf
27+
- name: (DEPRECATED) Backup existing nginx.conf
2828
copy:
2929
src: "{{ nginx_app_protect_conf_template.out_file_location }}{{ nginx_app_protect_conf_template.out_file_name }}"
3030
dest: "{{ nginx_app_protect_conf_template.out_file_location }}{{ nginx_app_protect_conf_template.out_file_name }}.orig"
@@ -33,7 +33,7 @@
3333
when: nginx_app_protect_conf_template_enable | bool
3434
changed_when: false
3535

36-
- name: Dynamically Generate NGINX conf file
36+
- name: (DEPRECATED) Dynamically generate nginx.conf file
3737
template:
3838
src: "{{ nginx_app_protect_conf_template.template_file }}"
3939
dest: "{{ nginx_app_protect_conf_template.out_file_location }}{{ nginx_app_protect_conf_template.out_file_name }}"
@@ -42,27 +42,25 @@
4242
- nginx_app_protect_conf_template_enable | bool
4343
- nginx_app_protect_state != "absent"
4444

45-
- name: Remove NGINX App Protect
45+
- name: (DEPRECATED) Remove NGINX App Protect
4646
block:
47-
- name: Comment out NGINX App Protect module reference in nginx.conf
47+
- name: (DEPRECATED) Comment out NGINX App Protect module reference in nginx.conf
4848
replace:
4949
path: /etc/nginx/nginx.conf
5050
regexp: '^([ \t]*load_module.*ngx_http_app_protect_module.so;)'
5151
replace: '# \1'
52-
mode: preserve
5352

54-
- name: Comment out NGINX App Protect directives in nginx.conf
53+
- name: (DEPRECATED) Comment out NGINX App Protect directives in nginx.conf
5554
replace:
5655
path: /etc/nginx/nginx.conf
5756
regexp: '^([ \t]*app_protect_)'
5857
replace: '# \1'
59-
mode: preserve
6058
when: nginx_app_protect_state == "absent"
6159

6260
- name: Reload NGINX
6361
debug:
6462
msg: Trigger nginx reload if needed
65-
notify: (Handler) Restart NGINX
63+
notify: (Handler) Run NGINX
6664
when: nginx_app_protect_security_policy_template_enable | bool
6765
or nginx_app_protect_log_policy_template_enable | bool
6866
or nginx_app_protect_conf_template_enable | bool

tasks/install/delete-license.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)