当您通过https://console.cloud.google.com登录到GCP上的项目时,您可以在选定的虚拟机上显示“网络接口详细信息”。有“网络分析”部分和“入口分析”和“出口分析”的酷表。“入口分析”根据防火墙规则和网络标记为VM NIC计算源IP和目标端口字段。是否可以通过API为每个虚拟机(或NIC)获取这些“分析”表?
目标:编写一个简单的脚本来检查/审计组织内部所有项目中的防火墙。
发布于 2019-12-11 20:02:16
在GCP监控API中没有防火墙规则的直接指标,但是Google Cloud指标中有一些子部分,您可能会对此特别感兴趣。这些小节中的一些单独指标类型是您所引用的数据可用于分析的方式。
计算指标:
https://cloud.google.com/monitoring/api/metrics_gcp#gcp-compute
Networking指标:
https://cloud.google.com/monitoring/api/metrics_gcp#gcp-networking
路由器指标:
https://cloud.google.com/monitoring/api/metrics_gcp#gcp-router
VPC指标:
https://cloud.google.com/monitoring/api/metrics_gcp#gcp-vpc%20access
和虚拟专用网指标:
https://cloud.google.com/monitoring/api/metrics_gcp#gcp-vpn
还有其他一些因素会影响网络指标,如Interconnect和Load Balancing
防火墙审计替代方案
您始终可以通过Cloud SDK检查防火墙规则
要以表格形式列出项目中的所有防火墙规则,请运行:
gcloud beta compute firewall-rules list
要列出项目中所有防火墙规则的URI,请运行:
gcloud beta compute firewall-rules list --uri
要列出项目中所有防火墙规则的所有字段,请运行:
gcloud beta compute firewall-rules list --format="table(
name,
network,
direction,
priority,
sourceRanges.list():label=SRC_RANGES,
destinationRanges.list():label=DEST_RANGES,
allowed[].map().firewall_rule().list():label=ALLOW,
denied[].map().firewall_rule().list():label=DENY,
sourceTags.list():label=SRC_TAGS,
sourceServiceAccounts.list():label=SRC_SVC_ACCT,
targetTags.list():label=TARGET_TAGS,
targetServiceAccounts.list():label=TARGET_SVC_ACCT,
disabled
)"
https://stackoverflow.com/questions/59292614
复制相似问题