Skip to content
This repository has been archived by the owner on Dec 26, 2020. It is now read-only.

Fix ssh config to handle custom options per Host #83

Merged
merged 1 commit into from
Mar 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Warning: This role disables root-login on the target server! Please make sure yo
|`ssh_host_key_files` | ['/etc/ssh/ssh_host_rsa_key', '/etc/ssh/ssh_host_dsa_key', '/etc/ssh/ssh_host_ecdsa_key'] |Host keys to look for when starting sshd.|
|`ssh_client_alive_interval` | 600 | specifies an interval for sending keepalive messages |
|`ssh_client_alive_count` | 3 | defines how often keep-alive messages are sent |
|`ssh_remote_hosts` | [] | one or more hosts, to which ssh-client can connect to. Default is empty, but should be configured for security reasons!|
|`ssh_remote_hosts` | [] | one or more hosts and their custom options for the ssh-client. Default is empty. See examples in `defaults/main.yml`.|
|`ssh_allow_root_with_key` | false | false to disable root login altogether. Set to true to allow root to login via key-based mechanism.|
|`ssh_allow_tcp_forwarding` | false | false to disable TCP Forwarding. Set to true to allow TCP Forwarding.|
|`ssh_allow_agent_forwarding` | false | false to disable Agent Forwarding. Set to true to allow Agent Forwarding.|
Expand Down
19 changes: 18 additions & 1 deletion default.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: wrapper playbook for kitchen testing "ansible-ssh-hardening" with default settings
- name: wrapper playbook for kitchen testing "ansible-ssh-hardening" with custom settings
hosts: localhost
pre_tasks:
- package: name="{{item}}" state=installed
Expand All @@ -15,3 +15,20 @@
- file: path="/var/run/sshd" state=directory
roles:
- ansible-ssh-hardening
vars:
network_ipv6_enable: true
ssh_allow_root_with_key: true
ssh_client_password_login: true
ssh_client_cbc_required: true
ssh_server_weak_hmac: true
ssh_client_weak_kex: true
ssh_remote_hosts:
- names: ['example.com', 'example2.com']
options: ['Port 2222', 'ForwardAgent yes']
- names: ['example3.com']
options: ['StrictHostKeyChecking no']

- name: wrapper playbook for kitchen testing "ansible-ssh-hardening" with default settings
hosts: localhost
roles:
- ansible-ssh-hardening
12 changes: 10 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,16 @@ ssh_max_auth_retries: 2

ssh_client_alive_interval: 600 # sshd
ssh_client_alive_count: 3 # sshd
# one or more hosts, to which ssh-client can connect to. Default is empty, but should be configured for security reasons!
ssh_remote_hosts: [] # ssh

# Hosts with custom options. # ssh
# Example:
# ssh_remote_hosts:
# - names: ['example.com', 'example2.com']
# options: ['Port 2222', 'ForwardAgent yes']
# - names: ['example3.com']
# options: ['StrictHostKeyChecking no']
ssh_remote_hosts: []

# false to disable root login altogether. Set to true to allow root to login via key-based mechanism.
ssh_allow_root_with_key: false # sshd

Expand Down
14 changes: 11 additions & 3 deletions templates/openssh.conf.j2
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,18 @@

# Address family should always be limited to the active network configuration.
AddressFamily {{ 'any' if network_ipv6_enable else 'inet' }}
# Restrict the following configuration to be limited to this Host.

{% for host in ssh_remote_hosts -%}
Host {{host}}
{% endfor %}
{% if loop.first %}
# Host-specific configuration
{% endif %}
Host {{ host.names | join(' ') }}
{{ host.options | join("\n") | indent(2) }}

{% endfor -%}

# Global defaults for all Hosts
Host *

# The port at the destination should be defined
{% for port in ssh_client_ports -%}
Expand Down