4

我正在尝试使用一些自定义内容(例如 logback 扩展)设置 docker 映像,因此我有一些 CLI 脚本,例如:

/subsystem=logging: remove()
/extension=org.jboss.as.logging: remove()

/extension=com.custom.logback: add()
/subsystem=com.custom.logback: add()

我还有 CLI 脚本来配置数据源池、主题、在keycloak-server子系统上添加一些 SPI 等。我将这些脚本放在/opt/jboss/startup-scripts目录中。但是,当我创建容器时,事情并不顺利。脚本未按预期加载,keycloak 以错误开始,未加载领域使用的密码策略等提供程序。

当我使用独立的 Keycloak 时,所有 SPI 提供程序都可以正常加载,如下所示:

2019-07-25 18:27:07.906 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-password-policy (com.custom.login.password.PasswordSecurityPolicyFactory) is implementing the internal SPI password-policy. This SPI is internal and may change without notice
2019-07-25 18:27:07.909 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-event (com.custom.event.KeycloakServerEventListenerProviderFactory) is implementing the internal SPI eventsListener. This SPI is internal and may change without notice
2019-07-25 18:27:08.026 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-mailer (com.custom.mail.MessageSenderProviderFactory) is implementing the internal SPI emailSender. This SPI is internal and may change without notice
2019-07-25 18:27:08.123 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-user-domain-verification (com.custom.login.domain.UserDomainVerificationFactory) is implementing the internal SPI authenticator. This SPI is internal and may change without notice
2019-07-25 18:27:08.123 WARN  [org.keycloak.services] (ServerService Thread Pool -- 65) KC-SERVICES0047: custom-recaptcha-username-password (com.custom.login.domain.RecaptchaAuthenticatorFactory) is implementing the internal SPI authenticator. This SPI is internal and may change without notice

如果我使用与 Docker 相同的包,jboss/keycloak:6.0.1用作图像库,则不会加载提供程序。我用作模块,在$JBOSS_HOME/modules文件夹中添加并配置如下脚本:

/subsystem=keycloak-server/: write-attribute(name=providers,value=[classpath:${jboss.home.dir}/providers/*,module:com.custom.custom-keycloak-server])

/subsystem=keycloak-server/theme=defaults/: write-attribute(name=welcomeTheme,value=custom)
/subsystem=keycloak-server/theme=defaults/: write-attribute(name=modules,value=[com.custom.custom-keycloak-server])

/subsystem=keycloak-server/spi=emailSender/: add(default-provider=custom-mailer)

当我在容器内执行脚本时,一切正常。

我尝试在构建自定义图像时使用卷来映射 jar 包和提供程序并复制 jar,但这些方法都不起作用。

我正在使用jboss:keycloak:6.0.1docker image 和 Keycloak 6.0.1 独立,层和模块放在相同的目录中。

我做错了什么?将 SPI 提供程序与 Docker 一起使用有什么技巧,或者该映像不是用于生产或此类需求的?

4

2 回答 2

3

好的,我找到了发生这种情况的原因

它来自opt/jboss/tools/docker-entrypoint.sh

#################
# Configuration #
#################

# If the server configuration parameter is not present, append the HA profile.
if echo "$@" | egrep -v -- '-c |-c=|--server-config |--server-config='; then
    SYS_PROPS+=" -c=standalone-ha.xml"
fi

它将作为集群启动 keycloak,因为我认为他们认为独立的生产不安全

独立运行模式仅在您想运行一个且只有一个 Keycloak 服务器实例时才有用。它不适用于集群部署,并且所有缓存都是非分布式且仅限本地的。不建议您在生产中使用独立模式,因为您将遇到单点故障。如果您的独立模式服务器出现故障,用户将无法登录。此模式仅对试驾和玩 Keycloak Blockquote 的功能有用

要保持“独立模式”,请覆盖图像以将属性添加-c standalone.xml为参数:

CMD ["-b", "0.0.0.0", "-c", "standalone.xml"]
于 2019-09-26T08:57:50.563 回答
1

https://hub.docker.com/r/jboss/keycloak/

要添加自定义提供程序,请扩展 Keycloak 映像并将提供程序添加到 /opt/jboss/keycloak/standalone/deployments/ 目录。

/opt/jboss/keycloak/standalone/deployments/您是否为自定义提供商使用了音量?

于 2019-07-25T22:27:31.313 回答