This is an extension of the base setup presented in the step by step guide. Make sure you have it running before reading further (unless you just want to look at how to integrate Keycloak with ACS component without trying it on your local machine).
Architecture of the deployment
The following components are deployed by the example chart:
Keycloak
As of Alfresco 23.1 Alfresco Identity Service is not required anymore. It is possible to use a vanilla Keyloak distribution. In this document we will use the Codecentric Keyloak chart so we can reuse similar patterns of integration we’ve been using earlier.
If you want to apply custom configuration as you build your own charts, refer to the chart README.
In this example we’ll start by simply adding the basic configuration in the values.yaml file:
keycloakx:nameOverride:keycloakcommand:-/opt/keycloak/bin/kc.sh-start---http-enabled=true---http-port=8080---hostname-strict=false---hostname-strict-https=false---import-realmhttp:relativePath:/auth# keycloak http api will be available under this pathingress:enabled:true# enabled external access the keycloaktls:[]# disable https for this examplerules:-host:>-{{ template "alfresco-common.external.host" $ }} # external hostnamepaths:-path:"{{.Values.http.relativePath}}"pathType:PrefixextraEnvFrom:|- configMapRef:name: keycloakextraEnv:|- name: JAVA_OPTS_APPENDvalue: >--Djgroups.dns.query={{ include "keycloak.fullname" . }}-headless
And create a configmap for basic configuration:
apiVersion:v1kind:ConfigMapmetadata:name:keycloaklabels:{{- include "acs-sso-example.labels" . | nindent 4}}data:KC_HOSTNAME:{{template "alfresco-common.external.host" .}}
Again here some named templates provided in the alfresco-common chart might come handy to avoid duplicating values.
This will start a keycloak instance with basic parameters and only a master realm. To make it usable we need to give it an admin username & password and also a realm Alfresco applications will be configured in as client(s).
Keycloak admin
Admin credentials can be passed as a kubernetes secret. Here we will create this secret from the umbrella chart values which we’ll add as shown below in the same values.yaml file:
And a new secret in templates/secret-idp-realm.yaml:
apiVersion:v1kind:Secretmetadata:name:keycloak-realmlabels:{{- include "acs-sso-example.labels" . | nindent 4}}data:{{- with .Values.keycloakx.admin.realm}}{{- range .}}{{- range .clients}}{{- $_:= set . "redirectUris" (tpl .redirectUris $ | list)}}{{- $_:= set . "webOrigins" (tpl .webOrigins $ | list)}}{{- end}}{{- printf "%s.json" .id | nindent 2}}:{{mustToJson . | b64enc | quote}}{{- end}}{{- end}}
Alfresco theme
Importing a theme requires adding the theme’s code to the /opt/keycloak/themes directory. Configmap or Secrets are not well suited for that as this is a whole directory structure we need to mount and also because such resources are also limited in size. A good alternative is to create an ephemeral volume and use an init container and use it to populate the ephemeral volume the main container of the keycloak will use later on in the pod’s lifecycle. All of this is done using values in the values.yaml file as shown below:
# Ephemeral volumeextraVolumes:|- name: themeemptyDir: {}# volume mount for the main containerextraVolumeMounts:|- name: thememountPath: /opt/keycloak/themesextraInitContainers:|- image: busybox:1.36imagePullPolicy: IfNotPresentname: theme-fetchercommand: [sh]args:- -c- |wget https://github.com/Alfresco/alfresco-keycloak-theme/releases/download/0.3.5/alfresco-keycloak-theme-0.3.5.zip -O alfresco.zipunzip -d /themes alfresco.zipvolumeMounts:- name: thememountPath: /themes
Alfresco repository SSO configuration
Now let’s amend the ACS config to enable SSO. Well do it using a feature of the alfresco-repository chart which allow us use a configmap as the alfresco-global.properties file.
The configmap needs to contains what you put in the alfresco-global.properties file and you can use templating to populate it. E.g. in templates/configmap-repo.yaml
identity-service.realm needs to match the name of the realm defined earlier. To get the right identity-service.auth-server-url we are computing the context of the keycloakx subcharts in $kCtx (using nameOverride) and pass that context to the same templating code used in the subchart to give the service a name. This is because here you here we’re using localhost as a domain, but if you use a true DNS domain the repo could point tpo this instead (which you can set in known_urls and use alfresco-common.external.url).
Then in the values.yaml file add below configuration to alfresco-repository:
The content-app basic and SSO configuration sits only in the values.yaml file. Pay special attention to providing OAUTH2 urls that match your realm configuration (realm name & client id).