本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
ElastiCache 傳輸中加密 (TLS)
為了協助保護您的資料安全,Amazon ElastiCache 和 Amazon EC2 提供保護您伺服器上的資料不受未授權存取的機制。ElastiCache 透過提供傳輸中加密功能,在您的資料於不同地點間移動時,讓您有工具可以協助保護資料。
所有 Valkey 或 Redis OSS 無伺服器快取都已啟用傳輸中加密。對於自行設計的叢集,您可以透過在建立複寫群組時,將參數 TransitEncryptionEnabled
設定為 true
(CLI:--transit-encryption-enabled
),以在複寫群組上啟用傳輸中加密。無論您是使用 AWS Management Console、 或 ElastiCache API 建立複寫群組 AWS CLI,都可以執行此操作。
所有無伺服器快取都會啟用傳輸中加密。對於自行設計的叢集,您可以在使用 CreateCacheCluster
(CLI:create-cache-cluster
) 操作建立快取叢集時,將參數 TransitEncryptionEnabled
設定為 true
(CLI:--transit-encryption-enabled
),以在快取叢集上啟用傳輸中加密。
傳輸中加密概觀
Amazon ElastiCache 傳輸中加密功能可讓您在資料於兩地之間傳輸時,在資料最易遭受攻擊的點提高資料的安全性。因為要加密和解密端點的資料需要一些處理,啟用傳輸中加密可能會有一些效能影響。您應該對您具有和不具有傳輸中加密的資料進行基準分析,以判斷對您的使用案例的影響。
ElastiCache 傳輸中加密會實作下列功能:
-
加密的用戶端連線:用戶端與快取節點的連線會經過 TLS 加密。
-
加密的伺服器連線:在叢集中的節點之間移動的資料會經過加密。
-
伺服器身分驗證 - 用戶端可以驗證是否已連線至正確的伺服器。
-
用戶端身分驗證 - 使用 Valkey 和 Redis OSS AUTH 功能,伺服器可以驗證用戶端。
傳輸中加密條件 (Valkey 和 Redis OSS)
規劃自行設計的叢集實作時,應謹記下列有關 Amazon ElastiCache 傳輸中加密的限制條件:
-
執行 Valkey 7.2 和更新版本以及 Redis OSS 3.2.6、4.0.10 和更新版本的複寫群組支援傳輸中加密。
-
執行 Valkey 7.2 和更新版本的複寫群組,以及 Redis OSS 第 7 版和更新版本,支援修改現有叢集的傳輸中加密設定。
-
只有在 Amazon VPC 中執行的複寫群組支援傳輸中加密。
-
執行下列節點類型的複寫群組不支援傳輸中加密:M1, M2。
如需詳細資訊,請參閱支援的節點類型。
-
透過將參數
TransitEncryptionEnabled
明確設定為true
,可啟用傳輸中加密。 -
請確定您的快取用戶端支援 TLS 連線,而且您已在用戶端組態中啟用它。
-
ElastiCache 第 6 版及更新版本的所有 AWS 區域皆已棄用舊 TLS 1.0 和 TLS 1.1 的使用。ElastiCache 將繼續支援 TLS 1.0 和 1.1,直到 2025 年 5 月 8 日為止。客戶必須在該日期之前更新其用戶端軟體。
傳輸中加密條件 (Memcached)
規劃自行設計的叢集實作時,應謹記下列有關 Amazon ElastiCache 傳輸中加密的限制條件:
-
執行 Memcached 1.6.12 和更新版本的叢集上支援傳輸中加密。
-
傳輸中加密支援 Transport Layer Security (TLS) 1.2 和 1.3 版。
-
只有在 Amazon VPC 中執行的叢集支援傳輸中加密。
-
執行下列節點類型的複寫群組不支援傳輸中加密:M1, M2, M3, R3, T2。
如需詳細資訊,請參閱支援的節點類型。
-
透過將參數
TransitEncryptionEnabled
明確設定為true
,可啟用傳輸中加密。 -
您只能在建立叢集時,在叢集上啟用傳輸中加密。您無法透過修改叢集來開啟和關閉傳輸中加密。
-
請確定您的快取用戶端支援 TLS 連線,而且您已在用戶端組態中啟用它。
傳輸中加密最佳實務
-
因為要加密和解密端點的資料需要一些處理,實作傳輸中加密可能會降低效能。對您自己的資料進行傳輸中加密與無加密基準分析的比較,來判斷對您實作的影響。
-
因為建立新連線可能所費不貲,您可以透過持續保存您的 TLS 連線來減少傳輸中加密的效能影響。
其他 Valkey 和 Redis OSS 選項
如需 Valkey 和 Redis OSS 可用選項的詳細資訊,請參閱下列連結。
啟用 Memcached 的傳輸中加密
若要在使用 AWS 管理主控台建立 Memcached 叢集時,啟用傳輸中加密,請選取以下項目:
-
選擇 Memcached 當作您的引擎。
-
選擇引擎 1.6.12 或更新版本。
-
在 Encryption in transit (傳輸中加密) 中,選擇 Enable (啟用)。
如需step-by-step程序,請參閱 為 Valkey 或 Redis OSS 建立叢集。
使用 Openssl (Memcached) 連線至已啟用傳輸中加密的節點
若要從啟用傳輸中加密的 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 用戶端
若要在 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 用戶端
若要在 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 叢集用戶端。