

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# ElastiCache 傳輸中加密 (TLS)
<a name="in-transit-encryption"></a>

為了協助保護您的資料安全，Amazon ElastiCache 和 Amazon EC2 提供保護您伺服器上的資料不受未授權存取的機制。ElastiCache 透過提供傳輸中加密功能，在您的資料於不同地點間移動時，讓您有工具可以協助保護資料。

所有 Valkey 或 Redis OSS 無伺服器快取都已啟用傳輸中加密。對於節點型叢集，您可以在建立複寫群組時將 參數設定為 `TransitEncryptionEnabled``true`(CLI：`--transit-encryption-enabled`)，以在複寫群組上啟用傳輸中加密。無論您是使用AWS 管理主控台AWS CLI、 或 ElastiCache API 建立複寫群組，都可以執行此操作。

所有無伺服器快取都會啟用傳輸中加密。對於節點型叢集，您可以在使用 `TransitEncryptionEnabled``true`(CLI：`--transit-encryption-enabled`) 操作建立叢集時，將 參數設定為 `CreateCacheCluster`(CLI：`create-cache-cluster`)，在叢集上啟用傳輸中加密。

**Topics**
+ [傳輸中加密概觀](#in-transit-encryption-overview)
+ [傳輸中加密條件 (Valkey 和 Redis OSS)](#in-transit-encryption-constraints)
+ [傳輸中加密條件 (Memcached)](#in-transit-encryption-constraints)
+ [傳輸中加密最佳實務](#in-transit-encryption-best-practices)
+ [進一步的 Valkey 和 Redis OSS 選項](#in-transit-encryption-see-also)
+ [啟用 Memcached 的傳輸中加密](#in-transit-encryption-enable-existing-mc)
+ [啟用傳輸中加密](in-transit-encryption-enable.md)
+ [使用 valkey-cli 透過傳輸中加密連線至 ElastiCache (Valkey) 或 Amazon ElastiCache for Redis OSS](connect-tls.md)
+ [使用 Python 在以節點為基礎的 Redis OSS 叢集上啟用傳輸中加密](in-transit-encryption-enable-python.md)
+ [啟用傳輸中加密時的最佳實務](enable-python-best-practices.md)
+ [使用 Openssl (Memcached) 連線至已啟用傳輸中加密的節點](#in-transit-encryption-connect-mc)
+ [使用 Java 建立 TLS Memcached 用戶端](#in-transit-encryption-connect-java)
+ [使用 PHP 建立 TLS Memcached 用戶端](#in-transit-encryption-connect-php-mc)

## 傳輸中加密概觀
<a name="in-transit-encryption-overview"></a>

Amazon ElastiCache 傳輸中加密功能可讓您在資料於兩地之間傳輸時，在資料最易遭受攻擊的點提高資料的安全性。因為要加密和解密端點的資料需要一些處理，啟用傳輸中加密可能會有一些效能影響。您應該對您具有和不具有傳輸中加密的資料進行基準分析，以判斷對您的使用案例的影響。

ElastiCache 傳輸中加密會實作下列功能：
+ **加密的用戶端連線**：用戶端與快取節點的連線會經過 TLS 加密。
+ **加密的伺服器連線**：在叢集中的節點之間移動的資料會經過加密。
+ **伺服器身分驗證** - 用戶端可以驗證是否已連線至正確的伺服器。
+ **用戶端身分驗證** - 使用 Valkey 和 Redis OSS AUTH 功能，伺服器可以驗證用戶端。

## 傳輸中加密條件 (Valkey 和 Redis OSS)
<a name="in-transit-encryption-constraints"></a>

當您規劃節點型叢集實作時，應謹記 Amazon ElastiCache 傳輸中加密的下列限制：
+ 執行 Valkey 7.2 和更新版本以及 Redis OSS 3.2.6、4.0.10 和更新版本的複寫群組支援傳輸中加密。
+ 執行 Valkey 7.2 和更新版本以及 Redis OSS 第 7 版和更新版本的複寫群組支援修改現有叢集的傳輸中加密設定。
+ 只有在 Amazon VPC 中執行的複寫群組支援傳輸中加密。
+ 執行下列節點類型的複寫群組不支援傳輸中加密：M1, M2。

  如需詳細資訊，請參閱[支援的節點類型](CacheNodes.SupportedTypes.md)。
+ 透過將參數 `TransitEncryptionEnabled` 明確設定為 `true`，可啟用傳輸中加密。
+ 請確定您的快取用戶端支援 TLS 連線，而且您已在用戶端組態中啟用它。
+ 自 2026 年 1 月 26 日起，AWS將在 ElastiCache for Valkey 7.2 版及更新版本，以及 ElastiCache for Redis OSS 第 6 版及更新版本上，將支援的 TLS 最低版本更新為 1.2。客戶必須在該日期之前更新其用戶端軟體。此更新可協助您滿足安全、合規和法規需求。

## 傳輸中加密條件 (Memcached)
<a name="in-transit-encryption-constraints"></a>

當您規劃節點型叢集實作時，應謹記 Amazon ElastiCache 傳輸中加密的下列限制：
+ 執行 Memcached 1.6.12 和更新版本的叢集上支援傳輸中加密。
+ 傳輸中加密支援 Transport Layer Security (TLS) 1.2 和 1.3 版。
+ 只有在 Amazon VPC 中執行的叢集支援傳輸中加密。
+ 執行下列節點類型的複寫群組不支援傳輸中加密：M1, M2, M3, R3, T2。

  如需詳細資訊，請參閱[支援的節點類型](CacheNodes.SupportedTypes.md)。
+ 透過將參數 `TransitEncryptionEnabled` 明確設定為 `true`，可啟用傳輸中加密。
+ 您只能在建立叢集時，在叢集上啟用傳輸中加密。您無法透過修改叢集來開啟和關閉傳輸中加密。
+ 請確定您的快取用戶端支援 TLS 連線，而且您已在用戶端組態中啟用它。

## 傳輸中加密最佳實務
<a name="in-transit-encryption-best-practices"></a>
+ 因為要加密和解密端點的資料需要一些處理，實作傳輸中加密可能會降低效能。對您自己的資料進行傳輸中加密與無加密基準分析的比較，來判斷對您實作的影響。
+ 因為建立新連線可能所費不貲，您可以透過持續保存您的 TLS 連線來減少傳輸中加密的效能影響。

## 進一步的 Valkey 和 Redis OSS 選項
<a name="in-transit-encryption-see-also"></a>

如需 Valkey 和 Redis OSS 可用選項的詳細資訊，請參閱下列連結。
+ [ElastiCache 中的靜態加密](at-rest-encryption.md)
+ [使用 Valkey 和 Redis OSS AUTH 命令進行驗證](auth.md)
+ [角色型存取控制 (RBAC) 規則數量](Clusters.RBAC.md)
+ [Amazon VPC 和 ElastiCache 安全性](VPCs.md)
+ [Amazon ElastiCache 中的 Identity and Access Management](IAM.md)

## 啟用 Memcached 的傳輸中加密
<a name="in-transit-encryption-enable-existing-mc"></a>

若要在使用AWS管理主控台建立 Memcached 叢集時，啟用傳輸中加密，請選取以下項目：
+ 選擇 Memcached 當作您的引擎。
+ 選擇引擎 1.6.12 或更新版本。
+ 在 **Encryption in transit** (傳輸中加密) 中，選擇 **Enable** (啟用)。

 如需step-by-step程序，請參閱 [為 Valkey 或 Redis OSS 建立叢集](Clusters.Create.md)。

## 使用 Openssl (Memcached) 連線至已啟用傳輸中加密的節點
<a name="in-transit-encryption-connect-mc"></a>

若要從啟用傳輸中加密的 ElastiCache for Memcached 節點存取資料，需使用可與 Secure Sockets Layer (SSL) 搭配的用戶端。您也可以在 Amazo Linux 和 Amazo Linux 2 上使用 Openssl s\_client。

在 Amazo Linux 或 Amazo Linux 2 上，使用 Openssl s\_client 來連線到啟用傳輸中加密的 Memcached 叢集：

```
/usr/bin/openssl s_client -connect {{memcached-node-endpoint}}:{{memcached-port}}
```

## 使用 Java 建立 TLS Memcached 用戶端
<a name="in-transit-encryption-connect-java"></a>

若要在 TLS 模式下建立用戶端，請執行下列操作，使用適當的 SSLContext 來初始化用戶端：

```
import java.security.KeyStore;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import net.spy.memcached.AddrUtil;
import net.spy.memcached.ConnectionFactoryBuilder;
import net.spy.memcached.MemcachedClient;
public class TLSDemo {
    public static void main(String[] args) throws Exception {
        ConnectionFactoryBuilder connectionFactoryBuilder = new ConnectionFactoryBuilder();
        // Build SSLContext
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init((KeyStore) null);
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, tmf.getTrustManagers(), null);
        // Create the client in TLS mode
        connectionFactoryBuilder.setSSLContext(sslContext);
        MemcachedClient client = new MemcachedClient(connectionFactoryBuilder.build(), AddrUtil.getAddresses("mycluster.fnjyzo.cfg.use1.cache.amazonaws.com:11211"));

        // Store a data item for an hour.
        client.set("theKey", 3600, "This is the data value");
    }
}
```

## 使用 PHP 建立 TLS Memcached 用戶端
<a name="in-transit-encryption-connect-php-mc"></a>

若要在 TLS 模式下建立用戶端，請執行下列操作，使用適當的 SSLContext 來初始化用戶端：

```
<?php

/**
 * Sample PHP code to show how to create a TLS Memcached client. In this example we
 * will use the Amazon ElastiCache Auto Descovery feature, but TLS can also be
 * used with a Static mode client. 
 * See Using the ElastiCache Cluster Client for PHP (https://docs.aws.amazon.com/AmazonElastiCache/latest/dg/AutoDiscovery.Using.ModifyApp.PHP.html) for more information 
 * about Auto Discovery and persistent-id.
 */

/* Configuration endpoint to use to initialize memcached client.
 * this is only an example */
$server_endpoint = "mycluster.fnjyzo.cfg.use1.cache.amazonaws.com";

/* Port for connecting to the cluster. 
 * This is only an example     */
$server_port = 11211;

/* Initialize a persistent Memcached client and configure it with the Dynamic client mode  */
$tls_client =  new Memcached('persistent-id');
$tls_client->setOption(Memcached::OPT_CLIENT_MODE, Memcached::DYNAMIC_CLIENT_MODE);

/* Add the memcached's cluster server/s */
$tls_client->addServer($server_endpoint, $server_port);

/* Configure the client to use TLS */
if(!$tls_client->setOption(Memcached::OPT_USE_TLS, 1)) {
    echo $tls_client->getLastErrorMessage(), "\n";
    exit(1);
}

/* Set your TLS context configurations values.
 * See MemcachedTLSContextConfig in memcached-api.php for all configurations */
$tls_config = new MemcachedTLSContextConfig();
$tls_config->hostname = '*.mycluster.fnjyzo.use1.cache.amazonaws.com';
$tls_config->skip_cert_verify = false;
$tls_config->skip_hostname_verify = false;

/* Use the created TLS context configuration object to create OpenSSL's SSL_CTX and set it to your client.
 * Note:  These TLS context configurations will be applied to all the servers connected to this client. */
$tls_client->createAndSetTLSContext((array)$tls_config);

/* test the TLS connection with set-get scenario: */

 /* store the data for 60 seconds in the cluster.
 * The client will decide which cache host will store this item.
 */
if($tls_client->set('key', 'value', 60)) {
    print "Successfully stored key\n";
} else {
    echo "Failed to set key: ", $tls_client->getLastErrorMessage(), "\n";
    exit(1);
}

/* retrieve the key */
if ($tls_client->get('key') === 'value') {
    print "Successfully retrieved key\n";
} else {
    echo "Failed to get key: ", $tls_client->getLastErrorMessage(), "\n";
    exit(1);
}
```

如需使用 PHP 用戶端的詳細資訊，請參閱[安裝適用於 PHP 的 ElastiCache 叢集用戶端](Appendix.PHPAutoDiscoverySetup.md)。