mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(ec2): reject prefix list names AWS reserves for its own lists (#2274)
* fix(ec2): reject prefix list names AWS reserves for its own lists CreateManagedPrefixList accepted names beginning com.amazonaws., com.amazon. or com.aws., which AWS refuses with InvalidParameterValue, so a customer list could shadow a seeded gateway-endpoint one. The trailing dot is part of each prefix. Checked against a live account: com.amazonaws-probe and comamazonaws.probe are both accepted there, so matching without the dot would refuse names AWS allows. Closes #2273 * fix(ec2): apply the reserved-name rule to a prefix list rename too ModifyManagedPrefixList persisted any nonblank name, so a list could be renamed to com.amazonaws.us-east-1.s3 and returned alongside the seeded AWS-managed list of that name. AWS applies the same rule to a rename, verified against a live account, and leaves the existing name in place when it rejects one. Create and rename now share the check. --------- Co-authored-by: Michal Schreiber <michal.schreiber@benefitsystems.pl>
This commit is contained in:
1 parent
62ff490619
commit
2d003b52f2
3 files changed
+69
No files matched your search
@@ -286,6 +286,11 @@ Two AWS-managed prefix lists exist in every region without being created —
|
||||
read-only, and served by both `DescribePrefixLists` and `DescribeManagedPrefixLists`;
|
||||
modifying or deleting one returns `UnsupportedOperation`.
|
||||
|
||||
A customer-managed list may not take a name AWS reserves for its own: `com.amazonaws.`,
|
||||
`com.amazon.` or `com.aws.`, each including the trailing dot. `CreateManagedPrefixList`
|
||||
rejects those with `InvalidParameterValue`; a name that merely resembles one, such as
|
||||
`com.amazonaws-internal`, is allowed.
|
||||
|
||||
Entries are versioned. A prefix list starts at version 1, and each `ModifyManagedPrefixList`
|
||||
that adds or removes entries stores a new version and bumps the counter, so
|
||||
`GetManagedPrefixListEntries` can serve an earlier `TargetVersion`. Renaming the list or
|
||||
|
||||
@@ -562,6 +562,23 @@ public class Ec2Service implements ContainerTeardown {
|
||||
// Managed prefix lists
|
||||
// =========================================================================
|
||||
|
||||
/**
|
||||
* Name prefixes AWS reserves for its own gateway-endpoint lists. The trailing dot is part of
|
||||
* each: {@code com.amazonaws-probe} is accepted on AWS, so matching without it over-rejects.
|
||||
*/
|
||||
private static final List<String> RESERVED_PREFIX_LIST_NAME_PREFIXES =
|
||||
List.of("com.amazonaws.", "com.amazon.", "com.aws.");
|
||||
|
||||
/** AWS applies the reserved-name rule to a rename as well as a create. */
|
||||
private void requireUnreservedPrefixListName(String prefixListName) {
|
||||
for (String reserved : RESERVED_PREFIX_LIST_NAME_PREFIXES) {
|
||||
if (prefixListName.startsWith(reserved)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"The prefix list name cannot begin with (com.amazonaws., com.amazon., com.aws.).", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<ManagedPrefixList> awsManagedPrefixLists(String region) {
|
||||
return List.of(
|
||||
awsManagedPrefixList(region, "pl-63a5400a", "com.amazonaws." + region + ".s3",
|
||||
@@ -595,6 +612,7 @@ public class Ec2Service implements ContainerTeardown {
|
||||
if (prefixListName == null || prefixListName.isBlank()) {
|
||||
throw new AwsException("MissingParameter", "The request must contain the parameter PrefixListName.", 400);
|
||||
}
|
||||
requireUnreservedPrefixListName(prefixListName);
|
||||
if (!"IPv4".equals(addressFamily) && !"IPv6".equals(addressFamily)) {
|
||||
throw new AwsException("InvalidParameterValue",
|
||||
"Invalid value '" + addressFamily + "' for addressFamily. Valid values are IPv4 and IPv6.", 400);
|
||||
@@ -705,6 +723,7 @@ public class Ec2Service implements ContainerTeardown {
|
||||
list.setMaxEntries(maxEntries);
|
||||
}
|
||||
if (prefixListName != null && !prefixListName.isBlank()) {
|
||||
requireUnreservedPrefixListName(prefixListName);
|
||||
list.setPrefixListName(prefixListName);
|
||||
}
|
||||
|
||||
|
||||
@@ -729,6 +729,51 @@ class Ec2ServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verified against a live AWS account: the three dotted prefixes are rejected, and the
|
||||
* trailing dot matters — {@code com.amazonaws-probe} and {@code comamazonaws.probe} are both
|
||||
* accepted there, so a dotless prefix match would refuse names AWS allows.
|
||||
*/
|
||||
@Test
|
||||
void createManagedPrefixListRejectsNamesReservedByAws() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
for (String reserved : new String[] {"com.amazonaws.probe", "com.amazon.probe", "com.aws.probe"}) {
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.createManagedPrefixList(
|
||||
"us-east-1", reserved, "IPv4", 5, List.of(), List.of()), "expected rejection for " + reserved);
|
||||
assertEquals("InvalidParameterValue", error.getErrorCode());
|
||||
}
|
||||
|
||||
// Names that only look reserved are still allowed.
|
||||
for (String allowed : new String[] {"com.amazonaws-probe", "comamazonaws.probe", "corp"}) {
|
||||
assertEquals(allowed, service.createManagedPrefixList(
|
||||
"us-east-1", allowed, "IPv4", 5, List.of(), List.of()).getPrefixListName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verified against a live AWS account: the rename path applies the same rule, and rejecting it
|
||||
* leaves the existing name in place. A lookalike is still allowed.
|
||||
*/
|
||||
@Test
|
||||
void renamingToAReservedNameIsRejected() {
|
||||
Ec2Service service = prefixListService();
|
||||
ManagedPrefixList list = service.createManagedPrefixList("us-east-1", "corp", "IPv4", 5,
|
||||
List.of(), List.of());
|
||||
|
||||
AwsException error = assertThrows(AwsException.class, () -> service.modifyManagedPrefixList(
|
||||
"us-east-1", list.getPrefixListId(), null, "com.amazonaws.us-east-1.s3", null,
|
||||
List.of(), List.of()));
|
||||
assertEquals("InvalidParameterValue", error.getErrorCode());
|
||||
assertEquals("corp", service.describeManagedPrefixLists("us-east-1",
|
||||
List.of(list.getPrefixListId()), Map.of()).getFirst().getPrefixListName());
|
||||
|
||||
service.modifyManagedPrefixList("us-east-1", list.getPrefixListId(), null,
|
||||
"com.amazonaws-renamed", null, List.of(), List.of());
|
||||
assertEquals("com.amazonaws-renamed", service.describeManagedPrefixLists("us-east-1",
|
||||
List.of(list.getPrefixListId()), Map.of()).getFirst().getPrefixListName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeManagedPrefixListsFiltersByName() {
|
||||
Ec2Service service = prefixListService();
|
||||
|
||||
Reference in new issue
Block a user