AWS VPC Networking Security Audit
Cloud resource audit for AWS Virtual Private Cloud (VPC) architecture,
security posture, and connectivity. This skill evaluates provider-specific
AWS networking constructs — VPC design, Security Groups, NACLs, Transit
Gateway topologies, VPC Flow Logs, Route Tables, and ENI placement — not
generic cloud networking advice.
Scope covers VPC-layer networking: CIDR planning, subnet tier layout,
security filtering, inter-VPC connectivity, and traffic observability.
Out of scope: CloudFront distributions, WAF rules, application-layer
load balancing (ALB content routing), and DNS (Route 53) configuration.
Reference references/cli-reference.md for read-only AWS CLI commands
organized by audit step, and references/vpc-architecture.md for the
VPC packet flow model, Security Group vs NACL evaluation order, and
Transit Gateway routing architecture.
When to Use
- - VPC architecture design review — validating CIDR allocation, subnet tier layout, and AZ distribution before or after deployment
- Post-migration networking audit — verifying VPC connectivity, Security Group rules, and Route Table entries after workload migration
- Security assessment — identifying overly permissive Security Group rules, default NACL exposure, and missing VPC Flow Log coverage
- Connectivity troubleshooting — diagnosing Transit Gateway route propagation failures, VPC peering asymmetric routing, or black-hole routes
- Compliance preparation — documenting VPC segmentation, Security Group justification, and Flow Log retention for auditors
- Cost optimization review — identifying unused Elastic Network Interfaces (ENIs), unattached Elastic IPs (EIPs), and cross-AZ traffic patterns
Prerequisites
- - AWS CLI v2 configured with valid credentials (
aws sts get-caller-identity succeeds) - IAM permissions — minimum read-only policy covering:
ec2:DescribeVpcs, ec2:DescribeSubnets, ec2:DescribeSecurityGroups, ec2:DescribeNetworkAcls, ec2:DescribeTransitGateways, ec2:DescribeTransitGatewayRouteTables, ec2:DescribeRouteTables, ec2:DescribeFlowLogs, ec2:DescribeNetworkInterfaces, ec2:DescribeVpcPeeringConnections, ec2:DescribeVpcEndpoints, ec2:DescribeAddresses, logs:FilterLogEvents, INLINECODE16 - Target scope identified — specific VPC ID(s), AWS account, and region. Multi-account audits require cross-account IAM roles or AWS Organizations access
- VPC Flow Logs enabled — Step 4 requires active Flow Logs publishing to CloudWatch Logs or S3. If Flow Logs are not enabled, document this as a Critical finding
Procedure
Follow these six steps sequentially. Each step builds on prior findings,
moving from inventory through security analysis to optimization.
Step 1: VPC Inventory and Design Assessment
Enumerate all VPCs in the target region and assess architectural design.
CODEBLOCK0
For each VPC, evaluate:
- - CIDR block allocation: Primary and secondary CIDR blocks. Check for RFC 1918 compliance, overlapping CIDRs across VPCs (blocks peering), and sufficient address space for growth. VPCs support up to 5 CIDR blocks.
- Subnet tier layout: Identify public subnets (Route Table routes to Internet Gateway), private subnets (Route Table routes to NAT Gateway), and isolated subnets (no internet route). Verify each tier exists and workloads are placed in the correct tier.
- Availability Zone distribution: Subnets should span at least 2 AZs for resilience. Single-AZ VPC designs are a High finding.
- DNS settings: Verify
enableDnsSupport and enableDnsHostnames are enabled — required for VPC endpoints and private DNS resolution. - Tenancy: Default vs dedicated. Dedicated tenancy has significant cost implications; verify it is intentional.
Step 2: Security Group and NACL Analysis
Audit stateful Security Group rules and stateless NACL rules for overly permissive access.
Security Group analysis:
CODEBLOCK1
For each Security Group, evaluate inbound and outbound rules:
- - 0.0.0.0/0 inbound rules: Any Security Group rule permitting inbound from
0.0.0.0/0 (or ::/0) is a finding. Severity depends on port: SSH/RDP from 0.0.0.0/0 is Critical; HTTPS from 0.0.0.0/0 on a public ALB may be acceptable. - SG-to-ENI mapping on public subnets: Cross-reference Security Groups with ENIs on public subnets. An overly permissive Security Group attached to an ENI in a public subnet with a public IP is higher risk than the same Security Group on a private subnet.
- Default Security Group: The VPC default Security Group allows all inbound from itself and all outbound. If any ENI uses the default Security Group, flag as Medium — workloads should use purpose-specific Security Groups.
- Unused Security Groups: Security Groups with no associated ENIs are cleanup candidates.
NACL analysis:
CODEBLOCK2
NACLs are stateless — evaluate both inbound and outbound rule sets:
- - Rule ordering: NACLs evaluate rules by rule number (lowest first). A broad permit at rule 100 cannot be overridden by a deny at rule 200. Verify deny rules are numbered lower than corresponding permits.
- Default NACL: Allows all inbound and outbound traffic. Subnets using the default NACL have no network-layer filtering beyond Security Groups. Flag as Medium if used on production subnets.
- Ephemeral port range: Outbound NACLs must permit ephemeral ports (1024–65535) for return traffic. Missing ephemeral port rules break TCP connections.
Step 3: Transit Gateway and Connectivity Assessment
Evaluate inter-VPC and hybrid connectivity through Transit Gateway (TGW), VPC Peering, and VPC Endpoints.
Transit Gateway:
CODEBLOCK3
- - TGW route table associations: Each VPC attachment should be associated with the correct TGW Route Table. Misassociations cause traffic to route to wrong VPCs.
- Route propagation: Verify propagation is enabled for VPC attachments that need dynamic routing. Disabled propagation requires manual static routes — check for stale entries.
- TGW peering: For multi-region Transit Gateway peering, verify routes are propagated across regions and CIDR blocks don't overlap.
VPC Peering:
CODEBLOCK4
- - Route validation: VPC peering is non-transitive. Verify Route Tables in both VPCs contain routes pointing to the peering connection for the peer CIDR. Missing routes cause silent packet drops.
- DNS resolution: Check
AllowDnsResolutionFromRemoteVpc for cross-VPC private DNS.
VPC Endpoints:
CODEBLOCK5
- - Gateway endpoints: S3 and DynamoDB. Verify Route Table entries exist for gateway endpoint prefix lists.
- Interface endpoints (PrivateLink): Verify ENI placement in appropriate subnets and Security Group rules permit traffic from workloads.
Step 4: VPC Flow Log Analysis
Analyze VPC Flow Logs for security events and traffic patterns.
CODEBLOCK6
Verify Flow Logs are enabled at the VPC level (not just subnet or ENI level) with REJECT and ACCEPT capture. If Flow Logs are not enabled, document as Critical and recommend enabling before further analysis.
For active Flow Logs, query CloudWatch Logs:
CODEBLOCK7
Analyze patterns:
- - Reject patterns: High-volume REJECTs from external IPs suggest scanning or attack traffic. REJECTs between internal subnets indicate Security Group or NACL misconfigurations.
- Cross-AZ traffic volume: Flow Logs show source/destination AZ. Significant cross-AZ traffic incurs data transfer costs — identify top cross-AZ flows.
- Top talkers: Aggregate by source/destination ENI to find highest-volume flows. Unexpected top talkers may indicate compromised instances or data exfiltration.
- SG deny correlation: Flow Log REJECTs from specific ENIs should correlate with Security Group rules. If an ENI shows REJECTs for traffic that its Security Group should permit, investigate NACL interference.
Step 5: Route Table Validation
Audit Route Tables for correctness, efficiency, and security.
CODEBLOCK8
For each Route Table, evaluate:
- - Main vs custom Route Tables: The VPC main Route Table is the default for subnets without explicit association. Verify the main Route Table has restrictive routes — an overly permissive main Route Table affects all unassociated subnets.
- Most-specific route precedence: AWS Route Tables use longest prefix match. Verify that more-specific routes take precedence as intended and don't create unintended traffic paths.
- Black-hole routes: Routes with status "blackhole" indicate the target (NAT Gateway, VPC peering, TGW attachment) was deleted. Black-hole routes silently drop traffic. Remove or replace.
- NAT Gateway routing: Private subnets should route
0.0.0.0/0 to a NAT Gateway for outbound internet access. Verify NAT Gateway is in a public subnet with an EIP. Multi-AZ deployments should have one NAT Gateway per AZ to avoid cross-AZ traffic and single-AZ failure. - VPC endpoint routes: Gateway endpoint routes (S3, DynamoDB prefix lists) should exist in Route Tables for subnets that access those services.
Step 6: Report and Optimization
Compile findings and identify resource optimization opportunities.
Unused resource cleanup:
CODEBLOCK9
- - Unused ENIs: ENIs in "available" status are not attached to instances. Identify orphaned ENIs from terminated instances or failed deployments.
- Unattached EIPs: Elastic IPs not associated with an ENI incur hourly charges. Release or associate.
- NAT Gateway optimization: Consolidate NAT Gateways if traffic volume doesn't justify per-AZ deployment, or deploy per-AZ if cross-AZ data transfer costs exceed NAT Gateway costs.
Compile the findings report using the Report Template section.
Threshold Tables
Security Group Rule Severity
| Finding | Severity | Rationale |
|---|
| SG allows SSH (22) from 0.0.0.0/0 | Critical | Direct shell access from internet |
| SG allows RDP (3389) from 0.0.0.0/0 |
Critical | Remote desktop open to internet |
| SG allows all ports from 0.0.0.0/0 | Critical | No port restriction on internet access |
| ENI on public subnet using default SG | High | Default SG permits all inbound from group members |
| SG with >50 inbound rules | High | Excessive complexity; likely over-permissive |
| SG allows database ports from non-app subnets | High | Database access not restricted to application tier |
| SG with no description on rules | Medium | Limits auditability and rule justification |
| SG with 0 associated ENIs | Medium | Unused — cleanup candidate |
VPC Flow Log Reject Rate
| Reject Rate (per minute) | Severity | Action |
|---|
| >1000 external-source REJECTs | High | Active scanning or DDoS — review source IPs |
| >100 internal-to-internal REJECTs |
High | Misconfigured SG or NACL — investigate rules |
| 10–100 external REJECTs | Medium | Background noise — monitor trend |
| <10 external REJECTs | Low | Normal background scanning |
Subnet Utilization
| Available IPs (% of CIDR) | Severity | Action |
|---|
| <10% remaining | High | Subnet exhaustion risk — plan CIDR expansion |
| 10–25% remaining |
Medium | Monitor growth — plan expansion proactively |
| >75% unused | Low | Over-provisioned — consider smaller CIDR next time |
Decision Trees
Is This Security Group Rule Overly Permissive?
CODEBLOCK10
Is This VPC Design Following AWS Best Practices?
CODEBLOCK11
Report Template
CODEBLOCK12
Troubleshooting
VPC Flow Logs Not Enabled
If aws ec2 describe-flow-logs returns empty for the target VPC, Flow Logs
are not configured. Document as a Critical finding — no traffic visibility.
Flow Logs require an IAM role with logs:CreateLogGroup, logs:CreateLogStream,
logs:PutLogEvents permissions. Enabling Flow Logs is a non-disruptive operation.
Security Group Not Attached to Expected ENI
Use aws ec2 describe-network-interfaces --filters "Name=group-id,Values=<sg-id>"
to find all ENIs associated with a Security Group. If the expected ENI is missing,
check whether the instance was replaced (Auto Scaling) or the SG was modified.
Transit Gateway Route Propagation Disabled
If TGW routes are missing, verify propagation is enabled on the TGW Route Table
for the relevant VPC attachment. Use aws ec2 get-transit-gateway-route-table-propagations
to check. Disabled propagation requires manual static route entries.
Black-Hole Routes in Route Tables
Routes with status "blackhole" occur when the target resource (NAT Gateway,
VPC Peering Connection, TGW Attachment) is deleted but the route entry remains.
Identify affected subnets and either remove the route or create a replacement target.
Cross-Account VPC Audit
For multi-account environments using AWS Organizations, use aws sts assume-role
to obtain temporary credentials for each account. Alternatively, use AWS Config
aggregator or AWS RAM (Resource Access Manager) shared resources for centralized visibility.
AWS VPC 网络安全审计
针对 AWS 虚拟私有云(VPC)架构、安全态势和连接性的云资源审计。该技能评估特定于 AWS 的网络结构——VPC 设计、安全组、NACL、中转网关拓扑、VPC 流日志、路由表和弹性网络接口(ENI)放置——而非通用云网络建议。
范围涵盖 VPC 层网络:CIDR 规划、子网层级布局、安全过滤、VPC 间连接性和流量可观测性。不涉及:CloudFront 分发、WAF 规则、应用层负载均衡(ALB 内容路由)和 DNS(Route 53)配置。请参考 references/cli-reference.md 获取按审计步骤组织的只读 AWS CLI 命令,以及 references/vpc-architecture.md 了解 VPC 数据包流模型、安全组与 NACL 评估顺序以及中转网关路由架构。
使用场景
- - VPC 架构设计审查 — 在部署前后验证 CIDR 分配、子网层级布局和可用区分布
- 迁移后网络审计 — 在工作负载迁移后验证 VPC 连接性、安全组规则和路由表条目
- 安全评估 — 识别过于宽松的安全组规则、默认 NACL 暴露和缺失的 VPC 流日志覆盖
- 连接性故障排除 — 诊断中转网关路由传播失败、VPC 对等连接非对称路由或黑洞路由
- 合规准备 — 为审计人员记录 VPC 分段、安全组理由和流日志保留策略
- 成本优化审查 — 识别未使用的弹性网络接口(ENI)、未关联的弹性 IP(EIP)和跨可用区流量模式
前提条件
- - AWS CLI v2 配置了有效凭证(aws sts get-caller-identity 执行成功)
- IAM 权限 — 最低只读策略涵盖:ec2:DescribeVpcs、ec2:DescribeSubnets、ec2:DescribeSecurityGroups、ec2:DescribeNetworkAcls、ec2:DescribeTransitGateways、ec2:DescribeTransitGatewayRouteTables、ec2:DescribeRouteTables、ec2:DescribeFlowLogs、ec2:DescribeNetworkInterfaces、ec2:DescribeVpcPeeringConnections、ec2:DescribeVpcEndpoints、ec2:DescribeAddresses、logs:FilterLogEvents、logs:DescribeLogGroups
- 确定目标范围 — 特定的 VPC ID、AWS 账户和区域。多账户审计需要跨账户 IAM 角色或 AWS Organizations 访问权限
- 启用 VPC 流日志 — 步骤 4 需要将活跃的流日志发布到 CloudWatch Logs 或 S3。如果未启用流日志,请将其记录为严重发现
操作步骤
按顺序执行以下六个步骤。每个步骤基于之前的发现,从清单盘点逐步推进到安全分析和优化。
步骤 1:VPC 清单和设计评估
枚举目标区域中的所有 VPC 并评估架构设计。
aws ec2 describe-vpcs --region --output table
aws ec2 describe-subnets --filters Name=vpc-id,Values= --output table
针对每个 VPC,评估:
- - CIDR 块分配: 主 CIDR 块和辅助 CIDR 块。检查是否符合 RFC 1918 标准、VPC 间是否存在 CIDR 重叠(阻碍对等连接)以及是否有足够的地址空间用于增长。VPC 最多支持 5 个 CIDR 块。
- 子网层级布局: 识别公有子网(路由表路由到互联网网关)、私有子网(路由表路由到 NAT 网关)和隔离子网(无互联网路由)。验证每个层级是否存在,以及工作负载是否放置在正确的层级中。
- 可用区分布: 子网应至少跨越 2 个可用区以实现弹性。单可用区 VPC 设计属于高严重性发现。
- DNS 设置: 验证 enableDnsSupport 和 enableDnsHostnames 已启用——VPC 端点和私有 DNS 解析需要此设置。
- 租期: 默认与专用。专用租期有显著的成本影响;验证其是否为有意设置。
步骤 2:安全组和 NACL 分析
审计有状态安全组规则和无状态 NACL 规则是否存在过于宽松的访问权限。
安全组分析:
aws ec2 describe-security-groups --filters Name=vpc-id,Values=
针对每个安全组,评估入站和出站规则:
- - 0.0.0.0/0 入站规则: 任何允许从 0.0.0.0/0(或 ::/0)入站的安全组规则均为发现项。严重性取决于端口:来自 0.0.0.0/0 的 SSH/RDP 为严重;来自 0.0.0.0/0 的 HTTPS(在公有 ALB 上)可能可接受。
- 公有子网上的安全组到 ENI 映射: 交叉引用安全组与公有子网上的 ENI。附加到公有子网中具有公有 IP 的 ENI 上的过于宽松的安全组,比同一安全组在私有子网上风险更高。
- 默认安全组: VPC 默认安全组允许来自自身的所有入站流量和所有出站流量。如果任何 ENI 使用默认安全组,标记为中严重性——工作负载应使用特定用途的安全组。
- 未使用的安全组: 没有关联 ENI 的安全组是清理候选对象。
NACL 分析:
aws ec2 describe-network-acls --filters Name=vpc-id,Values=
NACL 是无状态的——评估入站和出站规则集:
- - 规则排序: NACL 按规则编号评估规则(编号最小的优先)。规则 100 的宽泛允许无法被规则 200 的拒绝覆盖。验证拒绝规则的编号低于相应的允许规则。
- 默认 NACL: 允许所有入站和出站流量。使用默认 NACL 的子网除了安全组外没有网络层过滤。如果在生产子网上使用,标记为中严重性。
- 临时端口范围: 出站 NACL 必须允许临时端口(1024–65535)用于返回流量。缺少临时端口规则会中断 TCP 连接。
步骤 3:中转网关和连接性评估
通过中转网关(TGW)、VPC 对等连接和 VPC 端点评估 VPC 间和混合连接性。
中转网关:
aws ec2 describe-transit-gateways
aws ec2 describe-transit-gateway-route-tables --transit-gateway-id
aws ec2 search-transit-gateway-routes --transit-gateway-route-table-id --filters Name=state,Values=active
- - TGW 路由表关联: 每个 VPC 附件应关联到正确的 TGW 路由表。错误关联会导致流量路由到错误的 VPC。
- 路由传播: 验证需要动态路由的 VPC 附件已启用传播。禁用传播需要手动静态路由——检查是否有过时条目。
- TGW 对等连接: 对于多区域中转网关对等连接,验证路由是否跨区域传播,以及 CIDR 块是否不重叠。
VPC 对等连接:
aws ec2 describe-vpc-peering-connections --filters Name=status-code,Values=active
- - 路由验证: VPC 对等连接是非传递性的。验证两个 VPC 中的路由表是否包含指向对等连接的对等 CIDR 路由。缺少路由会导致数据包静默丢弃。
- DNS 解析: 检查 AllowDnsResolutionFromRemoteVpc 以支持跨 VPC 私有 DNS。
VPC 端点:
aws ec2 describe-vpc-endpoints --filters Name=vpc-id,Values=
- - 网关端点: S3 和 DynamoDB。验证路由表中是否存在网关端点前缀列表的路由条目。
- 接口端点(PrivateLink): 验证 ENI 放置在适当的子网中,并且安全组规则允许来自工作负载的流量。
步骤 4:VPC 流日志分析
分析 VPC 流日志以发现安全事件和流量模式。
aws ec2 describe-flow-logs --filter Name=resource-id,Values=
验证是否在 VPC 级别(而不仅仅是子网或 ENI 级别)启用了流日志,并捕获 REJECT 和 ACCEPT 流量。如果未启用流日志,记录为严重发现,并建议在进一步分析前启用。
对于活跃的流日志,查询 CloudWatch Logs:
aws