diff --git a/templates/template03-keycloak/Readme.md b/templates/template03-keycloak/Readme.md index 182b45b..abbac80 100644 --- a/templates/template03-keycloak/Readme.md +++ b/templates/template03-keycloak/Readme.md @@ -7,13 +7,13 @@ |File name | Description| | --- | --- | -| `keycloak-X.Y.Z.tar.gz` | The installer archive to be downloaded from [here](https://www.keycloak.org/downloads.html) | +| `keycloak-X.Y.Z.zip` | The installer archive to be downloaded from [here](https://www.keycloak.org/downloads.html) - Distribution powered by Quarkus | | `keycloak.service` | The systemd unit file for Keycloak service | -| `launch.sh` | Launch script for the Keycloak Server | | `mkcert` | mkcert command line utility to be downloaded [here](https://github.com/FiloSottile/mkcert/releases). Pick the latest binary for amd64 and rename it to `mkcert` | | `rootCA.pem` | The rootCA previously created in your host machine | | `rootCA-key.pem` | The rootCA key previously created in your host machine | -| `standalone.xml` | The Keycloak Server configuration file | +| `keycloak-env.conf` | The environment file for the systemd service | +| `keycloak.conf` | The Keycloak configuration file || * Create folder `log` * Open `Vagrantfile` and change the value of variable `lxd.name`. It makes sense to give the same name as the folder, in this example `keycloak-instance`. diff --git a/templates/template03-keycloak/Vagrantfile b/templates/template03-keycloak/Vagrantfile index 9dc222d..428d542 100644 --- a/templates/template03-keycloak/Vagrantfile +++ b/templates/template03-keycloak/Vagrantfile @@ -14,7 +14,7 @@ config.vm.provider 'lxd' do |lxd| lxd.api_endpoint = 'https://127.0.0.1:8443' lxd.timeout = 10 - lxd.name = 'keycloak-test' + lxd.name = 'your-container-name' # lxd.nesting = nil # lxd.privileged = nil # lxd.ephemeral = false diff --git a/templates/template03-keycloak/artifacts/keycloak-env.conf b/templates/template03-keycloak/artifacts/keycloak-env.conf new file mode 100644 index 0000000..2c80775 --- /dev/null +++ b/templates/template03-keycloak/artifacts/keycloak-env.conf @@ -0,0 +1,4 @@ + +KEYCLOAK_ADMIN=admin + +KEYCLOAK_ADMIN_PASSWORD=admin diff --git a/templates/template03-keycloak/artifacts/keycloak.conf b/templates/template03-keycloak/artifacts/keycloak.conf new file mode 100644 index 0000000..22f81f8 --- /dev/null +++ b/templates/template03-keycloak/artifacts/keycloak.conf @@ -0,0 +1,40 @@ +# Basic settings for running in production. Change accordingly before deploying the server. + +# Database + +# The database vendor. +#db=postgres + +# The username of the database user. +#db-username=keycloak + +# The password of the database user. +#db-password=password + +# The full database JDBC URL. If not provided, a default URL is set based on the selected database vendor. +#db-url=jdbc:postgresql://localhost/keycloak + +# Observability + +# If the server should expose healthcheck endpoints. +#health-enabled=true + +# If the server should expose metrics endpoints. +#metrics-enabled=true + +# HTTP +https-enabled=true +# The file path to a server certificate or certificate chain in PEM format. +https-certificate-file=/opt/keycloak/conf/server-crt.pem + +# The file path to a private key in PEM format. +https-certificate-key-file=/opt/keycloak/conf/server-key.pem + +# The proxy address forwarding mode if the server is behind a reverse proxy. +#proxy=reencrypt + +# Do not attach route to cookies and rely on the session affinity capabilities from reverse proxy +#spi-sticky-session-encoder-infinispan-should-attach-route=false + +# Hostname for the Keycloak server. +hostname=#MACHINE_HOSTNAME# diff --git a/templates/template03-keycloak/artifacts/keycloak.service b/templates/template03-keycloak/artifacts/keycloak.service index 8ff8d9f..8111327 100644 --- a/templates/template03-keycloak/artifacts/keycloak.service +++ b/templates/template03-keycloak/artifacts/keycloak.service @@ -1,17 +1,16 @@ [Unit] Description=The Keycloak Server + After=syslog.target network.target -Before=httpd.service [Service] -Environment=LAUNCH_JBOSS_IN_BACKGROUND=1 -EnvironmentFile=-/etc/keycloak/keycloak.conf -User=kck -Group=kck -LimitNOFILE=102642 -PIDFile=/var/run/keycloak/keycloak.pid -ExecStart=/opt/keycloak/bin/launch.sh $WILDFLY_MODE $WILDFLY_CONFIG $WILDFLY_BIND -StandardOutput=null +EnvironmentFile=-/etc/keycloak/keycloak-env.conf + +User=#KEYCLOAK_USER# + +Group=#KEYCLOAK_USER# + +ExecStart=/opt/keycloak/bin/kc.sh start-dev [Install] WantedBy=multi-user.target diff --git a/templates/template03-keycloak/artifacts/launch.sh b/templates/template03-keycloak/artifacts/launch.sh deleted file mode 100644 index be33f44..0000000 --- a/templates/template03-keycloak/artifacts/launch.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash - -if [ "x$WILDFLY_HOME" = "x" ]; then - WILDFLY_HOME="/opt/keycloak" -fi - -if [[ "$1" == "domain" ]]; then - $WILDFLY_HOME/bin/domain.sh -c $2 -b $3 -else - $WILDFLY_HOME/bin/standalone.sh -c $2 -b $3 -fi - diff --git a/templates/template03-keycloak/artifacts/standalone.xml b/templates/template03-keycloak/artifacts/standalone.xml deleted file mode 100644 index c09567e..0000000 --- a/templates/template03-keycloak/artifacts/standalone.xml +++ /dev/null @@ -1,615 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE - h2 - - sa - sa - - - - jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE - h2 - - sa - sa - - - - - org.h2.jdbcx.JdbcDataSource - - - - - - - - - false - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - auth - - - classpath:${jboss.home.dir}/providers/* - - - master - 900 - - 2592000 - true - true - ${jboss.home.dir}/themes - - - - - - - - - - - - - jpa - - - basic - - - - - - - - - - - - - - - - - - - default - - - - - - - - ${keycloak.jta.lookup.provider:jboss} - - - - - - - - - - - ${keycloak.x509cert.lookup.provider:default} - - - - default - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/templates/template03-keycloak/provision.sh b/templates/template03-keycloak/provision.sh index fbe0bdb..995f014 100644 --- a/templates/template03-keycloak/provision.sh +++ b/templates/template03-keycloak/provision.sh @@ -6,11 +6,16 @@ echo "provisioning started: ${start_time}" -MACHINE_HOSTNAME=keycloak-test.localenv.com +#### The user must fill these variables - START + +MACHINE_HOSTNAME= + +KEYCLOAK_VERSION= + +#### The user must fill these variables - END KEYCLOAK_USER=kck -KEYCLOAK_VERSION=14.0.0 KEYCLOAK_INSTALLER_VERSION=keycloak-${KEYCLOAK_VERSION} @@ -38,9 +43,9 @@ apt update -apt install -y default-jdk +apt install -y openjdk-11-jdk unzip -tar -xzf /vagrant/artifacts/${KEYCLOAK_INSTALLER_VERSION}.tar.gz +unzip /vagrant/artifacts/${KEYCLOAK_INSTALLER_VERSION}.zip mv ${KEYCLOAK_INSTALLER_VERSION} /opt @@ -50,36 +55,27 @@ mkdir /etc/keycloak -cp /opt/keycloak/docs/contrib/scripts/systemd/wildfly.conf /etc/keycloak/keycloak.conf +cp /vagrant/artifacts/keycloak-env.conf /etc/keycloak/keycloak-env.conf -cp /vagrant/artifacts/launch.sh /opt/keycloak/bin/ - -chown kck.kck /opt/keycloak/bin/launch.sh - -chmod u+x /opt/keycloak/bin/launch.sh - cp /vagrant/artifacts/keycloak.service /etc/systemd/system/keycloak.service +sed -i "s|#KEYCLOAK_USER#|${KEYCLOAK_USER}|g" /etc/systemd/system/keycloak.service + +cp /vagrant/artifacts/keycloak.conf /opt/keycloak/conf/keycloak.conf + +sed -i "s|#MACHINE_HOSTNAME#|${MACHINE_HOSTNAME}|g" /opt/keycloak/conf/keycloak.conf + export CAROOT=/vagrant/artifacts/ /vagrant/artifacts/mkcert -install -/vagrant/artifacts/mkcert --cert-file /tmp/fullchain.pem --key-file /tmp/privatekey.pem "${MACHINE_HOSTNAME}" +/vagrant/artifacts/mkcert --cert-file /opt/keycloak/conf/server-crt.pem --key-file /opt/keycloak/conf/server-key.pem "${MACHINE_HOSTNAME}" -openssl pkcs12 -export -inkey /tmp/privatekey.pem -in /tmp/fullchain.pem -out /tmp/kc.pkcs12 -passout 'pass:changeit' - -keytool -importkeystore -srckeystore /tmp/kc.pkcs12 -srcstoretype pkcs12 -destkeystore /opt/keycloak/standalone/configuration/kc.jks -deststoretype JKS -storepass changeit -srcstorepass changeit - -cp /vagrant/artifacts/standalone.xml /opt/keycloak/standalone/configuration/ - -chown ${KEYCLOAK_USER}.${KEYCLOAK_USER} /opt/keycloak/standalone/configuration/standalone.xml /opt/keycloak/standalone/configuration/kc.jks - +chown kck.kck /opt/keycloak/conf/server-crt.pem /opt/keycloak/conf/server-key.pem systemctl daemon-reload systemctl enable keycloak -/opt/keycloak/bin/add-user-keycloak.sh -u admin -p admin - systemctl start keycloak systemctl status keycloak