搜索

第 1 章 为管理界面和应用程序启用单向 SSL/TLS

download PDF

SSL/TLS 或传输层安全(TLS)是基于证书的安全协议,用于保护通过网络通信的两个实体之间的数据传输。

您可以为 JBoss EAP 管理界面和 JBoss EAP 上部署的应用程序启用单向 SSL/TLS。如需更多信息,请参阅以下步骤:

1.1. 为管理界面启用单向 SSL/TLS

为管理界面启用单向 SSL/TLS,以便 JBoss EAP 管理接口和连接接口的客户端之间的通信是安全的。

要为管理界面启用单向 SSL/TLS,您可以使用以下步骤:

另外,您可以使用 安全命令禁用 SSL/TLS 管理接口的步骤,为管理接口禁用 SSL/TLS

1.1.1. 使用向导为管理接口启用单向 SSL/TLS

Elytron 提供了一个向导来快速设置 SSL/TLS。您可以使用包含证书的现有密钥存储,或者使用向导生成的密钥存储和自签名证书来启用 SSL/TLS。您还可以使用 --lets-encrypt 选项从 Let 的 Encrypt 证书颁发机构获取和使用证书。有关 Let's Encrypt 的详情,请查看 Let 的加密文档

使用向导生成的自签名证书来启用 SSL/TLS,仅用于测试和开发目的。对于生产环境,始终使用证书颁发机构(CA)签名证书。

重要

不要在生产环境中使用自签名证书。仅使用证书颁发机构(CA)签名的证书。

向导配置为管理接口启用 SSL/TLS 所需的以下资源:

  • key-store
  • key-manager
  • server-ssl-context
  • 然后,server-ssl-context 应用到 http-interface

Elytron 将每个资源命名为 resource-type-UUID。例如,key-store-9e35a3be-62bb-4fff-afc2-2d8d141b82bc。通用唯一标识符(UUID)有助于避免资源的名称冲突。

先决条件

  • JBoss EAP 正在运行。

流程

  • 在管理 CLI 中输入以下命令来启动向导,为管理接口配置单向 SSL/TLS。

    语法

    security enable-ssl-management --interactive

    提示时输入所需信息。

    使用 --lets-encrypt 选项从 Let 的 Encrypt 证书颁发机构获取和使用证书。

    如果已经为管理界面启用了 SSL/TLS,向导会退出,并显示以下信息:

    SSL is already enabled for http-interface

    要更改现有配置,首先禁用对管理接口的 SSL/TLS,然后创建新配置。有关为管理接口禁用 SSL/TLS 的详情,请参考使用 向导为管理接口禁用 SSL/TLS

    注意

    要启用单向 SSL/TLS,请在提示启用 SSL 相互身份验证时输入 n 或 blank。设置 mutual 身份验证可启用双向 SSL/TLS。

    以互动方式使用向导的示例

    security enable-ssl-management --interactive

    向导提示输入示例

    Please provide required pieces of information to enable SSL:
    
    Certificate info:
    Key-store file name (default management.keystore): exampleKeystore.pkcs12
    Password (blank generated): secret
    What is your first and last name? [Unknown]: localhost
    What is the name of your organizational unit? [Unknown]:
    What is the name of your organization? [Unknown]:
    What is the name of your City or Locality? [Unknown]:
    What is the name of your State or Province? [Unknown]:
    What is the two-letter country code for this unit? [Unknown]:
    Is CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct y/n [y]?y
    Validity (in days, blank default): 365
    Alias (blank generated): localhost
    Enable SSL Mutual Authentication y/n (blank n):n //For one way SSL/TLS enter blank or n here
    
    SSL options:
    keystore file: exampleKeystore.pkcs12
    distinguished name: CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown,
    C=Unknown
    password: secret
    validity: 365
    alias: localhost
    Server keystore file exampleKeystore.pkcs12, certificate file exampleKeystore.pem and exampleKeystore.csr file will be generated in server configuration directory.
    
    Do you confirm y/n :y

    输入 y 后,服务器将重新加载。如果您配置了自签名证书,请使用向导来生成自签名证书或配置了 Java 虚拟机(JVM)信任的证书,管理 CLI 会提示您接受服务器提供的证书。

    Unable to connect due to unrecognised server certificate
    Subject    - CN=localhost,OU=Unknown,O=Unknown,L=Unknown,ST=Unknown,C=Unknown
    Issuer     - CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown
    Valid From - Mon Jan 30 23:32:20 IST 2023
    Valid To   - Tue Jan 30 23:32:20 IST 2024
    MD5 : b6:e7:f0:57:59:9e:bf:b8:20:99:10:fc:e2:0b:0f:d0
    SHA1 : 9c:f0:92:de:c1:11:df:71:0b:d7:16:02:c8:7e:c9:83:ab:e3:0c:2e
    
    
    Accept certificate? [N]o, [T]emporarily, [P]ermanently :

    输入 TP 以继续连接。

    您将获得以下输出:

    Server reloaded.
    SSL enabled for http-interface
    ssl-context is ssl-context-a18ba30e-6a26-4ed6-87c5-feb7f3e4dff1
    key-manager is key-manager-a18ba30e-6a26-4ed6-87c5-feb7f3e4dff1
    key-store   is key-store-a18ba30e-6a26-4ed6-87c5-feb7f3e4dff1

