Merge pull request #106 from schmaxit/main

Run service as `keycloak_service_user`
This commit is contained in:
Guido Grazioli 2023-08-30 11:07:25 +02:00 committed by GitHub
commit d12f62b89d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 43 additions and 10 deletions

View file

@ -6,6 +6,7 @@
keycloak_config_override_template: custom.xml.j2 keycloak_config_override_template: custom.xml.j2
keycloak_http_port: 8081 keycloak_http_port: 8081
keycloak_management_http_port: 19990 keycloak_management_http_port: 19990
keycloak_service_runas: True
roles: roles:
- role: keycloak - role: keycloak
tasks: tasks:
@ -51,4 +52,4 @@
sso_offline_install: True sso_offline_install: True
when: when:
- assets_server is defined - assets_server is defined
- assets_server | length > 0 - assets_server | length > 0

View file

@ -77,7 +77,7 @@ Role Defaults
|`keycloak_service_startlimitintervalsec`| systemd StartLimitIntervalSec | `300` | |`keycloak_service_startlimitintervalsec`| systemd StartLimitIntervalSec | `300` |
|`keycloak_service_startlimitburst`| systemd StartLimitBurst | `5` | |`keycloak_service_startlimitburst`| systemd StartLimitBurst | `5` |
|`keycloak_service_restartsec`| systemd RestartSec | `10s` | |`keycloak_service_restartsec`| systemd RestartSec | `10s` |
|`keycloak_service_pidfile`| pid file path for service | `/run/keycloak.pid` | |`keycloak_service_pidfile`| pid file path for service | `/run/keycloak/keycloak.pid` |
|`keycloak_features` | List of `name`/`status` pairs of features (also known as profiles on RH-SSO) to `enable` or `disable`, example: `[ { name: 'docker', status: 'enabled' } ]` | `[]` |`keycloak_features` | List of `name`/`status` pairs of features (also known as profiles on RH-SSO) to `enable` or `disable`, example: `[ { name: 'docker', status: 'enabled' } ]` | `[]`
|`keycloak_jvm_package`| RHEL java package runtime | `java-1.8.0-openjdk-headless` | |`keycloak_jvm_package`| RHEL java package runtime | `java-1.8.0-openjdk-headless` |
|`keycloak_java_home`| JAVA_HOME of installed JRE, leave empty for using specified keycloak_jvm_package RPM path | `None` | |`keycloak_java_home`| JAVA_HOME of installed JRE, leave empty for using specified keycloak_jvm_package RPM path | `None` |

View file

@ -17,9 +17,10 @@ keycloak_config_standalone_xml: "keycloak.xml"
keycloak_config_path_to_standalone_xml: "{{ keycloak_jboss_home }}/standalone/configuration/{{ keycloak_config_standalone_xml }}" keycloak_config_path_to_standalone_xml: "{{ keycloak_jboss_home }}/standalone/configuration/{{ keycloak_config_standalone_xml }}"
keycloak_config_override_template: '' keycloak_config_override_template: ''
keycloak_config_path_to_properties: "{{ keycloak_jboss_home }}/standalone/configuration/profile.properties" keycloak_config_path_to_properties: "{{ keycloak_jboss_home }}/standalone/configuration/profile.properties"
keycloak_service_runas: false
keycloak_service_user: keycloak keycloak_service_user: keycloak
keycloak_service_group: keycloak keycloak_service_group: keycloak
keycloak_service_pidfile: "/run/keycloak.pid" keycloak_service_pidfile: "/run/keycloak/keycloak.pid"
keycloak_service_name: keycloak keycloak_service_name: keycloak
keycloak_service_desc: Keycloak keycloak_service_desc: Keycloak
keycloak_service_start_delay: 10 keycloak_service_start_delay: 10

View file

@ -74,6 +74,11 @@ argument_specs:
default: "" default: ""
description: "Path to custom template for standalone.xml configuration" description: "Path to custom template for standalone.xml configuration"
type: "str" type: "str"
keycloak_service_runas:
# line 20 of keycloak/defaults/main.yml
default: false
description: "Enable execution of service as `keycloak_service_user`"
type: "bool"
keycloak_service_user: keycloak_service_user:
# line 29 of keycloak/defaults/main.yml # line 29 of keycloak/defaults/main.yml
default: "keycloak" default: "keycloak"
@ -86,7 +91,7 @@ argument_specs:
type: "str" type: "str"
keycloak_service_pidfile: keycloak_service_pidfile:
# line 31 of keycloak/defaults/main.yml # line 31 of keycloak/defaults/main.yml
default: "/run/keycloak.pid" default: "/run/keycloak/keycloak.pid"
description: "PID file path for service" description: "PID file path for service"
type: "str" type: "str"
keycloak_features: keycloak_features:

View file

