設定從邊緣至後端的傳輸層安全標準 (TLS) (雲端和私有雲)

您正在查看 Apigee Edge 說明文件。
查看 Apigee X 說明文件
資訊

API Proxy 的作用是將公開端點對應至後端服務。虛擬主機會定義對應用程式公開的 API Proxy 公開方式。舉例來說,虛擬主機會判斷 API Proxy 是否能使用 TLS 存取。設定 API Proxy 時,請編輯 Proxy Endpoint 定義,以設定其使用的虛擬主機。

TargetEndpoint 等同於 ProxyEndpoint。TargetEndpoint 可做為 HTTP 用戶端,從 Edge 至後端服務。建立 API Proxy 時,您可以將 API Proxy 設為使用零或多個目標端點。

瞭解詳情:

設定 TargetEndpoint 或 TargetServer

如要設定 TargetEndpoint,請編輯定義 TargetEndpoint 的 XML 物件。如要編輯 TargetEndpoint,您可以在 API Proxy 中編輯定義 TargetEndpoint 的 XML 檔案,或是在 Edge 管理 UI 中編輯該檔案。

如何使用 Edge 管理 UI 編輯 TargetEndpoint:

  1. 前往 https://enterprise.apigee.com 登入 Edge 管理 UI。
  2. 選取要更新的 API Proxy 名稱。
  3. 選取「開發」分頁標籤。
  4. 在「目標端點」下方,選取「預設」
  5. 程式碼區域會顯示 TargetEndpoint 定義,如下所示:
    <TargetEndpoint name="default">
      <Description/>
      <FaultRules/>
      <Flows/>
      <PreFlow name="PreFlow">
        <Request/>
        <Response/>
      </PreFlow>
      <PostFlow name="PostFlow">
        <Request/>
        <Response/>
      </PostFlow>
      <HTTPTargetConnection>
        <Properties/>
        <SSLInfo>
          <Enabled>true</Enabled>
          <TrustStore>ref://myTrustStoreRef</TrustStore>
        </SSLInfo>
        <URL>https://mocktarget.apigee.net</URL>
      </HTTPTargetConnection>
    </TargetEndpoint>
  6. 按照下方「關於後端的 TLS 設定」一節的說明設定信任儲存庫。
  7. 進行變更並儲存 Proxy。如果 API Proxy 已部署,儲存該 Proxy 就會使用新設定重新部署。

請注意,TargetEndpoint 定義包含 name 屬性。您可以使用 name 屬性的值,設定 API Proxy 的 ProxyEndpoint 定義,以便使用 TargetEndpoint。詳情請參閱 API Proxy 設定參考資料

您可以將 Target Endpoints 設為參照 TargetServer,而非明確的目標網址。TargetServer 設定可將具體端點網址與 TargetEndpoint 設定分離。TargetServer 可用於支援多個後端伺服器執行個體的負載平衡和容錯移轉。

以下為 TargetServer 定義範例:

<TargetServer name="target1">
  <Host>mocktarget.apigee.net</Host>
  <Port>80</Port>
  <IsEnabled>true</IsEnabled>
</TargetServer> 

系統會在 TargetEndpoint 定義中,以 <HTTPTargetConnection> 元素的名稱參照 TargetServer。您可以設定一或多個已命名的 TargetServers,如下所示。

<TargetEndpoint name="default">
  ...
  <HTTPTargetConnection>
    <LoadBalancer>
      <Server name="target1" />
      <Server name="target2" />
    </LoadBalancer>
    <Path>/test</Path>
  </HTTPTargetConnection>
  ...
</TargetEndpoint>

詳情請參閱「跨後端伺服器負載平衡」。

關於後端的 TLS 設定

設定後端的 TLS 存取權之前,您應該瞭解兩個重要事項:

  1. 根據預設,Edge 不會驗證後端憑證。您必須建立信任儲存庫,才能設定 Edge 來驗證憑證。
  2. 使用參照來指定 Edge 使用的 KeyStore 或信任儲存庫。

以下說明這兩種注意事項。

定義信任存放區以啟用憑證驗證功能

