Skip to content

Commit 879d44a

Browse files
authored
Add support for NGINX App Protect directives (#26)
1 parent 6a12005 commit 879d44a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+858
-472
lines changed

.travis.yml

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,30 @@
11
---
22
language: python
33
services: docker
4+
branches:
5+
only: main
46
jobs:
57
include:
6-
- name: "(Debian/Ubuntu) Cleanup config and try to install modules"
8+
- name: (Alpine Linux/CentOS/Debian/Ubuntu) Cleanup config and try to install modules
79
env:
810
scenario: cleanup_module
9-
- name: "(Alpine Linux) Cleanup config and try to install modules"
10-
env:
11-
scenario: cleanup_module_alpine
12-
- name: "(CentOS) Cleanup config and try to install modules"
13-
env:
14-
scenario: cleanup_module_centos
15-
- name: "(Debian/Ubuntu) Test config templates"
11+
- name: (Alpine Linux/CentOS/Debian/Ubuntu) Test config generation
1612
env:
1713
scenario: default
18-
- name: "(Alpine Linux) Test config templates"
19-
env:
20-
scenario: default_alpine
21-
- name: "(CentOS) Test config templates"
14+
- name: (CentOS/Debian/Ubuntu) Test config generation with NGINX Plus directives
2215
env:
23-
scenario: default_centos
24-
- name: "(Debian/Ubuntu) Install stable branch and push a config"
16+
scenario: plus
17+
- name: (Alpine Linux/CentOS/Debian/Ubuntu) Install stable branch and push a config
2518
env:
2619
scenario: stable_push
27-
- name: "(Alpine Linux) Install stable branch and push a config"
28-
env:
29-
scenario: stable_push_alpine
30-
- name: "(CentOS) Install stable branch and push a config"
31-
env:
32-
scenario: stable_push_centos
3320
before_install:
3421
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
3522
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
3623
- sudo apt-get update
3724
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce
3825
install:
3926
- pip install ansible==2.9.13
40-
- pip install ansible-lint==4.3.4
27+
- pip install ansible-lint==4.3.5
4128
- pip install yamllint==1.24.2
4229
- pip install molecule==3.0.8
4330
- pip install docker==4.3.1

CHANGELOG.md

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

3-
## 0.2.0 (September 13, 2020)
3+
## 0.2.0 (September 22, 2020)
44

55
BREAKING CHANGES:
66

@@ -12,15 +12,19 @@ Make sure you only use one variable or the other, since they will overwrite each
1212

1313
FEATURES:
1414

15+
* Support for all NGINX App Protect directives has been added. You can find details on the supported directives on `defaults/main/template.yml`. This is the first module to be included using J2 macros. Expect to slowly see a refactor of various modules to use macros where possible.
1516
* A new variable has been introduced:
1617
* `nginx_debug_tasks` -- Print task related information to give you a better insight into the current progress of the role.
17-
* Improved tasks naming conventions.
1818
* Add Alpine `3.12` to the list of supported platforms.
1919
* Remove Alpine `3.8` from the list of supported platforms .
20+
* Add NGINX Plus tests to TravisCI
2021

2122
ENHANCEMENTS:
2223

23-
* Update Ansible to `2.9.13` and Ansible Lint to `4.3.4`.
24+
* Added handlers to check for NGINX syntax validity and fail if any errors are detected.
25+
* Switch to using `ansible_facts` wherever possible.
26+
* Improved tasks naming conventions.
27+
* Update Ansible to `2.9.13` and Ansible Lint to `4.3.5`.
2428
* Explicitly defined `mode` in relevant tasks.
2529
* Improve configuration templating capabilities:
2630
* Allow setting `access_log`/`access_log_location` to `off`.

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ Role Variables
108108
This role has multiple variables. The descriptions and defaults for all these variables can be found in the **`defaults/main/`** directory in the following files:
109109

110110
- **[defaults/main/main.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/defaults/main/main.yml):** NGINX simple config variables
111+
- **[defaults/main/selinux.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/defaults/main/selinux.yml):** Set up SELinux to allow the necessary connections to your NGINX setup
111112
- **[defaults/main/template.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/defaults/main/template.yml):** NGINX config template variables
112113
- **[defaults/main/upload.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/defaults/main/upload.yml):** NGINX config/HTML/SSL upload variables
113114

@@ -116,9 +117,10 @@ Example Playbooks
116117

117118
Working functional playbook examples can be found in the **`molecule/common/`** directory in the following files:
118119

119-
- **[molecule/common/playbooks/cleanup_module_converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/common/playbooks/cleanup_module_converge.yml):** Cleanup an NGINX config and configure NGINX supported modules
120-
- **[molecule/common/playbooks/default_converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/common/playbooks/default_converge.yml):** Use the NGINX config templating variables to create an NGINX config
121-
- **[molecule/common/playbooks/stable_push_converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/common/playbooks/stable_push_converge.yml):** Install NGINX using the stable branch and push a preexisting config from your system to your NGINX instance
120+
- **[molecule/cleanup_module/converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/cleanup_module/converge.yml):** Cleanup an NGINX config and configure NGINX supported modules
121+
- **[molecule/default/converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/default/converge.yml):** Use the NGINX config templating variables to create an NGINX config
122+
- **[molecule/plus/converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/plus/converge.yml):** Use the NGINX config templating variables to create an NGINX Plus config
123+
- **[molecule/stable_push/converge.yml](https://github.com/nginxinc/ansible-role-nginx-config/blob/main/molecule/stable_push/converge.yml):** Install NGINX using the stable branch and push a preexisting config from your system to your NGINX instance
122124

123125
Do note that if you install this repository via Ansible Galaxy, you will have to replace the role variable in the sample playbooks from `ansible-role-nginx-config` to `nginxinc.nginx_config`.
124126

defaults/main/template.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ nginx_config_main_template:
2727
worker_connections: 1024
2828
http_enable: true
2929
http_settings:
30+
# app_protect_global: # Optional -- Configure NGINX App Protect
31+
# physical_memory_util_thresholds: # Optional
32+
# high: 100 # Required
33+
# low: 100 # Required
34+
# cpu_thresholds: # Optional
35+
# high: 100 # Required
36+
# low: 100 # Required
37+
# failure_mode_action: pass # Optional -- `pass` or `drop`
38+
# cookie_seed: encryptionseed # Optional
39+
# compressed_requests_action: drop # Optional -- `pass` or `drop`
40+
# request_buffer_overflow_action: pass # Optional -- `pass` or `drop`
41+
# user_defined_signatures: [] # Optional list
3042
access_log_format:
3143
- name: main
3244
format: |-
@@ -77,6 +89,13 @@ nginx_config_http_template:
7789
port: 8081
7890
ssl: true
7991
opts: [] # Listen opts like http2 which will be added (ssl is automatically added if you specify 'ssl:').
92+
# app_protect: # Optional -- Configure NGINX App Protect
93+
# enable: false # Optional
94+
# policy_file: path # Optional
95+
# security_log_enable: false # Optional
96+
# security_log: # Optional
97+
# path: path # Required
98+
# destination: dest # Required
8099
ssl:
81100
cert: /etc/ssl/certs/default.crt
82101
key: /etc/ssl/private/default.key
@@ -135,6 +154,13 @@ nginx_config_http_template:
135154
locations:
136155
default:
137156
location: /
157+
# app_protect: # Optional -- Configure NGINX App Protect
158+
# enable: false # Optional
159+
# policy_file: path # Optional
160+
# security_log_enable: false # Optional
161+
# security_log: # Optional
162+
# path: path # Required
163+
# destination: dest # Required
138164
include_files: []
139165
proxy_hide_headers: [] # A list of headers which shouldn't be passed to the application
140166
add_headers:
@@ -176,6 +202,13 @@ nginx_config_http_template:
176202
locations:
177203
backend:
178204
location: /
205+
# app_protect: # Optional -- Configure NGINX App Protect
206+
# enable: false # Optional
207+
# policy_file: path # Optional
208+
# security_log_enable: false # Optional
209+
# security_log: # Optional
210+
# path: path # Required
211+
# destination: dest # Required
179212
include_files: []
180213
proxy_hide_headers: [] # A list of headers which shouldn't be passed to the application
181214
add_headers:

defaults/main/upload.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
# Default location of files is the files folder within the NGINX Config Ansible role.
55
# Upload the main NGINX configuration file.
66
nginx_config_main_upload_enable: false
7-
nginx_config_main_upload_src: conf/nginx.conf
7+
nginx_config_main_upload_src: config/nginx.conf
88
nginx_config_main_upload_dest: /etc/nginx/
99
# Upload HTTP NGINX configuration files.
1010
nginx_config_http_upload_enable: false
11-
nginx_config_http_upload_src: conf/http/*.conf
11+
nginx_config_http_upload_src: config/http/*.conf
1212
nginx_config_http_upload_dest: /etc/nginx/conf.d/
1313
# Upload Stream NGINX configuration files.
1414
nginx_config_stream_upload_enable: false
15-
nginx_config_stream_upload_src: conf/stream/*.conf
15+
nginx_config_stream_upload_src: config/stream/*.conf
1616
nginx_config_stream_upload_dest: /etc/nginx/conf.d/
1717
# Upload HTML files.
1818
nginx_config_html_upload_enable: false
File renamed without changes.
File renamed without changes.

handlers/main.yml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
---
2-
- name: "(Handler) Run NGINX"
3-
block:
4-
- name: "(Handler) Start NGINX"
5-
service:
6-
name: nginx
7-
state: started
8-
enabled: yes
9-
notify: "(Handler) Check NGINX"
2+
- name: (Handler - NGINX Config) Check NGINX
3+
command: nginx -t
4+
register: config
5+
ignore_errors: yes
6+
changed_when: false
7+
listen: (Handler - NGINX Config) Run NGINX
108

11-
- name: "(Handler) Check NGINX"
12-
command: "nginx -t"
13-
notify: "(Handler) Start NGINX"
14-
changed_when: false
9+
- name: (Handler - NGINX Config) Print NGINX error if syntax check fails
10+
debug:
11+
var: config.stderr_lines
12+
failed_when: config.rc != 0
13+
when: config.rc != 0
14+
listen: (Handler - NGINX Config) Run NGINX
1515

16-
- name: "(Handler) Reload NGINX"
17-
command: "nginx -s reload"
18-
changed_when: false
16+
- name: (Handler - NGINX Config) Start/reload NGINX
17+
service:
18+
name: nginx
19+
state: reloaded
1920
when:
2021
- nginx_config_start | bool
21-
- not ansible_check_mode
22+
- not ansible_check_mode | bool
23+
listen: (Handler - NGINX Config) Run NGINX

molecule/cleanup_module/molecule.yml

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
dependency:
33
name: galaxy
44
options:
5-
role-file: molecule/common/requirements.yml
5+
role-file: molecule/common/playbooks/oss_requirements.yml
66
driver:
77
name: docker
88
lint: |
99
set -e
1010
yamllint .
1111
ansible-lint --force-color
1212
platforms:
13-
- name: debian-stretch
14-
image: debian:stretch-slim
13+
- name: alpine-3.11
14+
image: alpine:3.11
1515
dockerfile: ../common/Dockerfile.j2
1616
privileged: true
1717
volumes:
1818
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
1919
command: "/sbin/init"
20-
- name: debian-buster
21-
image: debian:buster-slim
20+
- name: centos-7
21+
image: centos:7
2222
dockerfile: ../common/Dockerfile.j2
2323
privileged: true
2424
volumes:
2525
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
26-
command: "/sbin/init"
27-
- name: ubuntu-xenial
28-
image: ubuntu:xenial
26+
command: "/usr/sbin/init"
27+
- name: debian-stretch
28+
image: debian:stretch-slim
2929
dockerfile: ../common/Dockerfile.j2
3030
privileged: true
3131
volumes:
@@ -38,16 +38,7 @@ platforms:
3838
volumes:
3939
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
4040
command: "/sbin/init"
41-
- name: ubuntu-focal
42-
image: ubuntu:focal
43-
dockerfile: ../common/Dockerfile.j2
44-
privileged: true
45-
volumes:
46-
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
47-
command: "/sbin/init"
4841
provisioner:
4942
name: ansible
5043
playbooks:
51-
prepare: ../common/playbooks/prepare.yml
52-
converge: ../common/playbooks/cleanup_module_converge.yml
53-
verify: ../common/playbooks/cleanup_module_verify.yml
44+
prepare: ../common/playbooks/oss_prepare.yml

0 commit comments

Comments
 (0)