ElastiCache 傳輸中加密 (TLS) - Amazon ElastiCache

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

ElastiCache 傳輸中加密 (TLS)

為了協助保護資料安全,Amazon ElastiCache 和 Amazon EC2提供機制來防止未經授權存取伺服器上的資料。透過提供傳輸中加密功能, ElastiCache 您可以提供工具,以便在資料從一個位置移至另一個位置時協助保護資料。

所有 Valkey 或 Redis 無OSS伺服器快取都已啟用傳輸中加密。對於自行設計的叢集,您可以在建立複寫群組時將 參數設定為 TransitEncryptionEnabledtrue(CLI:--transit-encryption-enabled),以啟用複寫群組的傳輸中加密。無論您是使用 AWS Management Console、 或 建立複寫群組 AWS CLI,都可以執行此操作 ElastiCache API。

所有無伺服器快取都會啟用傳輸中加密。對於自行設計的叢集,您可以在使用 TransitEncryptionEnabledtrue(CLI:--transit-encryption-enabled) 操作建立快取叢集時,將 參數設定為 CreateCacheCluster(CLI:create-cache-cluster),以啟用快取叢集的傳輸中加密。

傳輸中加密概觀

Amazon 傳輸 ElastiCache 中加密是一項功能,可讓您在資料從一個位置傳輸到另一個位置時,提高其最脆弱點的資料安全性。因為要加密和解密端點的資料需要一些處理,啟用傳輸中加密可能會有一些效能影響。您應該對您具有和不具有傳輸中加密的資料進行基準分析,以判斷對您的使用案例的影響。

ElastiCache 傳輸中加密實作下列功能:

  • 加密的用戶端連線 — 快取節點的用戶端連線會TLS加密。

  • 加密的伺服器連線:在叢集中的節點之間移動的資料會經過加密。

  • 伺服器身分驗證 - 用戶端可以驗證是否已連線至正確的伺服器。

  • 用戶端身分驗證:使用 Valkey 和 Redis OSSAUTH功能,伺服器可以驗證用戶端。

傳輸中加密條件 (Valkey 和 RedisOSS)

當您規劃自行設計的叢集實作時,應謹記 Amazon 傳輸 ElastiCache 中加密的下列限制:

  • 執行 Valkey 7.2 及更新版本以及 Redis 3.2.6、4.0.10 及更新OSS版本的複寫群組支援傳輸中加密。

  • 執行 Valkey 7.2 和更新版本以及 Redis 7 和更新OSS版本的複寫群組支援修改現有叢集的傳輸中加密設定。

  • 只有 Amazon 中執行的複寫群組才支援傳輸中加密VPC。

  • 執行下列節點類型的複寫群組不支援傳輸中加密:M1, M2。

    如需詳細資訊,請參閱支援的節點類型

  • 透過將參數 TransitEncryptionEnabled 明確設定為 true,可啟用傳輸中加密。

  • 確保您的快取用戶端支援TLS連線,且您已在用戶端組態中啟用連線。

  • 第 TLS 6 TLS 版及更高 ElastiCache 版本的所有 AWS 區域皆已棄用舊 1.0 和 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 (Memcached) 節點存取資料,您需要使用使用 Secure Socket 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"); } }

使用 建立 TLS Memcached 用戶端 PHP

若要在 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 叢集用戶端