Changeset - 4b964a31bd96
[Not reviewed]
0 4 0
Branko Majic (branko) - 7 years ago 2017-04-09 15:10:00
branko@majic.rs
MAR-95: Separated configuration for backing-up the /root and /home directories in the common role. This should allow user to have better fine-grained control over what gets backed-up in the home directory. Updated role reference documentation. Updated the testsite variable configuration so the new setting can be tested.
4 files changed with 16 insertions and 4 deletions:
0 comments (0 inline, 0 general)
docs/rolereference.rst
Show inline comments
 
@@ -91,450 +91,454 @@ Parameters
 

	
 
**preseed_language** (string, optional, ``en``)
 
  Language.
 

	
 
**preseed_locale** (string, optional, ``en_US.UTF-8``)
 
  Locale.
 

	
 
**preseed_mirror_directory** (string, optional, ``/debian``)
 
  Directory under which the Debian apt repositories can be found on the
 
  specified mirror.
 

	
 
**preseed_mirror_hostname** (string, optional, ``ftp.se.debian.org``)
 
  Resolvable hostname of FQDN where the Debian apt repositories can be
 
  found. Only HTTP mirrors are supported.
 

	
 
**preseed_mirror_proxy** (string, optional, ``None``)
 
  An HTTP proxy that should be used for accessing the Debian apt
 
  repositories.
 

	
 
**preseed_netmask** (string, mandatory if **preseed_network_auto** is ``no``)
 
  Netmask for the server network interface.
 

	
 
**preseed_network_auto** (boolean, optional, ``yes``)
 
  Specifies whether the network configuration should be automatic (using DHCP)
 
  or manual. If manual configuration is selected a number of additional options
 
  needs to be specified: ``preseed_hostname``, ``preseed_domain``,
 
  ``preseed_ip``, ``preseed_netmask``, ``preseed_gateway``,
 
  ``preseed_dns``. For some of these values you may want to use per-server
 
  overrides - see parameter ``preseed_server_overrides``.
 

	
 
**preseed_network_interface** (string, optional, ``eth0``)
 
  Name of network interface (for example ``eth0``, ``eth1`` etc) that should be
 
  configured.
 

	
 
**preseed_root_password** (string, optional, ``root``)
 
  Initial password that should be set for the server during the installation.
 

	
 
**preseed_server_overrides** (string, optional, ``{}``)
 
  A dictionary consisting out of one or more entries where individual values for
 
  preseed files can be overridden per-server. Each entry's key should be the
 
  name of the server, as specified in the inventory. Each value should also be a
 
  dictionary, where valid keys are: ``country``, ``dns``, ``domain``,
 
  ``gateway``, ``hostname``, ``ip``, ``keymap``, ``language``, ``locale``,
 
  ``mirror_directory``, ``mirror_hostname``, ``mirror_proxy``, ``netmask``,
 
  ``network_auto``, ``network_interface``, ``root_password``,
 
  ``timezone``. These have the same meaning as their ``preseed_`` counterparts.
 

	
 
**preseed_timezone** (string, optional, ``Europe/Stockholm``)
 
  Timezone that should be used when calculating server time. It is assumed that
 
  the local hardware clock is set to UTC.
 

	
 

	
 
Examples
 
~~~~~~~~
 

	
 
Here is an example configuration for a preseed file that sets some global
 
defaults to be used for all servers, and then overrides it for one server:
 

	
 
.. code-block:: yaml
 

	
 
  ---
 

	
 
  ansible_key: {{ lookup('file', '~/.ssh/id_rsa.pub') }}
 
  preseed_country: UK
 
  preseed_directory: /var/www/preseed
 
  preseed_keymap: UK
 
  preseed_language: en
 
  preseed_locale: en_UK.UTF-8
 
  preseed_mirror_directory: /debian
 
  preseed_mirror_hostname: ftp.uk.debian.org
 
  preseed_mirror_proxy: ""
 
  preseed_network_auto: yes
 
  preseed_network_interface: eth0
 
  preseed_root_password: secret
 
  preseed_timezone: Europe/London
 
  preseed_server_overrides:
 
    ldap.example.com:
 
      network_auto: no
 
      hostname: ldap
 
      domain: example.com
 
      ip: 192.168.1.20
 
      netmask: 255.255.255.0
 
      gateway: 192.168.1.1
 
      dns: 192.168.1.1,192.168.1.2
 
      timezone: Europe/Stockholm
 

	
 

	
 
Bootstrap
 
---------
 

	
 
The ``bootstrap`` role can be used for bootstraping a new server with
 
Ansible. In order to apply this role to a server, all that is necessary is root
 
access to the server (either via SSH or locally).
 

	
 
The role implements the following:
 

	
 
