mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -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
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user