跳至內容

如何解決 AWS Control Tower 中的 "Not authorized to baseline the VPC in the enrolled account" 錯誤?

4 分的閱讀內容
0

我在 AWS Control Tower 中收到與虛擬私有雲端 (VPC) 基準授權相關的錯誤。當我嘗試設定或更新 Control Tower 登陸區域,或註冊或更新 AWS 帳戶時,就會發生這些錯誤。

簡短說明

當您嘗試設定或更新登陸區域時,會收到以下錯誤:

"AWS Control Tower failed to set up your landing zone completely: AWS Control Tower is not authorized to baseline the VPC in the enrolled account."

當您使用 AWS Control Tower 帳戶工廠建立 AWS 帳戶或更新已註冊的帳戶時,會收到以下錯誤:

"AWS Control Tower could not enroll your account for the following reason: AWS Control Tower is not authorized to baseline the VPC in the enrolled account."

您可能會因以下原因收到上述錯誤:

注意: 如果您使用帳戶工廠建立帳戶,AWS Control Tower 會自動刪除預設 Amazon VPC。此外,AWS Control Tower 僅會根據您的帳戶工廠網路組態,在您管控的區域中設定新的 Amazon VPC。如果您註冊現有帳戶,AWS Control Tower 不會移除預設 Amazon VPC,也不會為該帳戶建立新的 Amazon VPC。

解決方法

注意: 如果您在執行 AWS Command Line Interface (AWS CLI) 命令時收到錯誤訊息,請參閱 Troubleshooting errors for the AWS CLI (對 AWS CLI 錯誤進行疑難排解)。此外,請務必使用最新版 AWS CLI。

重要事項: 會員帳戶所指的帳戶會依失敗類型而異。如果登陸區域發生故障,請在日誌封存和稽核帳戶中完成步驟。這些帳戶也稱為共用帳戶或整合帳戶。如果帳戶註冊失敗,請在註冊失敗的會員帳戶中完成步驟。

檢閱會員帳戶中的 CloudTrail 事件

若要識別失敗的動作,請在所有 AWS Control Tower 區域中完成下列步驟:

  1. 在註冊失敗的會員帳戶中開啟 AWS CloudTrail console (AWS CloudTrail 主控台),然後選擇 Event history (事件歷史記錄)。
  2. 在 Lookup attributes (查詢屬性) 功能表中,選擇 Event source (事件來源)。
  3. 在搜尋方塊中輸入 ec2.amazonaws.com 作為事件來源。
  4. 選取 Filter by date and time (依日期和時間篩選) 方塊,然後選擇 Absolute range (絕對範圍)。
  5. 輸入操作失敗期間的開始日期、結束日期和時間,然後選擇 Apply (套用)。
  6. 選擇設定圖示,啟用 Error Code (錯誤代碼),然後選擇 Confirm (確認)。
  7. 若要識別失敗的事件,請在 Error code (錯誤代碼) 欄中尋找 UnauthorizedOperation、AccessDenied、DependencyViolation 或 CannotDelete 錯誤代碼。
  8. 選取事件以查看詳細的錯誤訊息。
  9. 檢閱失敗 CloudTrail 事件的錯誤訊息,以識別可能的原因。如果錯誤訊息顯示未獲授權或權限不足錯誤,請完成驗證 SCP 和 AWSControlTowerExecution 角色許可一節中的步驟。如果錯誤與資源相依性有關,請完成識別並解決 AWS Control Tower 區域中的預設 VPC 相依性一節中的步驟。

驗證 SCP 和 AWSControlTowerExecution 角色許可

AWSControlTowerExecution IAM 角色必須具備 AdministratorAccess 政策,並與 AWS Organizations 的管理帳戶建立信任關係。確認組織的 SCP 或與 IAM 角色相關聯的政策不會限制角色的動作。

完成下列步驟:

  1. 在 AWS Control Tower 管理帳戶中開啟 Organizations console (Organizations 主控台)。
  2. 在導覽窗格中,選擇 AWS accounts (AWS 帳戶)。
  3. 在搜尋方塊中搜尋註冊失敗的帳戶 ID,然後選取該 ID。
  4. 選擇 Policies (政策) 索引標籤,並確認根、組織單位 (OU) 和帳戶等所有組織實體均套用 FullAWSAccess SCP。
  5. 檢閱所有已連接的 SCP,以識別對 ec2 動作的任何限制。
  6. 暫時從實體中卸離自訂 SCP。或者,修改 SCP 以使用 Condition 區塊,將 AWSControlTowerExecution IAM 角色排除在限制之外。

下列範例 SCP 會拒絕所有 Amazon Elastic Compute Cloud (Amazon EC2) 動作,但 AWSControlTowerExecution 角色執行的動作除外:

