拒否リスト戦略は、デフォルトですべての OU とアカウントにアタッチされている FullAWSAccess SCP を使用します。
拒否ポリシーのある OU のレベルの下のアカウントでは、拒否された API は使用できません。
許可リスト戦略では、すべての OU とアカウントにデフォルトで接続されている FullAWSAccess SCP を削除します。
サービス API を AWS アカウント で動作させるには、独自の SCP を作成し、アカウントとその上にあるルートまでのすべての OU にアタッチする必要があります。
どちらの戦略でもポリシーの継承のみでは機能せず、ルート、OU、アカウントに少なくとも一つのSCPを直接アタッチする必要がある
優先順位
ポリシーで拒否 > ポリシーで許可 > 暗黙の拒否
-- 1. コマンド等のインストール
-- 1.1 aws cli version 2 インストール
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
aws --version
-- 1.2 jqインストール
sudo yum -y install jq
-- 2. OUの作成
aws organizations list-roots
aws organizations list-children \
--parent-id r-1111 \
--child-type ORGANIZATIONAL_UNIT
aws organizations create-organizational-unit \
--parent-id r-1111 \
--name ou01
-- 3. ルートからOUへのアカウント移動
aws organizations move-account \
--account-id 999999999999 \
--source-parent-id r-1111 \
--destination-parent-id ou-1111-22222222
aws organizations list-children \
--parent-id ou-1111-22222222 \
--child-type ACCOUNT
aws organizations enable-policy-type \
--root-id r-1111 \
--policy-type SERVICE_CONTROL_POLICY
aws organizations list-policies \
--filter SERVICE_CONTROL_POLICY
aws organizations describe-policy \
--policy-id p-FullAWSAccess
aws organizations list-targets-for-policy \
--policy-id p-FullAWSAccess
aws organizations detach-policy \
--policy-id p-FullAWSAccess \
--target-id ou-1111-22222222
→ An error occurred (ConstraintViolationException) when calling the DetachPolicy operation:
You cannot remove the last policy attached to the specified target. You must have at least one attached at all times.
aws organizations detach-policy \
--policy-id p-FullAWSAccess \
--target-id r-1111
→ An error occurred (ConstraintViolationException) when calling the DetachPolicy operation:
You cannot remove the last policy attached to the specified target. You must have at least one attached at all times.
aws organizations detach-policy \
--policy-id p-FullAWSAccess \
--target-id 999999999999
→ An error occurred (ConstraintViolationException) when calling the DetachPolicy operation:
You cannot remove the last policy attached to the specified target. You must have at least one attached at all times.
アタッチされたポリシーを0個にすることはできない
-- 6. クリーンアップ
aws organizations disable-policy-type \
--root-id r-1111 \
--policy-type SERVICE_CONTROL_POLICY
-- OUからルートへのアカウント移動
aws organizations move-account \
--account-id 999999999999 \
--source-parent-id ou-1111-22222222 \
--destination-parent-id r-1111
-- OUの削除
aws organizations list-children \
--parent-id r-1111 \
--child-type ORGANIZATIONAL_UNIT
aws organizations delete-organizational-unit \
--organizational-unit-id ou-1111-22222222