Skip to content

Commit 7abe9c9

Browse files
authored
Merge pull request #199 from myii/ci/add-vagrant-testing-via-github-actions
ci: enable Vagrant-based testing using GitHub Actions
2 parents 35a2124 + 2f8c31c commit 7abe9c9

File tree

12 files changed

+678
-13
lines changed

12 files changed

+678
-13
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# -*- coding: utf-8 -*-
2+
# vim: ft=yaml
3+
---
4+
name: 'Kitchen Vagrant (FreeBSD & OpenBSD)'
5+
'on': ['push', 'pull_request']
6+
7+
env:
8+
KITCHEN_LOCAL_YAML: 'kitchen.vagrant.yml'
9+
10+
jobs:
11+
test:
12+
runs-on: 'macos-10.15'
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
instance:
17+
- default-freebsd-122-latest-py3
18+
- default-freebsd-114-latest-py3
19+
- default-openbsd-68-latest-py3
20+
steps:
21+
- name: 'Check out code'
22+
uses: 'actions/checkout@v2'
23+
- name: 'Set up Bundler cache'
24+
uses: 'actions/cache@v1'
25+
with:
26+
path: 'vendor/bundle'
27+
key: "${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}"
28+
restore-keys: "${{ runner.os }}-gems-"
29+
- name: 'Run Bundler'
30+
run: |
31+
ruby --version
32+
bundle config path vendor/bundle
33+
bundle install --jobs 4 --retry 3
34+
- name: 'Run Test Kitchen'
35+
run: 'bundle exec kitchen verify ${{ matrix.instance }}'

.yamllint

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ignore: |
1616
node_modules/
1717
test/**/states/**/*.sls
1818
.kitchen/
19+
test/salt/pillar/default.sls
1920
2021
yaml-files:
2122
# Default settings

docs/README.rst

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ e.g. ``debian-9-2019-2-py3``.
266266
``bin/kitchen converge``
267267
^^^^^^^^^^^^^^^^^^^^^^^^
268268

269-
Creates the docker instance and runs the ``template`` main state, ready for testing.
269+
Creates the docker instance and runs the ``openssh`` main states, ready for testing.
270270

271271
``bin/kitchen verify``
272272
^^^^^^^^^^^^^^^^^^^^^^
@@ -288,3 +288,64 @@ Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``veri
288288

289289
Gives you SSH access to the instance for manual testing.
290290

291+
Testing with Vagrant
292+
--------------------
293+
294+
Windows/FreeBSD/OpenBSD testing is done with ``kitchen-salt``.
295+
296+
Requirements
297+
^^^^^^^^^^^^
298+
299+
* Ruby
300+
* Virtualbox
301+
* Vagrant
302+
303+
Setup
304+
^^^^^
305+
306+
.. code-block:: bash
307+
308+
$ gem install bundler
309+
$ bundle install --with=vagrant
310+
$ bin/kitchen test [platform]
311+
312+
Where ``[platform]`` is the platform name defined in ``kitchen.vagrant.yml``,
313+
e.g. ``windows-81-latest-py3``.
314+
315+
Note
316+
^^^^
317+
318+
When testing using Vagrant you must set the environment variable ``KITCHEN_LOCAL_YAML`` to ``kitchen.vagrant.yml``. For example:
319+
320+
.. code-block:: bash
321+
322+
$ KITCHEN_LOCAL_YAML=kitchen.vagrant.yml bin/kitchen test # Alternatively,
323+
$ export KITCHEN_LOCAL_YAML=kitchen.vagrant.yml
324+
$ bin/kitchen test
325+
326+
Then run the following commands as needed.
327+
328+
``bin/kitchen converge``
329+
^^^^^^^^^^^^^^^^^^^^^^^^
330+
331+
Creates the Vagrant instance and runs the ``openssh`` main states, ready for testing.
332+
333+
``bin/kitchen verify``
334+
^^^^^^^^^^^^^^^^^^^^^^
335+
336+
Runs the ``inspec`` tests on the actual instance.
337+
338+
``bin/kitchen destroy``
339+
^^^^^^^^^^^^^^^^^^^^^^^
340+
341+
Removes the Vagrant instance.
342+
343+
``bin/kitchen test``
344+
^^^^^^^^^^^^^^^^^^^^
345+
346+
Runs all of the stages above in one go: i.e. ``destroy`` + ``converge`` + ``verify`` + ``destroy``.
347+
348+
``bin/kitchen login``
349+
^^^^^^^^^^^^^^^^^^^^^
350+
351+
Gives you RDP/SSH access to the instance for manual testing.