* Installs sudo package.
 
* Creates operating system user and group for Ansible (``ansible``).
 
* Sets-up an authorized_key for operating system user ``ansible`` (for remote
 
  SSH access).
 
* Configures sudo to allow operating system user ``ansible`` to run sudo
 
  commands without password authentication.
 
* Removes the Ansible user's key from the list of authorized keys for user root
 
  at the end of bootstrap process. This key was necessary only for the bootstrap
 
  process.
 

	
 

	
 
Parameters
 
~~~~~~~~~~
 

	
 
**ansible_key** (string, optional, ``{{ lookup('file', '~/.ssh/id_rsa.pub') }}``)
 
  SSH public key that should be deployed to authorized_keys truststore for
 
  operating system user ``ansible``.
 

	
 

	
 
Examples
 
~~~~~~~~
 

	
 
Since the role is meant to be used just after the server has been installed, and
 
using the ``root`` account, it is probably going to be invoked from a separate
 
playbook.
 

	
 
For example, a playbook (``bootstrap.yml``) could look something similar to:
 

	
 
.. code-block:: yaml
 

	
 
  ---
 

	
 
  - hosts: "{{ server }}"
 
    remote_user: root
 
    roles:
 
      - bootstrap
 
    vars:
 
      ansible_key: "{{ lookup('file', 'authorized_keys/ansible.pub') }}"
 

	
 
With such a playbook in place, it would be invoked with:
 

	
 
  ansible-playbook --ask-pass -e server=test1.example.com bootstrap.yml
 

	
 

	
 
Common
 
------
 

	
 
The ``common`` role can be used for applying a common configuration and
 
hardening across all servers, no matter what services they provide.
 

	
 
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.
 
* Sets-up uniform bash prompt for all accounts (optionally coloured and with
 
  identifier). This is useful for distinguishing machines and/or environments.
 
* Sets-up ability to have user-specific ``/etc/profile.d/`` entries via
 
  ``$HOME/.profile.d/``.
 
* Installs additional base packages, as configured.
 
* Disables ``electric-indent-mode`` in Emacs globally if either the ``emacs24``
 
  or ``emacs24-nox`` are installed through the role.
 
* 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
 
  ``/usr/local/share/ca-certificates/``.
 
* 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.
 

	
 

	
 
Role dependencies
 
~~~~~~~~~~~~~~~~~
 

	
 
Depends on the following roles:
 

	
 
* **backup_client**
 

	
 

	
 
Backups
 
~~~~~~~
 

	
 
If the backup for this role has been enabled, the following paths are backed-up:
 

	
 
**/var/log**
 
  Log files from the system.
 

	
 
**/home**
 
  Home directory for regular users.
 
  Home directory for regular users (this can be changed via role parameters).
 

	
 
**/root**
 
  Root user's home directory.
 
  Root user's home directory (this can be changed via role parameters).
 

	
 
**/etc/shadow**
 
  Operating system user passwords.
 

	
 
**/var/mail**
 
  Local user's mails.
 

	
 
**/var/spool/cron**
 
  Local user's cronjobs.
 

	
 

	
 
Parameters
 
~~~~~~~~~~
 

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

	
 
**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, optional, ``whatever OS picks``)
 
    UID for the operating system user. User's default group will have a GID
 
    identical to the user's UID if specified. Otherwise user's default group
 
    will have OS-determined GID.
 

	
 
  **additional_groups** (list, optional, ``[]``)
 
    Comma-separated list of additional groups that a user should belong to.
 

	
 
  **authorized_keys** (list, optional, ``[]``)
 
    List of SSH public keys that should be deployed to user's authorized_keys
 
    truststore.
 

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

	
 
**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, optional, ``whatever OS picks``)
 
    GID for the operating system group.
 

	
 
**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, ``{}``)
 
  Dictionary containing the CA certificates to deploy. Keys are base filenames
 
  (**without extension**) to be used when placing a certificate file in
 
  directory ``/usr/local/share/ca-certificates/``, while values are
 
  corresponding content to be placed in the file.
 

	
 
**extra_backup_patterns** (list, optional, ``[ "/home", "/root" ]]``)
 
  List of additional globbing patterns defining additional files or directories
 
  that should be backed-up.
 

	
 
**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, 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.
 

	
 
**prompt_colour** (string, optional, ``none``)
 
  Colour for showing the Bash prompt. Supported values are:
 

	
 
  ``black``, ``red``, ``green``, ``brown``, ``blue``, ``purple``, ``cyan``,
 
  ``light_gray``, ``dark_gray``, ``light_red``, ``light_green``, ``yellow``,
 
  ``light_blue``, ``light_purple``, ``light_cyan``, ``white``, ``none``.
 

	
 
  You should probably *not* use the ``black`` colour. Setting affects Bash
 
  shells *only*. Setting the value to ``none`` uses default terminal colour.
 

	
 
