SAP-C02 practice question 31 of 35

A company uses AWS Organizations to manage a multi-account structure. The company has hundreds of AWS accounts and expects the number of accounts to…

Full set: 689 questions

Domain Design for New Solutions

A company uses AWS Organizations to manage a multi-account structure. The company has hundreds of AWS accounts and expects the number of accounts to increase. The company is building a new application that uses Docker images. The company will push the Docker images to Amazon Elastic Container Registry (Amazon ECR). Only accounts that are within the company's organization should have access to the images. The company has a CI/CD process that runs frequently. The company wants to retain all the tagged images. However, the company wants to retain only the five most recent untagged images. Which solution will meet these requirements with the LEAST operational overhead?
Answer options
A: Create a private repository in Amazon ECR. Create a permissions policy for the repository that allows only required ECR operations. Include a condition to allow the ECR operations if the value of the aws:PrincipalOrglD condition key is equal to the ID of the company's organization. Add a lifecycle rule to the ECR repository that deletes all untagged images over the count of five. Correct answer
B: Create a public repository in Amazon ECR. Create an IAM role in the ECR account. Set permissions so that any account can assume the role if the value of the aws:PrincipalOrglD condition key is equal to the ID of the company's organization. Add a lifecycle rule to the ECR repository that deletes all untagged images over the count of five.
C: Create a private repository in Amazon ECR. Create a permissions policy for the repository that includes only required ECR operations. Include a condition to allow the ECR operations for all account IDs in the organization. Schedule a daily Amazon EventBridge rule to invoke an AWS Lambda function that deletes all untagged images over the count of five.
D: Create a public repository in Amazon ECR. Configure Amazon ECR to use an interface VPC endpoint with an endpoint policy that includes the required permissions for images that the company needs to pull. Include a condition to allow the ECR operations for all account IDs in the company's organization. Schedule a daily Amazon EventBridge rule to invoke an AWS Lambda function that deletes all untagged images over the count of five.
Correct Answer:
A. Create a private repository in Amazon ECR. Create a permissions policy for the repository that allows only required ECR operations. Include a condition to allow the ECR operations if the value of the aws:PrincipalOrglD condition key is equal to the ID of the company's organization. Add a lifecycle rule to the ECR repository that deletes all untagged images over the count of five.
Explanation

This solution correctly addresses all requirements with the least operational overhead. Using a private Amazon ECR repository ensures the images are not publicly accessible. The repository permissions policy leverages the aws:PrincipalOrgID condition key, which is a scalable method to grant access to all current and future accounts within the AWS Organization without needing to manually update a list of account IDs. This minimizes management overhead. Furthermore, using a native ECR lifecycle policy is the most efficient, built-in mechanism to automatically clean up untagged images based on a count, avoiding the need to develop and maintain a custom solution like an AWS Lambda function.

Why Incorrect

B. Creating a public repository is insecure and violates the principle of least privilege, as the requirement is to restrict access only to accounts within the organization.
C. Manually listing all account IDs in a policy is not scalable and creates high operational overhead, especially as the number of accounts grows. Using a Lambda function for cleanup is also more overhead than a native ECR lifecycle policy.
D. A public repository is inappropriate for this use case. While a VPC endpoint policy can restrict access from within a VPC, it does not secure the repository from public access, and it adds unnecessary complexity. ---
References:
1. AWS ECR User Guide - Private repository policies: This document explains how to use resource-based permissions (repository policies) to control access. It provides examples of using the aws:PrincipalOrgID condition key to grant permissions to all accounts in an organization. Source: AWS Documentation, Amazon ECR User Guide.
Reference: Section "Private repository policies", subsection "Using the aws:PrincipalOrgID condition key".
2. AWS IAM User Guide - AWS global condition context keys: This guide details the aws:PrincipalOrgID key, stating it can be used to "compare the ID of the organization in which the principal (user or role) making the request belongs to the organization ID specified in the policy." This confirms its suitability for scalable, organization-wide permissions. Source: AWS Documentation, IAM User Guide.
Reference: Page "AWS global condition context keys", entry for aws:PrincipalOrgID.
3. AWS ECR User Guide - Lifecycle policies: This documentation describes how to set up automated rules to manage the lifecycle of images in a repository. It explicitly details rule parameters like tagStatus (tagged or untagged) and countType with imageCountMoreThan to retain a specific number of recent images. Source: AWS Documentation, Amazon ECR User Guide.
Reference: Section "Lifecycle policies", subsection "Lifecycle policy examples".

Scroll to Top