diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9034acc..d2ceab8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,10 +28,9 @@ jobs: python -m pip install --upgrade pip pip install yamllint 'molecule[docker]~=3.5.2' ansible-core flake8 ansible-lint voluptuous - - name: Create default collection path symlink + - name: Create default collection path run: | - mkdir -p /home/runner/.ansible - ln -s /home/runner/work/middleware_automation/keycloak /home/runner/.ansible/collections + mkdir -p /home/runner/.ansible/collections/ansible_collections - name: Run sanity tests run: ansible-test sanity --docker -v --color --python ${{ matrix.python_version }} @@ -40,6 +39,7 @@ jobs: - name: Run molecule test run: molecule test --all working-directory: ./ansible_collections/middleware_automation/keycloak + env: PY_COLORS: '1' ANSIBLE_FORCE_COLOR: '1' diff --git a/galaxy.yml b/galaxy.yml index 5ebc6d4..4d325b4 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -1,6 +1,6 @@ namespace: middleware_automation name: keycloak -version: "0.1.7" +version: "0.1.8" readme: README.md authors: - Romain Pelisse diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 3c54d4a..68adf70 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -1,6 +1,7 @@ --- dependency: - name: galaxy + name: shell + command: ansible-galaxy collection install -r molecule/default/requirements.yml -p $HOME/.ansible/collections --force-with-deps driver: name: docker platforms: diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index a0fd601..8dbc48d 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -2,7 +2,11 @@ - name: Prepare hosts: all tasks: + - name: Disable beta repos + command: yum config-manager --disable '*beta*' + ignore_errors: yes + - name: Install sudo yum: name: sudo - state: present \ No newline at end of file + state: present diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml new file mode 100644 index 0000000..ca255ec --- /dev/null +++ b/molecule/default/requirements.yml @@ -0,0 +1,10 @@ +--- +collections: + - name: middleware_automation.redhat_csp_download + version: ">=1.2.1" + - name: middleware_automation.jcliff + version: ">=0.0.19" + - name: community.general + - name: community.docker + version: ">=1.9.1" + diff --git a/roles/keycloak/README.md b/roles/keycloak/README.md index 392705c..81480e0 100644 --- a/roles/keycloak/README.md +++ b/roles/keycloak/README.md @@ -13,6 +13,14 @@ This role requires the `python3-netaddr` library installed on the controller nod * or via pip: `pip install netaddr==0.8.0` +Versions +-------- + +| RH-SSO VERSION | Release Date | Keycloak Version | EAP Version | Notes | +|:---------------|:------------------|:-----------------|:------------|:----------------| +|`7.5.0 GA` |September 20, 2021 |`15.0.2` | `7.4.0` |[Release Notes](https://access.redhat.com/documentation/en-us/red_hat_single_sign-on/7.5/html/release_notes/index)| + + Role Defaults ------------- @@ -48,6 +56,7 @@ The following variables are _required_ only when `keycloak_ha_enabled` is True: | Variable | Description | Default | |:---------|:------------|:---------| |`keycloak_modcluster_url` | URL for the modcluster reverse proxy | `localhost` | +|`keycloak_frontend_url` | frontend URL for keycloak endpoints when a reverse proxy is used | `http://localhost` | |`keycloak_jdbc_engine` | backend database flavour when db is enabled: [ postgres, mariadb ] | `postgres` | |`infinispan_url` | URL for the infinispan remote-cache server | `localhost:11122` | |`infinispan_user` | username for connecting to infinispan | `supervisor` | diff --git a/roles/keycloak/defaults/main.yml b/roles/keycloak/defaults/main.yml index 2ea1d9a..de619ac 100644 --- a/roles/keycloak/defaults/main.yml +++ b/roles/keycloak/defaults/main.yml @@ -1,14 +1,15 @@ --- ### Configuration specific to keycloak -keycloak_version: 9.0.2 -keycloak_archive: keycloak-{{ keycloak_version }}.zip -keycloak_download_url: https://downloads.jboss.org/keycloak/{{ keycloak_version }}/{{ keycloak_archive }} +keycloak_version: 15.0.2 +keycloak_archive: "keycloak-{{ keycloak_version }}.zip" +keycloak_download_url: "https://github.com/keycloak/keycloak/releases/download/{{ keycloak_version }}/{{ keycloak_archive }}" +keycloak_download_url_9x: "https://downloads.jboss.org/keycloak/{{ keycloak_version }}/{{ keycloak_archive }}" keycloak_installdir: "{{ keycloak_dest }}/keycloak-{{ keycloak_version }}" ### Configuration specific to Red Hat Single Sing-On keycloak_rhsso_enable: False keycloak_rhsso_version: 7.5 -keycloak_rhsso_archive: rh-sso-{{ keycloak_rhsso_version }}-server-dist.zip +keycloak_rhsso_archive: "rh-sso-{{ keycloak_rhsso_version }}-server-dist.zip" keycloak_rhsso_installdir: "{{ keycloak_dest }}/rh-sso-{{ keycloak_rhsso_version }}" keycloak_rhsso_base_url: 'https://access.redhat.com/jbossnetwork/restricted/softwareDownload.html?softwareId=' @@ -50,6 +51,7 @@ keycloak_force_install: False ### mod_cluster reverse proxy keycloak_modcluster_url: localhost +keycloak_frontend_url: http://localhost ### infinispan remote caches access (hotrod) infinispan_user: supervisor diff --git a/roles/keycloak/tasks/install.yml b/roles/keycloak/tasks/install.yml index 6faafe0..a346da5 100644 --- a/roles/keycloak/tasks/install.yml +++ b/roles/keycloak/tasks/install.yml @@ -142,7 +142,7 @@ - name: "Deploy Keycloak's standalone.xml" become: yes template: - src: "{{ 'templates/standalone-rhsso.xml.j2' if keycloak_rhsso_enable else 'templates/standalone.xml.j2' }}" + src: templates/standalone.xml.j2 dest: "{{ keycloak_config_path_to_standalone_xml }}" owner: "{{ keycloak_service_user }}" group: "{{ keycloak_service_group }}" @@ -154,7 +154,7 @@ - name: "Deploy Keycloak's standalone.xml with remote cache store" become: yes template: - src: "{{ 'templates/standalone-rhsso-jdg.xml.j2' if keycloak_rhsso_enable else 'templates/standalone-infinispan.xml.j2' }}" + src: templates/standalone-infinispan.xml.j2 dest: "{{ keycloak_config_path_to_standalone_xml }}" owner: "{{ keycloak_service_user }}" group: "{{ keycloak_service_group }}" diff --git a/roles/keycloak/tasks/main.yml b/roles/keycloak/tasks/main.yml index 66f56b3..bcf0c06 100644 --- a/roles/keycloak/tasks/main.yml +++ b/roles/keycloak/tasks/main.yml @@ -6,9 +6,17 @@ tags: - prereqs -- include_tasks: tasks/install.yml +- name: Include install tasks + include_tasks: tasks/install.yml -- include_tasks: tasks/systemd.yml +- name: Include systemd tasks + include_tasks: tasks/systemd.yml + +- name: Link default logs directory + file: + state: link + src: "{{keycloak_jboss_home}}/standalone/log" + dest: /var/log/keycloak - block: - name: Check admin credentials by generating a token diff --git a/roles/keycloak/tasks/systemd.yml b/roles/keycloak/tasks/systemd.yml index 3cf1479..858f5d7 100644 --- a/roles/keycloak/tasks/systemd.yml +++ b/roles/keycloak/tasks/systemd.yml @@ -38,6 +38,9 @@ daemon_reload: yes when: systemdunit.changed +- set_fact: + health_url: "{{ keycloak_management_url }}/health" + - name: start keycloak systemd: name: keycloak @@ -56,9 +59,6 @@ - meta: flush_handlers -- set_fact: - health_url: "{{ keycloak_management_url }}/health" - - name: "Wait until Keycloak becomes active {{ health_url }}" uri: url: "{{ health_url }}" diff --git a/roles/keycloak/templates/standalone-rhsso-jdg.xml.j2 b/roles/keycloak/templates/9.0.2/standalone-infinispan.xml.j2 similarity index 88% rename from roles/keycloak/templates/standalone-rhsso-jdg.xml.j2 rename to roles/keycloak/templates/9.0.2/standalone-infinispan.xml.j2 index 09884b5..2b2842b 100644 --- a/roles/keycloak/templates/standalone-rhsso-jdg.xml.j2 +++ b/roles/keycloak/templates/9.0.2/standalone-infinispan.xml.j2 @@ -1,6 +1,6 @@ - + @@ -23,9 +23,10 @@ - - + + + @@ -44,7 +45,8 @@ - + @@ -141,7 +143,7 @@ - + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE @@ -152,15 +154,15 @@ -{% if keycloak_jdbc[keycloak_jdbc_engine].enabled %} - {{ keycloak_jdbc[keycloak_jdbc_engine].connection_url }} - {{ keycloak_jdbc[keycloak_jdbc_engine].driver_module_name }} +{% if keycloak_jdbc.postgres.enabled %} + {{ keycloak_jdbc.postgres.connection_url }} + {{ keycloak_jdbc.postgres.driver_module_name }} 20 - {{ keycloak_jdbc[keycloak_jdbc_engine].db_user }} - {{ keycloak_jdbc[keycloak_jdbc_engine].db_password }} + {{ keycloak_jdbc.postgres.db_user }} + {{ keycloak_jdbc.postgres.db_password }} {% else %} jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE @@ -172,10 +174,10 @@ {% endif %} -{% if keycloak_jdbc[keycloak_jdbc_engine].enabled %} - - {{ keycloak_jdbc[keycloak_jdbc_engine].driver_class }} - {{ keycloak_jdbc[keycloak_jdbc_engine].xa_datasource_class }} +{% if keycloak_jdbc.postgres.enabled %} + + org.postgresql.Driver + org.postgresql.xa.PGXADataSource {% endif %} @@ -187,7 +189,7 @@ - + false @@ -197,15 +199,17 @@ - + - + - + - + @@ -232,7 +236,7 @@ - + @@ -248,7 +252,7 @@ - + @@ -357,7 +361,7 @@ - + @@ -366,25 +370,24 @@ - - - + + - + - + - + -{% for cachename in [ "sessions", "offlineSessions", "clientSessions", "offlineClientSessions", "loginFailures", "actionTokens" ] %} + {% for cachename in [ "sessions", "offlineSessions", "clientSessions", "offlineClientSessions", "loginFailures", "actionTokens" ] %} {{ keycloak_remotecache.password }} {{ keycloak_remotecache.realm | default('default') }} {{ keycloak_remotecache.server_name }} - {{ keycloak_remotecache.sasl_mechanism }} - {{ keycloak_remotecache.use_ssl }} - {{ keycloak_remotecache.trust_store_path }} + {{ keycloak_remotecache.sasl_mechanism | default('SCRAM-SHA-512') }} + false + {{ keycloak_remotecache.trust_store_path | default('/etc/truststore/truststore.jks') }} JKS - {{ keycloak_remotecache.trust_store_password }} + {{ keycloak_remotecache.trust_store_password | default("changeme") }} TOPOLOGY_AWARE -{% endfor %} + {% endfor %} {{ keycloak_remotecache.password }} {{ keycloak_remotecache.realm | default('default') }} {{ keycloak_remotecache.server_name }} - {{ keycloak_remotecache.sasl_mechanism }} - {{ keycloak_remotecache.use_ssl }} - {{ keycloak_remotecache.trust_store_path }} + {{ keycloak_remotecache.sasl_mechanism | default('SCRAM-SHA-512') }} + false + {{ keycloak_remotecache.trust_store_path | default('/etc/truststore/truststore.jks') }} JKS - {{ keycloak_remotecache.trust_store_password }} + {{ keycloak_remotecache.trust_store_password | default("changeme") }} TOPOLOGY_AWARE - + - + - + - + @@ -457,13 +460,13 @@ - + - + - + @@ -473,7 +476,7 @@ - + @@ -493,7 +496,7 @@ - + @@ -530,7 +533,7 @@ - + auth @@ -606,19 +609,18 @@ default - - + + - + - -{% if keycloak_modcluster.enabled %} +{% if keycloak_modcluster.enabled %} @@ -626,7 +628,7 @@ -{% endif %} +{% endif %} @@ -673,7 +675,7 @@ - + @@ -683,7 +685,9 @@ - + @@ -708,12 +712,18 @@ - + + + + - + {% if ansible_default_ipv4 is defined %} {% else %} diff --git a/roles/keycloak/templates/standalone-rhsso.xml.j2 b/roles/keycloak/templates/9.0.2/standalone.xml.j2 similarity index 87% rename from roles/keycloak/templates/standalone-rhsso.xml.j2 rename to roles/keycloak/templates/9.0.2/standalone.xml.j2 index 95eb4e0..823357f 100644 --- a/roles/keycloak/templates/standalone-rhsso.xml.j2 +++ b/roles/keycloak/templates/9.0.2/standalone.xml.j2 @@ -1,6 +1,6 @@ - + @@ -22,9 +22,10 @@ - - + + + @@ -43,7 +44,8 @@ - + @@ -128,7 +130,7 @@ - + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE @@ -156,7 +158,7 @@ - + false @@ -166,15 +168,17 @@ - + - + - + - + @@ -201,7 +205,7 @@ - + @@ -217,7 +221,130 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +{% if keycloak_modcluster.enabled %} + + + + + + + +{% endif %} + + + + + + + + + + + + + + + @@ -275,7 +402,6 @@ - @@ -317,126 +443,78 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + auth - - classpath:${jboss.home.dir}/providers/* - + classpath:${jboss.home.dir}/providers/* master 900 @@ -505,103 +583,12 @@ default - - + + - - - - - - -{% if keycloak_modcluster.enabled %} - - - - - - - -{% endif %} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -621,12 +608,12 @@ - + -{% if keycloak_modcluster.enabled %} +{% if keycloak_modcluster.enabled %} -{% endif %} +{% endif %} diff --git a/roles/keycloak/templates/keycloak-service.sh.j2 b/roles/keycloak/templates/keycloak-service.sh.j2 index 422ccde..82e3a21 100755 --- a/roles/keycloak/templates/keycloak-service.sh.j2 +++ b/roles/keycloak/templates/keycloak-service.sh.j2 @@ -83,8 +83,7 @@ startKeycloak() { -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 %} \ - 2>&1 >> "${KEYCLOAK_LOGFILE}" & + {% if keycloak_config_standalone_xml is defined %}--server-config={{ keycloak_config_standalone_xml }}{% endif %} & while [ ! -f ${KEYCLOAK_PIDFILE} ]; do sleep 1; done fi } diff --git a/roles/keycloak/templates/standalone-infinispan.xml.j2 b/roles/keycloak/templates/standalone-infinispan.xml.j2 index e7d2a8c..e73bf19 100644 --- a/roles/keycloak/templates/standalone-infinispan.xml.j2 +++ b/roles/keycloak/templates/standalone-infinispan.xml.j2 @@ -1,6 +1,6 @@ - + @@ -23,10 +23,9 @@ + - - - + @@ -45,8 +44,7 @@ - + @@ -143,7 +141,7 @@ - + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE @@ -154,15 +152,15 @@ -{% if keycloak_jdbc.postgres.enabled %} - {{ keycloak_jdbc.postgres.connection_url }} - {{ keycloak_jdbc.postgres.driver_module_name }} +{% if keycloak_jdbc[keycloak_jdbc_engine].enabled %} + {{ keycloak_jdbc[keycloak_jdbc_engine].connection_url }} + {{ keycloak_jdbc[keycloak_jdbc_engine].driver_module_name }} 20 - {{ keycloak_jdbc.postgres.db_user }} - {{ keycloak_jdbc.postgres.db_password }} + {{ keycloak_jdbc[keycloak_jdbc_engine].db_user }} + {{ keycloak_jdbc[keycloak_jdbc_engine].db_password }} {% else %} jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE @@ -174,10 +172,10 @@ {% endif %} -{% if keycloak_jdbc.postgres.enabled %} - - org.postgresql.Driver - org.postgresql.xa.PGXADataSource +{% if keycloak_jdbc[keycloak_jdbc_engine].enabled %} + + {{ keycloak_jdbc[keycloak_jdbc_engine].driver_class }} + {{ keycloak_jdbc[keycloak_jdbc_engine].xa_datasource_class }} {% endif %} @@ -189,7 +187,7 @@ - + false @@ -199,17 +197,15 @@ - + - + - + - + @@ -236,7 +232,7 @@ - + @@ -252,7 +248,7 @@ - + @@ -361,7 +357,7 @@ - + @@ -370,24 +366,25 @@ - - + + + - + - + - + - {% for cachename in [ "sessions", "offlineSessions", "clientSessions", "offlineClientSessions", "loginFailures", "actionTokens" ] %} +{% for cachename in [ "sessions", "offlineSessions", "clientSessions", "offlineClientSessions", "loginFailures", "actionTokens" ] %} {{ keycloak_remotecache.password }} {{ keycloak_remotecache.realm | default('default') }} {{ keycloak_remotecache.server_name }} - {{ keycloak_remotecache.sasl_mechanism | default('SCRAM-SHA-512') }} - false - {{ keycloak_remotecache.trust_store_path | default('/etc/truststore/truststore.jks') }} + {{ keycloak_remotecache.sasl_mechanism }} + {{ keycloak_remotecache.use_ssl }} + {{ keycloak_remotecache.trust_store_path }} JKS - {{ keycloak_remotecache.trust_store_password | default("changeme") }} + {{ keycloak_remotecache.trust_store_password }} TOPOLOGY_AWARE - {% endfor %} +{% endfor %} {{ keycloak_remotecache.password }} {{ keycloak_remotecache.realm | default('default') }} {{ keycloak_remotecache.server_name }} - {{ keycloak_remotecache.sasl_mechanism | default('SCRAM-SHA-512') }} - false - {{ keycloak_remotecache.trust_store_path | default('/etc/truststore/truststore.jks') }} + {{ keycloak_remotecache.sasl_mechanism }} + {{ keycloak_remotecache.use_ssl }} + {{ keycloak_remotecache.trust_store_path }} JKS - {{ keycloak_remotecache.trust_store_password | default("changeme") }} + {{ keycloak_remotecache.trust_store_password }} TOPOLOGY_AWARE - + - + - + - + @@ -460,13 +457,13 @@ - + - + - + @@ -476,7 +473,7 @@ - + @@ -496,7 +493,7 @@ - + @@ -533,7 +530,7 @@ - + auth @@ -609,18 +606,19 @@ default - - + + - + -{% if keycloak_modcluster.enabled %} + +{% if keycloak_modcluster.enabled %} @@ -628,7 +626,7 @@ -{% endif %} +{% endif %} @@ -675,7 +673,7 @@ - + @@ -685,9 +683,7 @@ - + @@ -712,18 +708,12 @@ - - - - + - + {% if ansible_default_ipv4 is defined %} {% else %} diff --git a/roles/keycloak/templates/standalone.xml.j2 b/roles/keycloak/templates/standalone.xml.j2 index bf3ce0a..b48883a 100644 --- a/roles/keycloak/templates/standalone.xml.j2 +++ b/roles/keycloak/templates/standalone.xml.j2 @@ -1,6 +1,6 @@ - + @@ -22,10 +22,9 @@ + - - - + @@ -44,8 +43,7 @@ - + @@ -130,7 +128,7 @@ - + jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE @@ -158,7 +156,7 @@ - + false @@ -168,17 +166,15 @@ - + - + - + - + @@ -205,7 +201,7 @@ - + @@ -221,130 +217,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -{% if keycloak_modcluster.enabled %} - - - - - - - -{% endif %} - - - - - - - - - - - - - - - + @@ -402,6 +275,7 @@ + @@ -443,78 +317,126 @@ + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + auth - classpath:${jboss.home.dir}/providers/* + + classpath:${jboss.home.dir}/providers/* + master 900 @@ -583,12 +505,103 @@ default - - + + + + + + + + +{% if keycloak_modcluster.enabled %} + + + + + + + +{% endif %} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -608,12 +621,12 @@ - + -{% if keycloak_modcluster.enabled %} +{% if keycloak_modcluster.enabled %} -{% endif %} +{% endif %} diff --git a/roles/keycloak/vars/main.yml b/roles/keycloak/vars/main.yml index f135d99..cf1d6cc 100644 --- a/roles/keycloak/vars/main.yml +++ b/roles/keycloak/vars/main.yml @@ -55,6 +55,7 @@ keycloak_jdbc: keycloak_modcluster: enabled: "{{ keycloak_ha_enabled }}" reverse_proxy_url: "{{ keycloak_modcluster_url }}" + frontend_url: "{{ keycloak_frontend_url }}" # infinispan keycloak_remotecache: