Keycloak Installation and Configuration
Keycloak Installation
Important
If you already have Keycloak, skip this step and proceed to its configuration.
To install Keycloak, you can use the following chart.
Before installation, you need to create the following values.yaml file, replacing the variable IP_LOADBALANCER with your value everywhere. If you have your own domain name, replace IP_LOADBALANCER.nip.io with your domain name.
File values.yaml
keycloakUser: "admin"
keycloakPassword: "admin"
databaseUser: "keycloak-user"
databasePassword: "dbpassword"
replicas: 1
extraEnv: |
- name: JAVA_OPTS
value: >-
-XX:+UseContainerSupport
-XX:MaxRAMPercentage=50.0
-Djava.net.preferIPv4Stack=true
-Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS
-Djava.awt.headless=true
-Dkeycloak.profile.feature.upload_scripts=enabled
- name: KEYCLOAK_LOGLEVEL
value: INFO
- name: PROXY_ADDRESS_FORWARDING
value: "true"
extraEnvFrom: |
- secretRef:
name: '{{ include "keycloak.fullname" . }}-cred'
- secretRef:
name: '{{ include "keycloak.fullname" . }}-db'
secrets:
cred:
stringData:
KEYCLOAK_USER: "{{ .Values.keycloakUser }}"
KEYCLOAK_PASSWORD: "{{ .Values.keycloakPassword }}"
db:
stringData:
DB_USER: '{{ .Values.databaseUser }}'
DB_PASSWORD: '{{ .Values.databasePassword }}'
# resources:
# requests:
# cpu: 500m
# memory: 1024Mi
# limits:
# cpu: 2000m
# memory: 2048Mi
ingress:
enabled: true
ingressClassName: "nginx"
servicePort: http
annotations:
ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: "128k"
nginx.ingress.kubernetes.io/server-snippet: |
more_set_headers "Access-Control-Allow-Origin: $http_origin";
location ~* /auth/realms/[^/]+/metrics {
return 403;
}
rules:
- host: "IP_LOADBALANCER.nip.io"
paths:
- path: /auth
pathType: Prefix
tls:
- hosts:
- "IP_LOADBALANCER.nip.io"
secretName: dev-wildcard
console:
enabled: true
ingressClassName: "nginx"
annotations:
ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/ssl-redirect: "true"
nginx.ingress.kubernetes.io/proxy-body-size: "128k"
rules:
- host: "IP_LOADBALANCER.nip.io"
paths:
- path: /auth/admin/
pathType: Prefix
tls:
- hosts:
- "IP_LOADBALANCER.nip.io"
secretName: dev-wildcard
After creating the file, execute the Keycloak installation:
helm repo add codecentric https://codecentric.github.io/helm-charts
helm repo update
helm upgrade --install keycloak codecentric/keycloak \
--values values.yaml \
--namespace default \
--kube-context $CONTEXT_NAME
Configuring Access to Keycloak
- Go to
https://IP_LOADBALANCER.nip.io/auth/admin/master/console/and log in to the system. - Create a client named
klmgand add the current host in the Valid redirect URIs field in the formathttps://{HOST}/*(for local installation -https://IP_LOADBALANCER.nip.io/*). - In the client settings, the
Access Typefield should be set topublic. In newer versions of Keycloak, the equivalent of theAccess Typefield are theClient authenticationandAuthorizationfields, which should be set tooff. -
Configure the mapping:
- In the default version: In the client settings, go to
Mappers, click theCreatebutton. -
In the new version:
In the client settings, go toClient scopes. From the default list ofAssigned client scope, select<client name>-dedicatedand add theby configurationmapper by clickingAdd mapper.
Also click onAdd client scopeand selectopenid->Add->Default.
In the settings specify:- Name: roles
- Mapper type: User Client Role
- Token Claim Name: roles
- Leave other settings as default, click
Save.
- In the default version: In the client settings, go to
-
In the client settings, go to
Rolesand create the rolepredicate_adminto grant selected users admin rights (the ability to see and modify all entities created on the stand by any user) andpredicate_metric(access to basic metrics). - Create the necessary users and assign them the
predicate_adminrole if needed. If a user does not have thepredicate_adminrole, they will need to be assigned thepredicate_metricrole so they can see basic metrics. To do this, go to theUserssection, select the user, and go to theRole Mappingssection.- In the default version: In the
Client Rolesfield, select the clientklmg, in theAvailable Rolesfield select the rolepredicate_adminand clickAdd selected. - In the new version: Click
Assign role->Filter by client. In the search, enterpredicate_admin, select the role and clickAssign.
- In the default version: In the