Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add testing for OpenBSD and FreeBSD #642

Merged
merged 28 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
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
52 changes: 52 additions & 0 deletions .github/workflows/ssh_hardening_bsd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
name: "devsec.ssh_hardening BSD"
on: # yamllint disable-line rule:truthy
workflow_dispatch:
push:
branches: [master]
paths:
- 'roles/ssh_hardening/**'
- 'molecule/ssh_hardening_bsd/**'
- '.github/workflows/ssh_hardening_bsd.yml'
pull_request:
branches: [master]
paths:
- 'roles/ssh_hardening/**'
- 'molecule/ssh_hardening_bsd/**'
- '.github/workflows/ssh_hardening_bsd.yml'
schedule:
- cron: '0 6 * * 5'

concurrency:
group: >-
${{ github.workflow }}-${{
github.event.pull_request.number || github.sha
}}
cancel-in-progress: true

jobs:
build:
runs-on: self-hosted
env:
PY_COLORS: 1
ANSIBLE_FORCE_COLOR: 1
strategy:
fail-fast: false
matrix:
molecule_distro:
- openbsd7
- freebsd12
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
path: ansible_collections/devsec/hardening
submodules: true

- name: Test with molecule
run: |
molecule --version
molecule test -s ssh_hardening_bsd
env:
MOLECULE_DISTRO: ${{ matrix.molecule_distro }}
working-directory: ansible_collections/devsec/hardening
22 changes: 22 additions & 0 deletions molecule/ssh_hardening_bsd/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
*******
Docker driver installation guide
*******

Requirements
============

* Docker Engine

Install
=======

Please refer to the `Virtual environment`_ documentation for installation best
practices. If not using a virtual environment, please consider passing the
widely recommended `'--user' flag`_ when invoking ``pip``.

.. _Virtual environment: https://virtualenv.pypa.io/en/latest/
.. _'--user' flag: https://packaging.python.org/tutorials/installing-packages/#installing-to-the-user-site

.. code-block:: bash
$ python3 -m pip install 'molecule[docker]'
14 changes: 14 additions & 0 deletions molecule/ssh_hardening_bsd/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
- name: wrapper playbook for kitchen testing "ansible-ssh-hardening" with default settings
hosts: all
environment:
http_proxy: "{{ lookup('env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('env', 'https_proxy') | default(omit) }}"
no_proxy: "{{ lookup('env', 'no_proxy') | default(omit) }}"
collections:
- devsec.hardening
tasks:
- include_role:
name: ssh_hardening
vars:
sftp_enabled: false
62 changes: 62 additions & 0 deletions molecule/ssh_hardening_bsd/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
dependency:
name: galaxy
options:
role-file: molecule/ssh_hardening_bsd/requirements.yml
driver:
name: vagrant
provider:
name: libvirt
platforms:
# we need to name every instance differntly to start multiple VMs on the same host (parallelization)
# since we also need to use different OS users to run the tests because of how molecule operates,
# the VM names must be predictable by OS user (to clean up canceled runs)
- name: "${USER}"
box: "generic/${MOLECULE_DISTRO}"
memory: 1024
cpus: 2
provisioner:
name: ansible
options:
diff: true
env:
ANSIBLE_PIPELINING: "True"
config_options:
defaults:
interpreter_python: auto_silent
callback_whitelist: profile_tasks, timer, yaml
verifier:
name: ansible
env:
ANSIBLE_PIPELINING: "True"

scenario:
create_sequence:
- dependency
- create
- prepare
check_sequence:
- dependency
- destroy
- create
- prepare
- converge
- check
- destroy
converge_sequence:
- dependency
- create
- prepare
- converge
destroy_sequence:
- destroy
test_sequence:
- dependency
- destroy
- syntax
- create
- prepare
- converge
- idempotence
- verify
- destroy
32 changes: 32 additions & 0 deletions molecule/ssh_hardening_bsd/prepare.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
- name: prepare OpenBSD host
hosts: all
become: true
gather_facts: false
tasks:
- name: install python
# BSDs are special for Ansible - https://docs.ansible.com/ansible/latest/os_guide/intro_bsd.html
raw: "pkg_add python%3.10"
when: "lookup('env', 'MOLECULE_DISTRO') == 'openbsd7'"

- name: wrapper playbook for kitchen testing "ansible-ssh-hardening" with default settings
hosts: all
become: true
environment:
http_proxy: "{{ lookup('env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('env', 'https_proxy') | default(omit) }}"
no_proxy: "{{ lookup('env', 'no_proxy') | default(omit) }}"
tasks:
- name: created needed directory
file:
path: "/var/run/sshd"
state: directory