kitchen.vagrant.yml

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,26 @@
33
---
44
driver:
55
name: vagrant
6+
cache_directory: false
7+
customize:
8+
usbxhci: 'off'
9+
gui: false
10+
linked_clone: true
11+
ssh:
12+
shell: /bin/sh
613

714
platforms:
8-
- name: freebsd-120-2019-2-py3
15+
- name: freebsd-122-latest-py3
916
driver:
10-
box_url: https://freebsd.z.vstack.com/FreeBSD-12.0.box
11-
cache_directory: false
12-
customize:
13-
usbxhci: 'off'
14-
gui: false
15-
linked_clone: true
17+
box: bento/freebsd-12.2
18+
- name: freebsd-114-latest-py3
19+
driver:
20+
box: bento/freebsd-11.4
21+
- name: openbsd-68-latest-py3
22+
driver:
23+
box: generic/openbsd6
1624
ssh:
17-
shell: '/bin/sh'
25+
shell: /bin/ksh
26+
27+
provisioner:
28+
salt_install: bootstrap

kitchen.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ suites:
310310
- name: default
311311
driver:
312312
hostname: example.net
313+
vm_hostname: example.net
313314
provisioner:
314315
state_top:
315316
base:

openssh/known_hosts.sls

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
{%- from tplroot ~ "/libtofs.jinja" import files_switch %}
44
{%- set openssh = mapdata.openssh %}
55
6+
{%- if openssh.dig_pkg %}
67
ensure dig is available:
78
pkg.installed:
89
- name: {{ openssh.dig_pkg }}
10+
- require_in:
11+
- file: manage ssh_known_hosts file
12+
{%- endif %}
913
1014
manage ssh_known_hosts file:
1115
file.managed:
@@ -19,5 +23,3 @@ manage ssh_known_hosts file:
1923
- user: root
2024
- group: {{ openssh.ssh_config_group }}
2125
- mode: 644
22-
- require:
23-
- pkg: ensure dig is available

openssh/parameters/os_family/OpenBSD.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
values:
1313
openssh:
1414
service: sshd
15+
# Already installed: `base68:/usr/bin/dig`
16+
dig_pkg: ~
1517
sshd_config_group: wheel
1618
ssh_config_group: wheel
1719
sshd_config:

test/integration/default/controls/config_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
its('content') { should include 'PrintMotd no' }
2828
its('content') { should include 'AcceptEnv LANG LC_*' }
2929
its('content') { should include 'Subsystem sftp /usr/lib/openssh/sftp-server' }
30-
its('content') { should include 'UsePAM yes' }
30+
unless %w[openbsd].include?(platform[:name])
31+
its('content') { should include 'UsePAM yes' }
32+
end
3133
end
3234

