feat(ecr): registry policy, replication and scanning configuration (#5817)

* feat(ecr): registry policy, replication and scanning configuration

PutRegistryPolicy, GetRegistryPolicy, DeleteRegistryPolicy, PutReplicationConfiguration,
DescribeRegistry, PutRegistryScanningConfiguration and GetRegistryScanningConfiguration store
the registry's own settings per account and Region and return them as written. Floci does not
replicate or scan images or evaluate the policy, as with repository policies.

- The policy must be a JSON object; a missing one is RegistryPolicyNotFoundException.
- Replication destinations, filters and rule counts are checked against the service model, and
  an empty rules list clears the configuration.
- Scanning defaults to BASIC with no rules, and CONTINUOUS_SCAN is refused with BASIC.

Closes #5803

* fix(ecr): put the registry setting writes under one lock

PutRegistryPolicy, DeleteRegistryPolicy, PutReplicationConfiguration and
PutRegistryScanningConfiguration read the registry's one settings record, change a
field and write it back. Terraform applies the three resources in parallel, so two
writers could start from the same record and the later write dropped the other's
setting. The read, change and write now happen under a lock per account and Region.

* refactor(ecr): check registry setting requests against the vendored model

The Resource Groups request walker moves to core.common as RequestConstraintCheck, so
a service can check a JSON request against botocore's constraints: member types,
required members, lengths and counts, number ranges, patterns and enums, each
answered in the service's own words. Resource Groups keeps its BadRequestException
messages.

- tools/aws/request_shapes.py gains build_constraints, which
  regen_resource_groups_shapes.py now calls; its vendored file is unchanged.
- tools/aws/regen_ecr_shapes.py vendors ecr-request-shapes.json for the seven
  registry setting actions, and aws-data-sync and aws-data-check run it.
- EcrJsonHandler checks those requests first, answering InvalidParameterException in
  ECR's form. The hand-written checks the model states are gone; a policy that is
  not a JSON object and CONTINUOUS_SCAN with BASIC stay, as the model cannot say
  them.
This commit is contained in:
David authored and GitHub committed 2026-10-20 10:03:30 -04:00
1 parent c4a2c0a4f6
commit 1f96bf42f1
20 files changed
+1493 -116

No files matched your search

@@ -296,4 +296,54 @@ class EcrTest {
private static String sha256(byte[] bytes) throws Exception {
return "sha256:" + HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(bytes));
}
@Test
@Order(14)
@DisplayName("Registry policy, replication and scanning configuration round-trip")
void registrySettingsRoundTrip() {
String policy = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"Replicate\",\"Effect\":\"Allow\","
+ "\"Principal\":{\"AWS\":\"arn:" + TestFixtures.partition() + ":iam::111111111111:root\"},"
+ "\"Action\":[\"ecr:CreateRepository\",\"ecr:ReplicateImage\"],\"Resource\":\"*\"}]}";
try {
assertThatThrownBy(() -> ecr.getRegistryPolicy(b -> {}))
.isInstanceOf(RegistryPolicyNotFoundException.class);
ecr.putRegistryPolicy(b -> b.policyText(policy));
assertThat(ecr.getRegistryPolicy(b -> {}).policyText()).isEqualTo(policy);
ecr.putReplicationConfiguration(b -> b.replicationConfiguration(c -> c.rules(ReplicationRule.builder()
.destinations(ReplicationDestination.builder().region("us-west-2").registryId("111111111111").build())
.repositoryFilters(RepositoryFilter.builder().filter("prod").filterType("PREFIX_MATCH").build())
.build())));
DescribeRegistryResponse registry = ecr.describeRegistry(b -> {});
assertThat(registry.registryId()).matches("[0-9]{12}");
assertThat(registry.replicationConfiguration().rules()).hasSize(1);
assertThat(registry.replicationConfiguration().rules().get(0).destinations().get(0).region())
.isEqualTo("us-west-2");
ecr.putRegistryScanningConfiguration(b -> b.scanType(ScanType.ENHANCED).rules(RegistryScanningRule.builder()
.scanFrequency(ScanFrequency.CONTINUOUS_SCAN)
.repositoryFilters(ScanningRepositoryFilter.builder().filter("prod-*")
.filterType(ScanningRepositoryFilterType.WILDCARD).build())
.build()));
GetRegistryScanningConfigurationResponse scanning = ecr.getRegistryScanningConfiguration(b -> {});
assertThat(scanning.scanningConfiguration().scanType()).isEqualTo(ScanType.ENHANCED);
assertThat(scanning.scanningConfiguration().rules().get(0).scanFrequency())
.isEqualTo(ScanFrequency.CONTINUOUS_SCAN);
assertThatThrownBy(() -> ecr.putRegistryScanningConfiguration(b -> b.scanType(ScanType.BASIC)
.rules(RegistryScanningRule.builder().scanFrequency(ScanFrequency.CONTINUOUS_SCAN)
.repositoryFilters(ScanningRepositoryFilter.builder().filter("*")
.filterType(ScanningRepositoryFilterType.WILDCARD).build())
.build())))
.isInstanceOf(InvalidParameterException.class);
} finally {
// Registry settings are per account and Region, so put back what a fresh registry has.
try {
ecr.deleteRegistryPolicy(b -> {});
} catch (RegistryPolicyNotFoundException ignored) {
// Already absent.
}
ecr.putReplicationConfiguration(b -> b.replicationConfiguration(c -> c.rules(List.of())));
ecr.putRegistryScanningConfiguration(b -> b.scanType(ScanType.BASIC).rules(List.of()));
}
}
}