透過 TargetEndpoint 或 TargetServer 提出傳輸層安全標準 (TLS) 要求時,根據預設,Edge 不會 驗證從後端伺服器收到的 TLS 憑證。這表示 Edge 不會驗證

  • 憑證已由信任的 CA 簽署。
  • 憑證尚未過期。
  • 憑證具有通用名稱。如果有相同的名稱,Edge 不會驗證一般名稱與網址中指定的主機名稱是否相符。

如要設定 Edge 來驗證後端憑證,您必須:

  1. 在 Edge 中建立信任儲存庫。
  2. 將伺服器的憑證或憑證鏈結上傳至信任儲存庫。 如果伺服器憑證是由第三方簽署,您必須將完整的憑證鏈結上傳至信任儲存庫 (包括根 CA 憑證)。沒有隱含信任的 CA。
  3. 將 Truststore 新增至 TargetEndpoint 或 TargetServer 定義。

詳情請參閱「Keystores 和 Truststore」相關說明。

例如:

<TargetEndpoint name="default">
  …
  <HTTPTargetConnection>
    <SSLInfo>
      <Enabled>true</Enabled>
      <TrustStore>ref://myTrustStoreRef</TrustStore>
    </SSLInfo>
    <URL>https://myservice.com</URL>
  </HTTPTargetConnection>
  …
</TargetEndpoint>

使用 KeyStore 或信任儲存庫的參照

以下範例說明如何設定 TargetEndpoint 或 TargetServer 來支援傳輸層安全標準 (TLS)。在設定 TLS 的過程中,您可以指定 Truststore 和 KeyStore,做為 TargetEndpoint 或 TargetServer 定義的一部分。

Apigee「強烈」建議您在目標端點或 TargetServer 定義中,使用 KeyStore 和 Truststore 的參照。使用參照的優點是只需將參照更新為指向其他 KeyStore 或信任儲存庫,就能更新傳輸層安全標準 (TLS) 憑證。

在目標端點或目標伺服器定義中,KeyStore 和信任儲存庫的參照方式與虛擬主機相同。

轉換 TargetEndpoint 或 TargetServer 以使用參照

現有的 TargetEndpoint 或 TargetServer 定義可能使用 KeyStore 和 Truststore 的常值名稱。如要將 TargetEndpoint 或 TargetServer 定義轉換為使用參照:

  1. 請更新 TargetEndpoint 或 TargetServer 定義,以便使用參照。
  2. 重新啟動邊緣訊息處理器:
    • 如果是公用雲端客戶,請與 Apigee Edge 支援團隊聯絡,重新啟動訊息處理器。
    • 如果是 Private Cloud 客戶,請逐一重新啟動邊緣訊息處理器。
  3. 確認您的 TargetEndpoint 或 TargetServer 正常運作。

設定對後端伺服器的單向傳輸層安全標準 (TLS)

使用 TargetEndpoint 定義時,設定從 Edge (TLS 用戶端) 到後端伺服器 (TLS 伺服器) 的單向傳輸層安全標準 (TLS) 存取作業,並不需要在 Edge 上進行任何其他設定。後端伺服器可正確設定 TLS。

您只需要確認 TargetEndpoint 定義中的 <URL> 元素透過 HTTPS 通訊協定參照後端服務,並啟用 TLS:

<TargetEndpoint name="default">
  …
  <HTTPTargetConnection>
    <SSLInfo>
      <Enabled>true</Enabled>
    </SSLInfo>
    <URL>https://myservice.com</URL>
  </HTTPTargetConnection>
  …
</TargetEndpoint>

如果您使用 TargetServer 定義後端服務,請在 TargetServer 定義中啟用 TLS:

<TargetServer name="target1">
  <Host>mocktarget.apigee.net</Host>
  <Port>443</Port>
  <IsEnabled>true</IsEnabled>
  <SSLInfo>
    <Enabled>true</Enabled>
  </SSLInfo> 
</TargetServer> 

不過,如要讓 Edge 驗證後端憑證,您必須建立含有後端憑證或憑證鏈的信任儲存庫。接著您會在 TargetEndpoint 定義中指定信任儲存庫:

