This time I am going to add the modsec module and configure a very basic test rule (one more post to get to the complex rules).
Just a reminder for folks entering the series mid stream:
The assumptions: local file system inventory files, Ansible host deployed to the same VPC as the remote machines, variable files, run the playbooks from the same folder as the inventory and variable files.
For this article we will use the following playbook:
https://github.com/brianehlert/ansible-nginx-examples/blob/master/nginx_lb_plus_modsec.yaml
And this accompanying variables file:
https://github.com/brianehlert/ansible-nginx-examples/blob/master/nginx_lb_plus_modsec_vars.yaml
And we are using the Ansible Role for NGINX.
Running the playbook
Running the playbook is no different than the pattern in the previous posts:ansible-playbook nginx_lb_plus_modsec.yaml -i loadbalancers
Like the NGINX Plus post before this will:
Read in the webservers inventory file and read in the nginx_lb_plus_modsec_vars.yaml file.
The variable file defines the path to the Plus key and cert, to delete the license and clean up, enable the NGINX Plus API.
The new variable option is: nginx_modules
In this case the waf module is added, which indicates mod security.
The remainder of the configuration is all the same as the two load balancer blogs prior.
What does start to get unique to modsec is the post_tasks in the playbook.
Setting the waf module
In the post_tasks section of the playbook I am copying a framework config file for mod security rules.https://github.com/brianehlert/ansible-nginx-examples/blob/master/modsec_rules.conf
After the framework file is copied into place the Rule is being enabled.
Then the NGINX config is tested (to make sure nothing went pear-shaped).
Assuming the configuration test passes the nginx process is restarted.
At this time some limited traffic should be blocked.
If you take a look at the modsec_rules.conf file, we are blocking a URL with 'test' in it. As well as logging and returning a 403.
That is the basics of enabling a module with the Ansible Role on NGINX Plus.
In this case with additional settings of enabling a basic mod security rule.
No comments:
Post a Comment