Changeset - fe6cdb2443c7
[Not reviewed]
0 4 0
Branko Majic (branko) - 9 years ago 2015-08-30 19:14:54
branko@majic.rs
MAR-19: Simplified the parameters for common role, making a lot of them optional with some sane defaults. Switched to using an actual list for additional groups.
4 files changed with 33 insertions and 32 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -206,131 +206,128 @@ The role implements the following:
 
* Configures apt to use caching proxy (if any was specified).
 
* Sets-up umask for all logins to ``0027``.
 
* Installs sudo.
 
* Installs additional base packages, as configured.
 
* Creates additional operating system groups, as configured.
 
* Creates additional operating system users, as configured.
 
* Hardens the SSH server by disabling remote ``root`` logins and password-based
 
  authentication.
 
* Allows traversing of directory ``/etc/ssl/private/`` to everyone. This lets
 
  you put TLS private keys in central location where any operating system user
 
  can reach them provided they have appropriate read/write rights on the file
 
  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
 
~~~~~~~~~~
 

	
 
**apt_proxy** (string, optional)
 
**apt_proxy** (string, optional, ``None``)
 
  URI of a caching proxy that should be used when retrieving the packages via
 
  apt. Default is no proxy.
 
  apt.
 

	
 
**os_users** (list, optional)
 
**os_users** (list, optional, ``[]``)
 
  A list of operating system users that should be set-up on a server. Each item
 
  is a dictionary with the following options describing the user parameters:
 

	
 
  **name** (string, mandatory)
 
    Name of the operating system user that should be created. User's default
 
    group will have the same name as the user.
 

	
 
  **uid** (number, mandatory)
 
  **uid** (number, optional, ``whatever OS picks``)
 
    UID for the operating system user. User's default group will have a GID
 
    identical to the user's UID.
 
    identical to the user's UID if specified. Otherwise user's default group
 
    will have OS-determined GID.
 

	
 
  **additional_groups** (string, mandatory)
 
    Comma-separated list of additional groups that a user should belong to. If
 
    no additional groups should be appended to user's list of groups, set it to
 
    empty string (``""``).
 
  **additional_groups** (list, optional, ``[]``)
 
    Comma-separated list of additional groups that a user should belong to.
 

	
 
  **authorized_keys** (list, mandatory)
 
  **authorized_keys** (list, optional, ``[]``)
 
    List of SSH public keys that should be deployed to user's authorized_keys
 
    truststore. If no authorized keys should be deployed, set it to empty list
 
    (``[]``).
 
    truststore.
 

	
 
  **password** (string, mandatory)
 
  **password** (string, optional, ``!`` - no password)
 
    Encrypted password that should be set for the user.
 

	
 
**os_groups** (list, optional)
 
**os_groups** (list, optional, ``[]``)
 
  A list of operating system groups that should be set-up on a server. Each item
 
  is a dictionary with the following options describing the group parameters:
 

	
 
  **name** (string, mandatory)
 
    Name of the operating system group that should be created.
 

	
 
  **gid** (number, mandatory)
 
  **gid** (number, optional, ``whatever OS picks``)
 
    GID for the operating system group.
 

	
 
**common_packages** (list, optional)
 
**common_packages** (list, optional, ``[]``)
 
  List of additional operating system packages that should be installed on the
 
  server. Each element of the list should be a simple string denoting the name
 
  of the package.
 

	
 
**ca_certificates** (list, optional)
 
**ca_certificates** (list, optional, ``[]``)
 
  List of additional CA certificate files that should be deployed on the
 
  server. Each element of the list should be a filepath to a CA certificate file
 
  on originating (Ansible) host that should be copied to destination
 
  server.
 

	
 
**incoming_connection_limit** (string, mandatory)
 
**incoming_connection_limit** (string, optional, ``3/second``)
 
  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)
 
**incoming_connection_limit_burst** (string, optional, ``9``)
 
  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
 
~~~~~~~~
 

	
 
Here is an example configuration for setting-up some common users, groups, and
 
packages on all servers:
 

	
 
.. code-block:: yaml
 

	
 
  ---
 

	
 
  os_users:
 
    - name: admin
 
      uid: 1000
 
      additional_groups: sudo
 
      additional_groups:
 
        - sudo
 
      authorized_keys:
 
        - "{{ lookup('file', '/home/admin/.ssh/id_rsa.pub') }}"
 
      password: '$6$AaJRWtqyX5pk$IP8DUjgY0y2zqMom9BAc.O9qHoQWLFCmEsPRCika6l/Xh87cp2SnlMywH0.r4uEcbHnoicQG46V9VrJ8fxp2d.'
 
    - name: john
 
      uid: 1001
 
      additional_groups: ""
 
      authorized_keys: []
 
      password: '$6$AaJRWtqyX5pk$IP8DUjgY0y2zqMom9BAc.O9qHoQWLFCmEsPRCika6l/Xh87cp2SnlMywH0.r4uEcbHnoicQG46V9VrJ8fxp2d.'
 

	
 
  os_groups:
 
    - name: localusers
 
      gid: 2500
 

	
 
  common_packages:
 
    - emacs23-nox
 
    - screen
 
    - debconf-utils
 

	
 
  ca_certificates:
 
    - ../certs/truststore.pem
 

	
 
  incoming_connection_limit: 2/second
 

	
 
  incoming_connection_limit_burst: 6
 

	
 
.. _ldap_client:
 

	
 
LDAP Client
 
-----------
 

	
 
The ``ldap_client`` role can be used for setting-up an OpenLDAP client on
roles/common/defaults/main.yml
Show inline comments
 
