├── .gitignore ├── .travis.yml ├── CHANGES.rst ├── COPYRIGHT ├── LICENSE ├── README.md ├── defaults └── main.yml ├── docs ├── changelog.rst ├── copyright.rst ├── getting-started.rst ├── includes │ └── all.rst ├── index.rst ├── introduction.rst └── playbooks │ └── sshd.yml ├── files └── scripts │ ├── dpkg-state │ └── sshd.fact ├── handlers └── main.yml ├── meta ├── ansigenome.yml └── main.yml ├── tasks ├── authorized_keys_lookup.yml ├── main.yml └── sshd │ ├── post_main.yml │ └── pre_main.yml └── templates └── etc └── ssh ├── authorized_keys_lookup.d ├── ldap.j2 └── sss.j2 ├── authorized_keys_lookup.j2 └── sshd_config.j2 /.gitignore: -------------------------------------------------------------------------------- 1 | ## For quick testing. 2 | ## Generated by https://github.com/ypid/ypid-ansible-common/blob/master/bin/sphinx-debops-role-build 3 | docs/Makefile 4 | docs/_build/ 5 | docs/conf.py 6 | docs/defaults.rst 7 | docs/includes/global.rst 8 | docs/_static/.gitkeep 9 | docs/_static/custom.css 10 | docs/_templates/.gitkeep 11 | docs/_templates/page.html 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | sudo: True 4 | language: 'python' 5 | python: '2.7' 6 | 7 | virtualenv: 8 | system_site_packages: true 9 | 10 | before_install: True 11 | install: True 12 | 13 | script: 14 | - 'git clone --depth 1 https://github.com/nickjj/rolespec' 15 | - 'cd rolespec ; bin/rolespec -r https://github.com/debops/test-suite' 16 | 17 | notifications: 18 | webhooks: 19 | - 'https://galaxy.ansible.com/api/v1/notifications/' 20 | -------------------------------------------------------------------------------- /CHANGES.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | .. include:: includes/all.rst 5 | 6 | **debops.sshd** 7 | 8 | This project adheres to `Semantic Versioning `__ 9 | and `human-readable changelog `__. 10 | 11 | The current role maintainer_ is drybjed_. 12 | 13 | 14 | `debops.sshd master`_ - unreleased 15 | ---------------------------------- 16 | 17 | .. _debops.sshd master: https://github.com/debops/ansible-sshd/compare/v0.3.0...master 18 | 19 | 20 | `debops.sshd v0.3.0`_ - 2017-07-12 21 | ---------------------------------- 22 | 23 | .. _debops.sshd v0.3.0: https://github.com/debops/ansible-sshd/compare/v0.2.5...v0.3.0 24 | 25 | Added 26 | ~~~~~ 27 | 28 | - When OpenSSH server is installed for the first time, make sure that the 29 | service is not started before being properly secured. [sourcejedi] 30 | 31 | Changed 32 | ~~~~~~~ 33 | 34 | - LDAP lookup script now works with binary and text attributes. [pedroluislopez_] 35 | 36 | - Fix Ansible 2.2 deprecation warnings which requires Ansible 2.2 or higher. 37 | Support for older Ansible versions is dropped. [brzhk] 38 | 39 | - Update the :file:`sshd.fact` script to fix communication problems with an 40 | external :command:`dpkg-query` command. [bfabio_] 41 | 42 | - Update the parameters of the debops.ferm_ configuration to use new features 43 | introduced in the role. This might affect the firewall rules of the SSH 44 | service, therefore check first if your configuration is applied properly. 45 | Ansible inventory modification shouldn't be necessary. [drybjed_] 46 | 47 | - Don't include deprecated configuration options in the 48 | :file:`/etc/ssh/sshd_config` configuration file. [drybjed_] 49 | 50 | - Increase the default ``LoginGraceTime`` value from 20 to 30 seconds to help 51 | solve issues with unresponsive DNS servers. [drybjed_] 52 | 53 | Deprecated 54 | ~~~~~~~~~~ 55 | 56 | - The ``openssh-blacklist*`` Debian packages have been removed from Debian 57 | Archive and won't be available in Debian Stretch onwards. 58 | Ref: https://bugs.debian.org/859682 [ypid_, drybjed_] 59 | 60 | 61 | `debops.sshd v0.2.5`_ - 2016-10-10 62 | ---------------------------------- 63 | 64 | .. _debops.sshd v0.2.5: https://github.com/debops/ansible-sshd/compare/v0.2.4...v0.2.5 65 | 66 | Changed 67 | ~~~~~~~ 68 | 69 | - Moved some packages from :envvar:`sshd__base_packages` to 70 | :envvar:`sshd__recommended_packages` and :envvar:`sshd__optional_packages` to 71 | allow to overwrite them. [ypid_] 72 | 73 | - Use the ``accept_any`` parameter in debops.tcpwrappers_ role configuration 74 | to enable or disable entries depending on which lists of allowed hosts are 75 | active. [drybjed_] 76 | 77 | 78 | `debops.sshd v0.2.4`_ - 2016-07-31 79 | ---------------------------------- 80 | 81 | .. _debops.sshd v0.2.4: https://github.com/debops/ansible-sshd/compare/v0.2.3...v0.2.4 82 | 83 | Added 84 | ~~~~~ 85 | 86 | - Added :envvar:`sshd__ciphers_additional`, 87 | :envvar:`sshd__kex_algorithms_additional` and :envvar:`sshd__macs_additional` 88 | to allow to specify additional cryptography related settings which are also 89 | applied in :envvar:`sshd__paranoid` mode. 90 | This is needed for the ``debops-contrib.x2go_server`` role. 91 | [ypid_] 92 | 93 | - Replace static Ansible fact file with a script that exposes some ``sshd`` 94 | configuration variables as Ansible facts. [ganto_] 95 | 96 | Changed 97 | ~~~~~~~ 98 | 99 | - Fixed Ansible check mode support to not fail when running with 100 | ``ansible_connection=local`` against a host which does not have ``sshd`` 101 | installed yet. [ypid_] 102 | 103 | - Make sure that not registered conditional variable returns an empty list. 104 | [cultcom] 105 | 106 | - Update documentation and Changelog. [drybjed_] 107 | 108 | 109 | `debops.sshd v0.2.3`_ - 2016-02-21 110 | ---------------------------------- 111 | 112 | .. _debops.sshd v0.2.3: https://github.com/debops/ansible-sshd/compare/v0.2.2...v0.2.3 113 | 114 | Added 115 | ~~~~~ 116 | 117 | - Automatically remove Diffie-Hellman parameters from :file:`/etc/ssh/moduli` which 118 | are smaller than the size specified in ``sshd_moduli_minimum`` variable (by 119 | default 2048 bits). [drybjed_] 120 | 121 | Changed 122 | ~~~~~~~ 123 | 124 | - Fix deprecation warnings on Ansible 2.1.0. [drybjed_] 125 | 126 | - Rename all role variables to put them in ``sshd__`` namespace. You might need 127 | to update your Ansible inventory. [drybjed_] 128 | 129 | 130 | `debops.sshd v0.2.2`_ - 2015-11-13 131 | ---------------------------------- 132 | 133 | .. _debops.sshd v0.2.2: https://github.com/debops/ansible-sshd/compare/v0.2.1...v0.2.2 134 | 135 | Changed 136 | ~~~~~~~ 137 | 138 | - Make sure that role works in Ansible check mode. [drybjed_] 139 | 140 | Removed 141 | ~~~~~~~ 142 | 143 | - Removed ``debops.sshkeys`` from role dependencies as it is also run from the 144 | :file:`common.yml` playbook. [ypid_] 145 | 146 | - Remove most of the Ansible role dependencies, leaving only those that are 147 | required for the role to run correctly. 148 | 149 | Configuration of dependent services like firewall, TCP Wrappers, APT 150 | preferences is set in separate default variables. These variables can be used 151 | by Ansible playbooks to configure settings related to ``sshd`` in other 152 | services. [drybjed_] 153 | 154 | 155 | `debops.sshd v0.2.1`_ - 2015-08-16 156 | ---------------------------------- 157 | 158 | .. _debops.sshd v0.2.1: https://github.com/debops/ansible-sshd/compare/v0.2.0...v0.2.1 159 | 160 | Added 161 | ~~~~~ 162 | 163 | - New variable ``sshd_paranoid``, allows to limit the use of various encryption 164 | algorithms to only first (presumed safest) choice. [ypid_] 165 | 166 | Changed 167 | ~~~~~~~ 168 | 169 | - ``sshd_custom_options`` variable has been moved to top of the ``sshd_config`` 170 | file, that way it can be used to override any option if necessary, since 171 | ``sshd`` uses first instance of an option it finds in the config file. [ypid_] 172 | 173 | 174 | `debops.sshd v0.2.0`_ - 2015-08-16 175 | ---------------------------------- 176 | 177 | .. _debops.sshd v0.2.0: https://github.com/debops/ansible-sshd/compare/v0.1.0...v0.2.0 178 | 179 | Added 180 | ~~~~~ 181 | 182 | - Add debops.secret_ role dependency, it's needed for access to LDAP 183 | secrets. [drybjed_] 184 | 185 | - Add debops.apt_preferences_ role dependency. OpenSSH from 186 | ``wheezy-backports`` will be installed on Debian Wheezy, if the repository is 187 | present. This brings version parity with Debian Jessie (current Stable), adds 188 | support for better encryption ciphers and allows to look up SSH public keys 189 | in external authentication sources. [drybjed_] 190 | 191 | - Add separate ``sshd_ferm_ports`` variable which is a list that defines what 192 | ports are opened in the firewall for access to OpenSSH server. By default 193 | only :command:`ssh` port from :file:`/etc/services` is opened. [drybjed_] 194 | 195 | - Add tags for debops.tcpwrappers_ and ``debops.sshkeys`` role dependencies. 196 | [drybjed_] 197 | 198 | - Add ``sshd_listen`` list which can be used to specify IP addresses of 199 | interfaces on which ``sshd`` should listen for new connections. If list is 200 | not specified, ``sshd`` will listen on all interfaces. [drybjed_] 201 | 202 | - Add configuration variables for ``MaxAuthTries`` and ``LoginGraceTime`` 203 | options. [drybjed_] 204 | 205 | - Create ``Ed25519`` host key if it's not present and OpenSSH version supports 206 | it. [drybjed_] 207 | 208 | - Add support for public key lookup in external sources. 209 | 210 | Support for ``AuthorizedKeysCommand`` option will be disabled by default, and 211 | can be enabled on Debian Jessie as well as on Debian Wheezy with backported 212 | OpenSSH version using ``sshd_authorized_keys_lookup`` variable. Scripts that 213 | perform the lookups will be executed on a separate system UNIX account to 214 | provide privilege separation. [drybjed_] 215 | 216 | - Add LDAP lookup script and configuration. 217 | 218 | When a host is configured using debops.auth_ to access account information 219 | from LDAP and system-wide configuration in :file:`/etc/ldap/ldap.conf` is set 220 | properly, OpenSSH can perform LDAP lookups using external script to retrieve 221 | valid SSH public keys. LDAP lookup will be configured by default if 222 | ``AuthorizedKeysCommand`` lookup is enabled on a host. [drybjed_] 223 | 224 | - Add missing tags to Ansible tasks. [drybjed_] 225 | 226 | Changed 227 | ~~~~~~~ 228 | 229 | - Request :command:`sudo` access on Travis-CI. [drybjed_] 230 | 231 | - Update documentation. [drybjed_] 232 | 233 | - Change how OpenSSH packages are managed. 234 | 235 | Main list of packages is moved to ``sshd_base_packages`` variable, 236 | ``sshd_packages`` is an empty list which can be used to include additional 237 | packages if needed. 238 | 239 | By default ``debops.sshd`` will automatically upgrade packages - this is 240 | needed on Debian Wheezy to install newer version of OpenSSH from 241 | ``wheezy-backports``. To disable automatic upgrades, role will add a separate 242 | local fact which indicates that ``debops.sshd`` is configured on a given 243 | host. This will automatically switch the :command:`apt` module from upgrading the 244 | packages to ensuring that they are present. [drybjed_] 245 | 246 | - Rename ``sshd_config_ports`` to ``sshd_ports``. [drybjed_] 247 | 248 | - Rename ``sshd_PermitRootLogin`` to ``sshd_permit_root_login``. [drybjed_] 249 | 250 | - Rename ``sshd_PasswordAuthentication`` to ``sshd_password_authentication``. 251 | [drybjed_] 252 | 253 | - Rename ``sshd_X11Forwarding`` to ``sshd_x11_forwarding``. [drybjed_] 254 | 255 | - Rename ``sshd_AllowGroups`` to ``sshd_allow_groups`` and expand it to 256 | additional lists, ``sshd_group_allow_groups`` and ``sshd_host_allow_groups``. 257 | 258 | Variable is converted from a string to a YAML list. List of system groups 259 | that are allowed to login hasn't been changed. If no groups are specified, 260 | option is not enabled and no limits are imposed by ``sshd``. [drybjed_] 261 | 262 | - Reorganize various ``sshd_authorized_keys*`` variables into a list split into 263 | "system" and "user" authorized key files. Support for Monkeysphere authorized 264 | keys out of the box is dropped, might be re-added in the future if there is 265 | interest. [drybjed_] 266 | 267 | - Make ``PrivilegeSeparation`` option configurable. [drybjed_] 268 | 269 | - Make ``LogLevel`` configurable. [drybjed_] 270 | 271 | - Make ``MaxStartups`` option configurable. [drybjed_] 272 | 273 | - Make ``Banner`` option configurable. [drybjed_] 274 | 275 | - Refactor ``Ciphers``, ``KexAlgorithms`` and ``MACs`` options. 276 | 277 | Various OpenSSH encryption options are not static anymore. Instead, 278 | ``debops.sshd`` will check what version of OpenSSH package is installed on 279 | a host and will pick a list of algorithms for each of the mentioned options 280 | from a defined set according to what version is installed, to make sure that 281 | there won't be an issue with unsupported ciphers. 282 | 283 | Current set of algorithms has been taken from Mozilla and should work with 284 | OpenSSH available in Debian Jessie. There's a separate set of algorithms for 285 | Debian Wheezy without backported OpenSSH installed as well. [drybjed_] 286 | 287 | - Make ``Match`` options configurable. 288 | 289 | Static ``Match`` options defined previously are moved to 290 | a ``sshd_match_list`` list variable, with a SFTPonly configuration enabled by 291 | default. 292 | 293 | SFTPonly configuration will now use global ``PasswordAuthentication`` option 294 | instead of forcibly disabling password authentication. [drybjed_] 295 | 296 | - Update :file:`defaults/main.yml` file to support ``.rst`` documentation and add 297 | whitespace in various files for better readability. [drybjed_] 298 | 299 | Removed 300 | ~~~~~~~ 301 | 302 | - Remove :file:`tasks/backup.yml` and :file:`tasks/restore.yml`, they are not used in 303 | main role task list. [drybjed_] 304 | 305 | - Remove debops.auth_ role dependency. Configuration done by this role is 306 | assumed to be present, since it's executed as part of the :file:`common.yml` 307 | playbook. [drybjed_] 308 | 309 | - Remove ``sshd_HostKey`` list. Instead of a static list of host keys, 310 | ``debops.sshd`` role will check what host keys are present in :file:`/etc/ssh/` 311 | directory. Using ``sshd_host_keys`` list which provides types of keys and 312 | their preferred order, host keys that are present will be added to ``sshd`` 313 | configuration file. [drybjed_] 314 | 315 | - Remove ``sshd_config_options_begin`` and ``sshd_config_options_end`` 316 | variables and replace them with with ``sshd_custom_options`` YAML text block 317 | variable. [drybjed_] 318 | 319 | 320 | debops.sshd v0.1.0 - 2015-08-10 321 | ------------------------------- 322 | 323 | Added 324 | ~~~~~ 325 | 326 | - Add Changelog. [drybjed_] 327 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | debops.sshd - Manage OpenSSH server using Ansible 2 | 3 | Copyright (C) 2013-2016 Maciej Delmanowski 4 | Copyright (C) 2015-2017 Robin Schneider 5 | Copyright (C) 2014-2017 DebOps https://debops.org/ 6 | 7 | This Ansible role is part of DebOps. 8 | 9 | DebOps is free software; you can redistribute it and/or modify 10 | it under the terms of the GNU General Public License version 3, as 11 | published by the Free Software Foundation. 12 | 13 | DebOps is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | GNU General Public License for more details. 17 | 18 | You should have received a copy of the GNU General Public License 19 | along with DebOps. If not, see https://www.gnu.org/licenses/. 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | 676 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## [![DebOps project](http://debops.org/images/debops-small.png)](http://debops.org) sshd 2 | 3 | [![Travis CI](http://img.shields.io/travis/debops/ansible-sshd.svg?style=flat)](http://travis-ci.org/debops/ansible-sshd) [![test-suite](http://img.shields.io/badge/test--suite-ansible--sshd-blue.svg?style=flat)](https://github.com/debops/test-suite/tree/master/ansible-sshd/) [![Ansible Galaxy](http://img.shields.io/badge/galaxy-debops.sshd-660198.svg?style=flat)](https://galaxy.ansible.com/list#/roles/1602) 4 | 5 | [OpenSSH](http://www.openssh.com/) is a secure replacement for `telnet` 6 | and other remote control programs. It allows you to connect to remote hosts 7 | over a encrypted communication channel and perform a variety of tasks. It's 8 | also the main communication channel used by Ansible. 9 | 10 | ### Installation 11 | 12 | This role requires at least Ansible `v1.7.0`. To install it, run: 13 | 14 | ansible-galaxy install debops.sshd 15 | 16 | ### Documentation 17 | 18 | More information about `debops.sshd` can be found in the 19 | [official debops.sshd documentation](http://docs.debops.org/en/latest/ansible/roles/ansible-sshd/docs/). 20 | 21 | 22 | ### Role dependencies 23 | 24 | - `debops.secret` 25 | 26 | ### Are you using this as a standalone role without DebOps? 27 | 28 | You may need to include missing roles from the [DebOps common 29 | playbook](https://github.com/debops/debops-playbooks/blob/master/playbooks/common.yml) 30 | into your playbook. 31 | 32 | [Try DebOps now](https://github.com/debops/debops) for a complete solution to run your Debian-based infrastructure. 33 | 34 | 35 | 36 | 37 | 38 | ### Authors and license 39 | 40 | `sshd` role was written by: 41 | - Maciej Delmanowski | [e-mail](mailto:drybjed@gmail.com) | [Twitter](https://twitter.com/drybjed) | [GitHub](https://github.com/drybjed) 42 | 43 | License: [GPLv3](https://tldrlegal.com/license/gnu-general-public-license-v3-%28gpl-3%29) 44 | 45 | *** 46 | 47 | This role is part of the [DebOps](http://debops.org/) project. README generated by [ansigenome](https://github.com/nickjj/ansigenome/). 48 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # .. vim: foldmarker=[[[,]]]:foldmethod=marker 3 | 4 | # debops.sshd default variables [[[ 5 | # ================================= 6 | 7 | # .. contents:: Sections 8 | # :local: 9 | # 10 | # .. include:: includes/all.rst 11 | 12 | 13 | # OpenSSH packages [[[ 14 | # -------------------- 15 | 16 | # .. envvar:: sshd__base_packages [[[ 17 | # 18 | # List of base packages that should be installed for OpenSSH support. 19 | sshd__base_packages: [ 'openssh-server', 'openssh-client' ] 20 | 21 | # ]]] 22 | # .. envvar:: sshd__recommended_packages [[[ 23 | # 24 | # List of recommended packages that should be installed with OpenSSH. 25 | sshd__recommended_packages: '{{ [ "openssh-blacklist", "openssh-blacklist-extra" ] 26 | if (ansible_distribution_release in [ "wheezy", "jessie", 27 | "precise", "trusty", "xenial" ]) else [] }}' 28 | 29 | # ]]] 30 | # .. envvar:: sshd__optional_packages [[[ 31 | # 32 | # List of optional packages that should be installed with OpenSSH. 33 | sshd__optional_packages: [ 'molly-guard' ] 34 | 35 | # ]]] 36 | # .. envvar:: sshd__ldap_packages [[[ 37 | # 38 | # List of packages related to LDAP support required by OpenSSH. 39 | sshd__ldap_packages: '{{ [ "ldap-utils" ] 40 | if (sshd__authorized_keys_lookup|bool and 41 | ("ldap" in sshd__authorized_keys_lookup_type)) 42 | else [] }}' 43 | 44 | # ]]] 45 | # .. envvar:: sshd__packages [[[ 46 | # 47 | # List of additional packages to install. 48 | sshd__packages: [] 49 | # ]]] 50 | # ]]] 51 | # Host whitelists and allow lists [[[ 52 | # ----------------------------------- 53 | 54 | # .. envvar:: sshd__whitelist [[[ 55 | # 56 | # List of IP addresses or CIDR subnets which should be allowed to connect to 57 | # SSH without any restrictions. This list does not disallow connections from 58 | # other hosts. This is a global list. 59 | sshd__whitelist: [] 60 | 61 | # ]]] 62 | # .. envvar:: sshd__group_whitelist [[[ 63 | # 64 | # List of IP addresses or CIDR subnets which should be allowed to connect to 65 | # SSH without any restrictions. This list does not disallow connections from 66 | # other hosts. This is a group-based list. 67 | sshd__group_whitelist: [] 68 | 69 | # ]]] 70 | # .. envvar:: sshd__host_whitelist [[[ 71 | # 72 | # List of IP addresses or CIDR subnets which should be allowed to connect to 73 | # SSH without any restrictions. This list does not disallow connections from 74 | # other hosts. This is a host-based list. 75 | sshd__host_whitelist: [] 76 | 77 | # ]]] 78 | # .. envvar:: sshd__allow [[[ 79 | # 80 | # List of IP addresses or CIDR subnets that should be allowed to access SSH 81 | # service. If it's set, access from hosts and networks not specified here is 82 | # denied in TCP Wrappers and limited in :command:`iptables`. This is a global list. 83 | sshd__allow: [] 84 | 85 | # ]]] 86 | # .. envvar:: sshd__group_allow [[[ 87 | # 88 | # List of IP addresses or CIDR subnets that should be allowed to access SSH 89 | # service. If it's set, access from hosts and networks not specified here is 90 | # denied in TCP Wrappers and limited in :command:`iptables`. This is a group list. 91 | sshd__group_allow: [] 92 | 93 | # ]]] 94 | # .. envvar:: sshd__host_allow [[[ 95 | # 96 | # List of IP addresses or CIDR subnets that should be allowed to access SSH 97 | # service. If it's set, access from hosts and networks not specified here is 98 | # denied in TCP Wrappers and limited in :command:`iptables`. This is a host list. 99 | sshd__host_allow: [] 100 | # ]]] 101 | # ]]] 102 | # TCP Wrappers configuration [[[ 103 | # ------------------------------ 104 | 105 | # .. envvar:: sshd__tcpwrappers_default [[[ 106 | # 107 | # If list of allowed hosts is not specified, this value will be set in TCP 108 | # Wrappers for ``sshd`` service. By default any host is allowed to connect. 109 | sshd__tcpwrappers_default: 'ALL' 110 | # ]]] 111 | # ]]] 112 | # Firewall (ferm) configuration [[[ 113 | # --------------------------------- 114 | 115 | # .. envvar:: sshd__ferm_weight [[[ 116 | # 117 | # Specify the "weight" of the ``sshd`` firewall rules. The more weight they 118 | # have, he later in the firewall they will be defined. If you change the 119 | # default weight, you will need to remove the old rules manually from the remote 120 | # host. 121 | sshd__ferm_weight: '30' 122 | 123 | # ]]] 124 | # .. envvar:: sshd__ferm_limit [[[ 125 | # 126 | # Enable or disable limited SSH access from all hosts in :command:`ip(6)tables`. 127 | # Recent new connections are filtered and when too many new connections are 128 | # created in specified time window, host is added to the recent blocklist. 129 | sshd__ferm_limit: True 130 | 131 | # ]]] 132 | # .. envvar:: sshd__ferm_limit_seconds [[[ 133 | # 134 | # Length of the time window used by firewall to catch new offenders, 135 | # by default 5 minutes. 136 | sshd__ferm_limit_seconds: '{{ (60 * 5) }}' 137 | 138 | # ]]] 139 | # .. envvar:: sshd__ferm_limit_hits [[[ 140 | # 141 | # How many new connections to allow in specified time window. 142 | sshd__ferm_limit_hits: '8' 143 | 144 | # ]]] 145 | # .. envvar:: sshd__ferm_limit_chain [[[ 146 | # 147 | # Name of the iptables chain used for filtering SSH connections. 148 | sshd__ferm_limit_chain: 'filter-ssh' 149 | 150 | # ]]] 151 | # .. envvar:: sshd__ferm_limit_target [[[ 152 | # 153 | # Specify what happens with packets filtered by the firewall that are above the 154 | # specified limit. Either ``REJECT``, ``DROP`` or name of :command:`iptables` chain 155 | # where packets will be sent through. 156 | sshd__ferm_limit_target: 'REJECT' 157 | 158 | # ]]] 159 | # .. envvar:: sshd__ferm_ports [[[ 160 | # 161 | # List of TCP ports to open in the firewall for SSH connections. You can use 162 | # port numbers or service names from :file:`/etc/services`. 163 | sshd__ferm_ports: [ 'ssh' ] 164 | # ]]] 165 | # ]]] 166 | # OpenSSH server configuration [[[ 167 | # -------------------------------- 168 | 169 | # .. envvar:: sshd__ports [[[ 170 | # 171 | # List of ports which ``sshd`` will listen on. 172 | sshd__ports: [ '22' ] 173 | 174 | # ]]] 175 | # .. envvar:: sshd__listen [[[ 176 | # 177 | # List of IP addresses on which ``sshd`` should listen for new connections. If 178 | # it's empty, ``sshd`` listens on all interfaces. 179 | sshd__listen: [] 180 | 181 | # ]]] 182 | # .. envvar:: sshd__host_keys [[[ 183 | # 184 | # List of SSH host keys that should be enabled, in order of preference. 185 | sshd__host_keys: [ 'ed25519', 'rsa', 'ecdsa' ] 186 | 187 | # ]]] 188 | # .. envvar:: sshd__banner [[[ 189 | # 190 | # Path to file which should be displayed before user authentication. 191 | sshd__banner: 'none' 192 | 193 | # ]]] 194 | # .. envvar:: sshd__log_level [[[ 195 | # 196 | # How much information should be logged by ``sshd`` server. 197 | sshd__log_level: 'INFO' 198 | 199 | # ]]] 200 | # .. envvar:: sshd__permit_root_login [[[ 201 | # 202 | # Specify if access to ``root`` account should be granted. By default ``root`` 203 | # can be accessed only using SSH public keys. 204 | sshd__permit_root_login: 'without-password' 205 | 206 | # ]]] 207 | # .. envvar:: sshd__password_authentication [[[ 208 | # 209 | # Enable or disable password authentication. 210 | sshd__password_authentication: 'no' 211 | 212 | # ]]] 213 | # .. envvar:: sshd__accept_env [[[ 214 | # 215 | # Specifies what environment variables sent by the client will be copied into 216 | # the session's environment. 217 | sshd__accept_env: 218 | - 'LANG' 219 | - 'LC_*' 220 | # ]]] 221 | # .. envvar:: sshd__x11_forwarding [[[ 222 | # 223 | # Enable or disable X11 forwarding by the server. 224 | sshd__x11_forwarding: 'no' 225 | 226 | # ]]] 227 | # .. envvar:: sshd__max_auth_tries [[[ 228 | # 229 | # Maximum number of failed authentication attempts allowed by the server. 230 | sshd__max_auth_tries: '4' 231 | 232 | # ]]] 233 | # .. envvar:: sshd__max_startups [[[ 234 | # 235 | # Maximum number of unauthenticated connections (3), after which there's 80% 236 | # probability of next unauthenticated connection to be dropped, finishing at 7, 237 | # after which all new unauthenticated connections will be refused. 238 | sshd__max_startups: '3:80:7' 239 | 240 | # ]]] 241 | # .. envvar:: sshd__login_grace_time [[[ 242 | # 243 | # Time after which unauthenticated sessions are disconnected. 244 | sshd__login_grace_time: '30s' 245 | 246 | # ]]] 247 | # .. envvar:: sshd__privilege_separation [[[ 248 | # 249 | # Specify if ``sshd`` should use unprivileged processes for incoming session 250 | # authentication. Setting this to ``sandbox`` enables use of additional 251 | # kernel restrictions. 252 | sshd__privilege_separation: 'sandbox' 253 | 254 | # ]]] 255 | # .. envvar:: sshd__custom_options [[[ 256 | # 257 | # Additional :manpage:`sshd_config(5)` options specified in a YAML text block format. 258 | sshd__custom_options: '' 259 | # ]]] 260 | # ]]] 261 | # Group-based access control [[[ 262 | # ------------------------------ 263 | 264 | # .. envvar:: sshd__allow_groups [[[ 265 | # 266 | # List of UNIX groups which allow connections to SSH service (global). 267 | sshd__allow_groups: [ 'root', 'admins', 'sshusers', 'sftponly' ] 268 | 269 | # ]]] 270 | # .. envvar:: sshd__group_allow_groups [[[ 271 | # 272 | # List of UNIX groups which allow connections to SSH service (host group). 273 | sshd__group_allow_groups: [] 274 | 275 | # ]]] 276 | # .. envvar:: sshd__host_allow_groups [[[ 277 | # 278 | # List of UNIX groups which allow connections to SSH service (host). 279 | sshd__host_allow_groups: [] 280 | # ]]] 281 | # ]]] 282 | # Authorized keys management [[[ 283 | # ------------------------------ 284 | 285 | # .. envvar:: sshd__authorized_keys [[[ 286 | # 287 | # List of files which contain SSH public keys, to be used to authenticate 288 | # remote users. 289 | sshd__authorized_keys: '{{ sshd__authorized_keys_system + 290 | sshd__authorized_keys_user }}' 291 | 292 | # ]]] 293 | # .. envvar:: sshd__authorized_keys_system [[[ 294 | # 295 | # List of system-wide files containing SSH public keys. These files are 296 | # expected to be maintained by system administrator and might be used in 297 | # restricted environments (for example SFTPonly accounts). 298 | sshd__authorized_keys_system: 299 | - '/etc/ssh/authorized_keys/%u' 300 | 301 | # ]]] 302 | # .. envvar:: sshd__authorized_keys_user [[[ 303 | # 304 | # List of user files containing SSH public keys. These files are maintained by 305 | # the users themselves. 306 | sshd__authorized_keys_user: 307 | - '%h/.ssh/authorized_keys' 308 | - '%h/.ssh/authorized_keys2' 309 | # ]]] 310 | # ]]] 311 | # System-wide host fingerprints [[[ 312 | # --------------------------------- 313 | 314 | # .. envvar:: sshd__known_hosts [[[ 315 | # 316 | # List of FQDN hostnames that should be scanned to add host fingerprints to the 317 | # system-wide known hosts file (global). 318 | sshd__known_hosts: [] 319 | 320 | # ]]] 321 | # .. envvar:: sshd__group_known_hosts [[[ 322 | # 323 | # List of FQDN hostnames that should be scanned to add host fingerprints to the 324 | # system-wide known hosts file (host group). 325 | sshd__group_known_hosts: [] 326 | 327 | # ]]] 328 | # .. envvar:: sshd__host_known_hosts [[[ 329 | # 330 | # List of FQDN hostnames that should be scanned to add host fingerprints to the 331 | # system-wide known hosts file (host). 332 | sshd__host_known_hosts: [] 333 | 334 | # ]]] 335 | # .. envvar:: sshd__known_hosts_file [[[ 336 | # 337 | # System-wide file where host fingerprints are stored. 338 | sshd__known_hosts_file: '/etc/ssh/ssh_known_hosts' 339 | 340 | # ]]] 341 | # .. envvar:: sshd__known_hosts_command [[[ 342 | # 343 | # Command used to scan host fingerprints into system-wide known hosts file. 344 | sshd__known_hosts_command: 'ssh-keyscan -H -T 10' 345 | # ]]] 346 | # ]]] 347 | # Encryption parameters [[[ 348 | # ------------------------- 349 | 350 | # .. envvar:: sshd__ciphers_map [[[ 351 | # 352 | # Dict with list of ciphers which should be used by the ``sshd`` server, 353 | # depending on available version, ordered from strongest to weakest. Newer version 354 | # supersedes older version. 355 | sshd__ciphers_map: 356 | 357 | # Source: https://wiki.mozilla.org/Security/Guidelines/OpenSSH 358 | '6.5': [ 'chacha20-poly1305@openssh.com', 'aes256-gcm@openssh.com', 359 | 'aes128-gcm@openssh.com', 'aes256-ctr', 'aes192-ctr', 360 | 'aes128-ctr' ] 361 | 362 | # Source: https://xivilization.net/~marek/blog/2015/01/12/secure-secure-shell-on-debian-wheezy/ 363 | '6.0': [ 'aes256-ctr', 'aes192-ctr', 'aes128-ctr' ] 364 | 365 | # ]]] 366 | # .. envvar:: sshd__ciphers_additional [[[ 367 | # 368 | # List of additional key exchange algorithms which should be used by the 369 | # ``sshd`` server, depending on available version, depending on available 370 | # version, ordered from stronger to weaker. Newer version supersedes older 371 | # version. 372 | sshd__ciphers_additional: [] 373 | 374 | # ]]] 375 | # .. envvar:: sshd__kex_algorithms_map [[[ 376 | # 377 | # Dict with list of key exchange algorithms which should be used by the 378 | # ``sshd`` server, depending on available version, ordered from strongest to 379 | # oldest. Newer version supersedes older version. 380 | sshd__kex_algorithms_map: 381 | 382 | # Source: https://wiki.mozilla.org/Security/Guidelines/OpenSSH 383 | '6.5': [ 'curve25519-sha256@libssh.org', 'ecdh-sha2-nistp521', 384 | 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp256', 385 | 'diffie-hellman-group-exchange-sha256' ] 386 | 387 | # Source: https://xivilization.net/~marek/blog/2015/01/12/secure-secure-shell-on-debian-wheezy/ 388 | '6.0': [ 'diffie-hellman-group-exchange-sha256' ] 389 | 390 | # ]]] 391 | # .. envvar:: sshd__kex_algorithms_additional [[[ 392 | # 393 | # List of additional key exchange algorithms which should be used by the 394 | # ``sshd`` server, depending on available version, depending on available 395 | # version, ordered from stronger to weaker. Newer version supersedes older 396 | # version. 397 | sshd__kex_algorithms_additional: [] 398 | 399 | # ]]] 400 | # .. envvar:: sshd__macs_map [[[ 401 | # 402 | # Dict with list of message authentication code algorithms which should be used 403 | # by the ``sshd`` server, depending on available version, ordered from stronger 404 | # to weaker. Newer version supersedes older version. 405 | sshd__macs_map: 406 | 407 | # Source: https://wiki.mozilla.org/Security/Guidelines/OpenSSH 408 | '6.5': [ 'hmac-sha2-512-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 409 | 'umac-128-etm@openssh.com', 'hmac-sha2-512', 'hmac-sha2-256', 410 | 'umac-128@openssh.com' ] 411 | 412 | # Source: https://xivilization.net/~marek/blog/2015/01/12/secure-secure-shell-on-debian-wheezy/ 413 | '6.0': [ 'hmac-sha2-512', 'hmac-sha2-256' , 'hmac-ripemd160' ] 414 | 415 | # ]]] 416 | # .. envvar:: sshd__macs_additional [[[ 417 | # 418 | # List of additional message authentication code algorithms to support 419 | # by the ``sshd`` server, depending on available version, ordered from stronger 420 | # to weaker. Newer version supersedes older version. 421 | sshd__macs_additional: [] 422 | 423 | # ]]] 424 | # .. envvar:: sshd__moduli_minimum [[[ 425 | # 426 | # Specify minimum size of Diffie-Hellman parameters available to the SSH 427 | # server. Parameters smaller than the given amount will be removed from the 428 | # :file:`/etc/ssh/moduli` file. 429 | sshd__moduli_minimum: '2048' 430 | 431 | # ]]] 432 | # .. envvar:: sshd__paranoid [[[ 433 | # 434 | # If set to True, only the first item (which is considered the strongest method 435 | # available) from the lists :envvar:`sshd__ciphers_map`, 436 | # :envvar:`sshd__kex_algorithms_map` and :envvar:`sshd__macs_map` will be configured for 437 | # ``sshd``. Use this with care as it will deny access to anyone not able to use 438 | # the first cryptographic method. 439 | # See https://github.com/debops/ansible-sshd/issues/20 440 | sshd__paranoid: False 441 | # ]]] 442 | # ]]] 443 | # Authorized key lookup configuration [[[ 444 | # --------------------------------------- 445 | 446 | # .. envvar:: sshd__authorized_keys_lookup [[[ 447 | # 448 | # Enable support for looking up authorized public keys in external data sources 449 | # (currently LDAP is supported). This function works only with OpenSSH 6.2+. 450 | sshd__authorized_keys_lookup: False 451 | 452 | # ]]] 453 | # .. envvar:: sshd__authorized_keys_lookup_user [[[ 454 | # 455 | # System user account which will be used to look up authorized keys. 456 | sshd__authorized_keys_lookup_user: 'sshd-lookup' 457 | 458 | # ]]] 459 | # .. envvar:: sshd__authorized_keys_lookup_group [[[ 460 | # 461 | # System group which will be used to look up authorized keys. 462 | sshd__authorized_keys_lookup_group: 'sshd-lookup' 463 | 464 | # ]]] 465 | # .. envvar:: sshd__authorized_keys_lookup_home [[[ 466 | # 467 | # Home directory used by authorized key lookup user. 468 | sshd__authorized_keys_lookup_home: '/var/run/{{ sshd__authorized_keys_lookup_user }}' 469 | 470 | # ]]] 471 | # .. envvar:: sshd__authorized_keys_lookup_type [[[ 472 | # 473 | # List of lookup scripts that should be enabled on a host. 474 | sshd__authorized_keys_lookup_type: [ 'ldap' ] 475 | # ]]] 476 | # ]]] 477 | # LDAP lookup configuration [[[ 478 | # ----------------------------- 479 | 480 | # .. envvar:: sshd__ldap_domain [[[ 481 | # 482 | # Base DNS domain to use for LDAP BaseDN generation. 483 | sshd__ldap_domain: '{{ ansible_domain }}' 484 | 485 | # ]]] 486 | # .. envvar:: sshd__ldap_base [[[ 487 | # 488 | # LDAP base used for BaseDN generation. 489 | sshd__ldap_base: '{{ "dc=" + sshd__ldap_domain.split(".") | join(",dc=") }}' 490 | 491 | # ]]] 492 | # .. envvar:: sshd__ldap_bind_basedn [[[ 493 | # 494 | # LDAP BaseDN of the host account used to bind to the server. 495 | sshd__ldap_bind_basedn: '{{ "ou=Machines," + sshd__ldap_base }}' 496 | 497 | # ]]] 498 | # .. envvar:: sshd__ldap_bind_cn [[[ 499 | # 500 | # Host account name in LDAP. 501 | sshd__ldap_bind_cn: 'cn={{ ansible_hostname }}' 502 | 503 | # ]]] 504 | # .. envvar:: sshd__ldap_bind_dn [[[ 505 | # 506 | # Machine entry used to bind to the LDAP server. 507 | sshd__ldap_bind_dn: '{{ sshd__ldap_bind_cn + "," + sshd__ldap_bind_basedn }}' 508 | 509 | # ]]] 510 | # .. envvar:: sshd__ldap_bind_basepw [[[ 511 | # 512 | # Base path to file with host LDAP password in ``secret/`` directory. See 513 | # debops.secret_ Ansible role for more details. 514 | sshd__ldap_bind_basepw: '{{ secret + "/credentials/" + 515 | ansible_fqdn + "/ldap/host/binddn/" + 516 | sshd__ldap_bind_dn + ".password" }}' 517 | 518 | # ]]] 519 | # .. envvar:: sshd__ldap_bind_pw [[[ 520 | # 521 | # Machine password used for binding to LDAP database. 522 | sshd__ldap_bind_pw: '{{ lookup("password", sshd__ldap_bind_basepw + 523 | " length=" + sshd__ldap_password_length) }}' 524 | 525 | # ]]] 526 | # .. envvar:: sshd__ldap_bind_pw_file [[[ 527 | # 528 | # Path to file which stores machine bind password on remote host. 529 | sshd__ldap_bind_pw_file: '/etc/ssh/ldap_authorized_keys_bindpw' 530 | 531 | # ]]] 532 | # .. envvar:: sshd__ldap_password_length [[[ 533 | # 534 | # Length of generated LDAP machine password. 535 | sshd__ldap_password_length: '48' 536 | 537 | # ]]] 538 | # .. envvar:: sshd__ldap_filter [[[ 539 | # 540 | # Active ``ldapsearch`` filter used to select correct account while looking up 541 | # the SSH public key. 542 | sshd__ldap_filter: '{{ sshd__ldap_filter_map["service+host"] }}' 543 | 544 | # ]]] 545 | # .. envvar:: sshd__ldap_filter_map [[[ 546 | # 547 | # Dict with set of available LDAP filters that can be used to lookup the SSH 548 | # public key. 549 | sshd__ldap_filter_map: 550 | 551 | # User account needs 'authorizedService' attribute 552 | 'service': '(&(objectClass=posixAccount)(uid=$username)(authorizedService=$service))' 553 | 554 | # User account needs 'host' attribute 555 | 'host': '(&(objectClass=posixAccount)(uid=$username)(|(host=$hostname)(host=$fqdn)(host=\\*.$domain)(host=\\*)))' 556 | 557 | # User account needs both 'authorizedService' and 'host' attributes. 558 | 'service+host': '(&(objectClass=posixAccount)(uid=$username)(authorizedService=$service)(|(host=$hostname)(host=$fqdn)(host=\\*.$domain)(host=\\*)))' 559 | # ]]] 560 | # ]]] 561 | # Match conditional blocks [[[ 562 | # ---------------------------- 563 | 564 | # .. envvar:: sshd__match_list [[[ 565 | # 566 | # List of conditional ``Match`` blocks to include in ``sshd_config``. 567 | # Required parameters: 568 | # 569 | # - ``match``: specify User, Group, or other Match arguments which should 570 | # activate a given configuration block. 571 | # 572 | # - ``options``: YAML text block which contains :manpage:`sshd_config(5)` options 573 | # active in a given Match block. 574 | # 575 | sshd__match_list: [ '{{ sshd__match_group_sftponly }}' ] 576 | 577 | # ]]] 578 | # .. envvar:: sshd__match_group_sftponly [[[ 579 | # 580 | # Default ``Match`` conditional block which defines configuration for SFTPonly 581 | # accounts. 582 | sshd__match_group_sftponly: 583 | match: 'Group sftponly' 584 | options: | 585 | AuthorizedKeysFile {{ sshd__authorized_keys_system | join(' ') }} 586 | ChrootDirectory %h 587 | X11Forwarding no 588 | AllowAgentForwarding no 589 | AllowTcpForwarding no 590 | PermitTunnel no 591 | ForceCommand internal-sftp 592 | # ]]] 593 | # ]]] 594 | # Configuration of other services [[[ 595 | # ----------------------------------- 596 | 597 | # .. envvar:: sshd__apt_preferences__dependent_list [[[ 598 | # 599 | # List of :manpage:`apt_preferences(5)` rules. This is used to change what package 600 | # versions are installed on a particular distribution. 601 | sshd__apt_preferences__dependent_list: 602 | 603 | - package: 'ssh ssh-* openssh-*' 604 | backports: [ 'wheezy' ] 605 | reason: 'Version parity with Debian Jessie, support for AuthorizedKeysCommand, better ciphers' 606 | by_role: 'debops.sshd' 607 | 608 | # ]]] 609 | # .. envvar:: sshd__ferm__dependent_rules: [[[ 610 | # 611 | # Configuration for :command:`iptables` firewall managed by :program:`ferm`. 612 | sshd__ferm__dependent_rules: 613 | 614 | - type: 'accept' 615 | dport: '{{ sshd__ferm_ports }}' 616 | weight: '0' 617 | weight_class: 'sshd-chain' 618 | name: 'sshd_jump-filter-ssh' 619 | target: '{{ sshd__ferm_limit_chain }}' 620 | rule_state: '{{ "present" if sshd__ferm_limit|bool else "absent" }}' 621 | comment: 'Create a separate "iptables" chain for SSH rules' 622 | 623 | - chain: '{{ sshd__ferm_limit_chain if sshd__ferm_limit | bool else "INPUT" }}' 624 | type: 'accept' 625 | dport: '{{ sshd__ferm_ports }}' 626 | saddr: '{{ sshd__whitelist + sshd__group_whitelist + sshd__host_whitelist }}' 627 | weight: '1' 628 | weight_class: 'sshd-chain' 629 | name: 'sshd_whitelist' 630 | subchain: False 631 | accept_any: False 632 | comment: 'Accept any hosts in the whitelist unconditionally' 633 | 634 | - chain: '{{ sshd__ferm_limit_chain if sshd__ferm_limit | bool else "INPUT" }}' 635 | type: 'accept' 636 | dport: '{{ sshd__ferm_ports }}' 637 | saddr: '{{ sshd__allow + sshd__group_allow + sshd__host_allow }}' 638 | weight: '2' 639 | weight_class: 'sshd-chain' 640 | name: 'sshd_allow' 641 | subchain: False 642 | accept_any: '{{ False if sshd__ferm_limit | bool else True }}' 643 | comment: | 644 | Accept any hosts in the allow list. If there are any hosts specified, 645 | block connections from other hosts using TCP Wrappers. 646 | 647 | - chain: '{{ sshd__ferm_limit_chain }}' 648 | type: 'recent' 649 | weight: '3' 650 | weight_class: 'sshd-chain' 651 | name: 'sshd_block-ssh' 652 | dport: '{{ sshd__ferm_ports }}' 653 | state: [ 'NEW' ] 654 | subchain: False 655 | recent_name: 'ssh-new' 656 | recent_update: True 657 | recent_seconds: '{{ sshd__ferm_limit_seconds }}' 658 | recent_hitcount: '{{ sshd__ferm_limit_hits }}' 659 | recent_target: 'REJECT' 660 | rule_state: '{{ "present" if sshd__ferm_limit|bool else "absent" }}' 661 | comment: | 662 | Block new SSH connections that have been marked as recent if they make 663 | too many new connection attempts. 664 | 665 | - chain: '{{ sshd__ferm_limit_chain }}' 666 | type: 'recent' 667 | weight: '4' 668 | weight_class: 'sshd-chain' 669 | name: 'sshd_mark-ssh' 670 | dport: '{{ sshd__ferm_ports }}' 671 | state: [ 'NEW' ] 672 | subchain: False 673 | recent_set_name: 'ssh-new' 674 | recent_log: False 675 | rule_state: '{{ "present" if sshd__ferm_limit|bool else "absent" }}' 676 | comment: 'Mark new connections to the SSH service for recent tracking' 677 | 678 | - chain: '{{ sshd__ferm_limit_chain }}' 679 | type: 'accept' 680 | weight: '5' 681 | weight_class: 'sshd-chain' 682 | role: 'sshd' 683 | role_weight: '60' 684 | name: 'sshd_accept-ssh' 685 | dport: '{{ sshd__ferm_ports }}' 686 | rule_state: '{{ "present" if sshd__ferm_limit|bool else "absent" }}' 687 | comment: 'Accept connections to the SSH service' 688 | 689 | # ]]] 690 | # .. envvar:: sshd__tcpwrappers__dependent_allow [[[ 691 | # 692 | # Configure TCP wrappers to allow access to the ``sshd`` daemon. 693 | sshd__tcpwrappers__dependent_allow: 694 | 695 | - daemon: 'sshd' 696 | client: '{{ sshd__whitelist + sshd__group_whitelist + sshd__host_whitelist }}' 697 | accept_any: '{{ False if (sshd__allow + sshd__group_allow + sshd__host_allow) else True }}' 698 | weight: '25' 699 | filename: 'sshd_dependent_whitelist' 700 | comment: 'Whitelist of hosts allowed to connect to ssh' 701 | 702 | - daemon: 'sshd' 703 | client: '{{ sshd__allow + sshd__group_allow + sshd__host_allow }}' 704 | default: '{{ sshd__tcpwrappers_default }}' 705 | accept_any: '{{ True if (sshd__whitelist + sshd__group_whitelist + sshd__host_whitelist) else False }}' 706 | weight: '30' 707 | filename: 'sshd_dependent_allow' 708 | comment: 'List of hosts allowed to connect to ssh' 709 | # ]]] 710 | # ]]] 711 | # ]]] 712 | -------------------------------------------------------------------------------- /docs/changelog.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CHANGES.rst 2 | -------------------------------------------------------------------------------- /docs/copyright.rst: -------------------------------------------------------------------------------- 1 | Copyright 2 | ========= 3 | 4 | .. literalinclude:: ../COPYRIGHT 5 | 6 | -------------------------------------------------------------------------------- /docs/getting-started.rst: -------------------------------------------------------------------------------- 1 | Getting started 2 | =============== 3 | 4 | .. contents:: 5 | :local: 6 | 7 | .. include:: includes/all.rst 8 | 9 | Useful variables 10 | ---------------- 11 | 12 | This is a list of role variables which your most likely want to define in 13 | Ansible inventory to customize OpenSSH server: 14 | 15 | :envvar:`sshd__whitelist` / :envvar:`sshd__group_whitelist` / :envvar:`sshd__host_whitelist` 16 | Lists which contain IP addresses or CIDR subnets that are permitted to 17 | connect to OpenSSH without restrictions or firewall limits. Adding entries 18 | here will not impose additional restrictions, unlike using ``sshd__*_allow`` 19 | lists. 20 | 21 | :envvar:`sshd__known_hosts` / :envvar:`sshd__group_known_hosts` / :envvar:`sshd__host_known_hosts` 22 | You can add here lists of FQDN hostnames which should be added to systemwide 23 | :file:`/etc/ssh/ssh_known_hosts` file. For example, setting:: 24 | 25 | sshd__known_hosts: [ 'github.com' ] 26 | 27 | will add GitHub SSH fingerprint and allow you to clone git repositories over 28 | SSH with proper host authentication, without need to ignore host 29 | fingerprints. 30 | 31 | :envvar:`sshd__authorized_keys_lookup` 32 | Boolean. If ``True``, role will enable lookup of SSH public keys in external 33 | authentication databases, like LDAP. This might require additional 34 | configuration using ``sshd__ldap_*`` variables. 35 | 36 | LDAP key lookup depends on system-wide LDAP configuration in 37 | :file:`/etc/ldap/ldap.conf`, which can be performed (at the moment) using 38 | debops.auth_ role. 39 | 40 | Example inventory 41 | ----------------- 42 | 43 | ``debops.sshd`` role is part of the :file:`common.yml` DebOps playbook. It will be 44 | executed automatically on every host managed by DebOps. 45 | 46 | Example playbook 47 | ---------------- 48 | 49 | If you are using this role without DebOps, here's an example Ansible playbook 50 | that uses the ``debops.sshd`` role: 51 | 52 | .. literalinclude:: playbooks/sshd.yml 53 | :language: yaml 54 | 55 | Ansible tags 56 | ------------ 57 | 58 | You can use Ansible ``--tags`` or ``--skip-tags`` parameters to limit what 59 | tasks are performed during Ansible run. This can be used after a host was first 60 | configured to speed up playbook execution, when you are sure that most of the 61 | configuration is already in the desired state. 62 | 63 | Available role tags: 64 | 65 | ``role::sshd`` 66 | Main role tag, should be used in the playbook to execute all of the role 67 | tasks as well as role dependencies. 68 | 69 | ``role::sshd:config`` 70 | Execute tasks related to ``sshd`` configuration file. 71 | 72 | ``role::sshd:known_hosts`` 73 | Scan specified host fingerprints and add them to system-wide ``known_hosts``. 74 | -------------------------------------------------------------------------------- /docs/includes/all.rst: -------------------------------------------------------------------------------- 1 | .. include:: includes/global.rst 2 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. _debops.sshd: 2 | 3 | Ansible role: debops.sshd 4 | ========================= 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | introduction 10 | getting-started 11 | defaults 12 | copyright 13 | changelog 14 | 15 | .. 16 | Local Variables: 17 | mode: rst 18 | ispell-local-dictionary: "american" 19 | End: 20 | -------------------------------------------------------------------------------- /docs/introduction.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | `OpenSSH`_ is a secure replacement for ``telnet`` and other remote control 5 | programs. It allows you to connect to remote hosts over encrypted communication 6 | channel and perform variety of tasks. It's also primary communication channel 7 | used by Ansible. 8 | 9 | .. _OpenSSH: http://www.openssh.com/ 10 | 11 | Installation 12 | ~~~~~~~~~~~~ 13 | 14 | This role requires at least Ansible ``v1.7.0``. To install it, run: 15 | 16 | .. code-block:: console 17 | 18 | user@host:~$ ansible-galaxy install debops.sshd 19 | 20 | .. 21 | Local Variables: 22 | mode: rst 23 | ispell-local-dictionary: "american" 24 | End: 25 | -------------------------------------------------------------------------------- /docs/playbooks/sshd.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Manage OpenSSH Server 4 | hosts: [ 'debops_all_hosts', 'debops_service_sshd' ] 5 | become: True 6 | 7 | environment: '{{ inventory__environment | d({}) 8 | | combine(inventory__group_environment | d({})) 9 | | combine(inventory__host_environment | d({})) }}' 10 | 11 | roles: 12 | 13 | - role: debops.apt_preferences 14 | tags: [ 'role::apt_preferences' ] 15 | apt_preferences__dependent_list: 16 | - '{{ sshd__apt_preferences__dependent_list }}' 17 | 18 | - role: debops.ferm 19 | tags: [ 'role::ferm' ] 20 | ferm__dependent_rules: 21 | - '{{ sshd__ferm__dependent_rules }}' 22 | 23 | - role: debops.tcpwrappers 24 | tags: [ 'role::tcpwrappers' ] 25 | tcpwrappers_dependent_allow: 26 | - '{{ sshd__tcpwrappers__dependent_allow }}' 27 | 28 | - role: debops.sshd 29 | tags: [ 'role::sshd' ] 30 | -------------------------------------------------------------------------------- /files/scripts/dpkg-state: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | import sys 3 | import subprocess 4 | import signal 5 | 6 | # Get dpkg status. 7 | # Errors are printed to stderr, and should cause None to be returned. 8 | def dpkg_state(package): 9 | # As of Debian 8, this is the only documented method. 10 | # http://unix.stackexchange.com/questions/325594/script-a-test-for-installed-debian-package-error-handling/325595#325595 11 | 12 | command = ['dpkg-query', '--show', 13 | '--showformat=${Package} ${Status}\n'] 14 | 15 | proc = subprocess.Popen(command, stdout=subprocess.PIPE) 16 | (stdoutdata, _) = proc.communicate() 17 | for line in filter(bool, stdoutdata.split('\n')): 18 | line = line.decode('ASCII') 19 | line = line.rstrip() 20 | # "package desired-action error-flags state" 21 | (p, _, _, s) = line.split(' ') 22 | if p == package: 23 | state = s 24 | break 25 | else: 26 | state = 'not-installed' 27 | 28 | # dpkg-query returns 0 on success. 29 | if proc.returncode != 0: 30 | return None 31 | 32 | return state 33 | 34 | if len(sys.argv) != 2: 35 | print("Usage: dpkg-state ") 36 | sys.exit(1) 37 | package = sys.argv[1] 38 | 39 | status = dpkg_state(package) 40 | if not status: 41 | sys.exit(1) 42 | 43 | print(status) 44 | -------------------------------------------------------------------------------- /files/scripts/sshd.fact: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from __future__ import print_function 4 | from json import dumps 5 | from re import match, IGNORECASE 6 | from sys import exit 7 | 8 | 9 | sshd_facts = [ 10 | {'variable': 'AllowUsers', 11 | 'fact': 'allow_users', 12 | 'default': []}, 13 | {'variable': 'AllowGroups', 14 | 'fact': 'allow_groups', 15 | 'default': []} 16 | ] 17 | 18 | output = {'configured': 'true'} 19 | for item in sshd_facts: 20 | output.update({item['fact']: item['default']}) 21 | 22 | try: 23 | with open("/etc/ssh/sshd_config") as fd: 24 | for line in fd.readlines(): 25 | for item in sshd_facts: 26 | match_fact = match( 27 | r"^" + item['variable'] + " ([ \w]+)", line, flags=IGNORECASE) 28 | if match_fact: 29 | if isinstance(item['default'], list): 30 | output[item['fact']] = match_fact.groups()[0].split() 31 | elif isinstance(item['default'], str): 32 | output[item['fact']] = match_fact.groups()[0] 33 | elif isinstance(item['default'], int): 34 | output[item['fact']] = int(match_fact.groups()[0]) 35 | 36 | except Exception as e: 37 | print("{}") 38 | exit() 39 | 40 | print(dumps(output, sort_keys=True, indent=2)) 41 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Test sshd configuration and restart 4 | command: sshd -t 5 | notify: [ 'Restart sshd' ] 6 | 7 | - name: Restart sshd 8 | service: 9 | name: 'ssh' 10 | state: 'restarted' 11 | -------------------------------------------------------------------------------- /meta/ansigenome.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | ansigenome_info: 4 | galaxy_url: "https://galaxy.ansible.com/debops/sshd" 5 | github_url: "https://github.com/debops/ansible-sshd" 6 | git_branch: "master" 7 | 8 | travis: True 9 | 10 | license_url: 'https://tldrlegal.com/license/gnu-general-public-license-v3-(gpl-3)' 11 | 12 | authors: 13 | - name: 'Maciej Delmanowski' 14 | url: '' 15 | email: 'drybjed@gmail.com' 16 | twitter: 'drybjed' 17 | github: 'drybjed' 18 | 19 | synopsis: | 20 | [OpenSSH](http://www.openssh.com/) is a secure replacement for `telnet` 21 | and other remote control programs. It allows you to connect to remote hosts 22 | over a encrypted communication channel and perform variety of a tasks. It's 23 | also the main communication channel used by Ansible. 24 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | dependencies: 4 | 5 | - role: debops.secret 6 | 7 | galaxy_info: 8 | author: 'Maciej Delmanowski' 9 | description: 'Configure OpenSSH server' 10 | company: 'DebOps' 11 | license: 'GPL-3.0' 12 | min_ansible_version: '2.2.0' 13 | platforms: 14 | - name: Ubuntu 15 | versions: 16 | - precise 17 | - quantal 18 | - raring 19 | - saucy 20 | - trusty 21 | - name: Debian 22 | versions: 23 | - wheezy 24 | - jessie 25 | galaxy_tags: 26 | - ssh 27 | - sshd 28 | - openssh 29 | -------------------------------------------------------------------------------- /tasks/authorized_keys_lookup.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Create OpenSSH lookup system group 4 | group: 5 | name: '{{ sshd__authorized_keys_lookup_group }}' 6 | state: 'present' 7 | system: True 8 | 9 | - name: Create OpenSSH lookup system user 10 | user: 11 | name: '{{ sshd__authorized_keys_lookup_user }}' 12 | group: '{{ sshd__authorized_keys_lookup_group }}' 13 | home: '{{ sshd__authorized_keys_lookup_home }}' 14 | comment: 'OpenSSH Authorized Keys lookup' 15 | shell: '/bin/false' 16 | state: 'present' 17 | createhome: False 18 | append: False 19 | system: True 20 | 21 | - name: Create OpenSSH LDAP bind password file 22 | environment: 23 | ANSIBLE_SSHD_LDAP_BINDPW: '{{ sshd__ldap_bind_pw }}' 24 | shell: echo -n ${ANSIBLE_SSHD_LDAP_BINDPW} > {{ sshd__ldap_bind_pw_file }} ; 25 | chmod 0640 {{ sshd__ldap_bind_pw_file }} ; 26 | chown root.{{ sshd__authorized_keys_lookup_group }} {{ sshd__ldap_bind_pw_file }} 27 | args: 28 | creates: '{{ sshd__ldap_bind_pw_file }}' 29 | when: sshd__authorized_keys_lookup_type|d() and 30 | "ldap" in sshd__authorized_keys_lookup_type 31 | no_log: True 32 | 33 | - name: Create /etc/ssh/authorized_keys_lookup.d directory 34 | file: 35 | path: '/etc/ssh/authorized_keys_lookup.d' 36 | state: 'directory' 37 | owner: 'root' 38 | group: 'root' 39 | mode: '0755' 40 | 41 | - name: Generate authorized keys lookup scripts 42 | template: 43 | src: '{{ lookup("template_src", "etc/ssh/authorized_keys_lookup.d/" + item + ".j2") }}' 44 | dest: '/etc/ssh/authorized_keys_lookup.d/{{ item }}' 45 | owner: 'root' 46 | group: 'root' 47 | mode: '0755' 48 | with_items: '{{ sshd__authorized_keys_lookup_type }}' 49 | when: sshd__authorized_keys_lookup_type|d() 50 | 51 | - name: Generate authorized keys lookup hook 52 | template: 53 | src: 'etc/ssh/authorized_keys_lookup.j2' 54 | dest: '/etc/ssh/authorized_keys_lookup' 55 | owner: 'root' 56 | group: 'root' 57 | mode: '0755' 58 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: Pre hooks 4 | include: '{{ lookup("task_src", "sshd/pre_main.yml") }}' 5 | 6 | - name: Check if OpenSSH is installed (or half-installed) 7 | script: scripts/dpkg-state openssh-server 8 | register: sshd__register_prev_pkg_state 9 | changed_when: False 10 | failed_when: sshd__register_prev_pkg_state.rc != 0 or 11 | sshd__register_prev_pkg_state.stdout|trim not in 12 | ["not-installed", "config-files", 13 | "unpacked", "half-installed", "half-configured", 14 | "triggers-pending", "triggers-awaited", "installed"] 15 | check_mode: False 16 | 17 | - name: Make sure that OpenSSH configuration directory exists 18 | file: 19 | path: '/etc/ssh' 20 | state: 'directory' 21 | owner: 'root' 22 | group: 'root' 23 | mode: '0755' 24 | 25 | - name: Block OpenSSH server from starting immediately when installed 26 | # 27 | # SSH server must not start, until security options are configured! 28 | # http://unix.stackexchange.com/questions/321621/configuring-my-sshd-securely-with-automation 29 | # 30 | # However, SSH might already be configured, started, and in use. 31 | # In this case we should not block it. Something could try to restart 32 | # SSH e.g. unattended-upgrades. We would end up locking ourselves out. 33 | # 34 | # In-between states could result from an failed upgrade. The upgrade is 35 | # retried when we demand a package be installed. The service would be 36 | # restarted, so once again we must not block it. 37 | # 38 | # In-between states could also result from a failed install. We can't 39 | # tell the difference. (Note if the failed install was from this role, 40 | # then we blocked the SSH server already). 41 | # 42 | # Users are responsible for avoiding situations, where a retried install 43 | # starts an SSH server which does not meet their current security 44 | # requirements. Again, the trigger for the retry would be an install 45 | # of _any_ package. This may be considered further illustration of the 46 | # problem with how Debian packages work. It can be prevented by 47 | # remembering to remove the failed package first. Fortunately, it is not 48 | # common for a package to fail to install. 49 | # 50 | # The state "config-files" is the result of `apt-get remove` without 51 | # `--purge`; the SSH server will not be running in this state. 52 | copy: 53 | dest: /etc/ssh/sshd_not_to_be_run 54 | content: | 55 | This file disables the ssh server. It was created by debops.sshd. 56 | This file will be removed when configuration is successfully completed. 57 | when: sshd__register_prev_pkg_state.stdout|trim in 58 | ["not-installed", "config-files"] 59 | 60 | - name: Ensure OpenSSH support is installed 61 | apt: 62 | name: '{{ item }}' 63 | state: '{{ "present" 64 | if (ansible_local|d() and ansible_local.sshd|d()) 65 | else "latest" }}' 66 | install_recommends: False 67 | with_flattened: 68 | - '{{ sshd__base_packages }}' 69 | - '{{ sshd__recommended_packages }}' 70 | - '{{ sshd__optional_packages }}' 71 | - '{{ sshd__ldap_packages }}' 72 | - '{{ sshd__packages }}' 73 | 74 | - name: Check OpenSSH server version 75 | environment: 76 | LC_MESSAGES: 'C' 77 | shell: 'dpkg-query -W -f="\${Version}\n" "openssh-server" | sed -re "s/^.*:([0-9]+\.[0-9]+).*/\1/"' 78 | register: sshd__register_version 79 | changed_when: False 80 | check_mode: False 81 | tags: [ 'role::sshd:config' ] 82 | 83 | - name: Ensure that Ed25519 host key is present 84 | command: ssh-keygen -q -t ed25519 -N "" -f ssh_host_ed25519_key 85 | args: 86 | chdir: '/etc/ssh' 87 | creates: '/etc/ssh/ssh_host_ed25519_key' 88 | when: sshd__register_version.stdout|d() and 89 | sshd__register_version.stdout | version_compare('6.5', '>=') 90 | tags: [ 'role::sshd:config' ] 91 | 92 | - name: Configure authorized_keys lookup 93 | include: authorized_keys_lookup.yml 94 | when: sshd__register_version.stdout|d() and 95 | sshd__register_version.stdout | version_compare('6.2', '>=') and 96 | sshd__authorized_keys_lookup|bool 97 | tags: [ 'role::sshd:config' ] 98 | 99 | - name: Get list of available host keys 100 | shell: find /etc/ssh -maxdepth 1 -type f -name 'ssh_host_*_key.pub' -exec basename {} .pub \; 101 | register: sshd__register_host_keys 102 | changed_when: False 103 | check_mode: False 104 | tags: [ 'role::sshd:config' ] 105 | 106 | - name: Setup /etc/ssh/sshd_config 107 | template: 108 | src: '{{ lookup("template_src", "etc/ssh/sshd_config.j2") }}' 109 | dest: '/etc/ssh/sshd_config' 110 | owner: 'root' 111 | group: 'root' 112 | mode: '0644' 113 | notify: [ 'Test sshd configuration and restart' ] 114 | tags: [ 'role::sshd:config' ] 115 | 116 | - name: Make sure the system-wide known_hosts file exists 117 | copy: 118 | force: False 119 | dest: '{{ sshd__known_hosts_file }}' 120 | content: '' 121 | owner: 'root' 122 | group: 'root' 123 | mode: '0644' 124 | tags: [ 'role::sshd:known_hosts' ] 125 | 126 | - name: Get list of already scanned host fingerprints 127 | shell: ssh-keygen -f {{ sshd__known_hosts_file }} -F {{ item }} | grep -q '^# Host {{ item }} found' 128 | with_flattened: 129 | - '{{ sshd__known_hosts }}' 130 | - '{{ sshd__group_known_hosts }}' 131 | - '{{ sshd__host_known_hosts }}' 132 | when: item is defined and item 133 | register: sshd__register_known_hosts 134 | changed_when: False 135 | failed_when: False 136 | tags: [ 'role::sshd:known_hosts' ] 137 | 138 | - name: Scan SSH fingerprints of specified hosts 139 | shell: '{{ sshd__known_hosts_command }} {{ item.item }} >> {{ sshd__known_hosts_file }}' 140 | with_items: '{{ sshd__register_known_hosts.results|d([]) }}' 141 | when: item is defined and item.rc > 0 142 | tags: [ 'role::sshd:known_hosts' ] 143 | 144 | - name: Check if /etc/ssh/moduli contains weak DH parameters 145 | shell: awk '$5 < {{ sshd__moduli_minimum }}' /etc/ssh/moduli 146 | register: sshd__register_moduli 147 | changed_when: sshd__register_moduli.stdout 148 | check_mode: False 149 | 150 | - name: Remove DH parameters smaller than the requested size 151 | shell: awk '$5 >= {{ sshd__moduli_minimum }}' /etc/ssh/moduli > /etc/ssh/moduli.new ; 152 | [ -r /etc/ssh/moduli.new -a -s /etc/ssh/moduli.new ] && mv /etc/ssh/moduli.new /etc/ssh/moduli || true 153 | notify: [ 'Test sshd configuration and restart' ] 154 | when: sshd__register_moduli.stdout 155 | 156 | - name: Remove block on OpenSSH server startup 157 | file: 158 | name: '/etc/ssh/sshd_not_to_be_run' 159 | state: 'absent' 160 | notify: [ 'Test sshd configuration and restart' ] 161 | 162 | - name: Make sure that Ansible local fact directory exists 163 | file: 164 | path: '/etc/ansible/facts.d' 165 | state: 'directory' 166 | owner: 'root' 167 | group: 'root' 168 | mode: '0755' 169 | 170 | - name: Copy Ansible local fact script 171 | copy: 172 | src: 'scripts/sshd.fact' 173 | dest: '/etc/ansible/facts.d/sshd.fact' 174 | owner: 'root' 175 | group: 'root' 176 | mode: '0755' 177 | register: sshd__register_fact_script 178 | 179 | - name: Reload Ansible local facts 180 | setup: 181 | filter: ansible_local 182 | when: sshd__register_fact_script|changed 183 | 184 | - name: Post hooks 185 | include: '{{ lookup("task_src", "sshd/post_main.yml") }}' 186 | -------------------------------------------------------------------------------- /tasks/sshd/post_main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | -------------------------------------------------------------------------------- /tasks/sshd/pre_main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | -------------------------------------------------------------------------------- /templates/etc/ssh/authorized_keys_lookup.d/ldap.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # {{ ansible_managed }} 4 | 5 | # Lookup SSH public key in LDAP 6 | 7 | username="${1}" 8 | 9 | service="sshd" 10 | hostname="$(hostname)" 11 | domain="$(dnsdomainname)" 12 | fqdn="$(hostname --fqdn)" 13 | 14 | ldap_binddn="{{ sshd__ldap_bind_dn }}" 15 | ldap_bindpw="{{ sshd__ldap_bind_pw_file }}" 16 | 17 | ldap_filter="{{ sshd__ldap_filter }}" 18 | 19 | ATTRIBUTE=$(ldapsearch -LLL -x -y ${ldap_bindpw} -D ${ldap_binddn} -o ldif-wrap=no -S sshPublicKey "${ldap_filter}" sshPublicKey | grep -v 'dn:') 20 | 21 | if [[ $ATTRIBUTE == sshPublicKey::* ]]; 22 | then 23 | KEY=$(echo "$ATTRIBUTE" | perl -pe 's/sshPublicKey:: //;' | base64 -d) 24 | else 25 | KEY=$(echo "$ATTRIBUTE" | perl -pe 's/sshPublicKey: //;') 26 | fi 27 | 28 | [ -n "${KEY}" ] && echo "${KEY}" || true 29 | 30 | -------------------------------------------------------------------------------- /templates/etc/ssh/authorized_keys_lookup.d/sss.j2: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # {{ ansible_managed }} 4 | 5 | # Lookup SSH public key in SSSD 6 | 7 | /usr/bin/sss_ssh_authorizedkeys "${1}" 8 | -------------------------------------------------------------------------------- /templates/etc/ssh/authorized_keys_lookup.j2: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # {{ ansible_managed }} 4 | 5 | # Lookup SSH public keys 6 | 7 | username="${1}" 8 | 9 | if [ -d /etc/ssh/authorized_keys_lookup.d ] ; then 10 | keys="$(/bin/run-parts --arg=${username} /etc/ssh/authorized_keys_lookup.d)" 11 | 12 | [ -n "${keys}" ] && echo "${keys}" || true 13 | fi 14 | 15 | -------------------------------------------------------------------------------- /templates/etc/ssh/sshd_config.j2: -------------------------------------------------------------------------------- 1 | # {{ ansible_managed }} 2 | 3 | {% if sshd__custom_options|d() %} 4 | # Custom options 5 | {{ sshd__custom_options }} 6 | {% endif %} 7 | 8 | # What ports, IPs and protocols we listen for 9 | {% for port in sshd__ports %} 10 | Port {{ port }} 11 | {% endfor %} 12 | {% if sshd__listen|d() %} 13 | 14 | # Use these options to restrict which interfaces/protocols sshd will bind to 15 | {% for address in sshd__listen %} 16 | ListenAddress {{ address }} 17 | {% endfor %} 18 | {% endif %} 19 | 20 | Protocol 2 21 | 22 | # HostKeys for protocol version 2 23 | {% for hostkey in sshd__host_keys %} 24 | {% if ('ssh_host_' + hostkey + '_key') in sshd__register_host_keys.stdout_lines %} 25 | HostKey /etc/ssh/ssh_host_{{ hostkey }}_key 26 | {% endif %} 27 | {% endfor %} 28 | 29 | {% set sshd__tpl_ciphers = [] %} 30 | {% set sshd__tpl_ciphers_match = False %} 31 | {% for key, value in sshd__ciphers_map.iteritems() %} 32 | {% if not sshd__tpl_ciphers_match and 33 | sshd__register_version.stdout|d() and 34 | sshd__register_version.stdout | version_compare(key, '>=') %} 35 | {% set sshd__tpl_ciphers_match = True %} 36 | {% for element in value %} 37 | {% set _ = sshd__tpl_ciphers.append(element) %} 38 | {% endfor %} 39 | {% endif %} 40 | {% endfor %} 41 | {% set sshd__tpl_ciphers = (sshd__tpl_ciphers + sshd__ciphers_additional) | unique %} 42 | {% if sshd__tpl_ciphers and sshd__paranoid|bool %} 43 | Ciphers {{ ([ sshd__tpl_ciphers|first ] + sshd__ciphers_additional) | unique | join(",") }} 44 | 45 | {% elif sshd__tpl_ciphers %} 46 | Ciphers {{ sshd__tpl_ciphers | join(",") }} 47 | 48 | {% endif %} 49 | {% set sshd__tpl_kex_algorithms = [] %} 50 | {% set sshd__tpl_kex_algorithms_match = False %} 51 | {% for key, value in sshd__kex_algorithms_map.iteritems() %} 52 | {% if not sshd__tpl_kex_algorithms_match and 53 | sshd__register_version.stdout|d() and 54 | sshd__register_version.stdout | version_compare(key, '>=') %} 55 | {% set sshd__tpl_kex_algorithms_match = True %} 56 | {% for element in value %} 57 | {% set _ = sshd__tpl_kex_algorithms.append(element) %} 58 | {% endfor %} 59 | {% endif %} 60 | {% endfor %} 61 | {% set sshd__tpl_kex_algorithms = (sshd__tpl_kex_algorithms + sshd__kex_algorithms_additional) | unique %} 62 | {% if sshd__tpl_kex_algorithms and sshd__paranoid|bool %} 63 | KexAlgorithms {{ ([ sshd__tpl_kex_algorithms|first ] + sshd__kex_algorithms_additional) | unique | join(",") }} 64 | 65 | {% elif sshd__tpl_kex_algorithms %} 66 | KexAlgorithms {{ sshd__tpl_kex_algorithms | join(",") }} 67 | 68 | {% endif %} 69 | {% set sshd__tpl_macs = [] %} 70 | {% set sshd__tpl_macs_match = False %} 71 | {% for key, value in sshd__macs_map.iteritems() %} 72 | {% if not sshd__tpl_macs_match and 73 | sshd__register_version.stdout|d() and 74 | sshd__register_version.stdout | version_compare(key, '>=') %} 75 | {% set sshd__tpl_macs_match = True %} 76 | {% for element in value %} 77 | {% set _ = sshd__tpl_macs.append(element) %} 78 | {% endfor %} 79 | {% endif %} 80 | {% endfor %} 81 | {% set sshd__tpl_macs = (sshd__tpl_macs + sshd__macs_additional) | unique %} 82 | {% if sshd__tpl_macs and sshd__paranoid|bool %} 83 | MACs {{ ([ sshd__tpl_macs|first ] + sshd__macs_additional) | unique | join(",") }} 84 | 85 | {% elif sshd__tpl_macs %} 86 | MACs {{ sshd__tpl_macs | join(",") }} 87 | 88 | {% endif %} 89 | # Privilege Separation is turned on for security 90 | UsePrivilegeSeparation {{ sshd__privilege_separation }} 91 | 92 | {% if sshd__register_version.stdout | version_compare('7.4', '<') %} 93 | # Lifetime and size of ephemeral version 1 server key 94 | KeyRegenerationInterval 3600 95 | ServerKeyBits 1024 96 | 97 | {% endif %} 98 | # Logging 99 | SyslogFacility AUTH 100 | LogLevel {{ sshd__log_level }} 101 | 102 | MaxAuthTries {{ sshd__max_auth_tries }} 103 | MaxStartups {{ sshd__max_startups }} 104 | LoginGraceTime {{ sshd__login_grace_time }} 105 | 106 | # Authentication: 107 | PermitRootLogin {{ sshd__permit_root_login }} 108 | StrictModes yes 109 | 110 | {% if sshd__register_version.stdout | version_compare('7.4', '<') %} 111 | RSAAuthentication yes 112 | {% endif %} 113 | PubkeyAuthentication yes 114 | 115 | {% if sshd__authorized_keys_lookup|bool and 116 | sshd__register_version.stdout|d() and 117 | sshd__register_version.stdout | version_compare('6.2', '>=') %} 118 | AuthorizedKeysCommand /etc/ssh/authorized_keys_lookup 119 | AuthorizedKeysCommandUser {{ sshd__authorized_keys_lookup_user }} 120 | 121 | {% endif %} 122 | AuthorizedKeysFile {{ sshd__authorized_keys | join(" ") }} 123 | 124 | # Don't read the user's ~/.rhosts and ~/.shosts files 125 | IgnoreRhosts yes 126 | 127 | {% if sshd__register_version.stdout | version_compare('7.4', '<') %} 128 | # For this to work you will also need host keys in /etc/ssh_known_hosts 129 | RhostsRSAAuthentication no 130 | 131 | {% endif %} 132 | # similar for protocol version 2 133 | HostbasedAuthentication no 134 | 135 | # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication 136 | #IgnoreUserKnownHosts yes 137 | 138 | # To enable empty passwords, change to yes (NOT RECOMMENDED) 139 | PermitEmptyPasswords no 140 | 141 | # Change to yes to enable challenge-response passwords (beware issues with 142 | # some PAM modules and threads) 143 | ChallengeResponseAuthentication no 144 | 145 | # Change to no to disable tunnelled clear text passwords 146 | PasswordAuthentication {{ sshd__password_authentication }} 147 | 148 | # Kerberos options 149 | #KerberosAuthentication no 150 | #KerberosGetAFSToken no 151 | #KerberosOrLocalPasswd yes 152 | #KerberosTicketCleanup yes 153 | 154 | # GSSAPI options 155 | #GSSAPIAuthentication no 156 | #GSSAPICleanupCredentials yes 157 | 158 | X11Forwarding {{ sshd__x11_forwarding }} 159 | X11DisplayOffset 10 160 | PrintMotd no 161 | PrintLastLog yes 162 | TCPKeepAlive yes 163 | #UseLogin no 164 | 165 | Banner {{ sshd__banner }} 166 | 167 | # Allow client to pass locale environment variables 168 | AcceptEnv {{ sshd__accept_env | sort | join(" ") }} 169 | 170 | Subsystem sftp internal-sftp 171 | 172 | # Set this to 'yes' to enable PAM authentication, account processing, 173 | # and session processing. If this is enabled, PAM authentication will 174 | # be allowed through the ChallengeResponseAuthentication and 175 | # PasswordAuthentication. Depending on your PAM configuration, 176 | # PAM authentication via ChallengeResponseAuthentication may bypass 177 | # the setting of "PermitRootLogin without-password". 178 | # If you just want the PAM account and session checks to run without 179 | # PAM authentication, then enable this but set PasswordAuthentication 180 | # and ChallengeResponseAuthentication to 'no'. 181 | UsePAM yes 182 | 183 | {% if sshd__allow_groups|d() or sshd__group_allow_groups|d() or sshd__host_allow_groups|d() %} 184 | AllowGroups {{ ( 185 | (sshd__allow_groups|d([]) | list) + 186 | (sshd__group_allow_groups|d([]) | list) + 187 | (sshd__host_allow_groups|d([]) | list)) | unique | join(" ") }} 188 | 189 | {% endif %} 190 | 191 | {% for entry in sshd__match_list|d([]) %} 192 | {% if entry.match|d() and entry.options|d() %} 193 | Match {{ entry.match }} 194 | {{ entry.options | indent(8, true) }} 195 | 196 | {% endif %} 197 | {% endfor %} 198 | --------------------------------------------------------------------------------