fix(codeartifact): enforce domains-per-account and repositories-per-domain quotas (#3949)

CreateDomain and CreateRepository accepted an unlimited number of domains and
repositories, but AWS caps an account at 10 domains per Region and a domain at
1,000 repositories, returning ServiceQuotaExceededException once reached.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-09-19 19:38:27 -05:00
1 parent 1e8485830c
commit 15ed62f8cb
3 files changed
+111 -4

No files matched your search

@@ -76,6 +76,8 @@ public class CodeArtifactService implements Resettable {
private static final List<String> ASSET_HASH_ALGORITHMS = List.of("MD5", "SHA-1", "SHA-256", "SHA-512");
private static final long MAX_ASSET_FILE_SIZE_BYTES = 5L * 1024 * 1024 * 1024;
private static final int MAX_ASSETS_PER_PACKAGE_VERSION = 350;
private static final int MAX_DOMAINS_PER_ACCOUNT = 10;
private static final int MAX_REPOSITORIES_PER_DOMAIN = 1000;
private static final String ASSET_STORAGE_DIR = "codeartifact-assets";
public record DomainView(CodeArtifactDomain domain, int repositoryCount) {}
@@ -142,6 +144,11 @@ public class CodeArtifactService implements Resettable {
if (domains.getForAccount(owner, key).isPresent()) {
throw conflict("Domain with name '" + domain + "' already exists.");
}
if (domainCountForAccount(owner, region) >= MAX_DOMAINS_PER_ACCOUNT) {
throw new AwsException("ServiceQuotaExceededException",
"An AWS account can have a maximum of " + MAX_DOMAINS_PER_ACCOUNT + " domains.", 402,
Map.of("resourceId", domain, "resourceType", "domain"));
}
CodeArtifactDomain d = new CodeArtifactDomain();
d.setName(domain);
d.setOwner(owner);
@@ -235,6 +242,11 @@ public class CodeArtifactService implements Resettable {
if (repositories.getForAccount(owner, key).isPresent()) {
throw conflict("Repository with name '" + repository + "' already exists in domain '" + domain + "'.");
}
if (repositoryCountForDomain(owner, region, domain) >= MAX_REPOSITORIES_PER_DOMAIN) {
throw new AwsException("ServiceQuotaExceededException",
"A domain can have a maximum of " + MAX_REPOSITORIES_PER_DOMAIN + " repositories.", 402,
Map.of("resourceId", repository, "resourceType", "repository"));
}
validateUpstreams(owner, region, domain, repository, upstreams);
validateDescription(description);
@@ -622,6 +634,10 @@ public class CodeArtifactService implements Resettable {
return repositories.scanForAccount(owner, k -> k.startsWith(region + "::" + domain + "::")).size();
}
private int domainCountForAccount(String owner, String region) {
return domains.scanForAccount(owner, k -> k.startsWith(region + "::")).size();
}
private void validateUpstreams(String owner, String region, String domain, String repository,
List<String> upstreams) {
if (upstreams == null) {