验证

  • 使用管理 CLI 客户端连接来验证 SSL/TLS。

    您可以通过将 Elytron 客户端 SSL 上下文放在配置文件中,然后使用管理 CLI 连接到服务器并引用配置文件来测试 SSL/TLS。

    1. 前往包含密钥存储文件的目录。在本例中,密钥存储文件 exampleKeystore.pkcs12 在服务器的 standalone/configuration 目录中生成。

      Example

      $ cd JBOSS_HOME/standalone/configuration

    2. 使用服务器证书创建客户端 trust-store

      语法

      $ keytool -importcert -keystore <trust_store_name> -storepass <password> -alias <alias> -trustcacerts -file <file_containing_server_certificate>

      Example

      $ keytool -importcert -keystore client.truststore.pkcs12 -storepass secret -alias localhost -trustcacerts -file exampleKeystore.pem

      如果您使用了自签名证书,系统会提示您信任证书。

    3. 在文件中定义客户端 SSL 上下文,如 example-security.xml

      语法

      <?xml version="1.0" encoding="UTF-8"?>
      
      <configuration>
          <authentication-client xmlns="urn:elytron:client:1.2">
              <key-stores>
                  <key-store name="${key-store_name}" type="PKCS12" >
                      <file name="${path_to_truststore}"/>
                      <key-store-clear-password password="${keystore_password}" />
                  </key-store>
              </key-stores>
              <ssl-contexts>
                  <ssl-context name="${ssl_context_name}">
                      <trust-store key-store-name="${trust_store_name}" />
                  </ssl-context>
              </ssl-contexts>
              <ssl-context-rules>
                  <rule use-ssl-context="${ssl_context_name}" />
              </ssl-context-rules>
          </authentication-client>
      </configuration>

      Example

      <?xml version="1.0" encoding="UTF-8"?>
      
      <configuration>
          <authentication-client xmlns="urn:elytron:client:1.2">
              <key-stores>
                  <key-store name="clientStore" type="PKCS12" >
                      <file name="JBOSS_HOME/standalone/configuration/client.truststore.pkcs12"/>
                      <key-store-clear-password password="secret" />
                  </key-store>
              </key-stores>
              <ssl-contexts>
                  <ssl-context name="client-SSL-context">
                      <trust-store key-store-name="clientStore" />
                  </ssl-context>
              </ssl-contexts>
              <ssl-context-rules>
                  <rule use-ssl-context="client-SSL-context" />
              </ssl-context-rules>
          </authentication-client>
      </configuration>

    4. 连接到服务器并发出命令。

      Example

      $ EAP_HOME/bin/jboss-cli.sh -c --controller=remote+https://127.0.0.1:9993 -Dwildfly.config.url=<path_to_the_configuration_file>/example-security.xml :whoami

      预期输出

      {
          "outcome" => "success",
          "result" => {"identity" => {"username" => "$local"}}
      }

  • 使用浏览器验证 SSL/TLS。

    1. 进入 https://localhost:9993

      如果您使用了自签名证书,浏览器会显示一个警告,表示服务器出示的证书未知。

    2. 检查证书,并验证浏览器中显示的指纹是否与密钥存储中的证书的指纹匹配。您可以使用以下命令查看生成的证书:

      语法

      /subsystem=elytron/key-store=<server_keystore_name>:read-alias(alias=<alias>)

      Example

      /subsystem=elytron/key-store=key-store-a18ba30e-6a26-4ed6-87c5-feb7f3e4dff1:read-alias(alias="localhost")

      您可以从向导的输出中获取密钥存储名称,例如 "key-store 为 key-store-a18ba30e-6a26-4ed6-87c5-feb7f3e4dff1"。

      输出示例

      ...
      "sha-1-digest" => "48:e3:6f:16:d1:af:4b:31:8f:9b:0b:7f:33:94:58:af:69:85:c
      0:ea",
      "sha-256-digest" => "8f:3e:6b:b5:56:e0:d1:97:81:bc:f1:8d:c8:66:75:06:db:7d
      :4d:b6:b1:d3:34:dd:f5:6c:85:ca:c7:2b:5b:c7",
      ...

      接受服务器证书后,会提示您输入登录凭证。您可以使用现有 JBoss EAP 用户的用户凭证登录。