<TargetEndpoint name="default">
  …
  <HTTPTargetConnection>
    <SSLInfo>
      <Enabled>true</Enabled>
      <TrustStore>ref://myTrustStoreRef</TrustStore>
    </SSLInfo>
    <URL>https://myservice.com</URL>
  </HTTPTargetConnection>
  …
</TargetEndpoint>

或在 TargetServer 定義中:

<TargetServer name="target1">
  <Host>mockserver.apigee.net</Host>
  <Port>443</Port>
  <IsEnabled>true</IsEnabled>
  <SSLInfo>
    <Enabled>true</Enabled>
    <TrustStore>ref://myTrustStoreRef</TrustStore>
  </SSLInfo> 
</TargetServer>

如何設定單向傳輸層安全標準 (TLS):

  1. 如要驗證後端憑證,請在 Edge 中建立信任儲存庫,然後上傳後端憑證或 CA 鏈結,如 KeyStore 和 Truststores 所述。在這個範例中,如果您需要建立信任儲存庫,請將其命名為 myTrustStore
  2. 如果您建立了信任儲存庫,請使用下列 POST API 呼叫向您在上述步驟中建立的信任儲存庫,建立名為 myTrustStoreRef 的參照:

    curl -X POST  -H "Content-Type:application/xml" https://api.enterprise.apigee.com/v1/o/{org_name}/e/{env_name}/references \
      -d '<ResourceReference name="myTrustStoreRef">
        <Refers>myTrustKeystore</Refers>
        <ResourceType>KeyStore</ResourceType>
      </ResourceReference>' -u email:password
    
  3. 使用邊緣管理 UI 更新 API Proxy 的目標端點定義 (或者,如果您在 XML 中定義 API Proxy,請編輯 Proxy 的 XML 檔案):
    1. 前往 https://enterprise.apigee.com 登入 Edge 管理 UI。
    2. 在 Edge Management UI 選單中選取「API」
    3. 選取要更新的 API Proxy 名稱。
    4. 選取「開發」分頁標籤。
    5. 在「目標端點」下方,選取「預設」
    6. 在程式碼區域中編輯 <HTTPTargetConnection> 元素,以新增 <SSLInfo> 元素。 請務必指定正確的 Truststore 參照,並將 <Enabled> 設為 true:
      <TargetEndpoint name="default">
        …
        <HTTPTargetConnection>
          <SSLInfo>
            <Enabled>true</Enabled>
            <TrustStore>ref://myTrustStoreRef</TrustStore>
          </SSLInfo>
          <URL>https://myservice.com</URL>
        </HTTPTargetConnection>
        …
      </TargetEndpoint>
    7. 儲存 API Proxy。如果 API Proxy 已部署,儲存該 Proxy 就會使用新設定重新部署。

為後端伺服器設定雙向傳輸層安全標準 (TLS)

如要在 Edge (TLS 用戶端) 和後端伺服器 (TLS 伺服器) 之間支援雙向傳輸層安全標準 (TLS):

  • 在 Edge 中建立 KeyStore,並上傳 Edge 憑證和私密金鑰。
  • 如要驗證後端憑證,請在 Edge 中建立信任儲存庫,當中包含從後端伺服器接收的憑證和 CA 鏈結。
  • 針對參照後端伺服器的所有 API Proxy,更新其 TargetEndpoint,以便設定 TLS 存取權。

使用金鑰別名指定 KeyStore 憑證

您可以在同一個 KeyStore 中定義多個憑證,每個憑證都有專屬的別名。根據預設,Edge 會使用您在 KeyStore 中定義的第一個憑證。

您也可以選擇將 Edge 設定為使用 <KeyAlias> 屬性指定的憑證。如此一來,您就能為多個憑證定義單一 KeyStore,然後在 TargetServer 定義中選取要使用的 KeyStore。如果 Edge 無法找到別名與「<KeyAlias>」相符的憑證,則會使用預設動作,在 KeyStore 中選取第一個憑證。

