Add oidc_idp role

- Deploy cacert-idp from oidc_idp subdirectory
- configure systemd and start cacert-idp service
pull/1/head
Jan Dittberner 2 years ago
parent e631cf7072
commit 2bfa210140

@ -1,38 +1,19 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Setup the CAcert OpenID Connect identity provider application.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
GPL-2.0-or-later
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).
Jan Dittberner <jandd@cacert.org>

@ -1,2 +1,4 @@
---
# defaults file for roles/oidc_idp
cacert_os_user: cacert
cacert_os_group: cacert
cacert_home: /srv/cacert

@ -1,2 +1,7 @@
---
# handlers file for roles/oidc_idp
- name: idp_systemd_reload
ansible.builtin.systemd:
state: started
name: cacert-idp
daemon_reload: true
enabled: true

@ -1,52 +1,17 @@
---
galaxy_info:
author: your name
description: your role description
company: your company (optional)
author: Jan Dittberner
description: CAcert OpenID Connect identity provider application setup
company: CAcert
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
license: GPL-2.0-or-later
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
platforms:
- name: Debian
versions:
- bullseye
- bookworm
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

@ -1,2 +1,111 @@
---
# tasks file for roles/oidc_idp
- name: Create CAcert group
ansible.builtin.group:
name: "{{ cacert_os_group }}"
state: present
system: true
- name: Create CAcert user
ansible.builtin.user:
name: "{{ cacert_os_user }}"
group: "{{ cacert_os_group }}"
home: "{{ cacert_home }}"
state: present
system: true
- name: Create CAcert directories
ansible.builtin.file:
path: "{{ cacert_home }}/{{ item.path }}"
owner: "{{ cacert_os_user }}"
group: "{{ cacert_os_group }}"
mode: "{{ item.mode }}"
state: directory
loop:
- { path: etc, mode: '0750' }
- { path: bin, mode: '0750' }
- { path: download, mode: '0750' }
- name: Copy IDP binary
ansible.builtin.copy:
src: ../oidc_idp/cacert-idp
dest: "{{ cacert_home }}/bin/cacert-idp"
owner: root
group: "{{ cacert_os_group }}"
mode: "0750"
- name: Check whether certificate exists
ansible.builtin.stat:
path: "{{ idp_tls.cert }}"
register: idp_cert_st
- name: Create IDP key and certificate with mkcert
block:
- name: Create temporary directory for IDP key and certificate
ansible.builtin.tempfile:
prefix: "idp-cert."
state: directory
register: idp_cert_temp_dir
- name: Create IDP key and certificate
ansible.builtin.command:
cmd: "/home/{{ ansible_user | default(ansible_env.USER) }}/.local/bin/mkcert -cert-file {{ idp_cert_temp_dir.path }}/idp.pem -key-file {{ idp_cert_temp_dir.path }}/idp.key.pem {{ oidc_urls.idp.host }}"
- name: Move IDP certificate and key to target
ansible.builtin.copy:
src: "{{ idp_cert_temp_dir.path }}/{{ item.src }}"
dest: "{{ item.dest }}"
owner: root
group: "{{ cacert_os_group }}"
mode: "{{ item.mode }}"
remote_src: true
loop:
- {src: idp.pem, dest: "{{ idp_tls.cert }}", mode: '0644'}
- {src: idp.key.pem, dest: "{{ idp_tls.key }}", mode: '0640'}
become: true
- name: Remove temporary directory
ansible.builtin.file:
path: "{{ idp_cert_temp_dir.path }}"
state: absent
when: use_mkcert and not idp_cert_st.stat.exists
become: false
- name: Copy IDP key and certificate from inventory
block:
- name: Copy IDP certificate
ansible.builtin.copy:
dest: "{{ idp_tls.cert }}"
owner: root
group: "{{ cacert_os_group }}"
mode: '0644'
content: "{{ idp_tls.certdata }}"
- name: Copy IDP key
ansible.builtin.copy:
dest: "{{ idp_tls.key }}"
owner: root
group: "{{ cacert_os_group }}"
mode: '0640'
content: "{{ idp_tls.keydata }}"
when: not use_mkcert
- name: Create IDP configuration
ansible.builtin.template:
src: idp_config.toml.j2
dest: "{{ cacert_home }}/etc/cacert-idp.toml"
owner: root
group: "{{ cacert_os_group }}"
mode: '0640'
notify: idp_systemd_reload
- name: Create IDP systemd unit file
ansible.builtin.template:
src: cacert-idp.service.j2
dest: /etc/systemd/system/cacert-idp.service
owner: root
group: root
mode: "0640"
notify: idp_systemd_reload

@ -0,0 +1,14 @@
[Unit]
Description=CAcert OpenID Connect identity provider
After=network.target
Documentation=https://code.cacert.org/cacert/oidc-idp
[Service]
ExecStart={{ cacert_home }}/bin/cacert-idp --conf "{{ cacert_home }}/etc/cacert-idp.toml"
WorkingDirectory={{ cacert_home }}
User={{ cacert_os_user }}
Group={{ cacert_os_group }}
[Install]
WantedBy=multi-user.target

@ -0,0 +1,2 @@
[security]
csrf.key = "{{ idp_csrf_key | default(lookup('community.general.random_string', length=32, base64=true)) }}"
Loading…
Cancel
Save