Changeset - 941f4f372672
[Not reviewed]
0 4 3
Branko Majic (branko) - 9 years ago 2015-04-27 13:42:32
branko@majic.rs
MAR-12: Updated the common role to deploy ferm, and set-up a basic firewall for allowing incoming SSH and ICMP echo requsts (ping).
7 files changed with 101 insertions and 1 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -202,6 +202,11 @@ The role implements the following:
 
  itself, and provided they know the exact path of the file.
 
* Deploys CA certificate files, normally used for truststore purposes, to
 
  ``/etc/ssl/certs/``.
 
* Installs ferm (for iptables management), configuring a basic firewall which
 
  allows ICMP echo requests (PING), incoming connection on TCP port 22 (SSH),
 
  and also introduces rate-limitting for incoming ICMP echo request pacakges and
 
  (new) TCP connections. The rate-limitting is based on the source IP address,
 
  using the ``iptables hashlimit`` module.
 

	
 

	
 
Parameters
 
@@ -253,6 +258,17 @@ Parameters
 
  on originating (Ansible) host that should be copied to destination
 
  server.
 

	
 
**incoming_connection_limit** (string, mandatory)
 
  Rate at which the incoming ICMP echo-request packages and new TCP connections
 
  will be accepted at. The value should be specified in the same format as value
 
  for the ``iptables hashlimit`` option ``--hashlimit-upto``.
 

	
 
**incoming_connection_limit_burst** (string, mandatory)
 
  Initial burst of packages that should be accepted when the client with
 
  distinct source IP address connects to the server for the first time (usually
 
  higher than ``incoming_connection_limit``), even if it would go above the
 
  specified connection limit.
 

	
 

	
 
Examples
 
~~~~~~~~
 
@@ -289,6 +305,10 @@ packages on all servers:
 
  ca_certificates:
 
    - ../certs/truststore.pem
 

	
 
  incoming_connection_limit: 2/second
 

	
 
  incoming_connection_limit_burst: 6
 

	
 
.. _ldap_client:
 

	
 
LDAP Client
roles/common/files/ferm
Show inline comments
 
new file 100644
 
# configuration for /etc/init.d/ferm
 

	
 
# use iptables-restore for fast firewall initialization?
 
FAST=yes
 

	
 
# cache the output of ferm --lines in /var/cache/ferm?
 
CACHE=no
 

	
 
# additional paramaters for ferm (like --def '=bar')
 
OPTIONS=
 

	
 
# Enable the ferm init script? (i.e. run on bootup)
 
ENABLED="yes"
roles/common/files/ferm.conf
Show inline comments
 
new file 100644
 
@include '/etc/ferm/conf.d/';
roles/common/handlers/main.yml
Show inline comments
 
@@ -8,3 +8,6 @@
 

	
 
- name: Update CA certificate cache
 
  command: /usr/sbin/update-ca-certificates --fresh
 

	
 
- name: Restart ferm
 
  service: name=ferm state=restarted
 
\ No newline at end of file
roles/common/tasks/main.yml
Show inline comments
 
@@ -55,3 +55,28 @@
 
  with_items: ca_certificates
 
  notify:
 
    - Update CA certificate cache
 

	
 
- name: Install ferm (for firewall management)
 
  apt: name=ferm state=installed
 

	
 
- name: Configure ferm init script coniguration file
 
  copy: src=ferm dest=/etc/default/ferm owner=root group=root mode=644
 
  notify:
 
    - Restart ferm
 

	
 
- name: Create directory for storing ferm configuration files
 
  file: dest="/etc/ferm/conf.d/" mode=750 state=directory owner=root group=root
 

	
 
- name: Deploy main ferm configuration file
 
  copy: src=ferm.conf dest=/etc/ferm/ferm.conf
 
  notify:
 
    - Restart ferm
 

	
 
- name: Deploy ferm base rules
 
  template: src=00-base.conf.j2 dest=/etc/ferm/conf.d/00-base.conf
 
            owner=root group=root mode=640
 
  notify:
 
    - Restart ferm
 

	
 
- name: Enable ferm service
 
  service: name=ferm state=started
roles/common/templates/00-base.conf.j2
Show inline comments
 
new file 100644
 
table filter {
 
    chain INPUT {
 
        policy DROP;
 
        interface lo ACCEPT;
 
        # Make sure not to allow flooding via ICMP ping packages by sending them
 
        # to flood chain before state module kicks in.
 
        proto icmp icmp-type echo-request jump flood;
 
        mod state state (ESTABLISHED RELATED) ACCEPT;
 
        # For TCP packages we perform floods checks after state module took care
 
        # of established and related connections.
 
        proto tcp tcp-flags (FIN SYN RST ACK) SYN jump flood;
 
        # Accept some common incoming connections.
 
        proto icmp icmp-type echo-request ACCEPT;
 
        proto tcp dport 22 ACCEPT;
 
    }
 

	
 
    # The flood chain is used for controlling the rate of the incoming connections.
 
    chain flood {
 
        # Rate-limit the ping requests.
 
        proto icmp icmp-type echo-request {
 
            mod hashlimit hashlimit {{ incoming_connection_limit }} hashlimit-burst {{ incoming_connection_limit_burst }}
 
                hashlimit-mode srcip hashlimit-name icmp RETURN;
 
            DROP;
 
        }
 
        # Rate-limit the TCP connections.
 
        proto tcp tcp-flags (FIN SYN RST ACK) SYN {
 
            mod hashlimit hashlimit {{ incoming_connection_limit }} hashlimit-burst {{ incoming_connection_limit_burst }}
 
                hashlimit-mode srcip hashlimit-name icmp RETURN;
 
            LOG;
 
            DROP;
 
        }
 
    }
 

	
 
}
testsite/group_vars/all.yml
Show inline comments
 
@@ -25,4 +25,8 @@ common_packages:
 
  - debconf-utils
 

	
 
ca_certificates:
 
  - "{{ inventory_dir }}/tls/example_ca_chain.pem"
 
\ No newline at end of file
 
  - "{{ inventory_dir }}/tls/example_ca_chain.pem"
 

	
 
incoming_connection_limit: 2/second
 

	
 
incoming_connection_limit_burst: 6
 
\ No newline at end of file
0 comments (0 inline, 0 general)