Git initial commit

This commit is contained in:
Lars Hahn 2023-08-20 11:13:09 +02:00
commit 03fe3b5cf0
8 changed files with 184 additions and 0 deletions

9
LICENSE Executable file
View File

@ -0,0 +1,9 @@
MIT License
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3
README.md Executable file
View File

@ -0,0 +1,3 @@
# cloud-easyrsa
Ansible role to provide easyrsa for VPN CA setup. Can be used standalone aswell.

23
defaults/main.yml Executable file
View File

@ -0,0 +1,23 @@
---
cloud_apps: /opt
cloud_storage: /opt/storage
cloud_stage: prod
cloud_update: false
easy_rsa_ca: "{{ ansible_hostname }}"
easy_rsa_servers:
- name: some_server
state: present
easy_rsa_clients:
- name: username
state: present
- name: username.app
state: absent
easy_rsa_vars_conf:
country: "COUNTRY"
province: "PROVINCE"
city: "CITY"
company: "YOUR COMPANY"
mail: "admin@your-company.com"

1
handlers/main.yml Executable file
View File

@ -0,0 +1 @@
---

16
meta/main.yml Executable file
View File

@ -0,0 +1,16 @@
---
galaxy_info:
role_name: easy-rsa
namespace: hahn-cloud
author: Lars Hahn
company: OpenDevChain
license: MIT
description: Role to setup an easy-rsa for PKI, CA and certificates.
min_ansible_version: 2.7
platforms:
- name: Debian
versions:
- 10
galaxy_tags:
- easy-rsa
dependencies: []

107
tasks/main.yml Executable file
View File

@ -0,0 +1,107 @@
---
- name: install openvpn, easy-rsa and recommendations
apt:
update_cache: yes
state: "{% if cloud_update | bool %}latest{% else %}present{% endif %}"
install_recommends: yes
pkg:
- "easy-rsa"
- name: Setup easy-rsa variables
template:
src: "templates{{ easy_rsa_home }}/vars.j2"
dest: "{{ easy_rsa_home }}/vars"
mode: 0644
owner: root
group: root
- name: initialise PKI
shell:
creates: "{{ easy_rsa_home }}/pki"
chdir: "{{ easy_rsa_home }}"
cmd: ./easyrsa init-pki
- name: setup certificate authority
shell:
creates: "{{ easy_rsa_home }}/pki/ca.crt"
chdir: "{{ easy_rsa_home }}"
cmd: "echo '{{ easy_rsa_ca }}' | ./easyrsa build-ca nopass"
- name: setup diffie-hellman key-pair for key exchange
shell:
creates: "{{ easy_rsa_home }}/pki/dh.pem"
chdir: "{{ easy_rsa_home }}"
cmd: ./easyrsa gen-dh
- name: setup server certificates
shell:
cmd: |
echo '{{ srvr }}' | ./easyrsa gen-req {{ srvr }} nopass
echo 'yes' | ./easyrsa sign-req server {{ srvr }}
chdir: "{{ easy_rsa_home }}"
creates: "{{ easy_rsa_home }}/pki/issued/{{ srvr }}.crt"
loop: "{{ easy_rsa_servers_active }}"
loop_control:
loop_var: srvr
label: "{{ srvr }}"
- name: setup client certificates
shell:
cmd: |
echo '{{ client }}' | ./easyrsa gen-req {{ client }} nopass
echo 'yes' | ./easyrsa sign-req client {{ client }}
chdir: "{{ easy_rsa_home }}"
creates: "{{ easy_rsa_home }}/pki/issued/{{ client }}.crt"
loop: "{{ easy_rsa_clients_active }}"
loop_control:
loop_var: client
label: "{{ client }}"
- name: verify certificate integrety
command: "openssl verify -CAfile {{ easy_rsa_home }}/pki/ca.crt {{ easy_rsa_home }}/pki/issued/{{ cert }}.crt"
register: easy_rsa_cert_check
changed_when: ((easy_rsa_cert_check.stdout.split(' ') | length) > 1) and (easy_rsa_cert_check.stdout.split(' ')[1] != "OK")
loop: "{{ easy_rsa_entities_active }}"
loop_control:
loop_var: cert
label: "{{ cert }}"
- name: find abstent easy-rsa certifcates
find:
paths: "{{ easy_rsa_home }}/pki/issued/"
pattern: "{{ cert }}.crt"
loop: "{{ easy_rsa_entities_passive }}"
loop_control:
loop_var: cert
label: "{{ cert }}"
register: easy_rsa_absent_certs
- name: remove absent easy-rsa clients certs
file:
state: absent
path: "{{ client }}"
loop: "{{ easy_rsa_absent_certs.results | json_query('[*].files[*].path') | flatten }}"
loop_control:
loop_var: client
label: "{{ client | basename }}"
when: easy_rsa_absent_certs.results | length > 0
- name: find abstent easy-rsa keys
find:
paths: "{{ easy_rsa_home }}/pki/private/"
pattern: "{{ cert }}.key"
loop: "{{ easy_rsa_entities_passive }}"
loop_control:
loop_var: cert
label: "{{ cert }}"
register: easy_rsa_absent_keys
- name: remove absent easy-rsa clients keys
file:
state: absent
path: "{{ client }}"
loop: "{{ easy_rsa_absent_keys.results | json_query('[*].files[*].path') | flatten }}"
loop_control:
loop_var: client
label: "{{ client | basename }}"
when: easy_rsa_absent_keys.results | length > 0

View File

@ -0,0 +1,18 @@
set_var EASYRSA "$PWD"
set_var EASYRSA_PKI "$EASYRSA/pki"
set_var EASYRSA_DN "cn_only"
set_var EASYRSA_REQ_COUNTRY "{{ easy_rsa_vars_conf.country }}"
set_var EASYRSA_REQ_PROVINCE "{{ easy_rsa_vars_conf.province }}"
set_var EASYRSA_REQ_CITY "{{ easy_rsa_vars_conf.city }}"
set_var EASYRSA_REQ_ORG "{{ easy_rsa_vars_conf.company }} CERTIFICATE AUTHORITY"
set_var EASYRSA_REQ_EMAIL "{{ easy_rsa_vars_conf.mail }}"
set_var EASYRSA_REQ_OU "{{ easy_rsa_vars_conf.company }} EASY CA"
set_var EASYRSA_KEY_SIZE 2048
set_var EASYRSA_ALGO rsa
set_var EASYRSA_CA_EXPIRE 7500
set_var EASYRSA_CERT_EXPIRE 365
set_var EASYRSA_NS_SUPPORT "no"
set_var EASYRSA_NS_COMMENT "{{ easy_rsa_vars_conf.company }} CERTIFICATE AUTHORITY"
set_var EASYRSA_EXT_DIR "$EASYRSA/x509-types"
set_var EASYRSA_SSL_CONF "$EASYRSA/openssl-easyrsa.cnf"
set_var EASYRSA_DIGEST "sha256"

7
vars/main.yml Executable file
View File

@ -0,0 +1,7 @@
---
easy_rsa_home: "/usr/share/easy-rsa"
easy_rsa_servers_active: "{{ easy_rsa_servers | json_query('[?state==`present`].name') }}"
easy_rsa_clients_active: "{{ easy_rsa_clients | json_query('[?state==`present`].name') }}"
easy_rsa_entities_active: "{{ (easy_rsa_servers + easy_rsa_clients) | json_query('[?state==`present`].name') }}"
easy_rsa_entities_passive: "{{ (easy_rsa_servers + easy_rsa_clients) | json_query('[?state!=`present`].name') }}"