本文說明如何使用 Google Cloud 控制台和 Google Cloud CLI,建立、查看、列出、修改及刪除網址篩選安全性設定檔。
網址篩選安全性設定檔是第 7 層政策結構,可評估網路流量中的網域名稱,強制執行允許或拒絕動作。使用網址篩選安全性設定檔,有助於縮小攻擊面並控管外送流量。如要進一步瞭解這些概念,請參閱「網址篩選安全性設定檔」。
本文適用對象為設定及強制執行第 7 層網路安全政策的網路管理員和資安工程師。
事前準備
- 您必須在專案中啟用 網路安全 API。
- 如要執行本指南中的
gcloud指令列範例,請安裝 Google Cloud CLI。
角色
如要取得建立、查看、更新或刪除安全防護設定檔所需的權限,請要求管理員授予您組織必要的 Identity and Access Management (IAM) 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
如要查看本頁所列作業的進度,請確認您的使用者帳戶具備 Compute 網路使用者角色 (roles/compute.networkUser) 權限:
networksecurity.operations.getnetworksecurity.operations.list
建立網址篩選安全性設定檔
如要建立 url-filtering 安全性設定檔,請以字串或專屬網址 ID 的形式指定名稱。
控制台
前往 Google Cloud 控制台的「Security profiles」(安全設定檔) 頁面。
在專案選取器選單中,選取要建立安全性設定檔的組織或專案。
選取「安全性設定檔」分頁標籤。
按一下 Create profile。
在「名稱」欄位中輸入名稱。
選用:在「Description」(說明) 欄位輸入說明。
如要建立 Cloud Next Generation Firewall Enterprise 安全性設定檔,請在「Purpose」(用途) 專區選取「Cloud NGFW Enterprise」。
如要建立網址篩選安全性設定檔,請在「Type」(類型) 區段中選取「URL Filtering」(網址篩選)。
在「網址篩選器」部分,按一下「建立網址篩選器」按鈕。
在「Create a URL filter」(建立網址篩選器) 窗格中,指定下列詳細資料:
- 優先順序:指定網址篩選器的優先順序。
- 動作:指定 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 欄位中指定的值。您可以在網址篩選器中指定一或多個比對字串。
萬用字元
網址清單中的每個比對字串都支援萬用字元 (*),但使用方式有限制。
- 每個比對字串只能有一個星號 (*),而且必須是第一個或唯一的字元。
星號 (*) 的解讀方式如下:
在半形句號 (.) 前加上星號 (*),即代表要比對該網域的所有子網域。
舉例來說,比對字串
*.example.com與a.example.com和a.b.c.example.com相符,但與example.com不相符。urlFilteringProfile: 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與a.example.com、a.b.c.example.com和example.com均相符。urlFilteringProfile: 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) 前加上星號 (*),即代表要比對使用該網域擴充功能的所有網域 (及其子網域)。舉例來說,比對字串
*.com與example.com和examplepetstore.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才符合。如果只有一個星號 (*),沒有其他字元,則代表所有要求都符合。
舉例來說,優先順序最低的明確允許網址篩選器中,比對字串僅包含星號 (*),且具有
ALLOW動作,可覆寫預設動作DENY。這是因為隱含拒絕網址篩選器會針對不符合高優先順序網址篩選器的任何要求,強制執行預設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」(安全設定檔) 頁面。
選取「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: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 檔案的路徑。