现在为 JBoss EAP 管理界面启用了 SSL/TLS。

1.1.2. 使用 subsystem 命令为管理接口启用单向 SSL/TLS

使用 elytron 子系统命令通过 SSL/TLS 保护 JBoss EAP 管理接口。

出于测试和开发目的,您可以使用自签名证书。您可以使用包含证书的现有密钥存储,或者在创建 key-store 资源时使用 Elytron 生成的密钥存储。对于生产环境,始终使用证书颁发机构(CA)签名证书。

重要

不要在生产环境中使用自签名证书。仅使用证书颁发机构(CA)签名的证书。

先决条件

  • JBoss EAP 正在运行。

流程

  1. 配置密钥存储以存储证书。

    您可以提供到现有密钥存储的路径,例如,包含 CA 签名证书的路径,或者提供要创建的密钥存储的路径。

    /subsystem=elytron/key-store=<keystore_name>:add(path=<path_to_keystore>, credential-reference=<credential_reference>, type=<keystore_type>)

    Example

    /subsystem=elytron/key-store=exampleKeyStore:add(path=exampleserver.keystore.pkcs12, relative-to=jboss.server.config.dir,credential-reference={clear-text=secret},type=PKCS12)

  2. 如果密钥存储不包含任何证书,或者您使用上面的步骤来创建密钥存储,则必须生成证书并将证书存储在文件中。

    1. 在密钥存储中生成密钥对。

      语法

      /subsystem=elytron/key-store=<keystore_name>:generate-key-pair(alias=<keystore_alias>,algorithm=<algorithm>,key-size=<key_size>,validity=<validity_in_days>,credential-reference=<credential_reference>,distinguished-name="<distinguished_name>")

      Example

      /subsystem=elytron/key-store=exampleKeyStore:generate-key-pair(alias=localhost,algorithm=RSA,key-size=2048,validity=365,credential-reference={clear-text=secret},distinguished-name="CN=localhost")

    2. 将证书存储在文件中。

      语法

      /subsystem=elytron/key-store=<keystore_name>:store()

      Example

      /subsystem=elytron/key-store=exampleKeyStore:store()

  3. 配置引用 key-storekey-manager

    语法

    /subsystem=elytron/key-manager=<key-manager_name>:add(key-store=<key-store_name>,credential-reference=<credential_reference>)

    Example

    /subsystem=elytron/key-manager=exampleKeyManager:add(key-store=exampleKeyStore,credential-reference={clear-text=secret})

    重要

    红帽没有指定 algorithm 属性,因为 elytron 子系统使用 KeyManagerFactory.getDefaultAlgorithm () 来默认确定算法。但是,您可以指定 algorithm 属性。

    要指定 algorithm 属性,您需要知道您使用的 Java Development Kit (JDK)提供哪些密钥管理器算法。例如,使用 Java 安全套接字扩展(SunJSSE)的 JDK 提供了 PKIX 和 SunX509 算法。

    在命令中,您可以指定 SunX509 作为 key-manager 算法属性。

  4. 配置引用 key-managerserver-ssl-context

    语法

    /subsystem=elytron/server-ssl-context=<server-ssl-context_name>:add(key-manager=<key-manager_name>, protocols=<list_of_protocols>)

    Example

    /subsystem=elytron/server-ssl-context=examplehttpsSSC:add(key-manager=exampleKeyManager, protocols=["TLSv1.2"])

    重要

    您需要确定您要支持的 SSL/TLS 协议。示例命令使用 TLSv1.2。

    • 对于 TLSv1.2 及更早版本,请使用 cipher-suite-filter 参数指定允许哪些密码套件。
    • 对于 TLSv1.3,使用 cipher-suite-names 参数指定允许哪些密码套件。TLSv1.3 默认禁用。如果您没有使用 protocol 属性指定 协议,或者指定的集合包含 TLSv1.3,请配置 cipher-suite-names 启用 TLSv1.3。

    使用 use-cipher-suites-order 参数来遵循服务器密码套件顺序。use-cipher-suites-order 属性默认设置为 true。这与旧的 security 子系统行为不同,它默认为遵循客户端密码套件顺序。

  5. 更新管理界面,以使用配置的 server-ssl-context

    语法

    /core-service=management/management-interface=http-interface:write-attribute(name=ssl-context, value=<server-ssl-context_name>)
    /core-service=management/management-interface=http-interface:write-attribute(name=secure-socket-binding, value=management-https)

    Example

    /core-service=management/management-interface=http-interface:write-attribute(name=ssl-context, value=examplehttpsSSC)
    /core-service=management/management-interface=http-interface:write-attribute(name=secure-socket-binding, value=management-https)

  6. 重新加载服务器。

    reload

    如果您使用自签名证书启用 SSL/TLS,管理 CLI 会提示您接受服务器提供的证书。这是您通过配置密钥存储的证书。

    输出示例

    Unable to connect due to unrecognised server certificate
    Subject    - CN=localhost
    Issuer     - CN=localhost
    Valid From - Mon Jan 30 23:47:21 IST 2023
    Valid To   - Tue Jan 30 23:47:21 IST 2024
    MD5 : a1:00:84:78:a6:46:a4:78:4d:44:c8:6d:ba:1f:30:6a
    SHA1 : a4:e5:c1:34:ad:e0:91:18:6f:f6:57:09:91:ae:17:8d:70:f0:1a:7d
    
    
    Accept certificate? [N]o, [T]emporarily, [P]ermanently :

    输入 TP 以继续连接。