3335
describe file('/etc/ssh/ssh_config') do
@@ -45,7 +47,7 @@
4547
it { should be_file }
4648
its('mode') { should cmp '0644' }
4749
it { should be_owned_by 'root' }
48-
it { should be_grouped_into 'root' }
50+
it { should be_grouped_into root_group }
4951
its('content') { should include github_known_host }
5052
its('content') { should match(gitlab_known_host_re) }
5153
its('content') { should include minion_rsa_known_host }
Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# yamllint disable rule:indentation rule:line-length
2+
# FreeBSD-12
3+
---
4+
values:
5+
map_jinja:
6+
sources:
7+
- Y:G@osarch
8+
- Y:G@os_family
9+
- Y:G@os
10+
- Y:G@osfinger
11+
- C:SUB@openssh:lookup
12+
- C:SUB@openssh
13+
- C:SUB@sshd_config:lookup
14+
- C:SUB@sshd_config
15+
- C:SUB@ssh_config:lookup
16+
- C:SUB@ssh_config
17+
- Y:G@id
18+
openssh:
19+
absent_dsa_keys: false
20+
absent_ecdsa_keys: false
21+
absent_ed25519_keys: false
22+
absent_rsa_keys: false
23+
auth:
24+
joe-non-valid-ssh-key:
25+
- comment: obsolete key - removed
26+
enc: ssh-rsa
27+
present: false
28+
source: salt://ssh_keys/joe.no-valid.pub
29+
user: joe
30+
joe-valid-ssh-key-desktop:
31+
- comment: main key - desktop
32+
enc: ssh-rsa
33+
present: true
34+
source: salt://ssh_keys/joe.desktop.pub
35+
user: joe
36+
joe-valid-ssh-key-notebook:
37+
- comment: main key - notebook
38+
enc: ssh-rsa
39+
present: true
40+
source: salt://ssh_keys/joe.netbook.pub
41+
user: joe
42+
auth_map:
43+
personal_keys:
44+
source: salt://ssh_keys
45+
users:
46+
joe:
47+
joe.desktop: {}
48+
joe.netbook:
49+
options: []
50+
joe.no-valid:
51+
present: false
52+
banner: /etc/ssh/banner
53+
banner_src: banner
54+
banner_string: 'Welcome to example.net!
55+
'
56+
client_version: latest
57+
dig_pkg: bind-tools
58+
dsa:
59+
private_key: '-----BEGIN DSA PRIVATE KEY-----
60+
61+
NOT_DEFINED
62+
63+
-----END DSA PRIVATE KEY-----
64+
'
65+
public_key: 'ssh-dss NOT_DEFINED
66+
'
67+
ecdsa:
68+
private_key: '-----BEGIN EC PRIVATE KEY-----
69+
70+
NOT_DEFINED
71+
72+
-----END EC PRIVATE KEY-----
73+
'
74+
public_key: 'ecdsa-sha2-nistp256 NOT_DEFINED
75+
'
76+
ed25519:
77+
private_key: '-----BEGIN OPENSSH PRIVATE KEY-----
78+
79+
NOT_DEFINED
80+
81+
-----END OPENSSH PRIVATE KEY-----
82+
'
83+
public_key: 'ssh-ed25519 NOT_DEFINED
84+
'
85+
enforce_rsa_size: false
86+
generate_dsa_keys: false
87+
generate_ecdsa_keys: false
88+
generate_ed25519_keys: false
89+
generate_rsa_keys: false
90+
generate_rsa_size: 4096
91+
host_key_algos: ecdsa,ed25519,rsa
92+
known_hosts:
93+
aliases:
94+
- cname-to-minion.example.org
95+
- alias.example.org
96+
hostnames: false
97+
include_localhost: false
98+
mine_hostname_function: public_ssh_hostname
99+
mine_keys_function: public_ssh_host_keys
100+
omit_ip_address:
101+
- github.com
102+
salt_ssh:
103+
public_ssh_host_keys:
104+
minion.id: 'ssh-rsa [...]
105+
106+
ssh-ed25519 [...]
107+
'
108+
public_ssh_host_names:
109+
minion.id:
110+
- minion.id
111+
- alias.of.minion.id
112+
user: salt-master
113+
static:
114+
github.com: ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGm[...]
115+
gitlab.com: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCsj2bN[...]
116+
target: '*'
117+
tgt_type: glob
118+
moduli: '# Time Type Tests Tries Size Generator Modulus
119+
120+
20120821045639 2 6 100 2047 2 DD2047CBDBB6F8E919BC63DE885B34D0FD6E3DB2887D8B46FE249886ACED6B46DFCD5553168185FD376122171CD8927E60120FA8D01F01D03E58281FEA9A1ABE97631C828E41815F34FDCDF787419FE13A3137649AA93D2584230DF5F24B5C00C88B7D7DE4367693428C730376F218A53E853B0851BAB7C53C15DA7839CBE1285DB63F6FA45C1BB59FE1C5BB918F0F8459D7EF60ACFF5C0FA0F3FCAD1C5F4CE4416D4F4B36B05CDCEBE4FB879E95847EFBC6449CD190248843BC7EDB145FBFC4EDBB1A3C959298F08F3BA2CFBE231BBE204BE6F906209D28BD4820AB3E7BE96C26AE8A809ADD8D1A5A0B008E9570FA4C4697E116B8119892C604293680B09D63
121+
122+
20120821045830 2 6 100 2047 2 DD2047CBDBB6F8E919BC63DE885B34D0FD6E3DB2887D8B46FE249886ACED6B46DFCD5553168185FD376122171CD8927E60120FA8D01F01D03E58281FEA9A1ABE97631C828E41815F34FDCDF787419FE13A3137649AA93D2584230DF5F24B5C00C88B7D7DE4367693428C730376F218A53E853B0851BAB7C53C15DA7839CBE1285DB63F6FA45C1BB59FE1C5BB918F0F8459D7EF60ACFF5C0FA0F3FCAD1C5F4CE4416D4F4B36B05CDCEBE4FB879E95847EFBC6449CD190248843BC7EDB145FBFC4EDBB1A3C959298F08F3BA2CFBE231BBE204BE6F906209D28BD4820AB3E7BE96C26AE8A809ADD8D1A5A0B008E9570FA4C4697E116B8119892C6042936814C2FFB
123+
124+
20120821050046 2 6 100 2047 2 DD2047CBDBB6F8E919BC63DE885B34D0FD6E3DB2887D8B46FE249886ACED6B46DFCD5553168185FD376122171CD8927E60120FA8D01F01D03E58281FEA9A1ABE97631C828E41815F34FDCDF787419FE13A3137649AA93D2584230DF5F24B5C00C88B7D7DE4367693428C730376F218A53E853B0851BAB7C53C15DA7839CBE1285DB63F6FA45C1BB59FE1C5BB918F0F8459D7EF60ACFF5C0FA0F3FCAD1C5F4CE4416D4F4B36B05CDCEBE4FB879E95847EFBC6449CD190248843BC7EDB145FBFC4EDBB1A3C959298F08F3BA2CFBE231BBE204BE6F906209D28BD4820AB3E7BE96C26AE8A809ADD8D1A5A0B008E9570FA4C4697E116B8119892C60429368214FC53
125+
126+
20120821050054 2 6 100 2047 5 DD2047CBDBB6F8E919BC63DE885B34D0FD6E3DB2887D8B46FE249886ACED6B46DFCD5553168185FD376122171CD8927E60120FA8D01F01D03E58281FEA9A1ABE97631C828E41815F34FDCDF787419FE13A3137649AA93D2584230DF5F24B5C00C88B7D7DE4367693428C730376F218A53E853B0851BAB7C53C15DA7839CBE1285DB63F6FA45C1BB59FE1C5BB918F0F8459D7EF60ACFF5C0FA0F3FCAD1C5F4CE4416D4F4B36B05CDCEBE4FB879E95847EFBC6449CD190248843BC7EDB145FBFC4EDBB1A3C959298F08F3BA2CFBE231BBE204BE6F906209D28BD4820AB3E7BE96C26AE8A809ADD8D1A5A0B008E9570FA4C4697E116B8119892C60429368218E83F
127+
'
128+
provide_dsa_keys: false
129+
provide_ecdsa_keys: false
130+
provide_ed25519_keys: false
131+
provide_rsa_keys: false
132+
root_group: root
133+
rsa:
134+
private_key: '-----BEGIN RSA PRIVATE KEY-----
135+
136+
NOT_DEFINED
137+
138+
-----END RSA PRIVATE KEY-----
139+
'
140+
public_key: 'ssh-rsa NOT_DEFINED
141+
'
142+
server_version: latest
143+
service: sshd
144+
ssh_config: /etc/ssh/ssh_config
145+
ssh_config_backup: true
146+
ssh_config_group: wheel
147+
ssh_config_mode: '644'
148+
ssh_config_src: ssh_config
149+
ssh_config_user: root
150+
ssh_known_hosts: /etc/ssh/ssh_known_hosts
151+
ssh_known_hosts_src: ssh_known_hosts
152+
ssh_moduli: /etc/ssh/moduli
153+
sshd_binary: /usr/sbin/sshd
154+
sshd_config: /etc/ssh/sshd_config
155+
sshd_config_backup: true
156+
sshd_config_group: wheel
157+
sshd_config_mode: '644'
158+
sshd_config_src: sshd_config
159+
sshd_config_user: root
160+
sshd_enable: true
161+
tofs:
162+
source_files:
163+
manage ssh_known_hosts file:
164+
- alt_ssh_known_hosts
165+
ssh_config:
166+
- alt_ssh_config
167+
sshd_banner:
168+
- fire_banner
169+
sshd_config:
170+
- alt_sshd_config
171+
ssh_config:
172+
Hosts:
173+
'*':
174+
GSSAPIAuthentication: 'yes'
175+
HashKnownHosts: 'yes'
176+
SendEnv: LANG LC_*
177+
sshd_config:
178+
AcceptEnv: LANG LC_*
179+
ChallengeResponseAuthentication: 'no'
180+
PrintMotd: 'no'
181+
Subsystem: sftp /usr/lib/openssh/sftp-server
182+
UsePAM: 'yes'
183+
X11Forwarding: 'yes'

0 commit comments

Comments
 (0)