使用者 IP 位址

Google Cloud Armor 安全性政策規則會根據 IP 位址篩選,通常會使用呼叫端的用戶端 IP。如果服務位於中介層 (例如第三方內容傳遞網路 (CDN)) 後方,origin.ip 欄位中的用戶端 IP 會是最後一個中介層的 IP 位址,而非原始用戶端。

使用者 IP 功能可讓您設定替代欄位 origin.user_ip,從上游供應商填入的標頭解析。接著,您可以在安全性政策規則中使用 origin.user_ip 欄位,指定這些功能使用的 IP 位址。使用 origin.user_ip 時,您可以在安全性政策的 advancedOptionsConfig 欄位中設定 userIpRequestHeaders[] 選項。

使用者 IP 位址的運作方式

您可以設定 Cloud Armor,從特定要求標頭擷取使用者 IP 位址。這個值會填入 origin.user_ip 欄位,您可以在安全性政策規則中使用。

如果 userIpRequestHeaders[] 中指定的標頭不存在,或其值不是有效的 IP 位址,Cloud Armor 會改用用戶端 IP 位址 (origin.ip)。以下範例直接比較預設情況。

origin.ip != origin.user_ip

以下範例說明如何在規則語言、Google Threat Intelligence 和位址群組中使用 origin.user_ip。

inIpRange

inIpRange(origin.user_ip, '9.9.9.0/24')

如要進一步瞭解如何搭配使用 inIpRange 和 origin.user_ip,請參閱「屬性」。

Google Threat Intelligence

evaluateThreatIntelligence('iplist-known-malicious-ips', origin.user_ip)

詳情請參閱「套用 Google Threat Intelligence」。

位址群組

evaluateAddressGroup('example-address-group', origin.user_ip)

詳情請參閱「設定位址群組」。

組織範圍的位址群組

evaluateOrganizationAddressGroup('example-org-address-group', origin.user_ip)

詳情請參閱「使用組織範圍的位址群組」。

最佳做法

由於 origin.user_ip 是從要求標頭解析,不受信任的用戶端可以操控,因此您必須驗證流量是否來自受信任的上游來源。

如要驗證上游來源,請建立至少包含兩項規則的安全性政策。第一項規則的優先順序較高,會檢查直接用戶端 IP (origin.ip) 是否屬於信任的上游供應商。第二項規則的優先順序較低,會使用 origin.user_ip 欄位套用預期邏輯。

舉例來說,您可以建立包含下列兩項規則的政策:

  • 規則 1:evaluateThreatIntelligence('iplist-public-clouds', origin.ip)
  • 規則 2:inIpRange(origin.user_ip, '9.9.9.0/24')

後續步驟