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

Commit bb1e094

Browse files
author
Sebastian Gumprich
committed
parameterize PermitRootLogin
1 parent 833a173 commit bb1e094

File tree

8 files changed

+62
-6
lines changed

8 files changed

+62
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Warning: This role disables root-login on the target server! Please make sure yo
2626
|`ssh_client_alive_count` | 3 | defines how often keep-alive messages are sent |
2727
|`ssh_permit_tunnel` | false | true if SSH Port Tunneling is required |
2828
|`ssh_remote_hosts` | [] | one or more hosts and their custom options for the ssh-client. Default is empty. See examples in `defaults/main.yml`.|
29-
|`ssh_allow_root_with_key` | false | false to disable root login altogether. Set to true to allow root to login via key-based mechanism.|
29+
|`ssh_permit_root_login` | no | Disable root-login. Set to `without-password` or `yes` to enable root-login |
3030
|`ssh_allow_tcp_forwarding` | false | false to disable TCP Forwarding. Set to true to allow TCP Forwarding.|
3131
|`ssh_gateway_ports` | `false` | `false` to disable binding forwarded ports to non-loopback addresses. Set to `true` to force binding on wildcard address. Set to `clientspecified` to allow the client to specify which address to bind to.|
3232
|`ssh_allow_agent_forwarding` | false | false to disable Agent Forwarding. Set to true to allow Agent Forwarding.|

defaults/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ ssh_permit_tunnel: false
4848
# options: ['StrictHostKeyChecking no']
4949
ssh_remote_hosts: []
5050

51-
# false to disable root login altogether. Set to true to allow root to login via key-based mechanism.
52-
ssh_allow_root_with_key: false # sshd
51+
# Set this to "without-password" or "yes" to allow root to login
52+
ssh_permit_root_login: 'no' # sshd
5353

5454
# false to disable TCP Forwarding. Set to true to allow TCP Forwarding.
5555
ssh_allow_tcp_forwarding: false # sshd

molecule/default/molecule.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
dependency:
3+
name: galaxy
4+
driver:
5+
name: docker
6+
lint:
7+
name: yamllint
8+
options:
9+
config-file: molecule/default/yaml-lint.yml
10+
platforms:
11+
- name: instance
12+
image: "rndmh3ro/docker-centos7-ansible:latest"
13+
command: ${MOLECULE_DOCKER_COMMAND:-""}
14+
volumes:
15+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
16+
privileged: true
17+
pre_build_image: true
18+
provisioner:
19+
name: ansible
20+
lint:
21+
name: ansible-lint
22+
scenario:
23+
name: default
24+
verifier:
25+
name: testinfra
26+
lint:
27+
name: flake8

molecule/default/playbook.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
- name: wrapper playbook for kitchen testing "ansible-ssh-hardening" with default settings
3+
hosts: all
4+
become: true
5+
pre_tasks:
6+
- package: name="{{item}}" state=present
7+
with_items:
8+
- "openssh-clients"
9+
- "openssh-server"
10+
ignore_errors: true
11+
- apt: name="{{item}}" state=present update_cache=true
12+
with_items:
13+
- "openssh-client"
14+
- "openssh-server"
15+
ignore_errors: true
16+
- file: path="/var/run/sshd" state=directory
17+
- name: create ssh host keys
18+
command: "ssh-keygen -A"
19+
when: not ((ansible_os_family in ['Oracle Linux', 'RedHat']) and ansible_distribution_major_version < '7')
20+
21+
roles:
22+
- ansible-ssh-hardening

molecule/default/yaml-lint.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
extends: default
3+
rules:
4+
line-length:
5+
max: 150
6+
level: warning

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
molecule

templates/opensshd.conf.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# Basic configuration
77
# ===================
88

9-
# Either disable or only allowssh root login via certificates.
10-
PermitRootLogin {{ 'without-password' if (ssh_allow_root_with_key|bool) else 'no' }}
9+
# Either disable or only allow root login via certificates.
10+
PermitRootLogin {{ ssh_permit_root_login }}
1111

1212
# Define which port sshd should listen to. Default to `22`.
1313
{% for port in ssh_server_ports -%}

tests/default_custom.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
- ansible-ssh-hardening
2222
vars:
2323
network_ipv6_enable: true
24-
ssh_allow_root_with_key: true
2524
ssh_allow_tcp_forwarding: true
2625
ssh_gateway_ports: true
2726
ssh_allow_agent_forwarding: true
@@ -37,6 +36,7 @@
3736
ssh_deny_groups: 'foo bar'
3837
ssh_authorized_keys_file: '/etc/ssh/authorized_keys/%u'
3938
ssh_max_auth_retries: 10
39+
ssh_permit_root_login: "without-password"
4040
ssh_permit_tunnel: true
4141
ssh_print_motd: true
4242
ssh_print_last_log: true

0 commit comments

Comments
 (0)