Skip to content

Commit

Permalink
pull changes (#1)
Browse files Browse the repository at this point in the history
* use new docker images

* rm 1.9 from travis

* use centos 7 in vagrant, limit ssh conns

* use new docker images

* Replace deprecated always_run with check_mode

* Add Ed25519 SSH host key to match commit 28b4df3 in ssh-baseline InSpec profile

* update min ansible version

* Remove small dh primes

Thanks to debops!
https://github.com/debops/ansible-sshd/

* update travis to test debian 8

* change hostkey setting

* use sed isntead of perl

* fix order

* update readme

* remove debian9

Errors unrelated to this PR in travis, fill be fixed later

* actually remove debian 9

* make ChallengeResponseAuthentication configurable

* Add support for FreeBSD OpenSSH server and client

* List only one Port in ssh config

Only one Port will be used, so don't loop over a list of Ports.

* Fix ssh config to handle custom options per Host

Formerly printed Hosts on successive lines, applying all options
to the final Host only.

* Accommodate missing plugins in kitchen_vagrant_block.rb

Prevents Vagrant failures: 'Unknown configuration section <name>'.
Also accommodate missing http_proxy environment variable,
which will be nil and have no `empty?` method.

* remove duplicate section

* update changelog

* update changelog

* Adds option to set whether password authentication is allowed with sshd.

* Updates documentation.

* Added support for UseDNS config switch

* Added support for UseDNS config switch

* Added support for PermitTunnel config switch

* release new version 4.1.0

* fix validation error

* update changelog

* Template additional configuration options

All additional options are backwards compatible, and should not
introduce any unwanted vulnerability or side effect.

* PermitUserEnvironment/AcceptEnv now supports a list of accepted
  environment variables from the client.
* Compression is now configurable.
* UseDNS is now configurable.
* Both Match Group and Match User are now configurable.
* SSHD now supports being enabled and started.

* Only restart service when SSH is enabled

* finish PR

* remove 12.04 as its EOLd

* remove 12.04 as its EOLd for travis

* Update README.md

* added check_mode: no to "get openssh-version" task, so it won't fail in check-mode

* update changelog

* change vars to bool, put comments inside block

* Do not use shell when not needed + Lint whitespaces

* remove support for 12.04

* remove support for 12.04

* add back play

* use package instead of yum so the operation works on Fedora

* Adding in support for google authenticator TOTP.

This adds the PAM module package, changes the SSHd configuration and the
PAM configuration on RedHat and Debian systems to allow TOTP based
second factor auth to work with SSH keys.

* Add support to specify a list of revoked public keys

Signed-off-by: Pascal Bach <pascal.bach@siemens.com>

* update changelog

* Add comment filter to {{ansible_managed}} string

Multiline {{ansible_managed}} strings do not get properly commented
without the comment filter.
See http://docs.ansible.com/ansible/playbooks_filters.html#comment-filter

* Fix ansible.cfg settings

- using %Y-%m-%d in ansible_managed message is not recommended
as deploying from a new git checkout will change the ansible_managed
string in the template and Ansible will report the template file as changed
(see http://docs.ansible.com/ansible/intro_configuration.html#ansible-managed )
- no such setting called role_path (see
http://docs.ansible.com/ansible/intro_configuration.html )
- scp_if_ssh should be under [ssh_connection] header

* Finish the RedHat support.

This will remove password auth from RedHat distros to ensure that only
key based auth and 2FA codes can be used to authenticate users over SSH.

* Cannot have password auth when password is disabled.

* Moving the Google Auth section.

I had accidently placed this under an SELinux block rather than at the
end of it as I had planned. Now placed before the SELinux block to be
clear.

* Setting google auth to be off by default.

This will allow the current tests to run as they are failing because
this is not defined. A better step would be to add some tests.

* Don't overwrite ssh_host_key_files if set manually

before the manually set `ssh_host_key_files` would be overwritten if the openssh-version was greater than 5.3

* add bool checks to all relevant variables

* more bools

* update changelog

* Moving over to using Ansible PAM support.

Using the Ansible PAM support rather than regex based line editing for
two out of the three PAM changes required for 2FA support.

The last change does not appear to be supported by the Ansible PAM
support unless I have missed something from the documentation.

* Adding comment to config file.

This makes it clear why the ordering is public key then keyboard
interactive.

* Remove duplicate ssh_use_dns

ssh_use_dns was set twice in defaults/main.yml. This patch removes the last occurrence.

* update changelog

* corrected comments explaining the task's behaviour

* update default.yml because of broken travis

* update default.yml because of broken travis

* update default.yml because of broken travis

* force /bin/sh when getting openssh-version

(since the update to ansible 2.4.0.0) the C shell is used
on FreeBSD to run shell  tasks.  This breakes the
redirect.

Forcing /bin/sh fixes this.

* Added support for AuthorizedKeysFile config setting

* allow configuration of GatewayPorts

* Issue dev-sec#137: Fix sshd_config's "Match Group sftponly"

The "sftponly" Match Group in the sshd_config was not indented properly, so the settings that should only apply to sftp connections were overriding the global settings earlier in the file.

* test gateway ports var

* simplify macs, kex, ciphers

* divide plays to workaround gathered facts

* add ssh7.6 support

* change ssh.conf, add comments

* Remove deprecated UseLogin option

Since OpenSSH 7.4/7.4p1 (2016-12-19)[0] (The default in Debian Stretch,
CentOS 7 and others) the "UseLogin" option has been deprecated.

Setting this option originally prevented usage of a "traditional"
/usr/sbin/login-based login – but has been set to "no" by default since
quite a while, so even if this role would be applied on a host with an
older OpenSSH version, the default value should still be save.

Fixes dev-sec#140

0. https://www.openssh.com/txt/release-7.4

* remove uselogin-check

* remove merge conflict line

* fix lineending

* update MACs

* update changelog

* Add support for Amazon Linux

* Fixed trailing whitespace

* add amazon linux to travis and kitchen

* change init path on amazon

* change init path on amazon

* Update syntax to 2.4

* new parameter: ssh_max_startups

use this parameter to set 'MaxStartups' in sshd_config

* conform to current dev-sec/ssh-baseline

* Update README.md

* Use package state 'present' since 'installed' is deprecated

* Adds sshd config for keyboard-interactive pam device

- Adds configuration option for public key authentication with 2FA input
from a PAM device such as a Yubikey. This will allow keyboard
interaction from the _device only_. See the documentation on
AuthenticationMethods
[here](https://www.freebsd.org/cgi/man.cgi?sshd_config(5)).

* Added support for TrustedUserCAKeys and AuthorizedPrincipalsFile.

* ca keys & principals are now handle in a separated tasks file

* add examples for ssh_trusted_user_ca_keys & ssh_authorized_principals variables

* Handle a few deprecated OpenSSH options

RhostsRSAAuthentication + RSAAuthentication is deprecated as of 7.4
UsePrivilegeSeparation is deprecated as of 7.5 (the daemon is now
sandboxed on all modern OSes/platforms by default)

* Convert sshd_version.stdout string to float

Resolves error: '<' not supported between instances of 'AnsibleUnicode' and 'float'

* Deprecate UseRoaming after OpenSSH 7.1

* update readme for sftp, fix dev-sec#165

* Update README.md

* Update README.md

* Implement disabling chroot for sftp

By default enabled, of course, but give the option to disable sftp
chrooting.
  • Loading branch information
mkgin committed Jun 8, 2018
1 parent 45a464b commit 9892bd4
Show file tree
Hide file tree
Showing 28 changed files with 947 additions and 299 deletions.
12 changes: 1 addition & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
README.pdf
README.html
shared_test_repo/
test/integration
.kitchen
coverage
Vagrantfile.erb

Gemfile.lock
Berksfile.lock

ansible.cfg
hosts
Gemfile.lock
38 changes: 27 additions & 11 deletions .kitchen.vagrant.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
---
driver:
name: vagrant
driver_config:
http_proxy: <%= ENV['http_proxy'] || nil %>
https_proxy: <%= ENV['https_proxy'] || nil %>
vagrantfiles:
- kitchen_vagrant_block.rb

provisioner:
name: ansible_playbook
test_repo_uri: https://github.com/hardening-io/tests-ssh-hardening.git
hosts: all
require_ansible_repo: false
require_ansible_omnibus: true
Expand All @@ -13,6 +17,11 @@ provisioner:
ansible_verbose: true
roles_path: ../ansible-ssh-hardening/
playbook: default.yml
http_proxy: <%= ENV['http_proxy'] || nil %>
https_proxy: <%= ENV['https_proxy'] || nil %>

transport:
max_ssh_sessions: 5

platforms:
- name: ubuntu-12.04
Expand All @@ -23,14 +32,25 @@ platforms:
driver_config:
box: opscode-ubuntu-14.04
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-14.04_chef-provisionerless.box
- name: ubuntu-16.04
driver_config:
box: opscode-ubuntu-16.04
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_ubuntu-16.04_chef-provisionerless.box
- name: centos-6.4
- name: centos-7.2
driver_config:
box: opscode-centos-6.4
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_centos-6.4_provisionerless.box
box: opscode-centos-7.2
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-7.2_chef-provisionerless.box
- name: centos-6.5
driver_config:
box: opscode-centos-6.5
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_centos-6.5_chef-provisionerless.box
- name: centos-6.8
driver_config:
box: bento/centos-6.8
- name: centos-7
driver_config:
box: bento/centos-7.2
- name: oracle-6.4
driver_config:
box: oracle-6.4
Expand All @@ -39,10 +59,9 @@ platforms:
driver_config:
box: oracle-6.5
box_url: https://storage.us2.oraclecloud.com/v1/istoilis-istoilis/vagrant/oel65-64.box
- name: debian-6
- name: oracle-7
driver_config:
box: debian-6
box_url: https://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_debian-6.0.10_chef-provisionerless.box
box: boxcutter/ol72
- name: debian-7
driver_config:
box: debian-7
Expand All @@ -56,10 +75,7 @@ verifier:
name: inspec
sudo: true
inspec_tests:
- https://github.com/dev-sec/tests-ssh-hardening
- https://github.com/dev-sec/ssh-baseline/

suites:
- name: ssh-ansible_1.9
provisioner:
ansible_version: 1.9.4
- name: ssh-ansible_latest
- name: ssh
72 changes: 45 additions & 27 deletions .kitchen.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,78 @@
---
driver:
name: docker
privileged: true
use_sudo: false
provision_command:
- "mkdir /var/run/sshd"
privileged: true
http_proxy: <%= ENV['http_proxy'] || nil %>
https_proxy: <%= ENV['https_proxy'] || nil %>

transport:
max_ssh_sessions: 5

provisioner:
name: ansible_playbook
hosts: all
require_ansible_repo: false
require_ansible_omnibus: true
require_chef_for_busser: false
require_ruby_for_busser: false
ansible_verbose: true
ansible_diff: true
hosts: all
roles_path: ../ansible-ssh-hardening/
http_proxy: <%= ENV['http_proxy'] || nil %>
https_proxy: <%= ENV['https_proxy'] || nil %>
playbook: default.yml
ansible_diff: true
ansible_extra_flags:
- "--skip-tags=sysctl"

platforms:
- name: ubuntu-12.04
- name: centos6-ansible-latest
driver:
image: rndmh3ro/docker-centos6-ansible:latest
platform: centos
- name: centos7-ansible-latest
driver:
image: ubuntu:12.04
- name: ubuntu-14.04
image: rndmh3ro/docker-centos7-ansible:latest
platform: centos
- name: oracle6-ansible-latest
driver:
image: ubuntu:14.04
- name: ubuntu-16.04
image: rndmh3ro/docker-oracle6-ansible:latest
platform: centos
- name: oracle7-ansible-latest
driver:
image: ubuntu:16.04
- name: centos-6.6
image: rndmh3ro/docker-oracle7-ansible:latest
platform: centos
- name: ubuntu1404-ansible-latest
driver:
image: centos:6.6
- name: centos-6.7
image: rndmh3ro/docker-ubuntu1404-ansible:latest
platform: ubuntu
- name: ubuntu1604-ansible-latest
driver:
image: centos:6.7
- name: centos-7
image: rndmh3ro/docker-ubuntu1604-ansible:latest
platform: ubuntu
- name: debian7-ansible-latest
driver:
image: centos:7
privileged: true
run_command: /usr/sbin/init
- name: debian-7
image: rndmh3ro/docker-debian7-ansible:latest
platform: debian
- name: debian8-ansible-latest
driver:
image: debian:7
- name: debian-8
image: rndmh3ro/docker-debian8-ansible:latest
platform: debian
#- name: debian9-ansible-latest
# driver:
# image: rndmh3ro/docker-debian9-ansible:latest
# platform: debian
- name: amazon-ansible-latest
driver:
image: debian:8
image: rndmh3ro/docker-amazon-ansible:latest
platform: centos

verifier:
name: inspec
sudo: true
inspec_tests:
- https://github.com/dev-sec/tests-ssh-hardening
- https://github.com/dev-sec/ssh-baseline

suites:
- name: ssh-ansible_1.9
provisioner:
ansible_version: 1.9.4
- name: ssh-ansible_latest
- name: ssh
76 changes: 61 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,68 @@
---
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
language: python
python: "2.7"
services: docker

env:
- ANSIBLE_VERSION=latest
- ANSIBLE_VERSION=1.9.4
- distro: centos6
version: latest
init: /sbin/init

- distro: centos7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
version: latest

- distro: oracle6
version: latest
init: /sbin/init

- distro: oracle7
init: /usr/lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
version: latest

- distro: ubuntu1604
version: latest
init: /lib/systemd/systemd
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"

- distro: ubuntu1404
version: latest
init: /sbin/init

- distro: debian7
version: latest
init: /sbin/init

- distro: debian8
version: latest
run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"
init: /sbin/init

# - distro: debian9
# version: latest
# init: /lib/systemd/systemd
# run_opts: "--privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup:ro"

- distro: amazon
init: /sbin/init
version: latest

before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq python-apt python-pycurl
install:
- if [ "$ANSIBLE_VERSION" = "latest" ]; then pip install ansible; else pip install ansible==$ANSIBLE_VERSION; fi
- echo -e 'localhost ansible_connection=local' > spec/inventory
- echo -e '[defaults]\nroles_path = ../\nhostfile = ./spec/inventory' > ansible.cfg
# Pull container
- 'docker pull rndmh3ro/docker-${distro}-ansible:${version}'

script:
- ansible-playbook --syntax-check spec/travis.yml
- ansible-playbook --sudo -v --diff spec/travis.yml
- ansible-playbook --sudo -v --diff spec/travis.yml --extra-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 sftp_enabled=true"
- container_id=$(mktemp)
# Run container in detached state.
- 'docker run --detach --volume="${PWD}":/etc/ansible/roles/ansible-ssh-hardening:ro ${run_opts} rndmh3ro/docker-${distro}-ansible:${version} "${init}" > "${container_id}"'

# Test role.
- 'docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/ansible-ssh-hardening/default_custom.yml'
- 'docker exec "$(cat ${container_id})" ansible-playbook /etc/ansible/roles/ansible-ssh-hardening/default.yml'

# Verify role
# remove the UseLogin-check, see here for reasons: https://github.com/dev-sec/ansible-ssh-hardening/pull/141
- 'inspec exec https://github.com/dev-sec/ssh-baseline/ -t docker://$(cat ${container_id}) --controls=sshd-01 sshd-02 sshd-03 sshd-04 sshd-05 sshd-06 sshd-07 sshd-08 sshd-09 sshd-10 sshd-11 sshd-12 sshd-13 sshd-14 sshd-16 sshd-17 sshd-18 sshd-19 sshd-20 sshd-21 sshd-22 sshd-23 sshd-24 sshd-25 sshd-26 sshd-27 sshd-28 sshd-29 sshd-30 sshd-31 sshd-32 sshd-33 sshd-34 sshd-35 sshd-36 sshd-37 sshd-38 sshd-39 sshd-40'

notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

0 comments on commit 9892bd4

Please sign in to comment.