Skip to content

Conversation

@almightychang
Copy link

Summary

  • Fix is_subnet_public() to correctly identify public subnets that use the VPC's main route table
  • When a subnet has no explicit route table association, find the main route table instead of using route_tables[0]
  • Add explicit error handling when main route table cannot be found

Root Cause

When a subnet has no explicit route table association, it implicitly uses the VPC's main route table. The previous implementation fetched all VPC route tables but only checked route_tables[0], which may not be the main route table. This caused public subnets (using main route table with IGW) to be incorrectly identified as private.

Changes

cli/src/pcluster/aws/ec2.py

  • Find main route table by checking Associations[].Main flag
  • Raise explicit exception if main route table not found

cli/tests/pcluster/aws/test_ec2.py

  • Add helper functions for mocking route table responses
  • Add test for subnet using main route table with IGW (public)
  • Add test for subnet using main route table without IGW (private)

Test plan

  • Existing test_is_subnet_public passes
  • New test_is_subnet_public_with_main_route_table passes
  • New test_is_subnet_public_main_route_table_no_igw passes

Fixes #7173

…t explicit association

When a subnet has no explicit route table association, it uses the VPC's
main route table. The previous implementation incorrectly used route_tables[0]
which may not be the main route table, causing public subnets to be
incorrectly identified as private.

This fix explicitly finds the main route table by checking the "Main" flag
in route table associations. If no main route table is found (which should
not happen in a valid VPC), an exception is raised with a helpful message.

Fixes aws#7173
@almightychang almightychang requested review from a team as code owners December 23, 2025 06:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] LoginNodes NLB scheme incorrectly set to internal on public subnet

1 participant