验证

  • 通过客户端连接来验证 SSL/TLS。

    您可以通过在配置文件中放置 Elytron 客户端 SSL 上下文来测试 SSL/TLS,然后使用引用配置文件的管理 CLI 连接到服务器。

    1. 前往包含密钥存储文件的目录。在本例中,密钥存储文件 exampleserver.keystore.pkcs12 在服务器的 standalone/configuration 目录中生成。

      Example

      $ cd JBOSS_HOME/standalone/configuration

    2. 导出服务器证书,以便将其导入到客户端信任存储中。

      $ keytool -export -alias <alias> -keystore <key_store> -storepass <keystore_password>-file <file_name>

      Example

      $ keytool -export -alias localhost -keystore exampleserver.keystore.pkcs12 -file -storepass secret server.cer

    3. 使用服务器证书创建客户端 trust-store

      语法

      $ keytool -importcert -keystore <trust_store_name> -storepass <password> -alias <alias> -trustcacerts -file <file_containing_server_certificate>

      Example

      $ keytool -importcert -keystore client.truststore.pkcs12 -storepass secret -alias localhost -trustcacerts -file server.cer

      如果您使用了自签名证书,系统会提示您信任证书。

    4. 在文件中定义客户端 SSL 上下文,如 example-security.xml

      语法

      <?xml version="1.0" encoding="UTF-8"?>
      
      <configuration>
          <authentication-client xmlns="urn:elytron:client:1.2">
              <key-stores>
                  <key-store name="${key-store_name}" type="PKCS12" >
                      <file name="${path_to_truststore}"/>
                      <key-store-clear-password password="${keystore_password}" />
                  </key-store>
              </key-stores>
              <ssl-contexts>
                  <ssl-context name="${ssl_context_name}">
                      <trust-store key-store-name="${trust_store_name}" />
                  </ssl-context>
              </ssl-contexts>
              <ssl-context-rules>
                  <rule use-ssl-context="${ssl_context_name}" />
              </ssl-context-rules>
          </authentication-client>
      </configuration>

      Example

      <?xml version="1.0" encoding="UTF-8"?>
      
      <configuration>
          <authentication-client xmlns="urn:elytron:client:1.2">
              <key-stores>
                  <key-store name="clientStore" type="PKCS12" >
                      <file name="JBOSS_HOME/standalone/configuration/client.truststore.pkcs12"/>
                      <key-store-clear-password password="secret" />
                  </key-store>
              </key-stores>
              <ssl-contexts>
                  <ssl-context name="client-SSL-context">
                      <trust-store key-store-name="clientStore" />
                  </ssl-context>
              </ssl-contexts>
              <ssl-context-rules>
                  <rule use-ssl-context="client-SSL-context" />
              </ssl-context-rules>
          </authentication-client>
      </configuration>

    5. 连接到服务器并发出命令。

      Example

      $ EAP_HOME/bin/jboss-cli.sh -c --controller=remote+https://127.0.0.1:9993 -Dwildfly.config.url=example-security.xml :whoami

      预期输出

      {
          "outcome" => "success",
          "result" => {"identity" => {"username" => "$local"}}
      }

  • 使用浏览器验证 SSL/TLS。

    1. 进入 https://localhost:9993

      如果您使用了自签名证书,浏览器会显示一个警告,表示服务器出示的证书未知。

    2. 检查证书,并验证浏览器中显示的指纹是否与密钥存储中的证书的指纹匹配。您可以使用以下命令查看生成的证书:

      语法

      /subsystem=elytron/key-store=<server_keystore_name>:read-alias(alias=<alias>)

      Example

      /subsystem=elytron/key-store=exampleKeyStore:read-alias(alias="localhost")

      输出示例

      ...
      "sha-1-digest" => "48:e3:6f:16:d1:af:4b:31:8f:9b:0b:7f:33:94:58:af:69:85:c
      0:ea",
      "sha-256-digest" => "8f:3e:6b:b5:56:e0:d1:97:81:bc:f1:8d:c8:66:75:06:db:7d
      :4d:b6:b1:d3:34:dd:f5:6c:85:ca:c7:2b:5b:c7",
      ...

      接受服务器证书后,会提示您输入登录凭证。您可以使用现有 JBoss EAP 用户的用户凭证登录。

现在为 JBoss EAP 管理界面启用了 SSL/TLS。

1.1.3. 使用安全 命令为管理接口禁用 SSL/TLS

使用 security 命令为管理界面禁用 SSL/TLS。您可能希望进行此操作,将不同的 SSL/TLS 配置用于配置的不同 SSL/TLS 配置。

使用 命令禁用 SSL/TLS 不会删除 Elytron 资源。命令只是取消定义 http-interface management-interface 资源的 secure-socket-bindingssl-context 属性。

先决条件

  • JBoss EAP 正在运行。

流程

  • 在管理 CLI 中使用 disable-ssl-management 命令。

    security disable-ssl-management

    服务器使用以下输出重新加载:

    ...
    Server reloaded.
    Reconnected to server.
    SSL disabled for http-interface

您可以使用以下方法之一为服务器管理接口启用 SSL/TLS:

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.