- name: create ssh host keys # noqa ignore-errors
command: "ssh-keygen -A"
when: not ((ansible_facts.os_family in ['Oracle Linux', 'RedHat']) and ansible_facts.distribution_major_version < '7') or
ansible_facts.distribution == "Fedora" or
ansible_facts.distribution == "Amazon" or
ansible_facts.os_family == "Suse"
changed_when: false
ignore_errors: true
3 changes: 3 additions & 0 deletions molecule/ssh_hardening_bsd/requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
roles:
- geerlingguy.git
55 changes: 55 additions & 0 deletions molecule/ssh_hardening_bsd/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
- name: OpenBSD workaround - inspec detects OpenSBD as unix and not linux compatible
hosts: all
become: true
tasks:
- name: use the type command instead of which to detect existing commands
file:
src: "/usr/bin/which"
dest: "/usr/bin/type"
state: hard
when: "lookup('env', 'MOLECULE_DISTRO') == 'openbsd7'"

- name: Verify
hosts: localhost
environment:
http_proxy: "{{ lookup('env', 'http_proxy') | default(omit) }}"
https_proxy: "{{ lookup('env', 'https_proxy') | default(omit) }}"
no_proxy: "{{ lookup('env', 'no_proxy') | default(omit) }}"
tasks:
- name: get ssh-config
command:
cmd: "vagrant ssh-config"
chdir: "{{ molecule_ephemeral_directory }}"
register: ssh_config
changed_when: false

- name: create ssh-config file
copy:
content: "{{ ssh_config.stdout_lines | join ('\n') }}"
dest: "{{ molecule_ephemeral_directory }}/ssh-config"
changed_when: false

- name: Execute cinc-auditor tests
command: >
docker run
--volume {{ molecule_ephemeral_directory }}:{{ molecule_ephemeral_directory }}
--volume ./waivers_{{ lookup('env', 'MOLECULE_DISTRO') }}.yaml:/waivers.yaml
docker.io/cincproject/auditor exec
--ssh-config-file={{ molecule_ephemeral_directory }}/ssh-config
-t ssh://{{ lookup('env', 'USER') }}
--sudo --no-show-progress --no-color
--waiver-file /waivers.yaml
--no-distinct-exit https://github.com/dev-sec/ssh-baseline/archive/refs/heads/master.zip
register: test_results
changed_when: false
ignore_errors: true

- name: Display details about the cinc-auditor results
debug:
msg: "{{ test_results.stdout_lines }}"

- name: Fail when tests fail
fail:
msg: "Inspec failed to validate"
when: test_results.rc != 0
3 changes: 3 additions & 0 deletions molecule/ssh_hardening_bsd/waivers_freebsd12.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sshd-45:
run: false
justification: "PrintLastLog is broken on FreeBSD. see: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=209441"
21 changes: 21 additions & 0 deletions molecule/ssh_hardening_bsd/waivers_openbsd7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ssh-17:
run: false
justification: "GSSAPIAuthentication is disabled. see: https://github.com/dev-sec/ansible-collection-hardening/pull/598"
ssh-18:
run: false
justification: "GSSAPIDelegateCredentials is disabled. see: https://github.com/dev-sec/ansible-collection-hardening/pull/598"
sshd-30:
run: false
justification: "KerberosAuthentication is disabled. see: https://github.com/dev-sec/ansible-ssh-hardening/pull/171"
sshd-31:
run: false
justification: "KerberosOrLocalPasswd is disabled. see: https://github.com/dev-sec/ansible-ssh-hardening/pull/171"
sshd-32:
run: false
justification: "KerberosTicketCleanup is disabled. see: https://github.com/dev-sec/ansible-ssh-hardening/pull/171"
sshd-33:
run: false
justification: "GSSAPIAuthentication is disabled. see: https://github.com/dev-sec/ansible-collection-hardening/pull/598"
sshd-34:
run: false
justification: "GSSAPICleanupCredentials is disabled. see: https://github.com/dev-sec/ansible-collection-hardening/pull/598"
6 changes: 6 additions & 0 deletions roles/ssh_hardening/meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ galaxy_info:
- name: ArchLinux
- name: SmartOS
- name: opensuse
- name: FreeBSD
versions:
- "12.2"
- name: OpenBSD
versions:
- "7.0"
galaxy_tags:
- system
- security
Expand Down