---
 

	
 
packages: []
 
os_users: []
 
os_groups: []
 
ca_certificates: []
 
\ No newline at end of file
 
ca_certificates: []
 
incoming_connection_limit: 3/second
 
incoming_connection_limit_burst: 9
 
\ No newline at end of file
roles/common/tasks/main.yml
Show inline comments
 
@@ -9,65 +9,65 @@
 
  file: path="/etc/apt/apt.conf.d/00proxy" state=absent
 
  when: apt_proxy is undefined
 

	
 
- name: Deploy pam-auth-update configuration file for enabling pam_umask
 
  copy: src=pam_umask dest=/usr/share/pam-configs/umask mode=644 owner=root group=root
 
  notify: Update PAM configuration
 

	
 
- name: Set login UMASK
 
  lineinfile: dest=/etc/login.defs state=present backrefs=yes regexp='^UMASK(\s+)' line='UMASK\g<1>027'
 

	
 
- name: Set home directory mask
 
  lineinfile: dest=/etc/adduser.conf state=present backrefs=yes regexp='^DIR_MODE=' line='DIR_MODE=0750'
 

	
 
- name: Install sudo
 
  apt: name=sudo state=present
 

	
 
- name: Install ssl-cert package
 
  apt: name=ssl-cert state=present
 

	
 
- name: Install common packages
 
  apt: name="{{ item }}" state="present"
 
  with_items: common_packages
 

	
 
- name: Set-up operating system groups
 
  group: name="{{ item.name }}" gid="{{ item.gid }}" state=present
 
  group: name="{{ item.name }}" gid="{{ item.gid | default(omit) }}" state=present
 
  with_items: os_groups
 

	
 
- name: Set-up operating system user groups
 
  group: name="{{ item.name }}" gid="{{ item.uid }}" state=present
 
  group: name="{{ item.name }}" gid="{{ item.uid | default(omit) }}" state=present
 
  with_items: os_users
 

	
 
- name: Set-up operating system users
 
  user: name="{{ item.name }}" uid="{{ item.uid }}" group="{{ item.name }}"
 
        groups="{{ item.additional_groups }}" append=yes shell=/bin/bash state=present
 
        password="{{ item.password }}"
 
  user: name="{{ item.name }}" uid="{{ item.uid | default(omit) }}" group="{{ item.name }}"
 
        groups="{{ ",".join(item.additional_groups | default([])) }}" append=yes shell=/bin/bash state=present
 
        password="{{ item.password | default('!') }}"
 
  with_items: os_users
 

	
 
- name: Set-up authorised keys
 
  authorized_key: user="{{ item.0.name }}" key="{{ item.1 }}"
 
  with_subelements:
 
    - os_users
 
    - "{{ os_users | selectattr('authorized_keys', 'defined') | list }}"
 
    - authorized_keys
 

	
 
- name: Disable remote logins for root
 
  lineinfile: dest="/etc/ssh/sshd_config" state=present regexp="^PermitRootLogin" line="PermitRootLogin no"
 
  notify:
 
    - Restart SSH
 

	
 
- name: Disable remote login authentication via password
 
  lineinfile: dest="/etc/ssh/sshd_config" state=present regexp="^PasswordAuthentication" line="PasswordAuthentication no"
 
  notify:
 
    - Restart SSH
 

	
 
- name: Deploy CA certificates
 
  copy: src="{{ item }}" dest="/etc/ssl/certs/{{ item | basename }}" mode=644 owner=root group=root
 
  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:
testsite/group_vars/all.yml
Show inline comments
 
---
 

	
 
# Define domain for the test site that should be used.
 
testsite_domain: example.com
 

	
 
# Derive some additional values that will be used - basing them on domain.
 
testsite_domain_underscores: "{{ testsite_domain | regex_replace('\\.', '_') }}"
 
testsite_domain_alternative: "{{ testsite_domain | regex_replace('\\.[^.]+$', '.something') }}"
 
testsite_ldap_base: "{{ testsite_domain | regex_replace('\\.', ',dc=') | regex_replace('^', 'dc=') }}"
 

	
 
# Configuration for roles bootstrap and preseed.
 
ansible_key: "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
 

	
 
# Configuration for role 'common', shared across all servers.
 
os_users:
 
  - name: admin
 
    uid: 1000
 
    additional_groups: sudo
 
    additional_groups:
 
      - sudo
 
    authorized_keys:
 
      - "{{ lookup('file', '~/.ssh/id_rsa.pub') }}"
 
    password: '$6$/aerscJY6aevRG$ABBCymEDtk2mHW/dklre9dMEdgZNJvVHsGLCzgjGmy61FssZ.KW7ePcO2wsMGIkHcg3mZlrA4dhYh.APq9OQu0'
 
  - name: johndoe
 
    uid: 1001
 
    additional_groups: "office,developer"
 
    authorized_keys: []
 
    additional_groups:
 
      - office
 
      - developer
 
    password: '$6$cJnUatae7cMz23fl$O3HE2TslnEaKaTDSZnvuDDrfqILAiuMV1wOPGVnkUQFxUu3gIWZOyO7AI1OWYkqeQMVBiezpSqYNiQy6NF6bi0'
 

	
 
os_groups:
 
  - name: office
 
    gid: 1500
 
  - name: developer
 
    gid: 1501
 

	
 
common_packages:
 
  - emacs24-nox
 
  - screen
 
  - debconf-utils
 
  - colordiff
 
  - unzip
 

	
 
ca_certificates:
 
  - "{{ inventory_dir }}/tls/ca.pem"
 

	
 
incoming_connection_limit: 2/second
 

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