设置 JBoss/Keycloak 的 SSL/HTTPS

huangapple 未分类评论45阅读模式
英文:

Setting up ssl/https for jboss/Keycloak

问题

我想请教如何为Keycloak设置https(http已经正确运行)。
Keycloak在Docker中运行(jboss/keycloak),在域集群模式下运行。目前,我只想让服务器响应,所以其他所有功能现在都不相关。我按照官方的Keycloak文档进行了设置:

使用的版本:Keycloak 9.0.2(WildFly Core 10.0.3.Final)

  1. host-master.xml

> <security-realm name="UndertowRealm">
> <server-identities>
> <ssl>
> <keystore path="/opt/jboss/keycloak/domain/servers/auth-0/configuration/keycloak.keystore" keystore-password="123456keycloak" alias="t2rkeystore" />
> </ssl>
> </server-identities>
> </security-realm>

2.domain.xml

&gt;  &lt;subsystem xmlns=&quot;urn:jboss:domain:undertow:10.0&quot; default-server=&quot;default-server&quot;... &gt;
&gt;     &lt;buffer-cache name=&quot;default&quot;/&gt;
&gt;     &lt;server name=&quot;default-server&quot;&gt;
&gt;         &lt;ajp-listener name=&quot;ajp&quot; socket-binding=&quot;ajp&quot;/&gt;
&gt;         &lt;http-listener name=&quot;default&quot; socket-binding=&quot;http&quot; redirect-socket=&quot;https&quot; enable-http2=&quot;true&quot; proxy-address-forwarding=&quot;true&quot;/&gt;
&gt;         &lt;https-listener name=&quot;https&quot; socket-binding=&quot;https&quot;  security-realm=&quot;**UndertowRealm**&quot; enable-http2=&quot;true&quot; /&gt;
&gt;          &lt;host name=&quot;default-host&quot; alias=&quot;localhost&quot;&gt;
&gt;             &lt;location name=&quot;/&quot; handler=&quot;welcome-content&quot;/&gt;
&gt;             &lt;http-invoker security-realm=&quot;**UndertowRealm**&quot;/&gt;
&gt; 					&lt;filter-ref name=&quot;request-dumper&quot;/&gt;
&gt;           &lt;/host&gt;
&gt;     &lt;/server&gt;...

启动时显示https正在8443端口上运行

