HTTPS サービスの構築

データの機密性を確保するために、HTTPS ベースのサービスを使用して Mule アプリケーションをデプロイできます。次のものを構築する方法を学習します。

  • アプリケーションを CloudHub にデプロイする HTTPS サービス

  • API Manager プロキシを使用する HTTPS サービス

さらに、HTTP リクエストおよびレスポンスヘッダーの設定方法を学習します。

アプリケーションをローカルにデプロイする場合は、​「TLS 設定」​を参照してください。

前提条件

始める前に、サービス (シンプルな「Hello World」サービスなど) を構築してデプロイします。
「API ビルドの最初から最後まで」​チュートリアルを使用して、API を設計し、開発する方法を学習します。

HTTPS サービスの構築

HTTPS を使用してアプリケーションを CloudHub にデプロイするようにサービスを変更します。

  1. コマンドラインで JDK ​keytool​ ユーティリティを使用して ​keystore.jks​ ファイルを作成します。自己署名証明書を生成するには、コマンドラインでホスト名も指定する必要があります。

    たとえば、次のコマンドは、ホスト名に ​SAN=DNS:localhost,IP:127.0.0.1​ を指定して ​keystore.jks​ ファイルを作成します。

    keytool -genkeypair -keystore keystore.jks   -dname "CN=localhost, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown"  -keypass password  -storepass password  -keyalg RSA  -sigalg SHA1withRSA  -keysize 2048  -alias mule  -ext SAN=DNS:localhost,IP:127.0.0.1 -validity 9999
  2. 生成された ​keystore.jks​ ファイルを Anypoint Studio Mule アプリケーションフォルダーの ​src/main/resources​ に追加します。

  3. Mule アプリケーションの HTTP リスナーを HTTPS に設定し、次のものを指定します。

    • host​ の値に HTTPS スキームで使用するホスト IP アドレス。

    • 'port' の ${https.port} 変数の値。

...
<http:listener-config name="HTTPS_Listener_Configuration" protocol="HTTPS" host="0.0.0.0" port="${https.port}">
     <tls:context>
         <tls:key-store path="keystore.jks" keyPassword="${keystore.password}" password="${password}"/>
     </tls:context>
 </http:listener-config>
...
  1. HTTPS グローバルリスナー設定への ​config-ref​ 参照を含めます。

<flow name="httpsserviceFlow">
    <http:listener config-ref="HTTPS_Listener_Configuration" path="hello"/>
</flow>
  1. 外部アドレスへの HTTPS 要求を有効にするために必要な TLS 設定を使用して HTTP リクエスターを設定します。

    ...
    <http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="0.0.0.0" port="${https.port}" >
         <tls:context>
             <tls:key-store path="keystore.jks" password="${password}" keyPassword="${keystore.password}" />
         </tls:context>
    </http:request-config>
    ...
  1. HTTPS グローバル要求設定への ​config-ref​ 参照を含めます。

    <flow name="httpsserviceFlow">
      <http:request config-ref="HTTP_Request_Configuration" path="some-path" method="GET" host="0.0.0.0" port="${https.port}"/>
    </flow>

    これで、アプリケーションを CloudHub にデプロイする準備が整いました。HTTPS アドレス (​https://yourdomain.cloudhub.io​ など) を使用してエンドポイントにアクセスできます。

API Manager プロキシに基づくサービスの設定

API Manager からプロキシをダウンロードするように求められており、HTTPS 用に設定する必要がある場合、Anypoint Connector で HTTP 用に HTTP リクエスターを設定したのと同じ手順に従います。この HTTP リスナー設定はテンプレートとして提供されています。

設定を完了する手順は、次のとおりです。

  1. プロキシプロジェクトを Anypoint Studio にインポートします。

  2. プロキシフローの ​[Configuration XML (設定 XML)]​ タブを選択します。

    フローがコメントアウトされている HTTPS Connector を参照しているため、パーサーでエラーが検出されます。

  3. http:listener-config​ ブロックのコメントを解除します。

  4. keystore​ の値を追加します: path​、​password​、​keyPassword​。

    <tls:context name="tls-context-config">
        <tls:key-store path="keystore.jks" password="${password}"
           keyPassword="${keystore.password}"/>
    </tls:context>
    • 外部プロパティを使用できます。

    • path​ の値に ​src/main/resources​ を含めることはできません。

      設定は、次のようになります。

      <?xml version="1.0" encoding="UTF-8"?>
      
      <mule xmlns:api-platform-gw="http://www.mulesoft.org/schema/mule/api-platform-gw"
      	xmlns:tls="http://www.mulesoft.org/schema/mule/tls" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
      	xmlns:spring="http://www.springframework.org/schema/beans"
      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xsi:schemaLocation="
      http://www.mulesoft.org/schema/mule/api-platform-gw http://www.mulesoft.org/schema/mule/api-platform-gw/current/mule-api-platform-gw.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
      http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
      http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
      http://www.mulesoft.org/schema/mule/tls http://www.mulesoft.org/schema/mule/tls/current/mule-tls.xsd">
            <configuration defaultProcessingStrategy="non-blocking" />
      
          <expression-language:property-placeholder location="config.properties" />
      
          <api-platform-gw:api apiName="![p['api.name']]" version="![p['api.version']]" flowRef="proxy">
          </api-platform-gw:api>
      
          <http:listener-config name="https-lc-0.0.0.0-8082" host="0.0.0.0" port="![p['proxy.port']]" protocol="HTTPS">
              <tls:context name="tls-context-config">
                  <tls:key-store path="keystore.jks" password="${password}"
                                 keyPassword="${keystore.password}"/>
              </tls:context>
           </http:listener-config>
      ...

HTTP リクエストおよびレスポンスヘッダーの設定

wrapper.conf​ ファイルで次のシステムプロパティを変更することで、サーバーレスポンスヘッダー、サーバーリクエストヘッダー、クライアントリクエストヘッダーの最大値を変更できます。

名前 プロパティ 説明 デフォルト値

Server Response Headers (サーバーレスポンスヘッダー)

mule.http.MAX_SERVER_RESPONSE_HEADERS

HTTP サーバーから送信される応答で許容されるヘッダーの最大量。

100

Server Request Headers (サーバーリクエストヘッダー)

mule.http.MAX_SERVER_REQUEST_HEADERS

HTTP サーバーから送信される要求で許容されるヘッダーの最大量。

100

Client Request Headers (クライアントリクエストヘッダー)

mule.http.MAX_CLIENT_REQUEST_HEADERS

HTTP クライアントから送信される要求で許容されるヘッダーの最大量。

100

クライアントの HTTP レスポンスヘッダーには最大量の制限がないため、Max Client Response Header のようなシステムプロパティはありません。