Edge for Public Cloud 使用者必須與 Apigee Edge 支援團隊聯絡,才能啟用這項功能。

設定雙向 TLS

如何設定雙向傳輸層安全標準 (TLS):

  1. 按照 Keystores 和 Truststores 所述的程序,在 Edge 中建立 KeyStore,並上傳憑證和私密金鑰。在這個範例中,您會建立名為 myTestKeystore 的 KeyStore,這個 KeyStore 針對憑證和私密金鑰使用 myKey 的別名名稱。
  2. 使用下列 POST API 呼叫,為您在上述步驟中建立的 KeyStore 建立名為 myKeyStoreRef 的參照:

    curl -X POST  -H "Content-Type:application/xml" https://api.enterprise.apigee.com/v1/o/{org_name}/e/{env_name}/references \
    -d '<ResourceReference name="myKeyStoreRef">
        <Refers>myTestKeystore</Refers>
        <ResourceType>KeyStore</ResourceType>
    </ResourceReference>' -u email:password
    

    參照將 KeyStore 名稱和參照類型指定為 KeyStore

    請使用下列 GET API 呼叫來查看參照:

    curl -X GET https://api.enterprise.apigee.com/v1/o/[org_name}/e/{env_name}/references/myKeyStoreRef /
    -u email:password
    
  3. 如要驗證後端憑證,請在 Edge 中建立信任儲存庫,然後上傳憑證和憑證授權單位鏈結,相關說明如下:Keystores 和 Truststores。 舉例來說,您必須建立名為 myTrustStore 的信任儲存庫。
  4. 如果您建立了信任儲存庫,請使用下列 POST API 呼叫向您在上述步驟中建立的信任儲存庫,建立名為 myTrustStoreRef 的參照:

    curl -X POST  -H "Content-Type:application/xml" https://api.enterprise.apigee.com/v1/o/{org_name}/e/{env_name}/references \
    -d '<ResourceReference name="myTrustStoreRef">
        <Refers>myTrustKeystore</Refers>
        <ResourceType>KeyStore</ResourceType>
    </ResourceReference>' -u email:password
    
  5. 使用邊緣管理 UI 更新 API Proxy 的目標端點定義 (或者,如果您在 XML 中定義 API Proxy,請編輯 Proxy 的 XML 檔案):
    1. 前往 https://enterprise.apigee.com 登入 Edge 管理 UI。
    2. 在 Edge Management UI 選單中選取「API」
    3. 選取要更新的 API Proxy 名稱。
    4. 選取「開發」分頁標籤。
    5. 在「目標端點」下方,選取「預設」
    6. 在程式碼區域中編輯 <HTTPTargetConnection> 元素,以新增 <SSLInfo> 元素。請務必指定正確的 KeyStore 和金鑰別名,並將 <Enabled><ClientAuthEnabled> 元素都設為 true:
      <TargetEndpoint name="default">
        ...
        <HTTPTargetConnection>
          <SSLInfo>
            <Enabled>true</Enabled>
            <ClientAuthEnabled>true</ClientAuthEnabled>
            <KeyStore>ref://myKeyStoreRef</KeyStore>
            <KeyAlias>myKey</KeyAlias>
          </SSLInfo>
          <URL>https://myservice.com</URL>
        </HTTPTargetConnection>
        ...
      </TargetEndpoint>
    7. 儲存 API Proxy。如果 API Proxy 已部署,儲存該 Proxy 就會使用新設定重新部署。

如要進一步瞭解 <TargetEndpoint> 中的可用選項,包括使用變數來提供目標端點 <SSLInfo> 值,請參閱 API Proxy 設定參考資料

啟用 SNI

Edge 支援使用訊息處理器中的伺服器名稱指示 (SNI),以及 Cloud Edge 中的 Apigee Edge 中的目標端點,以及私人雲端部署作業。

針對 Private Cloud 適用的 Edge,如要提供與現有目標後端的回溯相容性,Apigee 預設會停用 SNI。如果目標後端設為支援 SNI,您可以啟用這項功能。詳情請參閱「搭配 Edge 使用 SNI」。