

# SEC03-BP01 定義存取需求
<a name="sec_permissions_define"></a>

管理員、終端使用者或其他元件都需要存取工作負載的每個元件或資源。請明確定義應該有權存取每個元件的人員和機器，選擇適當的身分類型及驗證和授權方法。

 **常見的反模式：**
+ 將機密硬式編碼或儲存在應用程式中。
+ 為每名使用者授予自訂許可。
+ 使用長期憑證。

 **未建立此最佳實務時的曝險等級：**高 

## 實作指引
<a name="implementation-guidance"></a>

 管理員、終端使用者或其他元件都需要存取工作負載的每個元件或資源。請明確定義應該有權存取每個元件的人員和機器，選擇適當的身分類型及驗證和授權方法。

應提供組織內對 AWS 帳戶 的定期存取 (使用[聯合存取](https://aws.amazon.com/identity/federation/)或集中式身分提供者)。您應集中進行身分管理，並確保有既定的實務，可將 AWS 存取整合至員工的存取生命週期。例如，當員工改為擔任具有不同存取層級的任務角色時，其群組成員資格也應變更，以反映新的存取需求。

 為非人類身分定義存取需求時，請判斷哪些應用程式和組成部分需要存取權，以及如何授予許可。使用透過最低權限存取模型建置的 IAM 角色是建議的方法。[AWS受管政策](https://docs.aws.amazon.com/singlesignon/latest/userguide/security-iam-awsmanpol.html)提供預先定義的 IAM 政策，其中涵蓋最常見的使用案例。

AWS 服務 (例如 [AWS Secrets Manager](https://aws.amazon.com/blogs/security/identify-arrange-manage-secrets-easily-using-enhanced-search-in-aws-secrets-manager/) 和 [AWS Systems Manager Parameter Store](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html)) 可協助將機密從應用程式或工作負載中安全地分離。在 Secrets Manager 中，您可以為憑證建立自動輪換。您可以使用 Systems Manager 來參考指令碼、命令、SSM 文件、組態和自動化工作流程中的參數，方法是使用您在建立參數時指定的唯一名稱。

 您可以使用 [AWS IAM Roles Anywhere](https://docs.aws.amazon.com/rolesanywhere/latest/userguide/introduction.html) 取得 [IAM 中的臨時安全憑證](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp.html)，以用於在 AWS 外部執行的工作負載。工作負載可以使用您在 AWS 應用程式中使用的相同 [IAM 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html)和 [IAM 角色](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles.html)來存取 AWS 資源。

 可能的話，請選擇短期暫時憑證，而不是長期靜態憑證。對於您希望使用者具備程式設計存取權和長期憑證的情況，請使用[存取金鑰上次使用的資訊](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_RotateAccessKey)來輪換和移除存取金鑰。

若使用者想要與 AWS 管理主控台 之外的 AWS 互動，則需要程式化存取權。授與程式化存取權的方式取決於存取 AWS 的使用者類型。

若要授予使用者程式設計存取權，請選擇下列其中一個選項。


****  

| 哪個使用者需要程式設計存取權？ | 到 | 根據 | 
| --- | --- | --- | 
| IAM | (建議事項) 將主控台憑證用作臨時憑證來簽署對 AWS CLI、AWS SDK 或 AWS API 的程式設計請求。 |  請依照您要使用的介面所提供的指示操作。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/wellarchitected/latest/security-pillar/sec_permissions_define.html)  | 
|  人力資源身分 (IAM Identity Center 中管理的使用者)  | 使用臨時憑證簽署對 AWS CLI、AWS SDK 或 AWS API 的程式設計請求。 |  請依照您要使用的介面所提供的指示操作。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/wellarchitected/latest/security-pillar/sec_permissions_define.html)  | 
| IAM | 使用臨時憑證簽署對 AWS CLI、AWS SDK 或 AWS API 的程式設計請求。 | 請遵循《IAM 使用者指南》中[使用臨時憑證搭配 AWS 資源](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_use-resources.html)中的指示。 | 
| IAM | (不建議使用)使用長期憑證簽署 AWS CLI、AWS SDK 或 AWS API 的程式設計要求。 |  請依照您要使用的介面所提供的指示操作。 [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/wellarchitected/latest/security-pillar/sec_permissions_define.html)  | 

## 資源
<a name="resources"></a>

 **相關文件：**
+  [屬性型存取控制 (ABAC)](https://docs.aws.amazon.com/IAM/latest/UserGuide/introduction_attribute-based-access-control.html) 
+  [AWS IAM Identity Center](https://aws.amazon.com/iam/identity-center/) 
+  [ IAM Roles Anywhere](https://docs.aws.amazon.com/rolesanywhere/latest/userguide/introduction.html) 
+  [IAM Identity Center 的 AWS 受管政策](https://docs.aws.amazon.com/singlesignon/latest/userguide/security-iam-awsmanpol.html) 
+  [AWS IAM 政策條件](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html) 
+  [IAM 使用案例](https://docs.aws.amazon.com/IAM/latest/UserGuide/IAM_UseCases.html) 
+  [移除不必要的憑證](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#remove-credentials) 
+  [使用 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage.html) 
+  [如何根據 AWS 帳戶、OU 或組織控制對 AWS 資源的存取權](https://aws.amazon.com/blogs/security/how-to-control-access-to-aws-resources-based-on-aws-account-ou-or-organization/) 
+  [使用 AWS Secrets Manager 中增強的搜尋功能來輕鬆識別、安排和管理機密](https://aws.amazon.com/blogs/security/identify-arrange-manage-secrets-easily-using-enhanced-search-in-aws-secrets-manager/) 

 **相關影片：**
+  [在 60 分鐘內精通 IAM 政策](https://youtu.be/YQsK4MtsELU) 
+  [責任區隔、最低權限、委派和 CI/CD](https://youtu.be/3H0i7VyTu70) 
+  [簡化身分和存取管理，以促進創新](https://www.youtube.com/watch?v=3qK0b1UkaE8) 