如何在Keycloft Operator(v13.0.0)上使用自定义主题



我使用Operator(13.0.0版(安装了Keycloft。更新后的代码具有主题相关的github存储库,并很好地支持自定义主题集成。我们只需要一个自定义theme所在的URL。我试过了,工作完美无瑕。

然而,如果我们在某个本地目录中有主题,而不是在某个公共URL上,该怎么办。那么我们假设如何上传Keycloft中的theme呢?

我也尝试过使用文件URL和文件路径,但对我不起作用。

Keycloak.yaml

apiVersion: keycloak.org/v1alpha1
kind: Keycloak
metadata:
name: keycloak-test
labels:
app: keycloak-test
spec:
instances: 1
extensions:
- https://SOME-PUBLIC-URL/keycloak-themes.jar                    
externalAccess:
enabled: False
podDisruptionBudget:
enabled: True

我们可以使用以下步骤在keycloft操作符(v13.0.0(中添加自定义keycloft主题:

  1. 使用此处显示的步骤为您的自定义主题创建一个jar文件部署密钥斗篷主题
  2. 使用以下命令创建jar的kubernetes配置映射
kubectl create cm customtheme --from-file customtheme.jar
  1. 要使用上述配置映射,请更新Keycloak.yaml并添加以下代码块
keycloakDeploymentSpec:
experimental:
volumes:
defaultMode: 0777
items:
- name: customtheme
mountPath: /opt/jboss/keycloak/standalone/deployments/custom-themes
subPath: customtheme.jar
configMaps:
- customtheme

注意:请确保主题的大小小于1MB。

您可以创建一个带有要在Key斗篷中使用的自定义主题的.tar文件(,例如custom_theme.tar(,然后将一个卷装载到存储Key斗篷主题的文件夹(,即/opt/jboss/keycloak/themes/my_custom_theme(,并将带有自定义主题的.tar文件从本地文件夹复制到Key斗篷容器中。

您可以在这里找到这种方法的完整示例。

我使用了一种稍微不同的方法。基本情况:我的主题是在一个单独的git项目中。k8s资源的创建是用github操作(GHA(和kustoize完成的,我不想手工构建配置映射命名的东西。

我做了以下事情:

  • 主题得到一个GHA/Dockerfile,它只是将主题复制到一个静态的busybox映像中
  • 此图像作为密钥斗篷中的InitContainer加载。InitContainer get是将主题复制到keycloft主题目录的命令

(1(Dockerfile

FROM busybox
COPY . /my-theme-directory

(2( 密钥斗篷CRD:

spec:
unsupported:
podTemplate:
spec:
containers:
- volumeMounts:
- name: theme-volume
mountPath: /opt/keycloak/themes/my-theme-name
volumes:
- name: theme-volume
emptyDir: {}
initContainers:
- name: init-container-theme-copy
image: my-generated-image-from-step-one
command: 
- sh 
args:
- -c
- |
echo "Copying theme..."
cp -R /my-theme-directory/* /theme
volumeMounts: 
- name: theme-volume
mountPath: /theme
  1. 生成一个空卷并将其装入init中的/theme集装箱
  2. 将init容器中主题的内容复制到我们刚刚创建的卷中
  3. 将卷装载到主题目录中的主密钥斗篷容器中

最新更新