**prompt_id** (string, optional, ``NONE``)
 
  Optional identifier appended to regular Bash prompt, useful for visually
 
  identifying distinct environments. For example, if set to ``test``, resulting
 
  prompt will be similar to ``admin@web[test]:~$``. Setting affects Bash shells
 
  *only*.
 

	
 

	
 
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
 
      authorized_keys:
 
        - "{{ lookup('file', '/home/admin/.ssh/id_rsa.pub') }}"
 
      password: '$6$AaJRWtqyX5pk$IP8DUjgY0y2zqMom9BAc.O9qHoQWLFCmEsPRCika6l/Xh87cp2SnlMywH0.r4uEcbHnoicQG46V9VrJ8fxp2d.'
 
    - name: john
 
      uid: 1001
 
      password: '$6$AaJRWtqyX5pk$IP8DUjgY0y2zqMom9BAc.O9qHoQWLFCmEsPRCika6l/Xh87cp2SnlMywH0.r4uEcbHnoicQG46V9VrJ8fxp2d.'
 

	
 
  os_groups:
 
    - name: localusers
 
      gid: 2500
 

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

	
 
  ca_certificates:
 
    "truststore": "{{ lookup('file', '../certs/truststore.pem') }}"
 

	
 
  incoming_connection_limit: 2/second
 

	
 
  incoming_connection_limit_burst: 6
 

	
 
  prompt_colour: light_green
 

	
 
  prompt_id: PROD
 

	
 
.. _ldap_client:
 

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

	
 
The ``ldap_client`` role can be used for setting-up an OpenLDAP client on
 
destination machine.
 

	
 
The role implements the following:
 

	
 
* Installs OpenLDAP client tools.
 
* Sets-up global configuration file for OpenLDAP clients at /etc/ldap/ldap.conf.
 

	
 

	
 
Parameters
 
~~~~~~~~~~
 

	
 
**ldap_client_config** (list, optional, ``[]``)
 
  A list of configuration options that should be put into the LDAP configuration
 
  file. Each item is a dictionary with the following options defining the
 
  configuration parameter:
 

	
 
  **comment** (string, mandatory)
 
    Comment that will be shown in the file just above the configuration option.
 

	
 
  **option** (string, mandatory)
 
    Name of configuration option.
 

	
 
  **value** (string, mandatory)
 
    Value for configuration option.
 

	
 

	
 
Examples
 
~~~~~~~~
 

	
 
Here is an example configuration for setting some common LDAP client options:
 

	
 
.. code-block:: yaml
 

	
 
  ---
 

	
 
  ldap_client_config:
 
    - comment: Set the base DN
 
      option: BASE
 
      value: dc=example,dc=com
 
    - comment: Set the default URI
 
      option: URI
 
      value: ldap://ldap.example.com/
 
    - comment: Set the truststore for TLS/SSL
 
      option: TLS_CACERT
 
      value: /etc/ssl/certs/example_ca.pem
 
    - commment: Force basic server certificate verification
 
      option: TLS_REQCERT
 
      value: demand
 
    - comment: Disable CRL checks for server certificate
 
      option: TLS_CRLCHECK
 
      value: none
 

	
 

	
 
LDAP Server
 
-----------
 

	
 
The ``ldap_server`` role can be used for setting-up an OpenLDAP server on
 
destination machine.
 

	
 
The role implements the following:
 

	
 
* Deploys LDAP TLS private key and certificate.
 
* Configures TLS versions and ciphers suppported by the server.
 
* Installs OpenLDAP server (package ``slapd``).
 
* Configures OpenLDAP server (base DN - domain, organisation, TLS, SSF, log levels).
 
* Sets-up separate log file for OpenLDAP server at ``/var/log/slapd.log`` (with
 
  log rotation included).
 
* Enables the ``misc`` LDAP schema (from ``/etc/ldap/schema/misc.ldif``). This
 
  is necessary for the mail server role.
 
