From 9a580023077242b1113f7a7d82bebfc14dd6911f Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Sat, 6 Mar 2021 12:18:05 -0500 Subject: [PATCH] Split config.cli templates into smaller files, use epp templates --- manifests/config.pp | 123 +++++++++- spec/classes/init_spec.rb | 8 - templates/config.cli.erb | 210 ------------------ templates/config.cli/00-header.epp | 10 + templates/config.cli/01-https-proxy.epp | 15 ++ templates/config.cli/02-datasource.epp | 52 +++++ templates/config.cli/03-truststore.epp | 26 +++ templates/config.cli/04-theming.epp | 9 + .../config.cli/05-deployment-scanner.epp | 7 + templates/config.cli/06-user-cache.epp | 10 + templates/config.cli/10-cluster.epp | 41 ++++ templates/config.cli/11-domain.epp | 70 ++++++ templates/config.cli/99-footer.epp | 6 + 13 files changed, 358 insertions(+), 229 deletions(-) delete mode 100644 templates/config.cli.erb create mode 100644 templates/config.cli/00-header.epp create mode 100644 templates/config.cli/01-https-proxy.epp create mode 100644 templates/config.cli/02-datasource.epp create mode 100644 templates/config.cli/03-truststore.epp create mode 100644 templates/config.cli/04-theming.epp create mode 100644 templates/config.cli/05-deployment-scanner.epp create mode 100644 templates/config.cli/06-user-cache.epp create mode 100644 templates/config.cli/10-cluster.epp create mode 100644 templates/config.cli/11-domain.epp create mode 100644 templates/config.cli/99-footer.epp diff --git a/manifests/config.pp b/manifests/config.pp index a9332123..d7da4e5f 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -30,7 +30,6 @@ $_add_user_keycloak_cmd = "${keycloak::install_base}/bin/add-user-keycloak.sh" $_add_user_keycloak_state = "${keycloak::install_base}/.create-keycloak-admin-${keycloak::datasource_driver}" - $_config_cli_content = template('keycloak/config.cli.erb') if $::keycloak::operating_mode != 'domain' { $_add_user_keycloak_args = "--user ${keycloak::admin_user} --password ${keycloak::admin_user_password} --realm master" @@ -63,29 +62,132 @@ user => $keycloak::user, } + if $keycloak::operating_mode == 'domain' { + $config_cli_prefix = '/profile=auth-server-clustered' + } else { + $config_cli_prefix = '' + } + concat { "${keycloak::install_base}/config.cli": - owner => $keycloak::user, - group => $keycloak::group, - mode => '0600', - notify => Exec['jboss-cli.sh --file=config.cli'], - show_diff => false, + owner => $keycloak::user, + group => $keycloak::group, + mode => '0600', + notify => Exec['jboss-cli.sh --file=config.cli'], + show_diff => false, + ensure_newline => true, } - concat::fragment { 'config.cli-keycloak': + concat::fragment { 'keycloak-config.cli-header': target => "${keycloak::install_base}/config.cli", - content => $_config_cli_content, + content => epp('keycloak/config.cli/00-header.epp', {'operating_mode' => $keycloak::operating_mode}), order => '00', } + if $keycloak::proxy_https { + concat::fragment { 'keycloak-config.cli-https-proxy': + target => "${keycloak::install_base}/config.cli", + content => epp('keycloak/config.cli/01-https-proxy.epp', {'prefix' => $config_cli_prefix}), + order => '01', + } + } + + concat::fragment { 'keycloak-config.cli-datasource': + target => "${keycloak::install_base}/config.cli", + content => epp('keycloak/config.cli/02-datasource.epp', { + 'datasource_driver' => $keycloak::datasource_driver, + 'datasource_connection_url' => $keycloak::datasource_connection_url, + 'datasource_username' => $keycloak::datasource_username, + 'datasource_password' => $keycloak::datasource_password, + 'mysql_datasource_class' => $keycloak::mysql_datasource_class, + 'prefix' => $config_cli_prefix, + }), + order => '02', + } + + concat::fragment { 'keycloak-config.cli-truststore': + target => "${keycloak::install_base}/config.cli", + content => epp('keycloak/config.cli/03-truststore.epp', { + 'truststore' => $keycloak::truststore, + 'operating_mode' => $keycloak::operating_mode, + 'install_base' => $keycloak::install_base, + 'truststore_password' => $keycloak::truststore_password, + 'truststore_hostname_verification_policy' => $keycloak::truststore_hostname_verification_policy, + 'prefix' => $config_cli_prefix, + }), + order => '03', + } + + concat::fragment { 'keycloak-config.cli-theming': + target => "${keycloak::install_base}/config.cli", + content => epp('keycloak/config.cli/04-theming.epp', { + 'theme_static_max_age' => $keycloak::theme_static_max_age, + 'theme_cache_themes' => $keycloak::theme_cache_themes, + 'theme_cache_templates' => $keycloak::theme_cache_templates, + 'prefix' => $config_cli_prefix, + }), + order => '04', + } + + # deployment scanner is not compatible with domain mode + if $keycloak::operating_mode != 'domain' { + concat::fragment { 'keycloak-config.cli-deployment-scanner': + target => "${keycloak::install_base}/config.cli", + content => epp('keycloak/config.cli/05-deployment-scanner.epp', { + 'auto_deploy_exploded' => $keycloak::auto_deploy_exploded, + 'auto_deploy_zipped' => $keycloak::auto_deploy_zipped, + 'prefix' => $config_cli_prefix, + }), + order => '05', + } + } + + concat::fragment { 'keycloak-config.cli-user-cache': + target => "${keycloak::install_base}/config.cli", + content => epp('keycloak/config.cli/06-user-cache.epp', { + 'user_cache' => $keycloak::user_cache, + 'prefix' => $config_cli_prefix, + }), + order => '06', + } + + concat::fragment { 'keycloak-config.cli-cluster': + target => "${keycloak::install_base}/config.cli", + content => epp('keycloak/config.cli/10-cluster.epp', { + 'operating_mode' => $keycloak::operating_mode, + 'enable_jdbc_ping' => $keycloak::enable_jdbc_ping, + 'datasource_driver' => $keycloak::datasource_driver, + 'jboss_bind_private_address' => $keycloak::jboss_bind_private_address, + 'jboss_bind_public_address' => $keycloak::jboss_bind_public_address, + 'prefix' => $config_cli_prefix, + }), + order => '10', + } + + if $keycloak::operating_mode == 'domain' { + concat::fragment { 'keycloak-config.cli-domain': + target => "${keycloak::install_base}/config.cli", + content => epp('keycloak/config.cli/11-domain.epp', { + 'prefix' => $config_cli_prefix, + }), + order => '11', + } + } + if $keycloak::custom_config_content or $keycloak::custom_config_source { - concat::fragment { 'config.cli-custom': + concat::fragment { 'keycloak-config.cli-custom': target => "${keycloak::install_base}/config.cli", content => $keycloak::custom_config_content, source => $keycloak::custom_config_source, - order => '01', + order => '50', } } + concat::fragment { 'keycloak-config.cli-footer': + target => "${keycloak::install_base}/config.cli", + content => epp('keycloak/config.cli/99-footer.epp', {'operating_mode' => $keycloak::operating_mode}), + order => '99', + } + exec { 'jboss-cli.sh --file=config.cli': command => "${keycloak::install_base}/bin/jboss-cli.sh --file=config.cli", cwd => $keycloak::install_base, @@ -150,7 +252,6 @@ } if $keycloak::role == 'master' { - # Remove load balancer group # Rename the server # Set port offset to zero to run server on port 8080 diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb index 70df8fa1..224d89ec 100644 --- a/spec/classes/init_spec.rb +++ b/spec/classes/init_spec.rb @@ -219,14 +219,6 @@ ) end - it do - is_expected.to contain_concat__fragment('config.cli-keycloak').with( - target: "/opt/keycloak-#{version}/config.cli", - content: %r{.*}, - order: '00', - ) - end - it do is_expected.to contain_file_line('keycloak-JAVA_OPTS').with( ensure: 'absent', diff --git a/templates/config.cli.erb b/templates/config.cli.erb deleted file mode 100644 index 709d2154..00000000 --- a/templates/config.cli.erb +++ /dev/null @@ -1,210 +0,0 @@ -<% if scope['keycloak::operating_mode'] == 'standalone'-%> -embed-server -<%- @prefix=''-%> -<%- elsif scope['keycloak::operating_mode'] == 'clustered'-%> -embed-server --server-config=standalone-ha.xml -<%- @prefix=''-%> -<% else -%> -embed-host-controller -<%- @prefix='/profile=auth-server-clustered'-%> -<% end -%> -<%- # https proxying -%> -<%- if scope['keycloak::proxy_https'] -%> -if (result.proxy-address-forwarding != true) of <%= @prefix -%>/subsystem=undertow/server=default-server/http-listener=default:read-resource -<%= @prefix -%>/subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=proxy-address-forwarding,value=true) -end-if -if (result.proxy-address-forwarding != true) of <%= @prefix -%>/subsystem=undertow/server=default-server/https-listener=https:read-resource -<%= @prefix -%>/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=proxy-address-forwarding,value=true) -end-if -if (outcome != success) of <%= @prefix -%>/socket-binding-group=standard-sockets/socket-binding=proxy-https:read-resource -<%= @prefix -%>/socket-binding-group=standard-sockets/socket-binding=proxy-https:add(port=443) -end-if -if (result.redirect-socket != proxy-https) of <%= @prefix -%>/subsystem=undertow/server=default-server/http-listener=default:read-resource -<%= @prefix -%>/subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=redirect-socket,value=proxy-https) -end-if -<%- end -%> -<%- # datasources -%> -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=driver-name, value=<%= scope['keycloak::datasource_driver'] %>) -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=connection-url, value="<%= scope['keycloak::datasource_connection_url'] %>") -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=jndi-name, value=java:jboss/datasources/KeycloakDS) -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=user-name, value=<%= scope['keycloak::datasource_username'] %>) -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=password, value=<%= scope['keycloak::datasource_password'] %>) -<%- if scope['keycloak::datasource_driver'] == 'mysql' -%> -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation, value=true) -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=check-valid-connection-sql, value="SELECT 1") -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation-millis, value=60000) -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=flush-strategy, value=IdleConnections) -try -<%= @prefix -%>/subsystem=datasources/jdbc-driver=mysql:add(driver-module-name=com.mysql.jdbc,driver-name=mysql,driver-xa-datasource-class-name=<%= scope['keycloak::mysql_datasource_class'] %>) -catch -<%= @prefix -%>/subsystem=datasources/jdbc-driver=mysql:remove -<%= @prefix -%>/subsystem=datasources/jdbc-driver=mysql:add(driver-module-name=com.mysql.jdbc,driver-name=mysql,driver-xa-datasource-class-name=<%= scope['keycloak::mysql_datasource_class'] %>) -end-try -<%- elsif scope['keycloak::datasource_driver'] == 'h2' -%> -/subsystem=datasources/data-source=KeycloakDS:undefine-attribute(name=background-validation) -/subsystem=datasources/data-source=KeycloakDS:undefine-attribute(name=check-valid-connection-sql) -/subsystem=datasources/data-source=KeycloakDS:undefine-attribute(name=background-validation-millis) -/subsystem=datasources/data-source=KeycloakDS:undefine-attribute(name=flush-strategy) -<%- elsif scope['keycloak::datasource_driver'] == 'oracle' -%> -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation, value=true) -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=check-valid-connection-sql, value="SELECT 1 FROM DUAL") -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation-millis, value=60000) -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=flush-strategy, value=IdleConnections) -try -<%= @prefix -%>/subsystem=datasources/jdbc-driver=oracle:add(driver-module-name=org.oracle,driver-name=oracle,driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource) -catch -<%= @prefix -%>/subsystem=datasources/jdbc-driver=oracle:remove -<%= @prefix -%>/subsystem=datasources/jdbc-driver=oracle:add(driver-module-name=org.oracle,driver-name=oracle,driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource) -end-try -<%- elsif scope['keycloak::datasource_driver'] == 'postgresql' -%> -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation, value=true) -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=check-valid-connection-sql, value="SELECT 1") -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation-millis, value=60000) -<%= @prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=flush-strategy, value=IdleConnections) -try -<%= @prefix -%>/subsystem=datasources/jdbc-driver=postgresql:add(driver-module-name=org.postgresql,driver-name=postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource) -catch -<%= @prefix -%>/subsystem=datasources/jdbc-driver=postgresql:remove -<%= @prefix -%>/subsystem=datasources/jdbc-driver=postgresql:add(driver-module-name=org.postgresql,driver-name=postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource) -end-try -<%- end -%> -<%- # truststore -%> -<%- if scope['keycloak::truststore'] -%> -if (outcome != success) of <%= @prefix -%>/subsystem=keycloak-server/spi=truststore:read-resource -<%= @prefix -%>/subsystem=keycloak-server/spi=truststore/:add -<%= @prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:add(enabled=true) -end-if -<% if scope['keycloak::operating_mode'] == 'domain'-%> -<%= @prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=file,value=<%= scope['keycloak::install_base'] %>/domain/configuration/truststore.jks) -<% else -%> -<%= @prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=file,value=<%= scope['keycloak::install_base'] %>/standalone/configuration/truststore.jks) -<% end -%> -<%= @prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=password,value=<%= scope['keycloak::truststore_password'] %>) -<%= @prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=hostname-verification-policy,value=<%= scope['keycloak::truststore_hostname_verification_policy'] %>) -<%= @prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=disabled,value=false) -<%- else -%> -if (outcome == success) of <%= @prefix -%>/subsystem=keycloak-server/spi=truststore:read-resource -<%= @prefix -%>/subsystem=keycloak-server/spi=truststore/:remove -end-if -<%- end -%> -<%- # theming -%> -<%= @prefix -%>/subsystem=keycloak-server/theme=defaults/:write-attribute(name=staticMaxAge, value=<%= scope['keycloak::theme_static_max_age'] %>) -<%= @prefix -%>/subsystem=keycloak-server/theme=defaults/:write-attribute(name=cacheThemes, value=<%= scope['keycloak::theme_cache_themes'] %>) -<%= @prefix -%>/subsystem=keycloak-server/theme=defaults/:write-attribute(name=cacheTemplates, value=<%= scope['keycloak::theme_cache_templates'] %>) -<%- # deployment scanner is not compatible with domain mode -%> -<% if scope['keycloak::operating_mode'] != 'domain'-%> -<%= @prefix -%>/subsystem=deployment-scanner/scanner=default:write-attribute(name="auto-deploy-exploded",value=<%= scope['keycloak::auto_deploy_exploded'] %>) -<%= @prefix -%>/subsystem=deployment-scanner/scanner=default:write-attribute(name="auto-deploy-zipped",value=<%= scope['keycloak::auto_deploy_zipped'] %>) -<% end -%> -try -<%= @prefix -%>/subsystem=keycloak-server/spi=userCache/provider=default/:add(enabled=<%= scope['keycloak::user_cache']%>) -catch -<%= @prefix -%>/subsystem=keycloak-server/spi=userCache/provider=default/:remove -<%= @prefix -%>/subsystem=keycloak-server/spi=userCache/provider=default/:add(enabled=<%= scope['keycloak::user_cache']%>) -end-try -<%- # JDBC_PING & remove udp stack -%> -<%- if scope['keycloak::operating_mode'] != 'standalone' && scope['keycloak::enable_jdbc_ping'] -%> -if (outcome != success) of <%= @prefix -%>/subsystem=jgroups/stack=tcp/protocol=JDBC_PING:read-resource -<%- if scope['keycloak::datasource_driver'] == 'postgresql' -%> -<%= @prefix -%>/subsystem=jgroups/stack=tcp/protocol=JDBC_PING: add(add-index=0, data-source="KeycloakDS", properties=[initialize_sql="CREATE TABLE IF NOT EXISTS JGROUPSPING ( own_addr varchar(200) NOT NULL, cluster_name varchar(200) NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, ping_data BYTEA, constraint PK_JGROUPSPING PRIMARY KEY (own_addr, cluster_name))"]) -<%- end -%> -<%- if scope['keycloak::datasource_driver'] == 'mysql' -%> -<%= @prefix -%>/subsystem=jgroups/stack=tcp/protocol=JDBC_PING: add(add-index=0, data-source="KeycloakDS", properties=[initialize_sql="CREATE TABLE IF NOT EXISTS JGROUPSPING (own_addr varchar(200) NOT NULL, cluster_name varchar(200) NOT NULL, updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, ping_data varbinary(5000) DEFAULT NULL, PRIMARY KEY (own_addr, cluster_name)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"]) -<%- end -%> -end-if -if (outcome == success) of <%= @prefix -%>/subsystem=jgroups/stack=tcp/protocol=MPING:read-resource -<%= @prefix -%>/subsystem=jgroups/stack=tcp/protocol=MPING: remove() -end-if -if (outcome == success) of <%= @prefix -%>/subsystem=jgroups/stack=tcp/protocol=pbcast.GMS:read-resource -<%= @prefix -%>/subsystem=jgroups/stack=tcp/protocol=pbcast.GMS: remove() -<%= @prefix -%>/subsystem=jgroups/stack=tcp/protocol=pbcast.GMS: add(properties=[join_timeout=30000, print_local_addr=true, print_physical_addrs=true]) -end-if -if (outcome != success) of <%= @prefix -%>/subsystem=jgroups/stack=tcp/protocol=JDBC_PING:read-resource -end-if -<%= @prefix -%>/subsystem=jgroups/channel=ee:write-attribute(name=stack, value="tcp") -if (outcome == success) of <%= @prefix -%>/subsystem=jgroups/stack=udp:read-resource -<%= @prefix -%>/subsystem=jgroups/stack=udp: remove() -end-if -if (outcome == success) of <%= @prefix -%>/socket-binding-group=standard-sockets/socket-binding=jgroups-udp:read-resource -<%= @prefix -%>/socket-binding-group=standard-sockets/socket-binding=jgroups-udp:remove() -end-if -if (outcome == success) of <%= @prefix -%>/socket-binding-group=standard-sockets/socket-binding=jgroups-mping:read-resource -<%= @prefix -%>/socket-binding-group=standard-sockets/socket-binding=jgroups-mping:remove() -end-if -<%- if scope['keycloak::operating_mode'] != 'domain' -%> -/interface=private:write-attribute(name=inet-address, value=${jboss.bind.address.private:<%= scope['keycloak::jboss_bind_private_address'] %>}) -/interface=public:write-attribute(name=inet-address, value=${jboss.bind.address:<%= scope['keycloak::jboss_bind_public_address'] %>}) -<%- end -%> -<%- end -%> -<%- # domain mode specific things -%> -<% if scope['keycloak::operating_mode'] == 'domain' -%> - -<%- # remove load balancer -%> -if (outcome == success) of /host=master/server-config=load-balancer:read-resource -/host=master/server-config=load-balancer:remove -end-if -if (outcome == success) of /server-group=load-balancer-group:read-resource -/server-group=load-balancer-group:remove -end-if -if (outcome == success) of /profile=load-balancer:read-resource -/profile=load-balancer:remove -end-if -if (outcome == success) of /socket-binding-group=load-balancer-sockets:read-resource -/socket-binding-group=load-balancer-sockets:remove -end-if - -<%- # ensure proxying for ha sockets -%> -if (outcome != success) of /socket-binding-group=ha-sockets/socket-binding=proxy-https:read-resource -/socket-binding-group=ha-sockets/socket-binding=proxy-https:add(port=443) -end-if - -<%- # caches -%> -<%= @prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=sessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) -<%= @prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=authenticationSessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) -<%= @prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=offlineSessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) -<%= @prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=clientSessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) -<%= @prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=offlineClientSessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) -<%= @prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=loginFailures:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) -<%= @prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=actionTokens:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) - -<%- # take control of the interfaces -%> -if (outcome != success) of /interface=management:read-resource() -/interface=management:add() -end-if -if (result != undefined) of /interface=management:read-attribute(name=inet-address) -/interface=management:write-attribute(name=inet-address, value=undefined) -end-if -if (outcome != success) of /interface=private:read-resource() -/interface=private:add() -end-if -if (result != undefined) of /interface=private:read-attribute(name=inet-address) -/interface=private:write-attribute(name=inet-address, value=undefined) -end-if -if (outcome != success) of /interface=public:read-resource() -/interface=public:add() -end-if -if (result != undefined) of /interface=public:read-attribute(name=inet-address) -/interface=public:write-attribute(name=inet-address, value=undefined) -end-if -if (result != public) of /socket-binding-group=ha-sockets:read-attribute(name=default-interface) -/socket-binding-group=ha-sockets:write-attribute(name=default-interface, value=public) -end-if -if (result != defined) of /socket-binding-group=ha-sockets/socket-binding=ajp:read-attribute(name=interface) -/socket-binding-group=ha-sockets/socket-binding=ajp:write-attribute(name=interface, value=undefined) -end-if -if (result != defined) of /socket-binding-group=ha-sockets/socket-binding=http:read-attribute(name=interface) -/socket-binding-group=ha-sockets/socket-binding=http:write-attribute(name=interface, value=undefined) -end-if -if (result != defined) of /socket-binding-group=ha-sockets/socket-binding=https:read-attribute(name=interface) -/socket-binding-group=ha-sockets/socket-binding=https:write-attribute(name=interface, value=undefined) -end-if -if (result != management) of /socket-binding-group=ha-sockets/socket-binding=jgroups-tcp:read-attribute(name=interface) -/socket-binding-group=ha-sockets/socket-binding=jgroups-tcp:write-attribute(name=interface,value=management) -end-if - -<%- # ensure datasource for ee default bindings is correct -%> -if (result != java:jboss/datasources/KeycloakDS) of <%= @prefix -%>/subsystem=ee/service=default-bindings:read-attribute(name=datasource) -<%= @prefix -%>/subsystem=ee/service=default-bindings:write-attribute(name=datasource,value=java:jboss/datasources/KeycloakDS) -end-if -stop-embedded-host-controller -<% end -%> diff --git a/templates/config.cli/00-header.epp b/templates/config.cli/00-header.epp new file mode 100644 index 00000000..ab4664db --- /dev/null +++ b/templates/config.cli/00-header.epp @@ -0,0 +1,10 @@ +<%- | +String $operating_mode +| -%> +<% if $operating_mode == 'standalone' { -%> +embed-server +<% } elsif $operating_mode == 'clustered' { -%> +embed-server --server-config=standalone-ha.xml +<% } else { -%> +embed-host-controller +<% } -%> diff --git a/templates/config.cli/01-https-proxy.epp b/templates/config.cli/01-https-proxy.epp new file mode 100644 index 00000000..c8daf1b1 --- /dev/null +++ b/templates/config.cli/01-https-proxy.epp @@ -0,0 +1,15 @@ +<%- | +String $prefix +| -%> +if (result.proxy-address-forwarding != true) of <%= $prefix -%>/subsystem=undertow/server=default-server/http-listener=default:read-resource +<%= $prefix -%>/subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=proxy-address-forwarding,value=true) +end-if +if (result.proxy-address-forwarding != true) of <%= $prefix -%>/subsystem=undertow/server=default-server/https-listener=https:read-resource +<%= $prefix -%>/subsystem=undertow/server=default-server/https-listener=https:write-attribute(name=proxy-address-forwarding,value=true) +end-if +if (outcome != success) of <%= $prefix -%>/socket-binding-group=standard-sockets/socket-binding=proxy-https:read-resource +<%= $prefix -%>/socket-binding-group=standard-sockets/socket-binding=proxy-https:add(port=443) +end-if +if (result.redirect-socket != proxy-https) of <%= $prefix -%>/subsystem=undertow/server=default-server/http-listener=default:read-resource +<%= $prefix -%>/subsystem=undertow/server=default-server/http-listener=default:write-attribute(name=redirect-socket,value=proxy-https) +end-if diff --git a/templates/config.cli/02-datasource.epp b/templates/config.cli/02-datasource.epp new file mode 100644 index 00000000..6673aa75 --- /dev/null +++ b/templates/config.cli/02-datasource.epp @@ -0,0 +1,52 @@ +<%- | +String $datasource_driver, +String $datasource_connection_url, +String $datasource_username, +String $datasource_password, +String $mysql_datasource_class, +String $prefix +| -%> +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=driver-name, value=<%= $datasource_driver %>) +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=connection-url, value="<%= $datasource_connection_url %>") +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=jndi-name, value=java:jboss/datasources/KeycloakDS) +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=user-name, value=<%= $datasource_username %>) +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=password, value=<%= $datasource_password %>) +<%- if $datasource_driver == 'mysql' { -%> +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation, value=true) +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=check-valid-connection-sql, value="SELECT 1") +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation-millis, value=60000) +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=flush-strategy, value=IdleConnections) +try +<%= $prefix -%>/subsystem=datasources/jdbc-driver=mysql:add(driver-module-name=com.mysql.jdbc,driver-name=mysql,driver-xa-datasource-class-name=<%= $mysql_datasource_class %>) +catch +<%= $prefix -%>/subsystem=datasources/jdbc-driver=mysql:remove +<%= $prefix -%>/subsystem=datasources/jdbc-driver=mysql:add(driver-module-name=com.mysql.jdbc,driver-name=mysql,driver-xa-datasource-class-name=<%= $mysql_datasource_class %>) +end-try +<%- } elsif $datasource_driver == 'h2' { -%> +/subsystem=datasources/data-source=KeycloakDS:undefine-attribute(name=background-validation) +/subsystem=datasources/data-source=KeycloakDS:undefine-attribute(name=check-valid-connection-sql) +/subsystem=datasources/data-source=KeycloakDS:undefine-attribute(name=background-validation-millis) +/subsystem=datasources/data-source=KeycloakDS:undefine-attribute(name=flush-strategy) +<%- } elsif $datasource_driver == 'oracle' { -%> +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation, value=true) +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=check-valid-connection-sql, value="SELECT 1 FROM DUAL") +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation-millis, value=60000) +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=flush-strategy, value=IdleConnections) +try +<%= $prefix -%>/subsystem=datasources/jdbc-driver=oracle:add(driver-module-name=org.oracle,driver-name=oracle,driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource) +catch +<%= $prefix -%>/subsystem=datasources/jdbc-driver=oracle:remove +<%= $prefix -%>/subsystem=datasources/jdbc-driver=oracle:add(driver-module-name=org.oracle,driver-name=oracle,driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource) +end-try +<%- } elsif $datasource_driver == 'postgresql' { -%> +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation, value=true) +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=check-valid-connection-sql, value="SELECT 1") +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=background-validation-millis, value=60000) +<%= $prefix -%>/subsystem=datasources/data-source=KeycloakDS:write-attribute(name=flush-strategy, value=IdleConnections) +try +<%= $prefix -%>/subsystem=datasources/jdbc-driver=postgresql:add(driver-module-name=org.postgresql,driver-name=postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource) +catch +<%= $prefix -%>/subsystem=datasources/jdbc-driver=postgresql:remove +<%= $prefix -%>/subsystem=datasources/jdbc-driver=postgresql:add(driver-module-name=org.postgresql,driver-name=postgresql,driver-xa-datasource-class-name=org.postgresql.xa.PGXADataSource) +end-try +<%- } -%> diff --git a/templates/config.cli/03-truststore.epp b/templates/config.cli/03-truststore.epp new file mode 100644 index 00000000..3f78fcec --- /dev/null +++ b/templates/config.cli/03-truststore.epp @@ -0,0 +1,26 @@ +<%- | +Boolean $truststore, +String $operating_mode, +String $install_base, +String $truststore_password, +String $truststore_hostname_verification_policy, +String $prefix +| -%> +<% if $truststore { -%> +if (outcome != success) of <%= $prefix -%>/subsystem=keycloak-server/spi=truststore:read-resource +<%= $prefix -%>/subsystem=keycloak-server/spi=truststore/:add +<%= $prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:add(enabled=true) +end-if +<% if $operating_mode == 'domain' { -%> +<%= $prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=file,value=<%= $install_base %>/domain/configuration/truststore.jks) +<% } else { -%> +<%= $prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=file,value=<%= $install_base %>/standalone/configuration/truststore.jks) +<% } -%> +<%= $prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=password,value=<%= $truststore_password %>) +<%= $prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=hostname-verification-policy,value=<%= $truststore_hostname_verification_policy %>) +<%= $prefix -%>/subsystem=keycloak-server/spi=truststore/provider=file/:map-put(name=properties,key=disabled,value=false) +<% } else { -%> +if (outcome == success) of <%= $prefix -%>/subsystem=keycloak-server/spi=truststore:read-resource +<%= $prefix -%>/subsystem=keycloak-server/spi=truststore/:remove +end-if +<% } -%> diff --git a/templates/config.cli/04-theming.epp b/templates/config.cli/04-theming.epp new file mode 100644 index 00000000..0f1b0292 --- /dev/null +++ b/templates/config.cli/04-theming.epp @@ -0,0 +1,9 @@ +<%- | +Integer $theme_static_max_age, +Boolean $theme_cache_themes, +Boolean $theme_cache_templates, +String $prefix +| -%> +<%= $prefix -%>/subsystem=keycloak-server/theme=defaults/:write-attribute(name=staticMaxAge, value=<%= $theme_static_max_age %>) +<%= $prefix -%>/subsystem=keycloak-server/theme=defaults/:write-attribute(name=cacheThemes, value=<%= $theme_cache_themes %>) +<%= $prefix -%>/subsystem=keycloak-server/theme=defaults/:write-attribute(name=cacheTemplates, value=<%= $theme_cache_templates %>) diff --git a/templates/config.cli/05-deployment-scanner.epp b/templates/config.cli/05-deployment-scanner.epp new file mode 100644 index 00000000..4e30bba5 --- /dev/null +++ b/templates/config.cli/05-deployment-scanner.epp @@ -0,0 +1,7 @@ +<%- | +Boolean $auto_deploy_exploded, +Boolean $auto_deploy_zipped, +String $prefix +| -%> +<%= $prefix -%>/subsystem=deployment-scanner/scanner=default:write-attribute(name="auto-deploy-exploded",value=<%= $auto_deploy_exploded %>) +<%= $prefix -%>/subsystem=deployment-scanner/scanner=default:write-attribute(name="auto-deploy-zipped",value=<%= $auto_deploy_zipped %>) diff --git a/templates/config.cli/06-user-cache.epp b/templates/config.cli/06-user-cache.epp new file mode 100644 index 00000000..77b83a37 --- /dev/null +++ b/templates/config.cli/06-user-cache.epp @@ -0,0 +1,10 @@ +<%- | +Boolean $user_cache, +String $prefix +| -%> +try +<%= $prefix -%>/subsystem=keycloak-server/spi=userCache/provider=default/:add(enabled=<%= $user_cache %>) +catch +<%= $prefix -%>/subsystem=keycloak-server/spi=userCache/provider=default/:remove +<%= $prefix -%>/subsystem=keycloak-server/spi=userCache/provider=default/:add(enabled=<%= $user_cache %>) +end-try diff --git a/templates/config.cli/10-cluster.epp b/templates/config.cli/10-cluster.epp new file mode 100644 index 00000000..0c94de53 --- /dev/null +++ b/templates/config.cli/10-cluster.epp @@ -0,0 +1,41 @@ +<%- | +String $operating_mode, +Boolean $enable_jdbc_ping, +String $datasource_driver, +String $jboss_bind_private_address, +String $jboss_bind_public_address, +String $prefix +| -%> +<%- if $operating_mode != 'standalone' and $enable_jdbc_ping { -%> +if (outcome != success) of <%= $prefix -%>/subsystem=jgroups/stack=tcp/protocol=JDBC_PING:read-resource +<%- if $datasource_driver == 'postgresql' { -%> +<%= $prefix -%>/subsystem=jgroups/stack=tcp/protocol=JDBC_PING: add(add-index=0, data-source="KeycloakDS", properties=[initialize_sql="CREATE TABLE IF NOT EXISTS JGROUPSPING ( own_addr varchar(200) NOT NULL, cluster_name varchar(200) NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, ping_data BYTEA, constraint PK_JGROUPSPING PRIMARY KEY (own_addr, cluster_name))"]) +<%- } -%> +<%- if $datasource_driver == 'mysql' { -%> +<%= $prefix -%>/subsystem=jgroups/stack=tcp/protocol=JDBC_PING: add(add-index=0, data-source="KeycloakDS", properties=[initialize_sql="CREATE TABLE IF NOT EXISTS JGROUPSPING (own_addr varchar(200) NOT NULL, cluster_name varchar(200) NOT NULL, updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, ping_data varbinary(5000) DEFAULT NULL, PRIMARY KEY (own_addr, cluster_name)) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin"]) +<%- } -%> +end-if +if (outcome == success) of <%= $prefix -%>/subsystem=jgroups/stack=tcp/protocol=MPING:read-resource +<%= $prefix -%>/subsystem=jgroups/stack=tcp/protocol=MPING: remove() +end-if +if (outcome == success) of <%= $prefix -%>/subsystem=jgroups/stack=tcp/protocol=pbcast.GMS:read-resource +<%= $prefix -%>/subsystem=jgroups/stack=tcp/protocol=pbcast.GMS: remove() +<%= $prefix -%>/subsystem=jgroups/stack=tcp/protocol=pbcast.GMS: add(properties=[join_timeout=30000, print_local_addr=true, print_physical_addrs=true]) +end-if +if (outcome != success) of <%= $prefix -%>/subsystem=jgroups/stack=tcp/protocol=JDBC_PING:read-resource +end-if +<%= $prefix -%>/subsystem=jgroups/channel=ee:write-attribute(name=stack, value="tcp") +if (outcome == success) of <%= $prefix -%>/subsystem=jgroups/stack=udp:read-resource +<%= $prefix -%>/subsystem=jgroups/stack=udp: remove() +end-if +if (outcome == success) of <%= $prefix -%>/socket-binding-group=standard-sockets/socket-binding=jgroups-udp:read-resource +<%= $prefix -%>/socket-binding-group=standard-sockets/socket-binding=jgroups-udp:remove() +end-if +if (outcome == success) of <%= $prefix -%>/socket-binding-group=standard-sockets/socket-binding=jgroups-mping:read-resource +<%= $prefix -%>/socket-binding-group=standard-sockets/socket-binding=jgroups-mping:remove() +end-if +<%- if $operating_mode != 'domain' { -%> +/interface=private:write-attribute(name=inet-address, value=${jboss.bind.address.private:<%= $jboss_bind_private_address %>}) +/interface=public:write-attribute(name=inet-address, value=${jboss.bind.address:<%= $jboss_bind_public_address %>}) +<%- } -%> +<%- } -%> diff --git a/templates/config.cli/11-domain.epp b/templates/config.cli/11-domain.epp new file mode 100644 index 00000000..a8b7dcf2 --- /dev/null +++ b/templates/config.cli/11-domain.epp @@ -0,0 +1,70 @@ +<%- | +String $prefix +| -%> +<%# remove load balancer -%> +if (outcome == success) of /host=master/server-config=load-balancer:read-resource +/host=master/server-config=load-balancer:remove +end-if +if (outcome == success) of /server-group=load-balancer-group:read-resource +/server-group=load-balancer-group:remove +end-if +if (outcome == success) of /profile=load-balancer:read-resource +/profile=load-balancer:remove +end-if +if (outcome == success) of /socket-binding-group=load-balancer-sockets:read-resource +/socket-binding-group=load-balancer-sockets:remove +end-if + +<%# ensure proxying for ha sockets -%> +if (outcome != success) of /socket-binding-group=ha-sockets/socket-binding=proxy-https:read-resource +/socket-binding-group=ha-sockets/socket-binding=proxy-https:add(port=443) +end-if + +<%# caches -%> +<%= $prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=sessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) +<%= $prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=authenticationSessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) +<%= $prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=offlineSessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) +<%= $prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=clientSessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) +<%= $prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=offlineClientSessions:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) +<%= $prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=loginFailures:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) +<%= $prefix -%>/subsystem=infinispan/cache-container=keycloak/distributed-cache=actionTokens:write-attribute(name=owners, value=${env.CACHE_OWNERS:2}) + +<%# take control of the interfaces -%> +if (outcome != success) of /interface=management:read-resource() +/interface=management:add() +end-if +if (result != undefined) of /interface=management:read-attribute(name=inet-address) +/interface=management:write-attribute(name=inet-address, value=undefined) +end-if +if (outcome != success) of /interface=private:read-resource() +/interface=private:add() +end-if +if (result != undefined) of /interface=private:read-attribute(name=inet-address) +/interface=private:write-attribute(name=inet-address, value=undefined) +end-if +if (outcome != success) of /interface=public:read-resource() +/interface=public:add() +end-if +if (result != undefined) of /interface=public:read-attribute(name=inet-address) +/interface=public:write-attribute(name=inet-address, value=undefined) +end-if +if (result != public) of /socket-binding-group=ha-sockets:read-attribute(name=default-interface) +/socket-binding-group=ha-sockets:write-attribute(name=default-interface, value=public) +end-if +if (result != defined) of /socket-binding-group=ha-sockets/socket-binding=ajp:read-attribute(name=interface) +/socket-binding-group=ha-sockets/socket-binding=ajp:write-attribute(name=interface, value=undefined) +end-if +if (result != defined) of /socket-binding-group=ha-sockets/socket-binding=http:read-attribute(name=interface) +/socket-binding-group=ha-sockets/socket-binding=http:write-attribute(name=interface, value=undefined) +end-if +if (result != defined) of /socket-binding-group=ha-sockets/socket-binding=https:read-attribute(name=interface) +/socket-binding-group=ha-sockets/socket-binding=https:write-attribute(name=interface, value=undefined) +end-if +if (result != management) of /socket-binding-group=ha-sockets/socket-binding=jgroups-tcp:read-attribute(name=interface) +/socket-binding-group=ha-sockets/socket-binding=jgroups-tcp:write-attribute(name=interface,value=management) +end-if + +<%# ensure datasource for ee default bindings is correct -%> +if (result != java:jboss/datasources/KeycloakDS) of <%= $prefix -%>/subsystem=ee/service=default-bindings:read-attribute(name=datasource) +<%= $prefix -%>/subsystem=ee/service=default-bindings:write-attribute(name=datasource,value=java:jboss/datasources/KeycloakDS) +end-if diff --git a/templates/config.cli/99-footer.epp b/templates/config.cli/99-footer.epp new file mode 100644 index 00000000..e71114e5 --- /dev/null +++ b/templates/config.cli/99-footer.epp @@ -0,0 +1,6 @@ +<%- | +String $operating_mode +| -%> +<% if $operating_mode == 'domain' { -%> +stop-embedded-host-controller +<% } -%>