Skip to content

Commit

Permalink
chore: upgrade keycloak to 18.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yelhouti committed Apr 22, 2022
1 parent 7096814 commit a94ff3d
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 178 deletions.
10 changes: 9 additions & 1 deletion generators/common/templates/README.md.jhi.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,22 @@ spring:
client:
provider:
oidc:
issuer-uri: http://localhost:9080/auth/realms/jhipster
issuer-uri: http://localhost:9080/realms/jhipster
registration:
oidc:
client-id: web_app
client-secret: web_app
scope: openid,profile,email
```
Some of Keycloak configuration is now done in build time and the other part before running the app, here is the [list](https://www.keycloak.org/server/all-config) of all build and configuration options.
Before moving to production, please make sure to follow this [guide](https://www.keycloak.org/server/configuration) for better security and performance.
Also, you should never use `start-dev` nor `KC_DB=dev-file` in production.
When using Kubernetes, importing should be done using init-containers (with a volume when using `db=dev-file`).
### Okta
If you'd like to use Okta instead of Keycloak, it's pretty quick using the [Okta CLI](https://cli.okta.com/). After you've installed it, run:
Expand Down
1 change: 0 additions & 1 deletion generators/docker-compose/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function writeFiles() {
writeKeycloakFiles() {
if (this.authenticationType === OAUTH2 && this.applicationType !== MICROSERVICE) {
this.template('realm-config/jhipster-realm.json.ejs', 'realm-config/jhipster-realm.json');
this.template('realm-config/jhipster-users-0.json.ejs', 'realm-config/jhipster-users-0.json');
}
},

Expand Down
18 changes: 9 additions & 9 deletions generators/docker-compose/templates/docker-compose.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ services:
<%_ } _%>
<%_ if (usesOauth2) { _%>
# For Keycloak to work, you need to add '127.0.0.1 keycloak' to your hosts file
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/auth/realms/jhipster
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:8080/realms/jhipster
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=jhipster-registry
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=jhipster-registry
<%_ } _%>
Expand All @@ -95,17 +95,17 @@ services:
<%_ if (usesOauth2) { _%>
keycloak:
image: <%= DOCKER_KEYCLOAK %>
command: ["-b", "0.0.0.0", "-Dkeycloak.migration.action=import", "-Dkeycloak.migration.provider=dir", "-Dkeycloak.migration.dir=/opt/jboss/keycloak/realm-config", "-Dkeycloak.migration.strategy=OVERWRITE_EXISTING", "-Djboss.socket.binding.port-offset=1000", "-Dkeycloak.profile.feature.upload_scripts=enabled"]
command: ['start-dev --import-realm']
volumes:
- ./realm-config:/opt/jboss/keycloak/realm-config
- ./realm-config:/opt/keycloak/data/import
environment:
- KEYCLOAK_USER=admin
- KEYCLOAK_PASSWORD=admin
- DB_VENDOR=h2
- KC_DB=dev-file
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
- KC_FEATURES=scripts
ports:
- 9080:9080
- 9443:9443
- 10990:10990
- 9080:8080
- 9443:8443
<%_ } _%>
<%_ if (monitoringPrometheus) { _%>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2492,12 +2492,70 @@
"clientOfflineSessionIdleTimeout": "0",
"cibaInterval": "5"
},
"keycloakVersion": "16.1.0",
"keycloakVersion": "18.0.0",
"userManagedAccessAllowed": false,
"clientProfiles": {
"profiles": []
},
"clientPolicies": {
"policies": []
}
},
"users": [
{
"id": "4c973896-5761-41fc-8217-07c5d13a004b",
"createdTimestamp": 1505479415590,
"username": "admin",
"enabled": true,
"totp": false,
"emailVerified": true,
"firstName": "Admin",
"lastName": "Administrator",
"email": "admin@localhost",
"credentials": [
{
"id": "b860462b-9b02-48ba-9523-d3a8926a917b",
"type": "password",
"createdDate": 1505479429154,
"secretData": "{\"value\":\"4pf9K2jWSCcHC+CwsZP/qidN5pSmDUe6AX6wBerSGdBVKkExay8MWKx+EKmaaObZW6FVsD8vdW/ZsyUFD9gJ1Q==\",\"salt\":\"1/qNkZ5kr77jOMOBPBogGw==\"}",
"credentialData": "{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\"}"
}
],
"disableableCredentialTypes": [],
"requiredActions": [],
"realmRoles": ["offline_access", "uma_authorization"],
"clientRoles": {
"account": ["view-profile", "manage-account"]
},
"notBefore": 0,
"groups": ["/Admins", "/Users"]
},
{
"id": "c4af4e2f-b432-4c3b-8405-cca86cd5b97b",
"createdTimestamp": 1505479373742,
"username": "user",
"enabled": true,
"totp": false,
"emailVerified": true,
"firstName": "",
"lastName": "User",
"email": "user@localhost",
"credentials": [
{
"id": "7821832b-1e82-45a2-b8d3-f1a6ad909e64",
"type": "password",
"createdDate": 1505479392766,
"secretData": "{\"value\":\"MbKsMgWPnZyImih8s4SaoCSCq+XIY/c6S9F93sXEidHF1TjPWxCqMkec0+o3860CMLXHt3az61cIJOWI0FW9aw==\",\"salt\":\"fmpBI1r8R1u75hDLMUlwBw==\"}",
"credentialData": "{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\"}"
}
],
"disableableCredentialTypes": [],
"requiredActions": [],
"realmRoles": ["offline_access", "uma_authorization"],
"clientRoles": {
"account": ["view-profile", "manage-account"]
},
"notBefore": 0,
"groups": ["/Users"]
}
]
}

This file was deleted.

2 changes: 1 addition & 1 deletion generators/generator-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const DOCKER_NEO4J = 'neo4j:4.4.4';
const DOCKER_HAZELCAST_MANAGEMENT_CENTER = 'hazelcast/management-center:4.2022.01';
const DOCKER_MEMCACHED = 'memcached:1.6.14-alpine';
const DOCKER_REDIS = 'redis:6.2.6';
const DOCKER_KEYCLOAK = 'jboss/keycloak:16.1.0'; // The version should match the attribute 'keycloakVersion' from /docker-compose/templates/realm-config/jhipster-realm.json.ejs and /server/templates/src/main/docker/config/realm-config/jhipster-realm.json.ejs
const DOCKER_KEYCLOAK = 'quay.io/keycloak/keycloak:18.0.0'; // The version should match the attribute 'keycloakVersion' from /docker-compose/templates/realm-config/jhipster-realm.json.ejs and /server/templates/src/main/docker/config/realm-config/jhipster-realm.json.ejs
const DOCKER_ELASTICSEARCH = 'docker.elastic.co/elasticsearch/elasticsearch:7.15.2'; // The version should be coherent with the one from spring-data-elasticsearch project
const DOCKER_KAFKA = `confluentinc/cp-kafka:${KAFKA_VERSION}`;
const DOCKER_ZOOKEEPER = `confluentinc/cp-zookeeper:${KAFKA_VERSION}`;
Expand Down
5 changes: 0 additions & 5 deletions generators/server/__snapshots__/generator.spec.mjs.snap
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ Object {
"file": "config/realm-config/jhipster-realm.json",
"renameTo": [Function],
},
Object {
"file": "config/realm-config/jhipster-users-0.json",
"method": "copy",
"renameTo": [Function],
},
],
},
Object {
Expand Down
6 changes: 1 addition & 5 deletions generators/server/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,7 @@ const baseServerFiles = {
{
condition: generator => generator.authenticationType === OAUTH2 && generator.applicationType !== MICROSERVICE,
path: DOCKER_DIR,
templates: [
'keycloak.yml',
{ file: 'config/realm-config/jhipster-realm.json', renameTo: () => 'realm-config/jhipster-realm.json' },
{ file: 'config/realm-config/jhipster-users-0.json', method: 'copy', renameTo: () => 'realm-config/jhipster-users-0.json' },
],
templates: ['keycloak.yml', { file: 'config/realm-config/jhipster-realm.json', renameTo: () => 'realm-config/jhipster-realm.json' }],
},
{
condition: generator => generator.serviceDiscoveryType || generator.applicationTypeGateway || generator.applicationTypeMicroservice,
Expand Down
2 changes: 1 addition & 1 deletion generators/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ module.exports = class JHipsterServerGenerator extends BaseBlueprintGenerator {
);
} else if (dockerConfig === 'keycloak') {
dockerAwaitScripts.push(
`echo "Waiting for keycloak to start" && wait-on -t ${WAIT_TIMEOUT} http-get://localhost:9080/auth/realms/jhipster && echo "keycloak started" || echo "keycloak not running, make sure oauth2 server is running"`
`echo "Waiting for keycloak to start" && wait-on -t ${WAIT_TIMEOUT} http-get://localhost:9080/realms/jhipster && echo "keycloak started" || echo "keycloak not running, make sure oauth2 server is running"`
);
}