* Enables the ``memberof`` overlay on top of default database. The overlay is
 
  configured to keep track of membership changes for object class
 
  ``groupOfUniqueNames`` via attribute ``uniqueMember``. Enforcement of
 
  referential integrity is turned on as well (modifications of ``memberof``
 
  attribute will update corresponding group as well.
 
* Creates a basic directory structure used by most of the other roles.
 
* Creates a basic directory structure used by the mail server role.
 
* Creates login entries for services that need to consume LDAP directory data in
 
  some way.
 
* Creates user-supplied groups in LDAP.
 
* Configures permissions.
 
* Creates LDAP entries.
 
* Configures firewall to allow incoming connections to the LDAP server (via both
 
  TCP 389 and 636).
 
* Sets the LDAP server administrator's password.
 

	
 

	
 
LDIF Templates
 
~~~~~~~~~~~~~~
 

	
 
For adding users, use::
 

	
 
  dn: uid=USERNAME,ou=people,BASE_DN
 
  objectClass: inetOrgPerson
 
  objectClass: simpleSecurityObject
 
  uid: USERNAME
 
  userPassword: PASSWORD_FROM_SLAPPASSWD
 
  cn: NAME SURNAME
 
  sn: SURNAME
 
  gn: NAME
 
  displayName: DISPLAYNAME
 
  initials: INITIALS
 
  mail: MAIL
 
  mobile: MOBILE
 

	
 

	
 

	
 
Role dependencies
 
~~~~~~~~~~~~~~~~~
 

	
 
Depends on the following roles:
 

	
 
* **common**
 
* **ldap_client**
 
* **backup_client**
 

	
 

	
roles/common/defaults/main.yml
Show inline comments
 
---
 

	
 
enable_backup: False
 
common_packages: []
 
os_users: []
 
os_groups: []
 
ca_certificates: {}
 
incoming_connection_limit: 3/second
 
incoming_connection_limit_burst: 9
 
prompt_colour: none
 
prompt_id: null
 
extra_backup_patterns:
 
  - "/root"
 
  - "/home"
 

	
 
# Internal use only.
 
prompt_colour_mapping:
 
  black: "0;30"
 
  red: "0;31"
 
  green: "0;32"
 
  brown: "0;33"
 
  blue: "0;34"
 
  purple: "0;35"
 
  cyan: "0;36"
 
  light_gray: "0;37"
 
  dark_gray: "1;30"
 
  light_red: "1;31"
 
  light_green: "1;32"
 
  yellow: "1;33"
 
  light_blue: "1;34"
 
  light_purple: "1;35"
 
  light_cyan: "1;36"
 
  white: "1;37"
 
  none: "0"
 
\ No newline at end of file
roles/common/meta/main.yml
Show inline comments
 
---
 

	
 
dependencies:
 
  - role: backup
 
    when: enable_backup
 
    backup_patterns_filename: common
 
    backup_patterns:
 
      - "/root"
 
      - "/home"
 
      - "/var/log"
 
      - "/etc/shadow"
 
      - "/var/mail"
 
      - "/var/spool/cron"
 
  - role: backup
 
    when: enable_backup
 
    backup_patterns_filename: common_extra
 
    backup_patterns: "{{ extra_backup_patterns }}"
testsite/group_vars/mail.yml
Show inline comments
 
---
 

	
 
mail_ldap_url: ldap://ldap.{{ testsite_domain }}/
 
mail_ldap_tls_truststore: "{{ lookup('file', inventory_dir + '/tls/ca.pem') }}"
 
mail_ldap_base_dn: "{{ testsite_ldap_base }}"
 
mail_ldap_postfix_password: postfix
 
mail_ldap_dovecot_password: dovecot
 

	
 
mail_user: vmail
 
mail_user_uid: 5000
 
mail_user_gid: 5000
 

	
 
local_mail_aliases:
 
  root: "root john.doe@{{ testsite_domain }}"
 

	
 
imap_tls_certificate: "{{ lookup('file', inventory_dir + '/tls/mail.' + testsite_domain + '_imap.pem') }}"
 
imap_tls_key: "{{ lookup('file', inventory_dir + '/tls/mail.' + testsite_domain + '_imap.key') }}"
 
smtp_tls_certificate: "{{ lookup('file', inventory_dir + '/tls/mail.' + testsite_domain + '_smtp.pem') }}"
 
smtp_tls_key: "{{ lookup('file', inventory_dir + '/tls/mail.' + testsite_domain + '_smtp.key') }}"
 
imap_folder_separator: /
 
smtp_rbl:
 
  - bl.spamcop.net
 
  - zen.spamhaus.org
 

	
 
mail_postmaster: postmaster@{{ testsite_domain }}
 

	
 
smtp_allow_relay_from:
 
  - ldap.{{ testsite_domain }}
 
  - xmpp.{{ testsite_domain }}
 
  - web.{{ testsite_domain }}
 

	
 
imap_max_user_connections_per_ip: 50
 

	
 
mail_server_tls_protocols:
 
  - TLSv1.2
 
  - TLSv1.1
 

	
 
mail_server_tls_ciphers: "DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA:!aNULL:!MD5:!EXPORT"
 

	
 
extra_backup_patterns:
 
  - "/root"
 
\ No newline at end of file
0 comments (0 inline, 0 general)