ECR で「You are about to set a repository policy that will prevent you from setting another one in the future」を回避するには

ECR で「You are about to set a repository policy that will prevent you from setting another one in the future」を回避するには

Clock Icon2025.02.06

困っていた内容

AWS マネジメントコンソールで ECR のリポジトリポリシーを編集、保存するとエラーが表示されます。

エラーメッセージ
You are about to set a repository policy that will prevent you from setting another one in the future. Use the force parameter to override this exception.

同様のポリシーを他の AWS アカウント環境でも設定済みですが、アカウントによって使用できない条件でも含まれているのでしょうか。
原因と対処法を教えてください。

どう対応すればいいの?

編集後のリポジトリポリシーに、変更を行うユーザーの許可が含まれているか確認してください。

意図せず ECR リポジトリが管理不能になるリスクを防ぐため、ECR では変更したポリシーを保存する前に、変更内容をチェックします。

例えば、VPC エンドポイント経由のみに制限するポリシーを、AWS マネージメントコンソールからリクエストすると、ロックアウトが発生するためYou are about to set a repository policy that will prevent you from setting another one in the future. Use the force parameter to override this exception.で失敗します。

そのため、リポジトリポリシーを変更する場合は、変更を行うユーザーをロックアウトするような内容がないか確認してください。

なお、意図的にロックアウトするようなポリシーを設定する場合はリクエストする API のforcetrueに設定してください。

ただし、2025年2月時点では、AWS マネジメントコンソールから該当する設定はできないため、設定する場合はAWS CLI のset-repository-policyから変更してください。

コマンド例
aws ecr set-repository-policy \
    --repository-name hato-ecr-repository \
    --policy-text file://hato-policy.json --force

参考資料

force
If the policy you are attempting to set on a repository policy would prevent you from setting another policy in the future, you must force the SetRepositoryPolicy operation. This is intended to prevent accidental repository lock outs.

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.