網址篩選安全性設定檔是第 7 層政策結構,會使用網址篩選器為防火牆端點定義安全性政策。這些設定檔會評估網路流量中的網域名稱,並根據特定比對字串和優先順序強制執行允許或拒絕動作。
本頁說明如何建立及管理網址篩選安全性設定檔。
事前準備
- 您必須在專案中啟用 Network Security API。
- 如要執行本指南中的
gcloud指令列範例,請安裝 Google Cloud CLI。
角色
如要取得建立、查看、更新或刪除安全設定檔所需的權限,請要求管理員授予您組織的必要 Identity and Access Management (IAM) 角色。如要進一步瞭解如何授予角色,請參閱「管理存取權」。
建立網址篩選安全性設定檔
如要建立 url-filtering 安全性設定檔,請指定名稱 (字串或專屬網址 ID)。
控制台
前往 Google Cloud 控制台的「Security profiles」(安全性設定檔) 頁面。
在專案選擇器選單中,選取要建立安全性設定檔的機構或專案。
選取「安全性設定檔」分頁標籤。
按一下 Create profile。
在「名稱」欄位中輸入名稱。
選用:在「Description」(說明) 欄位輸入說明。
如要建立 Cloud Next Generation Firewall Enterprise 安全性設定檔,請在「用途」部分選取「Cloud NGFW Enterprise」。
如要建立網址篩選安全性設定檔,請在「類型」部分選取「網址篩選」。
在「網址篩選器」部分中,按一下「建立網址篩選器」按鈕。
在「建立網址篩選器」窗格中,指定下列詳細資料:
- 優先順序:指定網址篩選器的優先順序。
- 動作:指定 Cloud NGFW 對流量執行的動作。
- 允許:允許符合網址的連線。
- 拒絕:拒絕與網址相符的連線。
- 網址清單:指定網址清單或比對字串。每行只能有一個網址或比對字串項目,不得有空格或分隔符號。一個項目只能有一個網域。如要進一步瞭解比對字串,請參閱「網址的比對字串」。
點選「建立」。
gcloud
建立含有下列內容的 YAML 檔案:
name: NAME type: url-filtering urlFilteringProfile: urlFilters: - filteringAction: ACTION priority: PRIORITY urls: [URL,URL,...]更改下列內容:
NAME:網址篩選安全設定檔的名稱;您可以將名稱指定為字串或專屬網址 ID。ACTION:指定下列其中一項動作:ALLOW:允許與網址相符的連線DENY:拒絕與網址相符的連線
PRIORITY:網址篩選器的優先順序,範圍從 0 到 2147483647。URLs:以半形逗號分隔的相符字串清單。例如www.example.com和www.examplepetstore.com。
如要建立網址篩選安全性設定檔,請執行
gcloud network-security security-profiles import指令:gcloud network-security security-profiles import NAME \ --source FILE_NAME \ [ --organization ORGANIZATION_ID | --project PROJECT_ID ] \ --location global
或者,您也可以使用
gcloud network-security security-profiles url-filtering create指令,建立不含 YAML 檔案的網址篩選安全設定檔:gcloud network-security security-profiles url-filtering create NAME \ [ --organization ORGANIZATION_ID | --project PROJECT_ID ] \ --description DESCRIPTION \ --location global更改下列內容:
NAME:網址篩選安全性設定檔的名稱。如果名稱不是採用專屬網址 ID 格式,則必須指定機構或專案名稱和位置。
FILE_NAME:YAML 檔案的名稱。例如:url-filtering-sp.yaml。ORGANIZATION_ID:組織 ID。使用這個標記建立機構層級的安全性設定檔。PROJECT_ID:專案 ID。使用這個旗標建立專案層級的安全性設定檔。DESCRIPTION:網址篩選安全設定檔的選用說明。
舉例來說,下列程式碼片段顯示網址篩選安全設定檔範例,允許對
www.example.com和www.examplepetstore.com的要求,但拒絕所有其他網域的要求:urlFilteringProfile: urlFilters: - filteringAction: ALLOW priority: 1000 urls: ['www.example.com', 'www.examplepetstore.com'] # the following URL filter is implicit and will be processed last - filteringAction: DENY priority: 2147483647 urls: ['*']
隱含拒絕網址篩選器
網址篩選安全性設定檔一律會包含預設網址篩選器,其優先順序最低 (2147483647),會拒絕所有不符合較高優先順序網址篩選器的連線。下列程式碼片段顯示隱含拒絕網址篩選器的範例:
urlFilteringProfile:
urlFilters:
# user-specified URL filters
- filteringAction: DENY
priority: 1000
urls: ['www.example.com','www.examplepetstore.com']
- filteringAction: ALLOW
priority: 2000
urls: ['www.example.org','www.example.net']
# implicit deny URL filter that will be processed last
- filteringAction: DENY
priority: 2147483647
urls: ['*']
查看或匯出網址篩選安全設定檔時,您會看到隱含拒絕網址篩選器。您無法修改或移除隱含篩選器。
舉例來說,如要將設定檔的預設動作從 DENY (由隱含篩選器強制執行) 變更為 ALLOW,您必須新增明確篩選器,讓 Cloud NGFW 在隱含篩選器之前處理。
urlFilteringProfile:
urlFilters:
# user-specified filters
- filteringAction: DENY
priority: 1000
urls: ['www.example.com','www.examplepetstore.com']
# explicit allow URL filter that you can add
- filteringAction: ALLOW
priority: 2000
urls: ['*']
# implicit deny URL filter that will be processed last
- filteringAction: DENY
priority: 2147483647
urls: ['*']
網址的比對器字串
比對字串是您在網址篩選器的 urls 欄位中指定的值。您可以在網址篩選器中指定一或多個比對字串。
萬用字元
網址清單中的每個比對字串都支援萬用字元 (*),但使用方式有限制。
- 每個比對字串只能有一個星號 (*),而且必須是第一個或唯一的字元。
星號 (*) 可有下列解讀方式:
在半形句號 (.) 前加上星號 (*),即代表要比對該網域的所有子網域。
舉例來說,比對字串「*.domain.com」與「a.domain.com」和「a.b.c.domain.com」相符,但與「domain.com」不相符。
*.example.coma.example.coma.b.c.example.comexample.comurlFilteringProfile: urlFilters: # user-specified filters - filteringAction: ALLOW priority: 1000 urls: ['*.example.com'] # implicit deny URL filter that will be processed last - filteringAction: DENY priority: 2147483647 urls: ['*']在上述範例中,Cloud NGFW 允許前往
example.com子網域的流量,但拒絕其餘輸出流量。在標籤前加上星號 (*),即代表要比對網域和所有子網域。
舉例來說,比對字串「*domain.com」與「a.domain.com」、「a.b.c.domain.com」和「domain.com」均相符。
*example.coma.example.coma.b.c.example.comexample.comurlFilteringProfile: urlFilters: # user-specified filters - filteringAction: ALLOW priority: 1000 urls: ['*example.com'] # implicit deny URL filter that will be processed last - filteringAction: DENY priority: 2147483647 urls: ['*']在上述範例中,Cloud NGFW 允許前往
example.com和example.com子網域的流量,但拒絕其餘輸出流量。在網域副檔名 (例如
.com) 前加上星號 (*),即代表要比對使用該網域副檔名的所有網域 (和子網域)。舉例來說,比對字串「*.domain.com」與「a.domain.com」和「a.b.c.domain.com」相符,但與「domain.com」不相符。
*.comexample.comexamplepetstore.com下列程式碼片段示範如何允許所有以
.com結尾的網域 (及其子網域),但拒絕其餘流量。urlFilteringProfile: urlFilters: # Allow all domains (and their subdomains) that end in '.com' - filteringAction: ALLOW priority: 2000 urls: ['*.com'] # implicit deny URL filter that will be processed last - filteringAction: DENY priority: 2147483647 urls: ['*']下列程式碼片段示範如何拒絕
example.com和examplepetstore.com的所有子網域,但允許這些網域和所有其他以.com結尾的網域 (及其子網域)。urlFilteringProfile: urlFilters: # Deny all subdomains of example.com - filteringAction: DENY priority: 1000 urls: ['*.example.com'] # Deny all subdomains of examplepetstore.com - filteringAction: DENY priority: 1500 urls: ['*.examplepetstore.com'] # Allow all domains (and their subdomains) that end in '.com' - filteringAction: ALLOW priority: 2000 urls: ['*.com'] # implicit deny URL filter that will be processed last - filteringAction: DENY priority: 2147483647 urls: ['*']Cloud NGFW 不會將星號 (*) 解讀為規則運算式萬用字元。
舉例來說,
*example.test與newexample.test或a.newexample.test不相符。只有example.test及其子網域才符合。example.test如果只有一個星號 (*) 而沒有其他字元,則代表所有要求都符合。
舉例來說,優先順序最低的明確允許網址篩選器中的比對字串只包含星號 (*),且具有會覆寫
DENY預設動作的ALLOW動作。這是因為隱含拒絕網址篩選器會針對不符合較高優先順序網址篩選器的任何要求,強制執行預設DENY。如果 Cloud NGFW 缺少 SNI 或網域資訊,系統會根據優先順序最高的網址篩選器 (明確的
ALLOW或隱含的DENY),判斷是否允許或拒絕連線。如果流量未加密 (HTTP 流量),或是加密訊息標頭的 TLS 檢查功能已停用,就可能發生這種情況。urlFilteringProfile: urlFilters: # user-specified filters - filteringAction: DENY priority: 1000 urls: ['www.example.com','www.examplepetstore.com'] # explicit allow URL filter that you can add - filteringAction: ALLOW priority: 2000 urls: ['*'] # implicit deny URL filter that will be processed last - filteringAction: DENY priority: 2147483647 urls: ['*']
限制
- 比對字串代表網域或子網域。
- 比對字串不支援正斜線字元 (/),例如「
www.example.com/images」。 - 比對字串不支援網址格式或通訊協定名稱,例如:
http://www.example.com。 - 比對字串不支援通訊埠編號,例如:
www.example.com:80。 - 比對字串僅支援 ASCII 字母、數字和特殊字元:連字號 (-)、半形句號 (.) 和星號 (*)。
如果網域名稱包含 ASCII 字母、數字、連字號 (-)、半形句號 (.) 或星號 (*) 以外的字元,請使用 Punycode 轉換。Punycode 是一種編碼標準,可將 Unicode 網域名稱轉換為 ASCII 相容格式。
如有兩個以上的標籤,請使用半形句號 (.) 分隔。標籤可以包含一或多個連字號 (-),但不能位於開頭或結尾。每個標籤的長度上限為 63 個字元。
網址篩選器不支援在網域名稱開頭使用半形句號,也不支援在比對字串中使用連續半形句號。網址篩選器允許結尾有半形句號,不過 Cloud NGFW 會在儲存網址篩選器之前,先將這類句號移除。
Cloud NGFW 會先將比對字串轉換為小寫,再儲存網址篩選器。Cloud NGFW 不會執行任何其他正規化。
每個網域名稱的長度上限為 255 個字元。
多層子網域的網址篩選條件
您可以搭配使用不同優先順序和動作的網址篩選器,控管多層子網域的網路流量。您也可以在比對字串中使用萬用字元 (*) 指定網域和子網域。
舉例來說,假設您實作下列行為:
- 允許「
a.b.c.example.com」 - 拒絕「
*.b.c.example.com」(拒絕b.c.example.com的所有其他子網域) - 允許
*.c.example.com(允許c.example.com的所有其他子網域) - 拒絕「
*.example.com」(拒絕example.com的所有其他子網域) - 允許「
example.com」 - 允許其他所有項目
下列程式碼片段會實作這個情境:
urlFilteringProfile:
urlFilters:
# Allow 'a.b.c.example.com'
- filteringAction: ALLOW
priority: 1000
urls: ['a.b.c.example.com']
# Deny all subdomains of 'b.c.example.com'
- filteringAction: DENY
priority: 2000
urls: ['*.b.c.example.com']
# Allow all subdomains of 'c.example.com'
- filteringAction: ALLOW
priority: 3000
urls: ['*.c.example.com']
# Deny all subdomains of 'example.com'
- filteringAction: DENY
priority: 4000
urls: ['*.example.com']
# explicit allow URL filter
- filteringAction: ALLOW
priority: 5000
urls: ['*']
# implicit deny URL filter that will be processed last
- filteringAction: DENY
priority: 2147483647
urls: ['*']
列出並查看網址篩選安全性設定檔的詳細資料
您可以列出在機構或專案中建立的網址過濾安全性設定檔。您也可以查看設定檔詳細資料,例如類型、用途和說明。
控制台
前往 Google Cloud 控制台的「Security profiles」(安全性設定檔) 頁面。
選取「安全性設定檔」分頁標籤,即可查看已設定的安全性設定檔清單。
如要篩選網址過濾安全性設定檔,請在「Filter」(篩選器) 欄位中,將「Profile type」(設定檔類型) 指定為「URL filtering」(網址過濾) 。
這個分頁會列出網址過濾安全性設定檔。
如要查看設定檔詳細資料,請按一下「網址篩選」安全性設定檔。
gcloud
如要列出所有網址篩選安全性設定檔,請使用 gcloud network-security security-profiles url-filtering list 指令:
gcloud network-security security-profiles url-filtering list \
[ --organization ORGANIZATION_ID | --project PROJECT_ID ] \
[--billing-project QUOTA_PROJECT_ID]
--location global
如要查看網址篩選安全性設定檔的詳細資料,請執行 gcloud network-security security-profiles url-filtering describe 指令:
gcloud network-security security-profiles url-filtering describe NAME \
[ --organization ORGANIZATION_ID | --project PROJECT_ID ] \
[--billing-project QUOTA_PROJECT_ID]
--location global
更改下列內容:
NAME:安全設定檔的名稱。如果名稱不是採用專屬網址 ID 格式,則必須指定機構或專案名稱和位置。
ORGANIZATION_ID:安全設定檔所在的機構 ID。PROJECT_ID:安全設定檔所在的專案 ID。QUOTA_PROJECT_ID:配額專案 ID。 這個旗標僅適用於機構層級的安全設定檔。
刪除網址篩選安全性設定檔
您可以指定網址篩選安全設定檔的名稱、位置和機構/專案,藉此刪除設定檔。如果安全性設定檔遭安全性設定檔群組參照,就無法刪除。
如要刪除網址篩選安全性設定檔,請使用 Google Cloud 控制台或 gcloud CLI。不過,如果安全性設定檔群組參照了安全性設定檔,就無法刪除該安全性設定檔。
控制台
前往 Google Cloud 控制台的「Security profiles」(安全性設定檔) 頁面。
選取「安全性設定檔」分頁標籤。這個分頁會顯示已設定的安全性設定檔清單。
選取要刪除的安全設定檔,然後按一下「刪除」。
再按一下 [刪除] 加以確認。
gcloud
如要刪除網址篩選安全性設定檔,請使用 gcloud network-security security-profiles url-filtering delete 指令:
gcloud network-security security-profiles url-filtering delete NAME \
[ --organization ORGANIZATION_ID | --project PROJECT_ID ] \
--location global
更改下列內容:
NAME:安全設定檔的名稱。如果沒有以專屬網址 ID 格式指定名稱,則必須指定機構或專案名稱,以及位置。
ORGANIZATION_ID:組織 ID。這個旗標適用於機構層級的安全設定檔。PROJECT_ID:專案 ID。請使用這個旗標,為專案層級安全設定檔設定。QUOTA_PROJECT_ID:配額專案 ID。 這個旗標僅適用於機構層級的安全設定檔。
匯入網址篩選安全性設定檔
您可以從 YAML 檔案匯入網址過濾安全性設定檔 (自訂建立或先前匯出)。匯入網址篩選安全性設定檔時,如果已有同名的設定檔,Cloud NGFW 會更新現有設定檔。
如要從 YAML 檔案匯入網址篩選安全性設定檔,請使用 gcloud CLI。如果匯入設定檔時,已有同名設定檔,Cloud NGFW 會更新該設定檔。
gcloud
如要從 YAML 檔案匯入網址篩選安全性設定檔,請使用 gcloud network-security security-profiles import 指令:
gcloud network-security security-profiles import NAME \
[ --organization ORGANIZATION_ID | --project PROJECT_ID ] \
--location global \
--source FILE_NAME
更改下列內容:
NAME:要匯入的url-filtering類型安全設定檔名稱。您可以將名稱指定為字串或專屬網址 ID。ORGANIZATION_ID:組織 ID。這個旗標適用於機構層級的安全設定檔。PROJECT_ID:專案 ID。使用這個旗標 設定專案層級的安全設定檔。FILE_NAME:包含設定匯出資料的 YAML 檔案路徑。
匯出網址篩選安全性設定檔
您可以將網址篩選安全設定檔匯出為 YAML 檔案。舉例來說,您可以使用這項功能匯出安全性設定檔、快速修改,然後匯回,不必透過使用者介面修改大型安全性設定檔。
如要將網址篩選安全性設定檔匯出至 YAML 檔案,請使用 gcloud CLI。
gcloud
如要將網址篩選安全性設定檔匯出至 YAML 檔案,請使用 gcloud network-security security-profiles export 指令:
gcloud network-security security-profiles export NAME \
[ --organization ORGANIZATION_ID | --project PROJECT_ID ] \
--location global \
--destination FILE_NAME
更改下列內容:
NAME:要匯出的url-filtering類型安全設定檔名稱,您可以將名稱指定為字串或專屬網址 ID。ORGANIZATION_ID:組織 ID。這個標記適用於機構層級的安全設定檔。PROJECT_ID:專案 ID。使用這個標記設定專案層級的安全設定檔。FILE_NAME:Cloud NGFW 將設定匯出的 YAML 檔案路徑。