

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

# 中的安全性 AWS ParallelCluster
<a name="security"></a>

的雲端安全性 AWS 是最高優先順序。身為 AWS 客戶，您可以受益於資料中心和網路架構，該架構專為滿足最安全敏感組織的需求而建置。

安全性是 AWS 與您之間的共同責任。[共同責任模型](https://aws.amazon.com/compliance/shared-responsibility-model/)將其描述為雲端*本身*的安全和雲端*內部*的安全：
+ **雲端的安全性** – AWS 負責保護在 AWS Cloud 中執行 AWS 服務的基礎設施。 AWS 也為您提供可安全使用的服務。在[AWS 合規計畫](https://aws.amazon.com/compliance/programs/)中，第三方稽核人員會定期測試和驗證我們的安全有效性。若要了解適用的合規計劃 AWS ParallelCluster，請參閱[AWS 合規計劃的 服務範圍合規](https://aws.amazon.com/compliance/services-in-scope/)。
+ **雲端的安全性** – 您的責任取決於您使用的特定 AWS 服務或 服務。您也必須負責幾個其他相關因素，包括資料的敏感度、公司的要求，以及適用的法律和法規。

本文件說明如何在使用 時套用共同責任模型 AWS ParallelCluster。下列主題說明如何設定 AWS ParallelCluster 以符合您的安全與合規目標。您也會了解如何 AWS ParallelCluster 以協助您監控和保護 AWS 資源的方式使用 。

**Topics**
+ [所使用服務的安全性資訊 AWS ParallelCluster](#security-seealso)
+ [中的資料保護 AWS ParallelCluster](data-protection.md)
+ [的 Identity and Access Management AWS ParallelCluster](security-iam.md)
+ [的合規驗證 AWS ParallelCluster](security-compliance-validation.md)
+ [強制執行最低版本為 TLS 1.2](security-enforcing-tls.md)
+ [設定受限環境的安全群組](security-groups-configuration.md)

## 所使用服務的安全性資訊 AWS ParallelCluster
<a name="security-seealso"></a>
+ [Amazon EC2 的安全性 ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-security.html)
+ [Amazon API Gateway 的安全性](https://docs.aws.amazon.com/apigateway/latest/developerguide/security.html)
+ [中的安全性 AWS Batch](https://docs.aws.amazon.com/batch/latest/userguide/security.html)
+ [CloudFormation中的安全性](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/security.html)
+ [Amazon CloudWatch 的安全性](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/security.html)
+ [AWS CodeBuild中的安全性](https://docs.aws.amazon.com/codebuild/latest/userguide/security.html)
+ [Amazon DynamoDB 的安全性](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/security.html)
+ [Amazon ECR 的安全性](https://docs.aws.amazon.com/AmazonECR/latest/userguide/security.html)
+ [Amazon ECS 的安全性](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/security.html)
+ [Amazon EFS 的安全性](https://docs.aws.amazon.com/efs/latest/ug/security-considerations.html)
+ [FSx for Lustre 中的安全性](https://docs.aws.amazon.com/fsx/latest/LustreGuide/security.html)
+ [AWS Identity and Access Management (IAM) 中的安全性 ](https://docs.aws.amazon.com/IAM/latest/UserGuide/security.html)
+ [EC2 Image Builder 的安全性](https://docs.aws.amazon.com/imagebuilder/latest/userguide/image-builder-security.html)
+ [中的安全性 AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/lambda-security.html)
+ [Amazon Route 53 的安全性](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/security.html)
+ [Amazon SNS 的安全性](https://docs.aws.amazon.com/sns/latest/dg/sns-security.html)
+ [Amazon SQS 的安全性 （適用於 2.x AWS ParallelCluster 版）。](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-security.html)
+ [Amazon S3 的安全性](https://docs.aws.amazon.com/AmazonS3/latest/dev/security.html)
+ [Amazon VPC 的安全性](https://docs.aws.amazon.com/vpc/latest/userguide/security.html)

# 中的資料保護 AWS ParallelCluster
<a name="data-protection"></a>

 AWS [共同責任模型](https://aws.amazon.com/compliance/shared-responsibility-model/)適用於 中的資料保護。如此模型所述， AWS 負責保護執行所有 的全域基礎設施 AWS 雲端。您負責維護在此基礎設施上託管內容的控制權。您也同時負責所使用 AWS 服務 的安全組態和管理任務。如需資料隱私權的詳細資訊，請參閱[資料隱私權常見問答集](https://aws.amazon.com/compliance/data-privacy-faq/)。如需有關歐洲資料保護的相關資訊，請參閱*AWS 安全性部落格*上的[AWS 共同責任模型和 GDPR](https://aws.amazon.com/blogs/security/the-aws-shared-responsibility-model-and-gdpr/) 部落格文章。

基於資料保護目的，我們建議您保護 AWS 帳戶 登入資料，並使用 AWS IAM Identity Center 或 AWS Identity and Access Management (IAM) 設定個別使用者。如此一來，每個使用者都只會獲得授與完成其任務所必須的許可。我們也建議您採用下列方式保護資料：
+ 每個帳戶均要使用多重要素驗證 (MFA)。
+ 使用 SSL/TLS 與 AWS 資源通訊。我們需要 TLS 1.2 並建議使用 TLS 1.3。
+ 使用 設定 API 和使用者活動記錄 AWS CloudTrail。如需有關使用 CloudTrail 追蹤擷取 AWS 活動的資訊，請參閱*AWS CloudTrail 《 使用者指南*》中的[使用 CloudTrail 追蹤](https://docs.aws.amazon.com/awscloudtrail/latest/userguide/cloudtrail-trails.html)。
+ 使用 AWS 加密解決方案，以及其中的所有預設安全控制 AWS 服務。
+ 使用進階的受管安全服務 (例如 Amazon Macie)，協助探索和保護儲存在 Amazon S3 的敏感資料。
+ 如果您在 AWS 透過命令列界面或 API 存取 時需要 FIPS 140-3 驗證的密碼編譯模組，請使用 FIPS 端點。如需有關 FIPS 和 FIPS 端點的更多相關資訊，請參閱[聯邦資訊處理標準 (FIPS) 140-3](https://aws.amazon.com/compliance/fips/)。

我們強烈建議您絕對不要將客戶的電子郵件地址等機密或敏感資訊，放在標籤或自由格式的文字欄位中，例如**名稱**欄位。這包括當您使用 或使用主控台、API AWS CLI或其他 AWS 服務 AWS SDKs 時。您在標籤或自由格式文字欄位中輸入的任何資料都可能用於計費或診斷日誌。如果您提供外部伺服器的 URL，我們強烈建議請勿在驗證您對該伺服器請求的 URL 中包含憑證資訊。

## 資料加密
<a name="data-encryption"></a>

任何安全服務都有一項重要功能，就是當資訊處於非使用中狀態時，就會將資訊加密。

### 靜態加密
<a name="encryption-rest"></a>

AWS ParallelCluster 除了代表 AWS 使用者與服務互動所需的登入資料之外， 本身不會存放任何客戶資料。

對於叢集中節點上的資料，可以靜態加密資料。

對於 Amazon EBS 磁碟區，加密是使用 [`EbsSettings`](SharedStorage-v3.md#SharedStorage-v3-EbsSettings)區段中的 [`EbsSettings`](SharedStorage-v3.md#SharedStorage-v3-EbsSettings)/`Encrypted` 和 [`EbsSettings`](SharedStorage-v3.md#SharedStorage-v3-EbsSettings)/`KmsKeyId` 設定進行設定。如需詳細資訊，請參閱《[Amazon EC2 使用者指南》中的 Amazon EBS 加密](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSEncryption.html)。 Amazon EC2 

對於 Amazon EFS 磁碟區，使用 [`EfsSettings`](SharedStorage-v3.md#SharedStorage-v3-EfsSettings)區段中的 [`EfsSettings`](SharedStorage-v3.md#SharedStorage-v3-EfsSettings)/`Encrypted` 和 [`EfsSettings`](SharedStorage-v3.md#SharedStorage-v3-EfsSettings)/`KmsKeyId` 設定來設定加密。如需詳細資訊，請參閱《Amazon Elastic File System 使用者指南》中的[靜態加密的運作方式](https://docs.aws.amazon.com/efs/latest/ug/encryption-at-rest.html#howencrypt)。 *Amazon Elastic File System *

對於 FSx for Lustre 檔案系統，建立 Amazon FSx 檔案系統時會自動啟用靜態資料加密。如需詳細資訊，請參閱《*Amazon FSx for Lustre 使用者指南*》中的[加密靜態資料](https://docs.aws.amazon.com/fsx/latest/LustreGuide/encryption-at-rest.html)。

對於具有 NVMe 磁碟區的執行個體類型，NVMe 執行個體存放磁碟區上的資料會使用在執行個體上的硬體模組上實作的 XTS-AES-256 密碼進行加密。加密金鑰是以硬體模組來產生，且對每個 NVMe 執行個體儲存體設備而言是唯一的。所有加密金鑰會在執行個體停止或終止時銷毀，且無法復原。您無法停用此加密，也無法提供您自己的加密金鑰。如需詳細資訊，請參閱《*Amazon EC2 使用者指南*》中的[靜態加密](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/data-protection.html#encryption-rest)。

如果您使用 AWS ParallelCluster 叫用將客戶資料傳輸至本機電腦以供儲存 AWS 的服務，請參閱該服務使用者指南中的安全與合規章節，以取得如何存放、保護和加密該資料的資訊。

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

根據預設，從執行 AWS ParallelCluster AWS 和服務端點的用戶端電腦傳輸的所有資料都會透過 HTTPS/TLS 連線傳送所有內容來加密。根據選取的執行個體類型，叢集中節點之間的流量可以自動加密。如需詳細資訊，請參閱《*Amazon EC2 使用者指南*》中的[傳輸中加密](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/data-protection.html#encryption-transit)。

## 另請參閱
<a name="security-data-protection-seealso"></a>
+ [Amazon EC2 中的資料保護 ](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/data-protection.html)
+ [EC2 Image Builder 中的資料保護](https://docs.aws.amazon.com/imagebuilder/latest/userguide/data-protection.html)
+ [中的資料保護 CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/security-data-protection.html)
+ [Amazon EFS 中的資料保護](https://docs.aws.amazon.com/efs/latest/ug/efs-backup-solutions.html)
+ [Amazon S3 中的資料保護](https://docs.aws.amazon.com/AmazonS3/latest/dev/DataDurability.html)
+ [FSx for Lustre 中的資料保護](https://docs.aws.amazon.com/fsx/latest/LustreGuide/data-protection.html)

# 的 Identity and Access Management AWS ParallelCluster
<a name="security-iam"></a>

AWS ParallelCluster 使用 角色來存取您的 AWS 資源及其服務。 AWS ParallelCluster 用於授予許可的執行個體和使用者政策記錄在 [AWS Identity and Access Management 中的 許可 AWS ParallelCluster](iam-roles-in-parallelcluster-v3.md)。

唯一的主要差異在於使用標準 使用者和長期登入資料時的驗證方式。雖然 使用者需要密碼才能存取 AWS 服務的主控台，但該使用者需要存取金鑰對，才能使用 執行相同的操作 AWS ParallelCluster。所有其他短期憑證的使用方式都與搭配主控台使用的方式一樣。

使用的登入資料 AWS ParallelCluster 會存放在純文字檔案中，***不會***加密。
+ `$HOME/.aws/credentials` 檔案會存放存取 AWS 資源所需的長期登入資料。這些包含您的存取金鑰 ID 和私密存取金鑰。
+ 短期憑證，像是您擔任的角色，或用於 AWS IAM Identity Center 服務的角色，也會分別儲存於 `$HOME/.aws/cli/cache` 和 `$HOME/.aws/sso/cache` 資料夾中。

**降低風險**
+ 強烈建議您設定 `$HOME/.aws` 資料夾及其子資料夾和檔案的檔案系統權限，以限制為僅供授權使用者進行存取。
+ 盡可能使用具有臨時憑證的角色，以在憑證洩漏時減少損害的機會。僅將長期憑證用於請求及重新整理短期角色憑證。

# 的合規驗證 AWS ParallelCluster
<a name="security-compliance-validation"></a>

在多個合規計畫中，第三方稽核人員會評估 AWS 服務的安全性和 AWS 合規性。使用 AWS ParallelCluster 存取服務並不會改變該服務的合規性。

如需特定合規計劃範圍內 AWS 的服務清單，請參閱[AWS 合規計劃的合規計劃範圍內的服務](https://aws.amazon.com/compliance/services-in-scope/)。如需一般資訊，請參閱[AWS 合規計劃](https://aws.amazon.com/compliance/programs/)。

您可以使用 下載第三方稽核報告 AWS Artifact。如需詳細資訊，請參閱[下載 AWS Artifact中的報告](https://docs.aws.amazon.com/artifact/latest/ug/downloading-documents.html)。

使用 時的合規責任 AWS ParallelCluster 取決於資料的機密性、您公司的合規目標，以及適用的法律和法規。 AWS 提供下列資源來協助合規：
+ [安全與合規快速入門指南](https://aws.amazon.com/quickstart/?awsf.quickstart-homepage-filter=categories%23security-identity-compliance) – 這些部署指南討論架構考量，並提供部署以安全與合規為中心之基準環境的步驟 AWS。
+ [Amazon Web Services 上的 HIPAA 安全與合規架構 AWS 白皮書 ](https://docs.aws.amazon.com/pdfs/whitepapers/latest/architecting-hipaa-security-and-compliance-on-aws/architecting-hipaa-security-and-compliance-on-aws.pdf) – 此白皮書說明公司如何使用 AWS 來建立符合 HIPAA 規範的應用程式。
+ [AWS 合規資源](https://aws.amazon.com/compliance/resources/) – 此工作手冊和指南集合可能適用於您的產業和位置。
+ *AWS Config 開發人員指南*中的[使用規則評估資源](https://docs.aws.amazon.com/config/latest/developerguide/evaluate-config.html) – AWS Config 服務會評估資源組態符合內部實務、產業準則和法規的程度。
+ [AWS Security Hub CSPM](https://docs.aws.amazon.com/securityhub/latest/userguide/what-is-securityhub.html) – AWS 此服務提供 內安全狀態的完整檢視 AWS ，協助您檢查是否符合安全產業標準和最佳實務。

# 強制執行最低版本為 TLS 1.2
<a name="security-enforcing-tls"></a>

若要在與服務通訊時增加安全性 AWS ，您應該將 AWS ParallelCluster 設定為使用 TLS 1.2 或更新版本。當您使用 時 AWS ParallelCluster，Python 會用來設定 TLS 版本。

為了確保 AWS ParallelCluster 不使用早於 TLS 1.2 的 TLS 版本，您可能需要重新編譯 OpenSSL 以強制執行此最小值，然後重新編譯 Python 以使用新建置的 OpenSSL。

## 判定目前支援的通訊協定
<a name="enforcing-tls-supported"></a>

首先，使用 OpenSSL 建立用於測試伺服器和 Python SDK 的自簽憑證。

```
$ openssl req -subj '/CN=localhost' -x509 -newkey rsa:4096 -nodes -keyout key.pem -out cert.pem -days 365
```

然後使用 OpenSSL 啟動測試伺服器。

```
$ openssl s_server -key key.pem -cert cert.pem -www
```

在新的終端機視窗中，建立虛擬環境並安裝 Python SDK。

```
$ python3 -m venv test-env
source test-env/bin/activate
pip install botocore
```

建立一個名為 `check.py` 的 Python 指令碼，此指令碼使用 SDK 的基礎 HTTP 程式庫。

```
$ import urllib3
URL = 'https://localhost:4433/'

http = urllib3.PoolManager(
ca_certs='cert.pem',
cert_reqs='CERT_REQUIRED',
)
r = http.request('GET', URL)
print(r.data.decode('utf-8'))
```

執行新的指令碼。

```
$ python check.py
```

這會顯示有關所建立連線的詳細資訊。在輸出中搜尋 "Protocol : " (通訊協定：)。如果輸出是 "TLSv1.2" 或更新版本，SDK 就預設為 TLS v1.2 或更新版本。如果是較早的版本，您就必須重新編譯 OpenSSL 再重新編譯 Python。

但是，即使您安裝的 Python 預設為 TLS v1.2 或更新版本，如果伺服器不支援 TLS v1.2 或更新版本，則 Python 仍然可能必須與 TLS v1.2 更早的版本重新交涉。若要確保 Python 不會自動與較早版本重新交涉，請使用以下命令重新啟動測試伺服器。

```
$ openssl s_server -key key.pem -cert cert.pem -no_tls1_3 -no_tls1_2 -www
```

如果您使用的是較早版本的 OpenSSL，您可能無法使用 `-no_tls_3` 旗標。如果是這種情況，請刪除該旗標，因為您使用的 OpenSSL 版本不支援 TLS v1.3。然後執行 Python 指令碼。

```
$ python check.py
```

如果您的 Python 安裝正確，不會與 TLS 1.2 之前的版本重新交涉，您應該會收到 SSL 錯誤。

```
$ urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='localhost', port=4433): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: UNSUPPORTED_PROTOCOL] unsupported protocol (_ssl.c:1108)')))
```

如果能夠建立連線，則您必須重新編譯 OpenSSL 和 Python，以禁止與 TLS v1.2 之前的通訊協定交涉。

## 編譯 OpenSSL 和 Python
<a name="enforcing-tls-compile"></a>

為了確保 AWS ParallelCluster 不會交涉早於 TLS 1.2 的任何內容，您需要重新編譯 OpenSSL 和 Python。若要執行此操作，請複製下列內容以建立並執行此指令碼。

```
#!/usr/bin/env bash
set -e

OPENSSL_VERSION="1.1.1d"
OPENSSL_PREFIX="/opt/openssl-with-min-tls1_2"
PYTHON_VERSION="3.8.1"
PYTHON_PREFIX="/opt/python-with-min-tls1_2"


curl -O "https://www.openssl.org/source/openssl-$OPENSSL_VERSION.tar.gz"
tar -xzf "openssl-$OPENSSL_VERSION.tar.gz"
cd openssl-$OPENSSL_VERSION
./config --prefix=$OPENSSL_PREFIX no-ssl3 no-tls1 no-tls1_1 no-shared
make > /dev/null
sudo make install_sw > /dev/null


cd /tmp
curl -O "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz"
tar -xzf "Python-$PYTHON_VERSION.tgz"
cd Python-$PYTHON_VERSION
./configure --prefix=$PYTHON_PREFIX --with-openssl=$OPENSSL_PREFIX --disable-shared > /dev/null
make > /dev/null
sudo make install > /dev/null
```

這樣會編譯一個 Python 版本，內含不會自動與 TLS 1.2 之前任何版本交涉的靜態連結 OpenSSL。這也會在 `/opt/openssl-with-min-tls1_2` 目錄中安裝 OpenSSL，並在 `/opt/python-with-min-tls1_2` 目錄中安裝 Python。執行此指令碼之後，確認已安裝新版本的 Python。

```
$ /opt/python-with-min-tls1_2/bin/python3 --version
```

這應該會列印以下內容。

```
Python 3.8.1
```

若要確認這個新版本的 Python 不會與 TLS 1.2 之前的版本交涉，請使用新安裝的 Python 版本 (也就是 `/opt/python-with-min-tls1_2/bin/python3`) 重新執行 [判定目前支援的通訊協定](#enforcing-tls-supported) 的步驟。

# 設定受限環境的安全群組
<a name="security-groups-configuration"></a>

根據預設， 會 AWS ParallelCluster 建立和設定安全群組，以允許叢集節點之間的所有流量。在高度受限的環境中，您可能需要將網路存取限制為僅叢集操作所需的連接埠。本節說明如何為 AWS ParallelCluster 部署設定具有限制存取的自訂安全群組。

## 安全群組概觀
<a name="security-groups-configuration-overview"></a>

AWS ParallelCluster 使用安全群組來控制前端節點、運算節點和登入節點之間的網路流量 （如果已設定）。根據預設，當 AWS ParallelCluster 建立叢集時，它會建立安全群組，以允許叢集內節點之間的所有流量。在具有嚴格安全要求的環境中，您可以提供自訂安全群組，將流量限制為僅必要的連接埠。

您可以在叢集組態的下列區段中設定安全群組：
+ [`HeadNode` / `Networking`](HeadNode-v3.md#HeadNode-v3-Networking) - 控制對前端節點的存取
+ [`Scheduling` / `SlurmQueues` / `Networking`](Scheduling-v3.md#Scheduling-v3-SlurmQueues-Networking) - 控制對運算節點的存取
+ [`LoginNodes`](LoginNodes-v3.md) - 控制登入節點的存取 （如果已設定）

對於這些區段，您可以指定：
+ `SecurityGroups` - 取代 AWS ParallelCluster 將建立的預設安全群組
+ `AdditionalSecurityGroups` - 新增安全群組，以及 建立的預設安全群組 AWS ParallelCluster

## 叢集操作所需的連接埠
<a name="security-groups-configuration-required-ports"></a>

設定自訂安全群組時，您必須確保在適當的節點之間開啟下列連接埠：


**前端節點所需的連接埠**  

| 連線埠 | 通訊協定 | Direction | 用途 | 
| --- | --- | --- | --- | 
| 22 | TCP | 傳入 | 前端節點的 SSH 存取 （從允許的 IP 範圍） | 
| 6817-6819 | TCP | 傳入 | Slurm 控制器連接埠 （來自運算和登入節點） | 
| 6817-6819 | TCP | 傳出 | Slurm 控制器連接埠 （用於運算和登入節點） | 
| 8443 | TCP | 傳入 | NICE DCV （如果啟用，從允許的 IP 範圍） | 
| 2049 年 111 月 | TCP/UDP | 傳入 | NFS （使用 NFS 進行共用儲存時，來自運算和登入節點） | 
| 443 | TCP | 傳出 | HTTPS 存取 AWS 服務 （如果未使用 VPC 端點） | 


**運算節點所需的連接埠**  

| 連線埠 | 通訊協定 | Direction | 用途 | 
| --- | --- | --- | --- | 
| 22 | TCP | 傳入 | SSH 存取 （來自前端節點和登入節點） | 
| 6818 | TCP | 傳入 | Slurm 協助程式連接埠 （來自前端節點） | 
| 6817-6819 | TCP | 傳出 | Slurm 控制器連接埠 （前端節點） | 
| 2049 年 111 月 | TCP/UDP | 傳出 | NFS （對於前端節點，如果使用 NFS 進行共用儲存） | 
| 443 | TCP | 傳出 | HTTPS 存取 AWS 服務 （如果未使用 VPC 端點） | 

如果您使用的是 EFA （彈性布料轉接器），您還必須允許已啟用 EFA 的運算節點之間的所有流量：
+ 運算節點與 EFA 之間的所有 TCP 和 UDP 流量
+ 具有 EFA 的運算節點之間的 EFA 裝置上所有流量

**注意**  
如果您使用的是 FSx for Lustre、Amazon EFS 或其他儲存解決方案等共用儲存系統，您也需要確保為這些服務開啟適當的連接埠。

## 建立自訂安全群組
<a name="security-groups-configuration-custom"></a>

若要為您的 AWS ParallelCluster 部署建立自訂安全群組，請遵循下列步驟：

1. 使用 AWS 管理主控台、 AWS CLI 或 AWS CloudFormation 為前端節點、運算節點和登入節點 （如適用） 建立安全群組。

1. 設定安全群組規則以僅允許必要的流量，如上一節所述。

1. 參考叢集組態檔案中的這些安全群組。

以下是如何使用 CLI AWS 建立安全群組的範例：

```
# Create security group for head node
aws ec2 create-security-group \
  --group-name pcluster-head-node-sg \
  --description "Security group for ParallelCluster head node" \
  --vpc-id vpc-12345678

# Create security group for compute nodes
aws ec2 create-security-group \
  --group-name pcluster-compute-node-sg \
  --description "Security group for ParallelCluster compute nodes" \
  --vpc-id vpc-12345678

# Add rules to allow necessary traffic between head and compute nodes
# (Add specific rules based on the required ports listed above)
```

## 在叢集組態中設定安全群組
<a name="security-groups-configuration-cluster-config"></a>

建立自訂安全群組之後，您可以在叢集組態檔案中參考這些群組：

```
# Example cluster configuration with custom security groups
HeadNode:
  ...
  Networking:
    SubnetId: subnet-12345678
    SecurityGroups:
      - sg-headnode12345  # Custom security group for head node
    # Or use AdditionalSecurityGroups if you want to keep the default security groups
    # AdditionalSecurityGroups:
    #   - sg-additional12345
  ...

Scheduling:
  Scheduler: slurm
  SlurmQueues:
    - Name: queue1
      ...
      Networking:
        SubnetIds:
          - subnet-12345678
        SecurityGroups:
          - sg-computenode12345  # Custom security group for compute nodes
        # Or use AdditionalSecurityGroups if you want to keep the default security groups
        # AdditionalSecurityGroups:
        #   - sg-additional12345
      ...

# If using login nodes
LoginNodes:
  Pools:
    - Name: login-pool
      ...
      Networking:
        SubnetIds:
          - subnet-12345678
        SecurityGroups:
          - sg-loginnode12345  # Custom security group for login nodes
        # Or use AdditionalSecurityGroups if you want to keep the default security groups
        # AdditionalSecurityGroups:
        #   - sg-additional12345
      ...
```

使用 時`SecurityGroups`， 只會 AWS ParallelCluster 使用您指定的安全群組，取代預設的安全群組。使用 時`AdditionalSecurityGroups`， AWS ParallelCluster 會使用其建立的預設安全群組，以及您指定的其他安全群組。

**警告**  
如果您為運算執行個體啟用 [Elastic Fabric Adapter (EFA)](Scheduling-v3.md#yaml-Scheduling-SlurmQueues-ComputeResources-Efa)，請確定已啟用 EFA 的執行個體是允許所有傳入和傳出流量本身的安全群組成員。這是 EFA 正常運作的必要項目。

## 在受限環境中使用 VPC 端點
<a name="security-groups-configuration-vpc-endpoints"></a>

在高度受限的環境中，您可能想要在沒有網際網路存取的情況下部署在子網路 AWS ParallelCluster 中。在這種情況下，您需要設定 VPC 端點，以允許叢集與 AWS 服務通訊。如需詳細說明，請參閱 [AWS ParallelCluster 在沒有網際網路存取的單一子網路中](aws-parallelcluster-in-a-single-public-subnet-no-internet-v3.md)。

使用 VPC 端點時，請確定您的安全群組允許往返 VPC 端點的流量。您可以將與 VPC 端點相關聯的安全群組新增至頭部節點和運算節點的`AdditionalSecurityGroups`組態，以執行此操作。

```
HeadNode:
  ...
  Networking:
    SubnetId: subnet-1234567890abcdef0
    AdditionalSecurityGroups:
      - sg-abcdef01234567890  # Security group that enables communication with VPC endpoints
  ...

Scheduling:
  Scheduler: slurm
  SlurmQueues:
    - ...
      Networking:
        SubnetIds:
          - subnet-1234567890abcdef0
        AdditionalSecurityGroups:
          - sg-1abcdef01234567890  # Security group that enables communication with VPC endpoints
```

## 安全群組組態的最佳實務
<a name="security-groups-configuration-best-practices"></a>

在受限環境中設定 的安全群組 AWS ParallelCluster 時，請考慮下列最佳實務：
+ **最低權限原則**：僅開啟叢集操作所需的連接埠。
+ **使用安全群組參考**：盡可能使用安全群組參考 （允許來自另一個安全群組的流量），而不是 CIDR 區塊來限制叢集元件之間的流量。
+ **限制 SSH 存取**：將前端節點的 SSH 存取限制為僅使用 [`HeadNode`/ / 組態所需的 IP `Ssh``AllowedIps`](HeadNode-v3.md#yaml-HeadNode-Ssh-AllowedIps) 範圍。
+ **限制 DCV 存取**：如果使用 NICE DCV，請使用 [`HeadNode`/ / 組態僅限制存取需要的 IP `Dcv``AllowedIps`](HeadNode-v3.md#yaml-HeadNode-Dcv-AllowedIps) 範圍。
+ **徹底測試**：設定自訂安全群組之後，請徹底測試所有叢集功能，以確保所有必要的通訊路徑都能正常運作。
+ **記錄您的組態**：維護安全群組組態的文件，包括開啟哪些連接埠，以及為什麼需要這些連接埠。

## 對安全群組問題進行故障診斷
<a name="security-groups-configuration-troubleshooting"></a>

如果您在設定自訂安全群組之後遇到問題，請考慮下列疑難排解步驟：
+ **檢查叢集日誌**：檢閱 CloudWatch Logs 中的叢集日誌是否有任何連線錯誤。
+ **驗證安全群組規則**：確保在適當的節點之間開啟所有必要的連接埠。
+ **測試連線**能力：使用 `telnet`或 等工具`nc`來測試特定連接埠上節點之間的連線能力。
+ **暫時展開規則**：如果您無法識別需要哪些連接埠，請暫時允許叢集節點之間的所有流量，然後在識別所需的連接埠時逐漸限制。
+ **檢查 VPC 端點組態**：如果您使用的是 VPC 端點，請確保它們已正確設定，且安全群組允許進出流量。

如果持續遇到問題，您可以從叢集組態檔案移除`SecurityGroups`組態 AWS ParallelCluster ，以還原為使用 建立的預設安全群組。