Skip to content

Commit 8b4c023

Browse files
aknot242jessegoodieralessfg
authored
Staging (#23)
* Update tests (#21) * minor udpates on docs and permissions * add sample playbook * add sample playbook * fixed typos * fixed typos * initial commit * updating supported OS versions * Keep working on tests And refactor all the things * Ensure molecule verifier passes * Add GitHub contribution guidelines * updating keys and repos for NAP * adding back nginx plus signing key * updating repo URL * removing changelog, as there is not one * Bring docs up to speed with other NGINX roles And move some default variables into the vars subfolder * add tests and fix linting issues * updating changelog * added linting fix Co-authored-by: Jesse Goodier <[email protected]> Co-authored-by: Alessandro Fael Garcia <[email protected]> * base 64 decoding of build secrets * only build for master and staging * fix formatting. dan hates yml. * adding syslog test * fix linting issues * ansible writing to remote syslog messed up a test. renaming master to main * add molecule test syntax * increasing service timeout as travisci is super slow today Co-authored-by: Jesse Goodier <[email protected]> Co-authored-by: Alessandro Fael Garcia <[email protected]>
1 parent 3cb5d6a commit 8b4c023

File tree

11 files changed

+160
-13
lines changed

11 files changed

+160
-13
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
---
2+
# safelist - build only on the following branches
3+
branches:
4+
only:
5+
- main
6+
- staging
27
language: python
38
services: docker
49
jobs:
@@ -18,6 +23,6 @@ install:
1823
- pip install molecule==3.0.8
1924
- pip install docker==4.3.1
2025
script:
21-
- travis_wait 50 molecule lint -s $scenario
26+
- molecule test -s $scenario
2227
notifications:
2328
webhooks: https://galaxy.ansible.com/api/v1/notifications/

CHANGELOG.md

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

3+
## 0.2.2 (September 14, 2020)
4+
5+
ENHANCEMENTS:
6+
7+
* Added molecule tests and verifications
8+
9+
BUG FIXES:
10+
11+
* Fixed newly appearing linting issues in role
12+
13+
## 0.2.1 (September 11, 2020)
14+
15+
ENHANCEMENTS:
16+
17+
* Bring docs up to speed with other NGINX roles
18+
* Move some default variables into the vars subfolder
19+
320
## 0.2.0 (September 10, 2020)
421

522
BREAKING CHANGES:

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ Instructions on how to install Ansible can be found in the [Ansible website](htt
2323

2424
Molecule is used to test the various functionalities of the role. Instructions on how to install Molecule can be found in the [Molecule website](https://molecule.readthedocs.io/en/stable/installation.html).
2525

26+
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:
27+
28+
``` bash
29+
export NGINX_CRT=$( cat <path to your certificate file> | base64)
30+
export NGINX_KEY=$( cat <path to your key file> | base64)
31+
molecule test
32+
```
33+
2634
Installation
2735
------------
2836

molecule/default/converge.yml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
- name: Converge
3-
hosts: all
3+
hosts: nap
44
tasks:
55
- name: Install NGINX App Protect
66
include_role:
@@ -15,10 +15,11 @@
1515
nginx_app_protect_log_policy_template_enable: true
1616
nginx_app_protect_log_policy_filter_request_type: all
1717
nginx_app_protect_conf_template_enable: true
18-
nginx_app_protect_log_policy_syslog_target: 10.1.10.105:5144
18+
nginx_app_protect_log_policy_syslog_target: localhost:514
1919
nginx_app_protect_demo_workload_protocol: http://
20-
nginx_app_protect_demo_workload_host: 10.1.10.105:8080
20+
nginx_app_protect_demo_workload_host: test-workload:80
2121
nginx_app_protect_license:
2222
certificate: "license/nginx-repo.crt"
2323
key: "license/nginx-repo.key"
24-
nginx_app_protect_delete_license: false
24+
nginx_app_protect_delete_license: true
25+
nginx_app_protect_timeout: 300

molecule/default/molecule.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,49 @@ lint: |
66
yamllint .
77
ansible-lint --force-color
88
platforms:
9+
- name: test-workload
10+
groups:
11+
- workload
12+
image: nginxdemos/hello
13+
privileged: true
14+
networks:
15+
- name: molecule-test
916
- name: centos-7
17+
groups:
18+
- nap
1019
image: centos:7
1120
dockerfile: ../Dockerfile.j2
1221
privileged: true
22+
networks:
23+
- name: molecule-test
1324
volumes:
1425
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
1526
command: "/usr/sbin/init"
1627
- name: ubuntu-bionic
28+
groups:
29+
- nap
1730
image: ubuntu:bionic
1831
dockerfile: ../Dockerfile.j2
1932
privileged: true
33+
networks:
34+
- name: molecule-test
2035
volumes:
2136
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
2237
command: "/sbin/init"
2338
- name: debian-stretch
39+
groups:
40+
- nap
2441
image: debian:stretch-slim
2542
dockerfile: ../Dockerfile.j2
2643
privileged: true
44+
networks:
45+
- name: molecule-test
2746
volumes:
2847
- "/sys/fs/cgroup:/sys/fs/cgroup:rw"
2948
command: "/sbin/init"
3049
provisioner:
3150
name: ansible
51+
config_options:
52+
defaults:
53+
no_target_syslog: true
54+
log: false

molecule/default/prepare.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
---
2+
- name: Prepare
3+
hosts: localhost
4+
connection: local
5+
gather_facts: false
6+
vars:
7+
nginx_license:
8+
certificate: "./license/nginx-repo.crt"
9+
key: "./license/nginx-repo.key"
10+
11+
tasks:
12+
- name: Create license directory
13+
file:
14+
path: "./license"
15+
state: directory
16+
mode: 0755
17+
18+
- name: Create ephemeral license certificate file from b64 decoded env var
19+
copy:
20+
content: "{{ lookup('env','NGINX_CRT') | b64decode }}"
21+
dest: "{{ nginx_license.certificate }}"
22+
mode: 0444
23+
24+
- name: Create ephemeral license key file from b64 decoded env var
25+
copy:
26+
content: "{{ lookup('env','NGINX_KEY') | b64decode }}"
27+
dest: "{{ nginx_license.key }}"
28+
mode: 0444
29+
30+
- name: Set up rsyslog server for verifying NAP syslog events
31+
hosts: nap
32+
vars:
33+
rsyslog_receiver: true
34+
rsyslog_remote_tcp: true
35+
rsyslog_remote_port: 514
36+
roles:
37+
- role: robertdebock.rsyslog
38+
39+
- name: Prepare workload for tests
40+
hosts: workload
41+
gather_facts: false
42+
tasks:
43+
- name: Start nginx on test workload
44+
raw: nohup nginx </dev/null >/dev/null 2>&1 & sleep 1
45+
changed_when: false

molecule/default/requirements.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
roles:
3+
- robertdebock.rsyslog

molecule/default/verify.yml

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,60 @@
11
---
22
- name: Verify
3-
hosts: all
3+
hosts: nap
44
tasks:
55
- name: Check if NGINX is installed
66
package:
77
name: nginx-plus
8-
check_mode: yes
8+
check_mode: true
9+
register: install
10+
failed_when: (install is changed) or (install is failed)
11+
12+
- name: Check if NGINX App Protect is installed
13+
package:
14+
name: app-protect
15+
check_mode: true
16+
register: install
17+
failed_when: (install is changed) or (install is failed)
18+
19+
- name: Check if NGINX App Protect Signatures is installed
20+
package:
21+
name: app-protect-attack-signatures
22+
check_mode: true
23+
register: install
24+
failed_when: (install is changed) or (install is failed)
25+
26+
- name: Check if NGINX App Protect Threat Campaigns is installed
27+
package:
28+
name: app-protect-threat-campaigns
29+
check_mode: true
930
register: install
1031
failed_when: (install is changed) or (install is failed)
1132

1233
- name: Check if NGINX service is running
1334
service:
1435
name: nginx
1536
state: started
16-
enabled: yes
17-
check_mode: yes
37+
enabled: true
38+
check_mode: true
1839
register: service
1940
failed_when: (service is changed) or (service is failed)
41+
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"
48+
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"
55+
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"

tasks/config/configure-app-protect.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
- name: "Ensure NGINX main directory exists"
2+
- name: Ensure NGINX main directory exists
33
file:
44
path: "{{ nginx_app_protect_conf_template.out_file_location }}"
55
state: directory
@@ -8,15 +8,15 @@
88
or nginx_app_protect_log_policy_template_enable | bool
99
or nginx_app_protect_conf_template_enable | bool
1010

11-
- name: "Dynamically generate NGINX App Protect security policy file"
11+
- name: Dynamically generate NGINX App Protect security policy file
1212
template:
1313
src: "{{ nginx_app_protect_security_policy_template.template_file }}"
1414
dest: "{{ nginx_app_protect_security_policy_template.out_file_location }}{{ nginx_app_protect_security_policy_template.out_file_name }}"
1515
mode: 0644
1616
backup: true
1717
when: nginx_app_protect_security_policy_template_enable | bool
1818

19-
- name: "Dynamically generate NGINX App Protect log policy file"
19+
- name: Dynamically generate NGINX App Protect log policy file
2020
template:
2121
src: "{{ nginx_app_protect_log_policy_template.template_file }}"
2222
dest: "{{ nginx_app_protect_log_policy_template.out_file_location }}{{ nginx_app_protect_log_policy_template.out_file_name }}"
@@ -49,12 +49,14 @@
4949
path: /etc/nginx/nginx.conf
5050
regexp: '^([ \t]*load_module.*ngx_http_app_protect_module.so;)'
5151
replace: '# \1'
52+
mode: preserve
5253

5354
- name: Comment out NGINX App Protect directives in nginx.conf
5455
replace:
5556
path: /etc/nginx/nginx.conf
5657
regexp: '^([ \t]*app_protect_)'
5758
replace: '# \1'
59+
mode: preserve
5860
when: nginx_app_protect_state == "absent"
5961

6062
- name: Reload NGINX

tasks/install/setup-debian-repos.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
apt_repository:
44
repo: deb [arch=amd64] https://plus-pkgs.nginx.com/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} nginx-plus
55
filename: nginx-app-protect
6+
mode: 0644
67
update_cache: false
78
state: "{{ nginx_app_protect_license_status | default ('present') }}"
89

910
- name: Setup Debian and Ubuntu NGINX App Protect security updates repository
1011
apt_repository:
1112
repo: deb [arch=amd64] https://app-protect-security-updates.nginx.com/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} nginx-plus
1213
filename: app-protect-security-updates
14+
mode: 0644
1315
update_cache: false
1416
state: "{{ nginx_app_protect_license_status | default ('present') }}"
1517

0 commit comments

Comments
 (0)