&gt; keycloak_1  | [Server:auth-0] 13:18:15,700 INFO 
&gt; [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0006:
&gt; Undertow HTTPS listener https listening on 0.0.0.0:8443

操作系统也显示端口8443正在侦听

&gt; tcp6       0      0 :::8443        :::*          LISTEN  

密钥库看起来也没问题:

&gt; keytool -keystore
&gt; /opt/jboss/keycloak/domain/servers/auth-0/configuration/keycloak.keystore
&gt; -list -v
&gt; 
&gt; Alias name: t2rkeystore Creation date: Apr 3, 2020 Entry type:
&gt; PrivateKeyEntry Certificate chain length: 1 Certificate[1]: Owner:
&gt; CN=t2r, O=Default Company Ltd, L=Default City, C=SK Issuer:
&gt; CN=tatramed.sk, O=Default Company Ltd, L=Default City, C=SK Serial
&gt; number: e59614237777c77e Valid from: Thu Apr 02 09:20:36 GMT 2020
&gt; until: Sun Mar 31 09:20:36 GMT 2030 Certificate fingerprints:
&gt;          SHA1: D7:20:9B:A0:B7:B6:67:B5:1A:CA:8C:72:66:3C:DF:43:EA:CD:2E:92
&gt;          SHA256: 5B:AA:19:45:D5:F6:41:48:B3:F1:85:A7:CB:F9:97:22:58:B2:F3:C7:F1:7E:83:DC:35:DB:B0:A7:B9:26:64:0F
&gt; Signature algorithm name: SHA256withRSA Subject Public Key Algorithm:
&gt; 2048-bit RSA key Version: 1

但是在Chrome中打开页面会显示ERR_CONNECTION_REFUSED错误,使用curl也是相同的结果:

&gt; curl -k -i -v --trace - https://localhost:8443 Warning: --trace
&gt; overrides an earlier trace/verbose option
&gt; == Info: About to connect() to localhost port 8443 (#0)
&gt; == Info:   Trying ::1...
&gt; == Info: Connected to localhost (::1) port 8443 (#0)
&gt; == Info: Initializing NSS with certpath: sql:/etc/pki/nssdb
&gt; == Info: NSS error -5938 (PR_END_OF_FILE_ERROR)
&gt; == Info: Encountered end of file
&gt; == Info: Closing connection 0 curl: (35) Encountered end of file

证书是使用以下方式使用openssl自行创建的:

&gt; openssl genrsa -out keycloak.key 2048 openssl req -new -key
&gt; keycloak.key -out keycloak.csr openssl x509 -req -days 3650 -in
&gt; keycloak.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out
&gt; keycloak.crt openssl pkcs12 -export -in keycloak.crt -inkey
&gt; keycloak.key -out keycloak.p12 -name t2rkeystore -CAfile ca.crt
&gt; //password: 123456keycloak
&gt; 
&gt; keytool -importkeystore -deststorepass 123456keycloak -destkeystore
&gt; /opt/jboss/keycloak/domain/servers/auth-0/configuration/keycloak.keystore
&gt; -srckeystore /opt/jboss/keycloak/domain/servers/auth-0/configuration/keycloak.p12
&gt; -srcstoretype PKCS12 -src
英文:

I would like to ask for help with setting up https for Keycloak (http is correctly running)
Keycloak is running in docker (jboss/keycloak) in domain clustered mode. For now, I just want to make server respond so all other features are irrelevant now. I followed the official keycloak docs and set up:

Using: Keycloak 9.0.2 (WildFly Core 10.0.3.Final)

  1. host-master.xml

> <security-realm name="UndertowRealm">
> <server-identities>
> <ssl>
> <keystore path="/opt/jboss/keycloak/domain/servers/auth-0/configuration/keycloak.keystore" keystore-password="123456keycloak" alias="t2rkeystore" />
> </ssl>
> </server-identities>
> </security-realm>

2.domain.xml

&gt;  &lt;subsystem xmlns=&quot;urn:jboss:domain:undertow:10.0&quot; default-server=&quot;default-server&quot;... &gt;
&gt;     &lt;buffer-cache name=&quot;default&quot;/&gt;
&gt;     &lt;server name=&quot;default-server&quot;&gt;
&gt;         &lt;ajp-listener name=&quot;ajp&quot; socket-binding=&quot;ajp&quot;/&gt;
&gt;         &lt;http-listener name=&quot;default&quot; socket-binding=&quot;http&quot; redirect-socket=&quot;https&quot; enable-http2=&quot;true&quot; proxy-address-forwarding=&quot;true&quot;/&gt;
&gt;         &lt;https-listener name=&quot;https&quot; socket-binding=&quot;https&quot;  security-realm=&quot;**UndertowRealm**&quot; enable-http2=&quot;true&quot; /&gt;
&gt;          &lt;host name=&quot;default-host&quot; alias=&quot;localhost&quot;&gt;
&gt;             &lt;location name=&quot;/&quot; handler=&quot;welcome-content&quot;/&gt;
&gt;             &lt;http-invoker security-realm=&quot;**UndertowRealm**&quot;/&gt;
&gt; 					&lt;filter-ref name=&quot;request-dumper&quot;/&gt;
&gt;           &lt;/host&gt;
&gt;     &lt;/server&gt;...

Booting up shows that https is running on 8443 port

&gt; keycloak_1  | [Server:auth-0] 13:18:15,700 INFO 
&gt; [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0006:
&gt; Undertow HTTPS listener https listening on 0.0.0.0:8443

also OS shows that port 8443 is listening

&gt; tcp6       0      0 :::8443        :::*          LISTEN  

Keystore looks ok too:

&gt; keytool -keystore
&gt; /opt/jboss/keycloak/domain/servers/auth-0/configuration/keycloak.keystore
&gt; -list -v
&gt; 
&gt; Alias name: t2rkeystore Creation date: Apr 3, 2020 Entry type:
&gt; PrivateKeyEntry Certificate chain length: 1 Certificate[1]: Owner:
&gt; CN=t2r, O=Default Company Ltd, L=Default City, C=SK Issuer:
&gt; CN=tatramed.sk, O=Default Company Ltd, L=Default City, C=SK Serial
&gt; number: e59614237777c77e Valid from: Thu Apr 02 09:20:36 GMT 2020
&gt; until: Sun Mar 31 09:20:36 GMT 2030 Certificate fingerprints:
&gt;          SHA1: D7:20:9B:A0:B7:B6:67:B5:1A:CA:8C:72:66:3C:DF:43:EA:CD:2E:92
&gt;          SHA256: 5B:AA:19:45:D5:F6:41:48:B3:F1:85:A7:CB:F9:97:22:58:B2:F3:C7:F1:7E:83:DC:35:DB:B0:A7:B9:26:64:0F
&gt; Signature algorithm name: SHA256withRSA Subject Public Key Algorithm:
&gt; 2048-bit RSA key Version: 1

But still, in chrome page results in ERR_CONNECTION_REFUSED
and curl too:

&gt; curl -k -i -v --trace - https://localhost:8443 Warning: --trace
&gt; overrides an earlier trace/verbose option
&gt; == Info: About to connect() to localhost port 8443 (#0)
&gt; == Info:   Trying ::1...
&gt; == Info: Connected to localhost (::1) port 8443 (#0)
&gt; == Info: Initializing NSS with certpath: sql:/etc/pki/nssdb
&gt; == Info: NSS error -5938 (PR_END_OF_FILE_ERROR)
&gt; == Info: Encountered end of file
&gt; == Info: Closing connection 0 curl: (35) Encountered end of file

Certificates are self created using openssl in following way:

&gt; openssl genrsa -out keycloak.key 2048 openssl req -new -key
&gt; keycloak.key -out keycloak.csr openssl x509 -req -days 3650 -in
&gt; keycloak.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out
&gt; keycloak.crt openssl pkcs12 -export -in keycloak.crt -inkey
&gt; keycloak.key -out keycloak.p12 -name t2rkeystore -CAfile ca.crt
&gt; //password: 123456keycloak
&gt; 
&gt; keytool -importkeystore -deststorepass 123456keycloak -destkeystore
&gt; /opt/jboss/keycloak/domain/servers/auth-0/configuration/keycloak.keystore
&gt; -srckeystore /opt/jboss/keycloak/domain/servers/auth-0/configuration/keycloak.p12
&gt; -srcstoretype PKCS12 -srcstorepass 123456keycloak

Also tried "elytron->server-ssl-context" way, with same result 设置 JBoss/Keycloak 的 SSL/HTTPS

Is there something I missing?

Thank you for any advices...

huangapple
  • 本文由 发表于 2020年4月3日 22:22:17
  • 转载请务必保留本文链接:https://java.coder-hub.com/61014000.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定