@ -53,6 +53,15 @@
group: "{{ keycloak_service_group }}" group: "{{ keycloak_service_group }}"
mode: 0750 mode: 0750
- name: Create pidfile folder
become: yes
ansible.builtin.file:
dest: "{{ keycloak_service_pidfile | dirname }}"
state: directory
owner: "{{ keycloak_service_user if keycloak_service_runas else omit }}"
group: "{{ keycloak_service_group if keycloak_service_runas else omit }}"
mode: 0750
## check remote archive ## check remote archive
- name: Set download archive path - name: Set download archive path
ansible.builtin.set_fact: ansible.builtin.set_fact:
@ -194,6 +203,12 @@
become: yes become: yes
changed_when: false changed_when: false
- name: Ensure permissions are correct on existing deploy
ansible.builtin.command: chown -R "{{ keycloak_service_user }}:{{ keycloak_service_group }}" "{{ keycloak.home }}"
when: keycloak_service_runas
become: yes
changed_when: false
# driver and configuration # driver and configuration
- name: "Install {{ keycloak_jdbc_engine }} driver" - name: "Install {{ keycloak_jdbc_engine }} driver"
ansible.builtin.include_tasks: jdbc_driver.yml ansible.builtin.include_tasks: jdbc_driver.yml

View file

@ -8,4 +8,12 @@ KEYCLOAK_HTTPS_PORT={{ keycloak_https_port }}
KEYCLOAK_MANAGEMENT_HTTP_PORT={{ keycloak_management_http_port }} KEYCLOAK_MANAGEMENT_HTTP_PORT={{ keycloak_management_http_port }}
KEYCLOAK_MANAGEMENT_HTTPS_PORT={{ keycloak_management_https_port }} KEYCLOAK_MANAGEMENT_HTTPS_PORT={{ keycloak_management_https_port }}
JBOSS_PIDFILE='{{ keycloak_service_pidfile }}' JBOSS_PIDFILE='{{ keycloak_service_pidfile }}'
LAUNCH_JBOSS_IN_BACKGROUND=1
WILDFLY_OPTS=-Djboss.bind.address=${KEYCLOAK_BIND_ADDRESS} \
-Djboss.http.port=${KEYCLOAK_HTTP_PORT} \
-Djboss.https.port=${KEYCLOAK_HTTPS_PORT} \
-Djboss.management.http.port=${KEYCLOAK_MANAGEMENT_HTTP_PORT} \
-Djboss.management.https.port=${KEYCLOAK_MANAGEMENT_HTTPS_PORT} \
-Djboss.node.name={{ inventory_hostname }} \
{% if keycloak_prefer_ipv4 %}-Djava.net.preferIPv4Stack=true -Djava.net.preferIPv4Addresses=true {% endif %}\
{% if keycloak_config_standalone_xml is defined %}--server-config={{ keycloak_config_standalone_xml }}{% endif %}

View file

@ -7,11 +7,14 @@ StartLimitBurst={{ keycloak_service_startlimitburst }}
[Service] [Service]
Type=forking {% if keycloak_service_runas %}
User={{ keycloak_service_user }}
Group={{ keycloak_service_group }}
{% endif -%}
EnvironmentFile=-/etc/sysconfig/keycloak EnvironmentFile=-/etc/sysconfig/keycloak
PIDFile={{ keycloak_service_pidfile }} PIDFile={{ keycloak_service_pidfile }}
ExecStart={{ keycloak_dest }}/keycloak-service.sh start ExecStart={{ keycloak.home }}/bin/standalone.sh $WILDFLY_OPTS
ExecStop={{ keycloak_dest }}/keycloak-service.sh stop WorkingDirectory={{ keycloak.home }}
TimeoutStartSec=30 TimeoutStartSec=30
TimeoutStopSec=30 TimeoutStopSec=30
LimitNOFILE=102642 LimitNOFILE=102642

View file

@ -17,7 +17,7 @@ keycloak_quarkus_config_dir: "{{ keycloak_quarkus_home }}/conf"
keycloak_quarkus_start_dev: False keycloak_quarkus_start_dev: False
keycloak_quarkus_service_user: keycloak keycloak_quarkus_service_user: keycloak
keycloak_quarkus_service_group: keycloak keycloak_quarkus_service_group: keycloak
keycloak_quarkus_service_pidfile: "/run/keycloak.pid" keycloak_quarkus_service_pidfile: "/run/keycloak/keycloak.pid"
keycloak_quarkus_configure_firewalld: False keycloak_quarkus_configure_firewalld: False
### administrator console password ### administrator console password

View file

@ -61,7 +61,7 @@ argument_specs:
type: "str" type: "str"
keycloak_quarkus_service_pidfile: keycloak_quarkus_service_pidfile:
# line 18 of defaults/main.yml # line 18 of defaults/main.yml
default: "/run/keycloak.pid" default: "/run/keycloak/keycloak.pid"
description: "Pid file path for service" description: "Pid file path for service"
type: "str" type: "str"
keycloak_quarkus_configure_firewalld: keycloak_quarkus_configure_firewalld: