mirror of
https://github.com/ansible-middleware/keycloak.git
synced 2025-07-30 08:31:39 -07:00
Merge pull request #189 from world-direct/feature/188_config_keystore
#188: add support for configuration key store
This commit is contained in:
commit
4f8ed5194c
10 changed files with 172 additions and 20 deletions
52
roles/keycloak_quarkus/tasks/config_store.yml
Normal file
52
roles/keycloak_quarkus/tasks/config_store.yml
Normal file
|
@ -0,0 +1,52 @@
|
|||
---
|
||||
- name: "Initialize configuration key store variables to be written"
|
||||
ansible.builtin.set_fact:
|
||||
store_items:
|
||||
- key: "kc.db-password"
|
||||
value: "{{ keycloak_quarkus_db_pass }}"
|
||||
|
||||
- name: "Initialize empty configuration key store"
|
||||
become: true
|
||||
# keytool doesn't allow creating an empty key store, so this is a hacky way around it
|
||||
ansible.builtin.shell: |
|
||||
set -o nounset # abort on unbound variable
|
||||
set -o pipefail # do not hide errors within pipes
|
||||
set -o errexit # abort on nonzero exit status
|
||||
|
||||
echo dummy | keytool -noprompt -importpass -alias dummy -keystore {{ keycloak_quarkus_config_key_store_file | quote }} -storepass {{ keycloak_quarkus_config_key_store_password | quote }} -storetype PKCS12
|
||||
keytool -delete -alias dummy -keystore {{ keycloak_quarkus_config_key_store_file | quote }} -storepass {{ keycloak_quarkus_config_key_store_password | quote }}
|
||||
args:
|
||||
creates: "{{ keycloak_quarkus_config_key_store_file }}"
|
||||
|
||||
- name: "Set configuration key store using keytool"
|
||||
ansible.builtin.shell: |
|
||||
set -o nounset # abort on unbound variable
|
||||
set -o pipefail # do not hide errors within pipes
|
||||
|
||||
keytool -list -alias {{ item.key | quote }} -keystore {{ keycloak_quarkus_config_key_store_file | quote }} -storepass {{ keycloak_quarkus_config_key_store_password | quote }}
|
||||
retVal=$?
|
||||
|
||||
set -o errexit # abort on nonzero exit status
|
||||
|
||||
if [ $retVal -eq 0 ]; then
|
||||
# value is already in keystore, but keytool has no replace function: delete and re-create instead
|
||||
# note that we can not read whether the value has changed either[^1], so we need to override it
|
||||
# [^1]: https://stackoverflow.com/a/37491400
|
||||
keytool -delete -alias {{ item.key | quote }} -keystore {{ keycloak_quarkus_config_key_store_file | quote }} -storepass {{ keycloak_quarkus_config_key_store_password | quote }}
|
||||
fi
|
||||
|
||||
echo {{ item.value | quote }} | keytool -noprompt -importpass -alias {{ item.key | quote }} -keystore {{ keycloak_quarkus_config_key_store_file | quote }} -storepass {{ keycloak_quarkus_config_key_store_password | quote }} -storetype PKCS12
|
||||
with_items: "{{ store_items }}"
|
||||
no_log: true
|
||||
become: true
|
||||
changed_when: true
|
||||
notify:
|
||||
- restart keycloak
|
||||
|
||||
- name: "Set owner of configuration key store {{ keycloak_quarkus_config_key_store_file }}"
|
||||
ansible.builtin.file:
|
||||
path: "{{ keycloak_quarkus_config_key_store_file }}"
|
||||
owner: "{{ keycloak.service_user }}"
|
||||
group: "{{ keycloak.service_group }}"
|
||||
mode: '0400'
|
||||
become: true
|
36
roles/keycloak_quarkus/tasks/deprecations.yml
Normal file
36
roles/keycloak_quarkus/tasks/deprecations.yml
Normal file
|
@ -0,0 +1,36 @@
|
|||
---
|
||||
- name: Check deprecation keycloak_quarkus_key_store -> keycloak_quarkus_http_key_store
|
||||
delegate_to: localhost
|
||||
run_once: true
|
||||
when:
|
||||
- keycloak_quarkus_https_key_store_enabled
|
||||
block:
|
||||
- name: Ensure backward compatibility for `keycloak_quarkus_key_store_file`, superseded by `keycloak_quarkus_https_key_store_file`
|
||||
when:
|
||||
- keycloak_quarkus_key_store_file is defined
|
||||
- keycloak_quarkus_key_store_file != ''
|
||||
- keycloak_quarkus_https_key_store_file == keycloak.home + "/conf/key_store.p12" # default value
|
||||
changed_when: true
|
||||
ansible.builtin.set_fact:
|
||||
keycloak_quarkus_https_key_store_file: "{{ keycloak_quarkus_key_store_file }}"
|
||||
deprecated_variable: "keycloak_quarkus_key_store_file" # read in deprecation handler
|
||||
notify:
|
||||
- print deprecation warning
|
||||
|
||||
- name: Flush handlers
|
||||
ansible.builtin.meta: flush_handlers
|
||||
|
||||
- name: Ensure backward compatibility for `keycloak_quarkus_key_store_password`, superseded by `keycloak_quarkus_https_key_store_password`
|
||||
when:
|
||||
- keycloak_quarkus_key_store_password is defined
|
||||
- keycloak_quarkus_key_store_password != ''
|
||||
- keycloak_quarkus_https_key_store_password == "" # default value
|
||||
changed_when: true
|
||||
ansible.builtin.set_fact:
|
||||
keycloak_quarkus_https_key_store_password: "{{ keycloak_quarkus_key_store_password }}"
|
||||
deprecated_variable: "keycloak_quarkus_key_store_password" # read in deprecation handler
|
||||
notify:
|
||||
- print deprecation warning
|
||||
|
||||
- name: Flush handlers
|
||||
ansible.builtin.meta: flush_handlers
|
|
@ -6,6 +6,11 @@
|
|||
- prereqs
|
||||
- always
|
||||
|
||||
- name: Check for deprecations
|
||||
ansible.builtin.include_tasks: deprecations.yml
|
||||
tags:
|
||||
- always
|
||||
|
||||
- name: Distro specific tasks
|
||||
ansible.builtin.include_tasks: "{{ ansible_os_family | lower }}.yml"
|
||||
tags:
|
||||
|
@ -21,6 +26,12 @@
|
|||
tags:
|
||||
- systemd
|
||||
|
||||
- name: Include configuration key store tasks
|
||||
when: keycloak.config_key_store_enabled
|
||||
ansible.builtin.include_tasks: config_store.yml
|
||||
tags:
|
||||
- install
|
||||
|
||||
- name: "Configure config for keycloak service"
|
||||
ansible.builtin.template:
|
||||
src: keycloak.conf.j2
|
||||
|
|
|
@ -42,3 +42,17 @@
|
|||
ansible.builtin.include_tasks: fastpackages.yml
|
||||
vars:
|
||||
packages_list: "{{ keycloak_quarkus_prereq_package_list }}"
|
||||
|
||||
- name: "Validate keytool"
|
||||
when: keycloak.config_key_store_enabled
|
||||
block:
|
||||
- name: "Attempt to run keytool"
|
||||
changed_when: false
|
||||
ansible.builtin.command: keytool -help
|
||||
register: keytool_check
|
||||
ignore_errors: true
|
||||
|
||||
- name: "Fail when no keytool found"
|
||||
when: keytool_check.rc != 0
|
||||
ansible.builtin.fail:
|
||||
msg: "keytool NOT found in the PATH, but is required for setting up the configuration key store"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue