├── .gitignore ├── LICENSE ├── README.md ├── ansible.cfg ├── group_vars └── all.sample ├── inventory.sample ├── playbooks ├── bootstrap.yml └── cosmovisor.yml ├── playbooks_dependencies.yml ├── python_dependencies.txt ├── roles ├── apt │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── bootstrap │ ├── meta │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── cosmovisor │ └── tasks │ │ └── main.yml ├── exim │ ├── defaults │ │ └── main.yml │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ └── templates │ │ ├── passwd.client.j2 │ │ └── update-exim4.conf.conf.j2 ├── fail2ban │ └── tasks │ │ └── main.yml ├── firewall │ ├── defaults │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ └── vars │ │ └── main.yml ├── ntp │ └── tasks │ │ └── main.yml ├── rkhunter │ ├── defaults │ │ └── main.yml │ ├── tasks │ │ └── main.yml │ └── templates │ │ ├── rkhunter.conf.local.j2 │ │ └── rkhunter.j2 ├── rkhunter_upgrade │ ├── defaults │ │ └── main.yml │ └── tasks │ │ └── main.yml ├── rsyslog │ ├── handlers │ │ └── main.yml │ ├── meta │ │ └── main.yml │ ├── molecule │ │ └── default │ │ │ ├── converge.yml │ │ │ ├── molecule.yml │ │ │ └── tests │ │ │ └── test_default.py │ └── tasks │ │ └── main.yml ├── ssh │ ├── handlers │ │ └── main.yml │ ├── molecule │ │ └── default │ │ │ ├── converge.yml │ │ │ ├── molecule.yml │ │ │ ├── prepare.yml │ │ │ └── tests │ │ │ └── test_default.py │ └── tasks │ │ └── main.yml ├── sudo │ └── tasks │ │ └── main.yml └── tmux │ ├── files │ └── tmux.conf │ ├── tasks │ └── main.yml │ └── templates │ ├── rkhunter.conf.local.j2 │ └── rkhunter.j2 ├── run_tests.sh └── setup_venv.sh /.gitignore: -------------------------------------------------------------------------------- 1 | ansible.log 2 | 3 | ### Python ### 4 | # Byte-compiled / optimized / DLL files 5 | __pycache__/ 6 | *.py[cod] 7 | *$py.class 8 | 9 | !group_vars/all.sample 10 | group_vars/ 11 | 12 | inventory 13 | 14 | # Molecule python environment 15 | molecule-venv/ 16 | 17 | # Ignore ansible galazy roles 18 | roles/jnv.unattended-upgrades/ 19 | roles/singleplatform-eng.users/ 20 | roles/cloudalchemy.node_exporter/ 21 | roles/gantsign.golang/ 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Validator initial server configuration 2 | 3 | This repository contains ansible playbooks to setup Cosmos SDK based infrastructure. 4 | 5 | ## Minimum requirements 6 | 7 | * Debian 10 "Buster"; 8 | * Access to root using ssh by pub key or password; 9 | * Ansible > 2.9 10 | 11 | ## Initial configuration 12 | 13 | Before you will start using this software it is required to provide initial configuration to the roles. 14 | First of all you will need to copy content of the `.sample` files in the project root (`inventory.sample`) and `groups_vars` directories to the appropriate names without extensions. In most cases it is enough to set variables in the `group_vars/all` and add IP address of the server to the `invenotory` file into `bootstrap` group. 15 | 16 | ## Running 17 | 18 | - Init python virual environment with all dependencies: `source setup_venv.sh` 19 | 20 | ## Keys special directory 21 | 22 | `vars/` directory should contain additional variables for different purposes. Also please use directory to store Ansible Vault files. 23 | 24 | ## Documentation 25 | 26 | Most of the variable uses self explanatory names , but in some cases additional comments added to the sources. 27 | 28 | Please note that prior production usage you should test those scripts on available testnets. For this you need to create separate clone of this repo and configure it to use testnet of the supported networks. 29 | 30 | ## Examples 31 | 32 | ### Initial hosts configuration 33 | 34 | ``` 35 | $ ansible-playbook playbooks/bootstrap.yml 36 | ``` 37 | 38 | This command will install all required software, services and users to operate infrastructure hosts. 39 | 40 | # Testing 41 | 42 | ## Required software 43 | 44 | - Docker 45 | 46 | -------------------------------------------------------------------------------- /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | inventory = inventory 3 | retry_files_enabled = false 4 | callbacks_enabled = profile_tasks 5 | log_path=./ansible.log 6 | roles_path=./roles 7 | filter_plugins=./filter_plugins 8 | 9 | [ssh_connection] 10 | ssh_args = -o ControlMaster=auto -o ControlPersist=600s 11 | pipelining = True 12 | -------------------------------------------------------------------------------- /group_vars/all.sample: -------------------------------------------------------------------------------- 1 | --- 2 | # In order to create password has please use following instructions: 3 | # https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module 4 | root_password: "" 5 | 6 | unattended_origins_patterns: 7 | - "origin=${distro_id},codename=${distro_codename},label=${distro_id}-Security" 8 | 9 | 10 | # All fields are self explained except password and ssh_key. 11 | # Password field: Hashed password string. From https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module 12 | # ssh_key field: array of public ssh keys to install to the system. 13 | # For instane: 14 | # ssh_key: 15 | # - "ssh-rsa key_identifier_1" 16 | # - "ssh-rsa key_identifier_2" 17 | 18 | users: 19 | - username: 20 | name: 21 | uid: 22 | groups: ["sudo"] # if you want to allow this user to run commands with super user priveleges then leave "sudo" groups her. Otherwise remove it 23 | password: "" # Hashed password string. This password will be used to run "sudo" commands 24 | profile: | 25 | export GOPATH=$HOME/work 26 | export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin 27 | ssh_key: 28 | - "ssh-rsa key_identifier_1" 29 | 30 | # Exim mail server configuration. Used to send notification messages and different reports 31 | # You can get SMTP settings from Mailgun (https://www.mailgun.com/). But you can use your own SMTP service provider. 32 | exim_dc_eximconfig_configtype: 'satellite' 33 | exim_dc_hide_mailname: 'true' 34 | exim_dc_readhost: '' # system host. You can use "{{ ansible_hostname }}." value 35 | exim_dc_smarthost: '' # Relay SMTP server address. 36 | 37 | reports_email: '' # Email where to send reports and notifications 38 | 39 | prometheus_server: # Prometheus server IP 40 | 41 | # Put default firewall rules here. Current rule allows all connections from class C internal network 42 | firewall_default_rules: 43 | - rule: allow 44 | from: 192.168.0.0/16 45 | - port: 9100 # allow access to node_explorer from prometheus server 46 | rule: allow 47 | from: "{{ prometheus_server }}" 48 | 49 | 50 | -------------------------------------------------------------------------------- /inventory.sample: -------------------------------------------------------------------------------- 1 | [bootstrap:children] 2 | # Hosts to for bootstrapping 3 | 4 | -------------------------------------------------------------------------------- /playbooks/bootstrap.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: bootstrap 3 | strategy: free 4 | vars_files: 5 | - ../vars/infrastructure.yml # It should point to the Ansible Vault file. If you do not use vault then you can remove this. 6 | roles: 7 | - bootstrap 8 | -------------------------------------------------------------------------------- /playbooks/cosmovisor.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: bootstrap 3 | strategy: free 4 | roles: 5 | - cosmovisor 6 | -------------------------------------------------------------------------------- /playbooks_dependencies.yml: -------------------------------------------------------------------------------- 1 | - src: singleplatform-eng.users 2 | - src: jnv.unattended-upgrades 3 | - src: cloudalchemy.node_exporter 4 | - src: gantsign.golang 5 | -------------------------------------------------------------------------------- /python_dependencies.txt: -------------------------------------------------------------------------------- 1 | wheel 2 | pylint 3 | molecule[lint] 4 | molecule-docker 5 | testinfra 6 | ansible ~= 4.6.0 -------------------------------------------------------------------------------- /roles/apt/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Sets the amount of time the cache is valid (1h) 3 | apt_cache_valid_time: 3600 4 | -------------------------------------------------------------------------------- /roles/apt/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: update cache 3 | apt: 4 | update_cache: yes 5 | cache_valid_time: "{{ apt_cache_valid_time | int }}" 6 | 7 | - name: install apt-transport-https 8 | apt: 9 | pkg=apt-transport-https 10 | state=present 11 | 12 | - name: install aptitude 13 | apt: 14 | pkg=aptitude 15 | state=present 16 | -------------------------------------------------------------------------------- /roles/bootstrap/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: 3 | - { role: apt } 4 | - { role: fail2ban } 5 | - { role: sudo } 6 | - { role: gantsign.golang } 7 | - { role: singleplatform-eng.users } 8 | - { role: ssh } 9 | - { role: firewall } 10 | - { role: jnv.unattended-upgrades } 11 | - { role: ntp } 12 | - { role: exim } 13 | - { role: rsyslog } 14 | - { role: tmux } 15 | - { role: rkhunter } 16 | - { role: cloudalchemy.node_exporter } 17 | -------------------------------------------------------------------------------- /roles/bootstrap/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: set root password 3 | user: 4 | name: root 5 | password: "{{ root_password }}" 6 | 7 | - name: install additional packages 8 | package: 9 | pkg: "{{ item }}" 10 | state: present 11 | with_items: 12 | - vim 13 | - git-core 14 | - unzip 15 | - htop 16 | - curl 17 | - sudo 18 | - net-tools 19 | - mailutils 20 | - build-essential 21 | - mc 22 | - jq 23 | - bc 24 | -------------------------------------------------------------------------------- /roles/cosmovisor/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install Cosmovisor 3 | shell: go install github.com/cosmos/cosmos-sdk/cosmovisor/cmd/cosmovisor@latest 4 | environment: 5 | GOPATH: "{{ ansible_env.HOME }}/work" 6 | PATH: "{{ ansible_env.PATH }}:{{ ansible_local['golang']['general']['home'] }}/bin:{{ ansible_env.HOME }}/work/bin" 7 | -------------------------------------------------------------------------------- /roles/exim/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | exim_dc_eximconfig_configtype: 'local' 3 | exim_dc_other_hostnames: '{{ ansible_hostname }}' 4 | exim_dc_local_interfaces: '127.0.0.1 ; ::1' 5 | exim_dc_readhost: '' 6 | exim_dc_relay_domains: '' 7 | exim_dc_minimaldns: 'false' 8 | exim_dc_relay_nets: '' 9 | exim_dc_smarthost: '' 10 | exim_CFILEMODE: '644' 11 | exim_dc_use_split_config: 'false' 12 | exim_dc_hide_mailname: '' 13 | exim_dc_mailname_in_oh: 'true' 14 | exim_dc_localdelivery: 'mail_spool' 15 | 16 | exim_passwd_clients: [] 17 | -------------------------------------------------------------------------------- /roles/exim/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: reconfigure exim 3 | shell: /usr/sbin/update-exim4.conf 4 | 5 | - name: restart exim 6 | service: 7 | name: exim4 8 | state: restarted 9 | -------------------------------------------------------------------------------- /roles/exim/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Néstor Salceda 4 | description: 5 | company: 6 | license: license (GPLv2, CC-BY, etc) 7 | min_ansible_version: 1.2 8 | platforms: 9 | - name: Debian 10 | versions: 11 | - buster 12 | # 13 | # Below are all categories currently available. Just as with 14 | # the platforms above, uncomment those that apply to your role. 15 | # 16 | categories: 17 | - networking 18 | - system 19 | 20 | dependencies: 21 | [] 22 | # List your role dependencies here, one per line. 23 | # Be sure to remove the '[]' above if you add dependencies 24 | # to this list. 25 | -------------------------------------------------------------------------------- /roles/exim/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install package 3 | package: 4 | pkg: exim4 5 | state: present 6 | 7 | # In order to configure exim you need to provide list of "exim_passwd_clients", 8 | # It is good to store variable in the Ansible Vault https://docs.ansible.com/ansible/latest/user_guide/vault.html 9 | - name: configure 10 | template: 11 | src: update-exim4.conf.conf.j2 12 | dest: /etc/exim4/update-exim4.conf.conf 13 | notify: 14 | - reconfigure exim 15 | - restart exim 16 | 17 | - name: configure authentication with external SMTP services 18 | template: 19 | src: passwd.client.j2 20 | dest: /etc/exim4/passwd.client 21 | 22 | - name: start service 23 | service: 24 | name: exim4 25 | state: started 26 | -------------------------------------------------------------------------------- /roles/exim/templates/passwd.client.j2: -------------------------------------------------------------------------------- 1 | # password file used when the local exim is authenticating to a remote 2 | # host as a client. 3 | # 4 | # see exim4_passwd_client(5) for more documentation 5 | # 6 | # Example: 7 | ### target.mail.server.example:login:password 8 | 9 | {% for item in exim_passwd_clients %} 10 | {{ item }} 11 | {% endfor %} 12 | 13 | -------------------------------------------------------------------------------- /roles/exim/templates/update-exim4.conf.conf.j2: -------------------------------------------------------------------------------- 1 | # /etc/exim4/update-exim4.conf.conf 2 | # 3 | # Edit this file and /etc/mailname by hand and execute update-exim4.conf 4 | # yourself or use 'dpkg-reconfigure exim4-config' 5 | # 6 | # Please note that this is _not_ a dpkg-conffile and that automatic changes 7 | # to this file might happen. The code handling this will honor your local 8 | # changes, so this is usually fine, but will break local schemes that mess 9 | # around with multiple versions of the file. 10 | # 11 | # update-exim4.conf uses this file to determine variable values to generate 12 | # exim configuration macros for the configuration file. 13 | # 14 | # Most settings found in here do have corresponding questions in the 15 | # Debconf configuration, but not all of them. 16 | # 17 | # This is a Debian specific file 18 | 19 | dc_eximconfig_configtype='{{ exim_dc_eximconfig_configtype }}' 20 | dc_other_hostnames='{{ exim_dc_other_hostnames }}' 21 | dc_local_interfaces='{{ exim_dc_local_interfaces }}' 22 | dc_readhost='{{ exim_dc_readhost }}' 23 | dc_relay_domains='{{ exim_dc_relay_domains }}' 24 | dc_minimaldns='{{ exim_dc_minimaldns }}' 25 | dc_relay_nets='{{ exim_dc_relay_nets }}' 26 | dc_smarthost='{{ exim_dc_smarthost }}' 27 | CFILEMODE='{{ exim_CFILEMODE }}' 28 | dc_use_split_config='{{ exim_dc_use_split_config }}' 29 | dc_hide_mailname='{{ exim_dc_hide_mailname }}' 30 | dc_mailname_in_oh='{{ exim_dc_mailname_in_oh }}' 31 | dc_localdelivery='{{ exim_dc_localdelivery }}' 32 | -------------------------------------------------------------------------------- /roles/fail2ban/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install package 3 | package: 4 | pkg=fail2ban 5 | state=present 6 | 7 | - name: start service 8 | service: 9 | name=fail2ban 10 | state=started 11 | -------------------------------------------------------------------------------- /roles/firewall/defaults/main.yml: -------------------------------------------------------------------------------- 1 | firewall_default_rules: [] 2 | firewall_rules: [] 3 | -------------------------------------------------------------------------------- /roles/firewall/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Néstor Salceda 4 | description: 5 | company: 6 | license: license (GPLv2, CC-BY, etc) 7 | min_ansible_version: 1.2 8 | platforms: 9 | - name: Debian 10 | versions: 11 | - buster 12 | # 13 | # Below are all categories currently available. Just as with 14 | # the platforms above, uncomment those that apply to your role. 15 | # 16 | categories: 17 | - networking 18 | - system 19 | 20 | dependencies: 21 | [] 22 | # List your role dependencies here, one per line. 23 | # Be sure to remove the '[]' above if you add dependencies 24 | # to this list. 25 | -------------------------------------------------------------------------------- /roles/firewall/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install package 3 | apt: 4 | pkg=ufw 5 | state=present 6 | 7 | - name: reset 8 | ufw: 9 | state=reset 10 | 11 | - name: configure rules 12 | ufw: 13 | name="{{ item.name | default(omit) }}" 14 | rule="{{ item.rule }}" 15 | port="{{ item.port | default(omit) }}" 16 | from="{{ item.from | default(omit) }}" 17 | to="{{ item.to | default(omit) }}" 18 | proto="{{ item.proto | default (omit) }}" 19 | 20 | with_flattened: 21 | - '{{ firewall_ssh_rules }}' 22 | - '{{ firewall_default_rules }}' 23 | - '{{ firewall_rules }}' 24 | 25 | - name: enable 26 | ufw: 27 | logging=on 28 | state=enabled 29 | policy=deny 30 | -------------------------------------------------------------------------------- /roles/firewall/vars/main.yml: -------------------------------------------------------------------------------- 1 | firewall_ssh_rules: 2 | - rule: allow 3 | port: ssh 4 | -------------------------------------------------------------------------------- /roles/ntp/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install package 3 | package: 4 | pkg=ntp 5 | state=present 6 | -------------------------------------------------------------------------------- /roles/rkhunter/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | rkhunter_cron_daily_run: "true" 3 | rkhunter_cron_db_update: "true" 4 | rkhunter_db_update_email: "true" 5 | rkhunter_apt_autogen: "true" 6 | 7 | rkhunter_report_email: "root" 8 | -------------------------------------------------------------------------------- /roles/rkhunter/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install epel repository 3 | package: 4 | pkg=epel-release 5 | state=present 6 | when: ansible_os_family == 'CentOS' 7 | 8 | - name: install package 9 | package: 10 | pkg=rkhunter 11 | state=present 12 | 13 | - name: configure init 14 | template: 15 | src=rkhunter.j2 16 | dest=/etc/default/rkhunter 17 | 18 | - name: upload rkhunter local config 19 | template: 20 | src=rkhunter.conf.local.j2 21 | dest=/etc/rkhunter.conf.local 22 | owner=root 23 | group=root 24 | mode=644 -------------------------------------------------------------------------------- /roles/rkhunter/templates/rkhunter.conf.local.j2: -------------------------------------------------------------------------------- 1 | {% if rkhunter_config_local.allowhiddendir is defined %} 2 | {% for hiddendir in rkhunter_config_local.allowhiddendir %} 3 | ALLOWHIDDENDIR={{ hiddendir }} 4 | {% endfor %} 5 | {% endif %} 6 | 7 | {% if rkhunter_config_local.allowhiddenfile is defined %} 8 | {% for hiddenfile in rkhunter_config_local.allowhiddenfile %} 9 | ALLOWHIDDENFILE={{ hiddenfile }} 10 | {% endfor %} 11 | {% endif %} 12 | 13 | {% if rkhunter_config_local.allowdevfile is defined %} 14 | {% for devfile in rkhunter_config_local.allowdevfile %} 15 | ALLOWDEVFILE={{ devfile }} 16 | {% endfor %} 17 | {% endif %} 18 | 19 | {% if rkhunter_config_local.scriptwhitelist is defined %} 20 | {% for whitelist in rkhunter_config_local.scriptwhitelist %} 21 | SCRIPTWHITELIST={{ whitelist }} 22 | {% endfor %} 23 | {% endif %} 24 | 25 | {% if rkhunter_config_local.pwdless_accounts is defined %} 26 | {% for pwdless_account in rkhunter_config_local.pwdless_accounts %} 27 | PWDLESS_ACCOUNTS={{ pwdless_account }} 28 | {% endfor %} 29 | {% endif %} 30 | 31 | {% if rkhunter_config_local.otherrules is defined %} 32 | {% for otherrules in rkhunter_config_local.otherrules %} 33 | {{ otherrules }} 34 | {% endfor %} 35 | {% endif %} 36 | -------------------------------------------------------------------------------- /roles/rkhunter/templates/rkhunter.j2: -------------------------------------------------------------------------------- 1 | # Defaults for rkhunter automatic tasks 2 | # sourced by /etc/cron.*/rkhunter and /etc/apt/apt.conf.d/90rkhunter 3 | # 4 | # This is a POSIX shell fragment 5 | # 6 | 7 | # Set this to yes to enable rkhunter daily runs 8 | # (default: true) 9 | CRON_DAILY_RUN="{{ rkhunter_cron_daily_run }}" 10 | 11 | # Set this to yes to enable rkhunter weekly database updates 12 | # (default: true) 13 | CRON_DB_UPDATE="{{ rkhunter_cron_db_update }}" 14 | 15 | # Set this to yes to enable reports of weekly database updates 16 | # (default: false) 17 | DB_UPDATE_EMAIL="{{ rkhunter_db_update_email }}" 18 | 19 | # Set this to the email address where reports and run output should be sent 20 | # (default: root) 21 | REPORT_EMAIL="{{ rkhunter_report_email }}" 22 | 23 | # Set this to yes to enable automatic database updates 24 | # (default: false) 25 | APT_AUTOGEN="{{ rkhunter_apt_autogen }}" 26 | 27 | # Nicenesses range from -20 (most favorable scheduling) to 19 (least favorable) 28 | # (default: 0) 29 | NICE="0" 30 | 31 | # Should daily check be run when running on battery 32 | # powermgmt-base is required to detect if running on battery or on AC power 33 | # (default: false) 34 | RUN_CHECK_ON_BATTERY="false" 35 | -------------------------------------------------------------------------------- /roles/rkhunter_upgrade/defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | rkhunter_download_url: 'http://downloads.sourceforge.net/project/rkhunter/rkhunter/1.4.6/rkhunter-1.4.6.tar.gz' 3 | rkhunter_version: '1.4.6' 4 | -------------------------------------------------------------------------------- /roles/rkhunter_upgrade/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: download and extract 3 | unarchive: 4 | src="{{ rkhunter_download_url }}" 5 | dest="/tmp" 6 | copy=no 7 | 8 | 9 | - name: Install rkhunter upgrade. 10 | become: true 11 | become_user: root 12 | command: ./installer.sh --layout /usr --install 13 | args: 14 | chdir: /tmp/rkhunter-{{rkhunter_version}} 15 | 16 | - name: Update rkhunter database 17 | become: true 18 | become_user: root 19 | command: rkhunter --propupd 20 | 21 | - name: Remove rkhunter installation files 22 | file: 23 | path: /tmp/rkhunter-{{rkhunter_version}} 24 | state: absent 25 | -------------------------------------------------------------------------------- /roles/rsyslog/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: restart journald 3 | service: name=systemd-journald 4 | state=restarted 5 | -------------------------------------------------------------------------------- /roles/rsyslog/meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Néstor Salceda 4 | description: This role configure redirection from the JournalD to the SyslogD. 5 | license: Apache-2.0 6 | min_ansible_version: 1.2 7 | platforms: 8 | - name: Debian 9 | versions: 10 | - buster 11 | galaxy_tags: 12 | - system 13 | -------------------------------------------------------------------------------- /roles/rsyslog/molecule/default/converge.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | tasks: 5 | - name: "Include rsyslog" 6 | include_role: 7 | name: "rsyslog" 8 | -------------------------------------------------------------------------------- /roles/rsyslog/molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependency: 3 | name: galaxy 4 | driver: 5 | name: docker 6 | platforms: 7 | - name: Debian10 8 | image: geerlingguy/docker-debian10-ansible 9 | tmpfs: 10 | - /run 11 | - /tmp 12 | volumes: 13 | - /sys/fs/cgroup:/sys/fs/cgroup:ro 14 | command: "/sbin/init" 15 | privileged: true 16 | pre_build_image: true 17 | provisioner: 18 | name: ansible 19 | config_options: 20 | defaults: 21 | interpreter_python: auto_silent 22 | callback_whitelist: profile_tasks, timer, yaml 23 | ssh_connection: 24 | pipelining: false 25 | verifier: 26 | name: testinfra 27 | lint: | 28 | set -e 29 | yamllint . 30 | ansible-lint . 31 | -------------------------------------------------------------------------------- /roles/rsyslog/molecule/default/tests/test_default.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import testinfra.utils.ansible_runner 4 | import pytest 5 | 6 | testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( 7 | os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') 8 | 9 | 10 | def test_journald_syslogd_forwarding_set(host): 11 | sshd_config = host.file("/etc/systemd/journald.conf") 12 | assert sshd_config.contains("^ForwardToSyslog=yes$") 13 | -------------------------------------------------------------------------------- /roles/rsyslog/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: check for journald logs 3 | stat: 4 | path: /etc/systemd/journald.conf 5 | register: journald_logs_stat 6 | 7 | - name: forward journald logs to syslog 8 | lineinfile: 9 | dest: /etc/systemd/journald.conf 10 | regexp: "#ForwardToSyslog=yes" 11 | line: "ForwardToSyslog=yes" 12 | state: present 13 | notify: restart journald 14 | when: journald_logs_stat.stat.exists 15 | -------------------------------------------------------------------------------- /roles/ssh/handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: restart ssh 3 | action: service name=ssh state=restarted 4 | -------------------------------------------------------------------------------- /roles/ssh/molecule/default/converge.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | tasks: 5 | - name: "Include ssh" 6 | include_role: 7 | name: "ssh" 8 | -------------------------------------------------------------------------------- /roles/ssh/molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependency: 3 | name: galaxy 4 | driver: 5 | name: docker 6 | platforms: 7 | - name: Debian10 8 | image: geerlingguy/docker-debian10-ansible 9 | tmpfs: 10 | - /run 11 | - /tmp 12 | volumes: 13 | - /sys/fs/cgroup:/sys/fs/cgroup:ro 14 | command: "/sbin/init" 15 | privileged: true 16 | pre_build_image: true 17 | provisioner: 18 | name: ansible 19 | playbooks: 20 | prepare: prepare.yml 21 | config_options: 22 | defaults: 23 | interpreter_python: auto_silent 24 | callback_whitelist: profile_tasks, timer, yaml 25 | ssh_connection: 26 | pipelining: false 27 | verifier: 28 | name: testinfra 29 | lint: | 30 | set -e 31 | yamllint . 32 | ansible-lint . 33 | -------------------------------------------------------------------------------- /roles/ssh/molecule/default/prepare.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Prepare 3 | hosts: all 4 | gather_facts: false 5 | tasks: 6 | - name: install ssh 7 | package: 8 | pkg: ssh 9 | state: latest 10 | -------------------------------------------------------------------------------- /roles/ssh/molecule/default/tests/test_default.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | import testinfra.utils.ansible_runner 4 | import pytest 5 | 6 | testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( 7 | os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') 8 | 9 | 10 | def test_password_and_root_login_disabled(host): 11 | sshd_config = host.file("/etc/ssh/sshd_config") 12 | assert sshd_config.contains("PasswordAuthentication no") 13 | assert sshd_config.contains("PermitRootLogin no") 14 | 15 | def test_sshd_is_running_and_enabled(host): 16 | sshd = host.service("sshd") 17 | assert sshd.is_running 18 | assert sshd.is_enabled 19 | -------------------------------------------------------------------------------- /roles/ssh/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: disable SSH password authentication 3 | lineinfile: 4 | dest: /etc/ssh/sshd_config 5 | regexp: "^PasswordAuthentication" 6 | line: "PasswordAuthentication no" 7 | state: present 8 | notify: restart ssh 9 | 10 | - name: disable SSH root login 11 | lineinfile: 12 | dest: /etc/ssh/sshd_config 13 | regexp: "^PermitRootLogin" 14 | line: "PermitRootLogin no" 15 | state: present 16 | notify: restart ssh 17 | -------------------------------------------------------------------------------- /roles/sudo/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install package 3 | apt: 4 | pkg: sudo 5 | state: present 6 | -------------------------------------------------------------------------------- /roles/tmux/files/tmux.conf: -------------------------------------------------------------------------------- 1 | set -g mouse on 2 | -------------------------------------------------------------------------------- /roles/tmux/tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: install package 3 | package: 4 | pkg: tmux 5 | state: present 6 | 7 | - name: configure tmux 8 | copy: 9 | src: tmux.conf 10 | dest: /etc/tmux.conf 11 | owner: root 12 | group: root 13 | mode: 644 14 | -------------------------------------------------------------------------------- /roles/tmux/templates/rkhunter.conf.local.j2: -------------------------------------------------------------------------------- 1 | {% if rkhunter_config_local.allowhiddendir is defined %} 2 | {% for hiddendir in rkhunter_config_local.allowhiddendir %} 3 | ALLOWHIDDENDIR={{ hiddendir }} 4 | {% endfor %} 5 | {% endif %} 6 | 7 | {% if rkhunter_config_local.allowhiddenfile is defined %} 8 | {% for hiddenfile in rkhunter_config_local.allowhiddenfile %} 9 | ALLOWHIDDENFILE={{ hiddenfile }} 10 | {% endfor %} 11 | {% endif %} 12 | 13 | {% if rkhunter_config_local.allowdevfile is defined %} 14 | {% for devfile in rkhunter_config_local.allowdevfile %} 15 | ALLOWDEVFILE={{ devfile }} 16 | {% endfor %} 17 | {% endif %} 18 | 19 | {% if rkhunter_config_local.scriptwhitelist is defined %} 20 | {% for whitelist in rkhunter_config_local.scriptwhitelist %} 21 | SCRIPTWHITELIST={{ whitelist }} 22 | {% endfor %} 23 | {% endif %} 24 | 25 | {% if rkhunter_config_local.pwdless_accounts is defined %} 26 | {% for pwdless_account in rkhunter_config_local.pwdless_accounts %} 27 | PWDLESS_ACCOUNTS={{ pwdless_account }} 28 | {% endfor %} 29 | {% endif %} 30 | 31 | {% if rkhunter_config_local.otherrules is defined %} 32 | {% for otherrules in rkhunter_config_local.otherrules %} 33 | {{ otherrules }} 34 | {% endfor %} 35 | {% endif %} 36 | -------------------------------------------------------------------------------- /roles/tmux/templates/rkhunter.j2: -------------------------------------------------------------------------------- 1 | # Defaults for rkhunter automatic tasks 2 | # sourced by /etc/cron.*/rkhunter and /etc/apt/apt.conf.d/90rkhunter 3 | # 4 | # This is a POSIX shell fragment 5 | # 6 | 7 | # Set this to yes to enable rkhunter daily runs 8 | # (default: true) 9 | CRON_DAILY_RUN="{{ rkhunter_cron_daily_run }}" 10 | 11 | # Set this to yes to enable rkhunter weekly database updates 12 | # (default: true) 13 | CRON_DB_UPDATE="{{ rkhunter_cron_db_update }}" 14 | 15 | # Set this to yes to enable reports of weekly database updates 16 | # (default: false) 17 | DB_UPDATE_EMAIL="{{ rkhunter_db_update_email }}" 18 | 19 | # Set this to the email address where reports and run output should be sent 20 | # (default: root) 21 | REPORT_EMAIL="{{ rkhunter_report_email }}" 22 | 23 | # Set this to yes to enable automatic database updates 24 | # (default: false) 25 | APT_AUTOGEN="{{ rkhunter_apt_autogen }}" 26 | 27 | # Nicenesses range from -20 (most favorable scheduling) to 19 (least favorable) 28 | # (default: 0) 29 | NICE="0" 30 | 31 | # Should daily check be run when running on battery 32 | # powermgmt-base is required to detect if running on battery or on AC power 33 | # (default: false) 34 | RUN_CHECK_ON_BATTERY="false" 35 | -------------------------------------------------------------------------------- /run_tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG 6 | trap 'echo "\"${role}\" role tests was failed."' EXIT 7 | 8 | for role in ./roles/*/ ; do 9 | if [[ -d "$role/molecule" ]] 10 | then 11 | cd $role 12 | molecule test 13 | cd ../.. 14 | fi 15 | done -------------------------------------------------------------------------------- /setup_venv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | python3 -m venv validator-venv 3 | source validator-venv/bin/activate 4 | python3 -m pip install --upgrade pip 5 | python3 -m pip install -r python_dependencies.txt 6 | ansible-galaxy install -r playbooks_dependencies.yml 7 | --------------------------------------------------------------------------------