Skip to content

Commit 72536bb

Browse files
authored
add static policy file deployment feature (#38)
* add static policy file deployment feature * moving var conflict check into block * create a default source * missing var * vars were not expanded * added change note * flattening file variables, add deprecation notice * added variable checks * pr feedback updates
1 parent bb45299 commit 72536bb

File tree

6 files changed

+77
-3
lines changed

6 files changed

+77
-3
lines changed

.ansible-lint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
skip_list:
22
- '106'
3+
- '204'

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Changelog
22

3+
34
## 0.3.3 (Unreleased)
45

56
ENHANCEMENTS:
67

78
* Add survey to README.
89
* Improve README structure and use tables where relevant.
910
* Update Ansible (now Ansible base) to `2.10.2`, Ansible (now Ansible Community Distribution) to `2.10.0`, and yamllint to `1.25.0`.
11+
* Ability to deploy static security policy files via the `nginx_app_protect_security_policy_file_enable` and `nginx_app_protect_security_policy_file_*` variables. NOTE: `nginx_app_protect_configure` must be set to true.
12+
* Ability to deploy static log policy files via the `nginx_app_protect_log_policy_file_enable` and `nginx_app_protect_log_policy_file_*` variables. NOTE: `nginx_app_protect_configure` must be set to true.
13+
14+
DEPRECATION WARNING:
15+
* The ability to dynamically create App Protect security and log policies via Jinja2 templates will be removed in a future release, as they weren't used much due to relative inflexibility. The `nginx_app_protect_security_policy_file_enable`, `nginx_app_protect_security_policy_file_*`, `nginx_app_protect_log_policy_file_enable` and `nginx_app_protect_log_policy_file_*` variables should be used instead of the `nginx_app_protect_*_policy_template*` variables. These new variables have been introduced in this release.
1016

1117
## 0.3.2 (September 30, 2020)
1218

@@ -100,4 +106,4 @@ BUG FIXES:
100106

101107
Supports App Protect 2.0, which brings a number of features including support for Ubuntu 18.04.
102108

103-
Release notes for NGINX App Protect 2.0: docs.nginx.com/nginx-app-protect/releases/#release-2-0
109+
Release notes for NGINX App Protect 2.0: docs.nginx.com/nginx-app-protect/releases/#release-2-0

defaults/main.yml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ nginx_app_protect_timeout: 180
5252
# Creates basic configuration files and enables NGINX App Protect on the target host
5353
nginx_app_protect_configure: false
5454

55-
# Create a basic NGINX App Protect security policy file
55+
## DEPRECATED -- Use nginx_app_protect_security_policy_enable and nginx_app_protect_security_policy_file_* variables instead
56+
# Create a basic NGINX App Protect security policy file based on a template
5657
nginx_app_protect_security_policy_template_enable: true
5758
nginx_app_protect_security_policy_template:
5859
template_file: app-protect-security-policy.j2
@@ -61,7 +62,8 @@ nginx_app_protect_security_policy_template:
6162
# possible values: transparent, blocking
6263
nginx_app_protect_security_policy_enforcement_mode: transparent
6364

64-
# Create a basic NGINX App Protect log policy file
65+
## DEPRECATED -- Use nginx_app_protect_log_policy_file_enable and nginx_app_protect_log_policy_file_* variables instead
66+
# Create a basic NGINX App Protect log policy file based on a template
6567
nginx_app_protect_log_policy_template_enable: true
6668
nginx_app_protect_log_policy_template:
6769
template_file: app-protect-log-policy.j2
@@ -81,3 +83,13 @@ nginx_app_protect_demo_workload_protocol: http://
8183
nginx_app_protect_demo_workload_host: 10.1.1.1:8080
8284
nginx_app_protect_log_policy_syslog_target: 127.0.0.1:514 # DEPRECATED -- use nginx_app_protect_log_policy_target instead
8385
nginx_app_protect_log_policy_target: "syslog:server={{ nginx_app_protect_log_policy_syslog_target }}"
86+
87+
# Copy local NGINX App Protect security policy to host
88+
nginx_app_protect_security_policy_file_enable: false
89+
nginx_app_protect_security_policy_file_src: files/config/security-policy.json
90+
nginx_app_protect_security_policy_file_dest: /etc/nginx/security-policy.json
91+
92+
# Copy local NGINX App Protect log policy to host
93+
nginx_app_protect_log_policy_file_enable: false
94+
nginx_app_protect_log_policy_file_src: files/config/log-policy.json
95+
nginx_app_protect_log_policy_file_dest: /etc/nginx/log-policy.json

molecule/default/verify.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,15 @@
3838
check_mode: true
3939
register: service
4040
failed_when: (service is changed) or (service is failed)
41+
42+
- name: Check that the security policy exists
43+
stat:
44+
path: /etc/nginx/app-protect-security-policy.json
45+
register: stat_result
46+
failed_when: not stat_result.stat.exists
47+
48+
- name: Check that the log policy exists
49+
stat:
50+
path: /etc/nginx/app-protect-log-policy.json
51+
register: stat_result
52+
failed_when: not stat_result.stat.exists

tasks/config/configure-app-protect.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,20 @@
88
or nginx_app_protect_log_policy_template_enable | bool
99
or nginx_app_protect_conf_template_enable | bool
1010

11+
- name: Copy NGINX App Protect security policy file
12+
copy:
13+
src: "{{ nginx_app_protect_security_policy_file_src }}"
14+
dest: "{{ nginx_app_protect_security_policy_file_dst }}"
15+
mode: 0644
16+
when: nginx_app_protect_security_policy_file_enable | bool
17+
18+
- name: Copy NGINX App Protect log policy file
19+
copy:
20+
src: "{{ nginx_app_protect_log_policy_file_src }}"
21+
dest: "{{ nginx_app_protect_log_policy_file_dst }}"
22+
mode: 0644
23+
when: nginx_app_protect_log_policy_file_enable | bool
24+
1125
- name: Dynamically generate NGINX App Protect security policy file
1226
template:
1327
src: "{{ nginx_app_protect_security_policy_template.template_file }}"

tasks/main.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,35 @@
2828
msg: "NGINX App Protect is not supported on os family {{ ansible_facts['distribution'] }} version {{ ansible_facts['distribution_version'] }}"
2929
when: not supported_os
3030

31+
- name: Check for conflicting config variables
32+
block:
33+
- name: Abort if there are conflicting security policy config variables
34+
fail:
35+
msg: "Conflicting variables: nginx_app_protect_security_policy_template_enable and nginx_app_protect_security_policy_file_enable cannot be truthy in the same play"
36+
when: nginx_app_protect_security_policy_template_enable | bool and nginx_app_protect_security_policy_file_enable | bool
37+
38+
- name: Abort if there are conflicting log policy config variables
39+
fail:
40+
msg: "Conflicting variables: nginx_app_protect_log_policy_template_enable and nginx_app_protect_log_policy_file_enable cannot be truthy in the same play"
41+
when: nginx_app_protect_log_policy_template_enable | bool and nginx_app_protect_log_policy_file_enable | bool
42+
43+
- name: Fail if variables for nginx_app_protect_security_policy_file_enable are not defined
44+
assert:
45+
that: ("{{ item }} is defined") and ("{{ item }} | length > 0")
46+
loop:
47+
- nginx_app_protect_security_policy_file_src
48+
- nginx_app_protect_security_policy_file_dst
49+
when: nginx_app_protect_security_policy_file_enable | bool
50+
51+
- name: Fail if variables for nginx_app_protect_log_policy_file_enable are not defined
52+
assert:
53+
that: ("{{ item }} is defined") and ("{{ item }} | length > 0")
54+
loop:
55+
- nginx_app_protect_log_policy_file_src
56+
- nginx_app_protect_log_policy_file_dst
57+
when: nginx_app_protect_log_policy_file_enable | bool
58+
when: nginx_app_protect_configure | bool
59+
3160
- name: Install NGINX App Protect
3261
block:
3362
- name: Install prerequisites

0 commit comments

Comments
 (0)