{
   "Version":"2012-10-17",
   "Statement": [
       {
           "Sid": "Statement1",
           "Effect": "Deny",
           "Action": "ec2:*",
           "Resource": "*",
           "Condition": {
               "ArnNotLike": {
                   "aws:PrincipalARN": [
                       "arn:aws:iam::*:role/AWSControlTowerExecution"
                   ]
               }
           }
       }
   ]
}

識別並解決 AWS Control Tower 區域中的預設 VPC 相依性

由於資源相依性,AWS Control Tower 無法刪除受管控區域中現有的預設 VPC。若要尋找並手動刪除 AWS Control Tower 區域中的預設 VPC,請執行以下動作。

尋找預設 VPC

您可以使用 AWS 全域檢視、Amazon VPC 主控台或 AWS CLI,在會員帳戶的 AWS Control Tower 區域中尋找預設 VPC。

AWS 全域檢視

使用 AWS 全域檢視在單一檢視中同時列出多個區域中的所有 VPC 資源。在 View resources across Regions using AWS Global View (使用 AWS 全域檢視跨區域檢視資源) 中,檢視 Required permissions (所需的許可) 一節並遵循 To use AWS Global View (使用 AWS 全域檢視) 下的步驟。

選取管控區域的 VPC ID,以確認 Default VPC (預設 VPC) 是否設定為 YES (是)。

Amazon VPC 主控台

在每個 AWS Control Tower 區域中完成下列步驟:

  1. 登入會員帳戶,然後開啟 Amazon VPC 主控台。
  2. 在導覽窗格中,選擇 Your VPCs (您的 VPC)。
  3. 找出 Default VPC (預設 VPC) 顯示為 Yes (是) 的 VPC。

AWS CLI

若要使用 AWS CLI,請在會員帳戶中執行以下 bash 指令碼:

for region in $(aws ec2 describe-regions \
   --all-regions \
   --query 'Regions[?OptInStatus!=`not-opted-in`].RegionName' \
   --output text); do

   vpc=$(aws ec2 describe-vpcs \
       --filters Name=isDefault,Values=true \
       --region "$region" \
       --query 'Vpcs[*].{VpcId:VpcId,CIDR:CidrBlock}' \
       --output text 2>/dev/null)

   [ -n "$vpc" ] && echo "$region: $vpc" || echo "$region: No default VPC"
done

取消註冊然後重新註冊帳戶

重要事項: 請僅當會員帳戶註冊失敗時,才完成下列步驟。如果登陸區域發生故障,請略過本節。

若要避免 AWS Control Tower 移除會員帳戶中具有重要相依性的預設 VPC,請從 AWS Control Tower 取消註冊帳戶。然後,在符合先決條件後手動註冊帳戶。

重新註冊組織單位 (OU)

重要事項: 請僅當會員帳戶註冊失敗時,才完成下列步驟。如果登陸區域發生故障,請略過本節。

為了防止 AWS Control Tower 移除會員帳戶中具有重要相依性的預設 VPC,請重新註冊 OU,該帳戶即位於該 OU 中。重新註冊 OU 將會略過 VPC 基準設定、註冊帳戶,並保留預設 VPC。

刪除預設 VPC

重要事項: 刪除 VPC 前,您必須移除與該 VPC 建立關聯的所有資源。刪除預設 VPC 可能會影響依賴這些 VPC 的現有資源或應用程式。最佳實務是在刪除 VPC 前先檢閱其內容。

您可以使用 Amazon VPC 主控台或 AWS CLI,刪除 AWS Control Tower 區域中的預設 VPC。

若要使用主控台,請完成下列步驟:

  1. 登入會員帳戶,然後開啟 Amazon VPC console (Amazon VPC 主控台)。
  2. 選取您的預設 VPC。
  3. 選擇 Actions (動作),然後選擇 Delete VPC (刪除 VPC)。
  4. 在 Delete VPC (刪除 VPC) 對話方塊中,選取 I acknowledge that I want to delete my Default VPC (我確認要刪除我的預設 VPC) 核取方塊。
    注意: 選取此選項時,您會刪除與 VPC 建立關聯的所有元素,包括子網路和安全群組。
  5. 在確認方塊中輸入 delete default vpc,然後選擇 Delete (刪除)。

若要使用 AWS CLI,請執行以下 delete-vpc 命令:

aws ec2 delete-vpc --vpc-id YOUR_VPC_ID --region YOUR_REGION

注意: 請將 YOUR_VPC_ID 替換為您的 VPC ID,並將 YOUR_REGION 替換為您的區域。

最後,在 AWS Control Tower 中重試登陸區域設定或帳戶註冊操作。

AWS 官方已更新 7 個月前