Expand Down
20 changes: 10 additions & 10 deletions generators/server/templates/src/main/docker/app.yml.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ _%>
# - JHIPSTER_CACHE_REDIS_CLUSTER=true
<%_ } _%>
<%_ if (authenticationTypeOauth2) { _%>
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/auth/realms/jhipster
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:8080/realms/jhipster
<%_ if (applicationTypeGateway || applicationTypeMonolith) { _%>
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=web_app
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=web_app
Expand Down Expand Up @@ -300,7 +300,7 @@ _%>
# - SPRING_CLOUD_CONFIG_SERVER_COMPOSITE_0_SEARCH_PATHS=central-config
<%_ if (authenticationTypeOauth2) { _%>
# For keycloak to work, you need to add '127.0.0.1 keycloak' to your hosts file
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:9080/auth/realms/jhipster
- SPRING_SECURITY_OAUTH2_CLIENT_PROVIDER_OIDC_ISSUER_URI=http://keycloak:8080/realms/jhipster
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_ID=jhipster-registry
- SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_OIDC_CLIENT_SECRET=jhipster-registry
<%_ } _%>
Expand Down Expand Up @@ -336,17 +336,17 @@ _%>
<%_ if (authenticationTypeOauth2 && !applicationTypeMicroservice) { _%>
keycloak:
image: <%= DOCKER_KEYCLOAK %>
command: ["-b", "0.0.0.0", "-Dkeycloak.migration.action=import", "-Dkeycloak.migration.provider=dir", "-Dkeycloak.migration.dir=/opt/jboss/keycloak/realm-config", "-Dkeycloak.migration.strategy=OVERWRITE_EXISTING", "-Djboss.socket.binding.port-offset=1000", "-Dkeycloak.profile.feature.upload_scripts=enabled"]
command: ['start-dev --import-realm']
volumes:
- ./realm-config:/opt/jboss/keycloak/realm-config
- ./realm-config:/opt/keycloak/data/import
environment:
- KEYCLOAK_USER=admin
- KEYCLOAK_PASSWORD=admin
- DB_VENDOR=h2
- KC_DB=dev-file
- KEYCLOAK_ADMIN=admin
- KEYCLOAK_ADMIN_PASSWORD=admin
- KC_FEATURES=scripts
# If you want to expose these ports outside your dev PC,
# remove the "127.0.0.1:" prefix
ports:
- 127.0.0.1:9080:9080
- 127.0.0.1:9443:9443
- 127.0.0.1:10990:10990
- 127.0.0.1:9080:8080
- 127.0.0.1:9443:8443
<%_ } _%>
Original file line number Diff line number Diff line change
Expand Up @@ -859,8 +859,7 @@
"offline_access",
"microprofile-jwt"
]
},
<%_ if (serviceDiscoveryEureka) { _%>
},<% if (serviceDiscoveryEureka) { %>
{
"id": "9057870f-8775-448d-a194-1d4e122f44d5",
"clientId": "jhipster-registry",
Expand Down Expand Up @@ -920,8 +919,7 @@
"offline_access",
"microprofile-jwt"
]
},
<%_ } _%>
},<% } %>
{
"id": "898488c8-e260-41c5-a463-7ceea14d587a",
"clientId": "realm-management",
Expand Down Expand Up @@ -2492,12 +2490,70 @@
"clientOfflineSessionIdleTimeout": "0",
"cibaInterval": "5"
},
"keycloakVersion": "16.1.0",
"keycloakVersion": "18.0.0",
"userManagedAccessAllowed": false,
"clientProfiles": {
"profiles": []
},
"clientPolicies": {
"policies": []
}
},
"users": [
{
"id": "4c973896-5761-41fc-8217-07c5d13a004b",
"createdTimestamp": 1505479415590,
"username": "admin",
"enabled": true,
"totp": false,
"emailVerified": true,
"firstName": "Admin",
"lastName": "Administrator",
"email": "admin@localhost",
"credentials": [
{
"id": "b860462b-9b02-48ba-9523-d3a8926a917b",
"type": "password",
"createdDate": 1505479429154,
"secretData": "{\"value\":\"4pf9K2jWSCcHC+CwsZP/qidN5pSmDUe6AX6wBerSGdBVKkExay8MWKx+EKmaaObZW6FVsD8vdW/ZsyUFD9gJ1Q==\",\"salt\":\"1/qNkZ5kr77jOMOBPBogGw==\"}",
"credentialData": "{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\"}"
}
],
"disableableCredentialTypes": [],
"requiredActions": [],
"realmRoles": ["offline_access", "uma_authorization"],
"clientRoles": {
"account": ["view-profile", "manage-account"]
},
"notBefore": 0,
"groups": ["/Admins", "/Users"]
},
{
"id": "c4af4e2f-b432-4c3b-8405-cca86cd5b97b",
"createdTimestamp": 1505479373742,
"username": "user",
"enabled": true,
"totp": false,
"emailVerified": true,
"firstName": "",
"lastName": "User",
"email": "user@localhost",
"credentials": [
{
"id": "7821832b-1e82-45a2-b8d3-f1a6ad909e64",
"type": "password",
"createdDate": 1505479392766,
"secretData": "{\"value\":\"MbKsMgWPnZyImih8s4SaoCSCq+XIY/c6S9F93sXEidHF1TjPWxCqMkec0+o3860CMLXHt3az61cIJOWI0FW9aw==\",\"salt\":\"fmpBI1r8R1u75hDLMUlwBw==\"}",
"credentialData": "{\"hashIterations\":27500,\"algorithm\":\"pbkdf2-sha256\"}"
}
],
"disableableCredentialTypes": [],
"requiredActions": [],
"realmRoles": ["offline_access", "uma_authorization"],
"clientRoles": {
"account": ["view-profile", "manage-account"]
},
"notBefore": 0,
"groups": ["/Users"]
}
]
}
Loading

0 comments on commit a94ff3d

Please sign in to comment.