forked from bau-sec/ansible-openvpn-hardened
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.travis.yml
92 lines (73 loc) · 3.04 KB
/
.travis.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
language: python
cache: pip
sudo: required
env:
matrix:
- distribution: centos
version: 7
init: /usr/lib/systemd/systemd
run_opts: "'--detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup'"
ssh: sshd
- distribution: ubuntu
version: 16.04
init: /sbin/init
#--volume=\"/tmp/$(mktemp -d):/run\"
run_opts: "'--detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup'"
ssh: ssh
- distribution: debian
version: 8.7
init: /bin/systemd
run_opts: "'--detach --privileged --volume=/sys/fs/cgroup:/sys/fs/cgroup'"
ssh: ssh
services:
- docker
before_install:
# Pull container
- sudo docker pull ${distribution}:${version}
- ssh-keygen -t rsa -f /home/travis/.ssh/id_rsa -q -N ""
- cp /home/travis/.ssh/id_rsa.pub test/id_rsa.pub
# Customize container
- sudo docker build --rm=true --file=test/Dockerfile.${distribution}-${version} --tag=${distribution}-${version}:ansible .
# Run container in detached state
- sudo docker run ${run_opts} ${distribution}-${version}:ansible "${init}"
install:
- sudo -H pip install ansible ansible-lint
- sudo apt-get -y install openssl
script:
- container_id=$(mktemp)
- container_ip=$(mktemp)
- sudo docker ps -q > "${container_id}"
- sudo docker exec $(cat ${container_id}) /bin/systemctl status ${ssh}.service
# Ansible syntax check.
- ansible-lint playbooks/install.yml
- ansible-lint playbooks/add_clients.yml
- ansible-lint playbooks/revoke_client.yml
- ansible-lint playbooks/audit.yml
# Get the IP of the container and add it to the inventory
- sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' $(cat ${container_id}) > "${container_ip}"
- sed -i -e 's/172\.17\.0\.2/'"$(cat ${container_ip})"'/' test/docker-inventory
# Verify ssh connection
- ssh-keyscan -H $(cat ${container_ip}) >> ~/.ssh/known_hosts
# - ssh -vvv docker@$(cat ${container_ip}) /bin/true
# Test role.
- ansible-playbook -i test/docker-inventory --diff playbooks/install.yml
# Test role idempotence.
- >
ansible-playbook -i test/docker-inventory playbooks/install.yml
| grep -q 'changed=0.*failed=0'
&& (echo 'Idempotence test: pass' && exit 0)
|| (echo 'Idempotence test: fail' && exit 1)
# Test adding a client
- ansible-playbook -i test/docker-inventory -e "cmd_hosts=openvpn-internet clients_to_add=cool_client" playbooks/add_clients.yml
# Test removing a client
- ansible-playbook -i test/docker-inventory -e "cmd_hosts=openvpn-internet client=cool_client" playbooks/revoke_client.yml
# Test adding a client using a CSR
- openssl genrsa -out ~/test.key 2048
- openssl req -new -sha256 -key ~/test.key -out ~/test.csr -batch -subj "/CN=test@domain.com"
- ansible-playbook -i test/docker-inventory -e "cmd_hosts=openvpn-internet csr_path=~/test.csr cn=test@domain.com" playbooks/add_clients.yml
# Test audit
- ansible-playbook -i test/docker-inventory -e "cmd_hosts=openvpn-internet" playbooks/audit.yml
after_script:
# Clean up
- 'sudo docker stop "$(cat ${container_id})"'