This guide shows how to use URL lists to define URLs that your users can access.
Before you begin
Complete the initial setup steps.
Verify that you have the Google Cloud CLI version 406.0.0 or later installed:
gcloud version | head -n1
If you have an earlier gcloud CLI version installed, update the version:
gcloud components update --version=406.0.0
Create a Secure Web Proxy instance with an empty policy
To create a Secure Web Proxy instance, first create an empty security policy and then create a web proxy.
Create an empty security policy
Console
In the Google Cloud console, go to the Network Security page.
Click Secure Web Proxy.
Click the Policies tab.
Click Create a policy.
Enter a name for the policy that you want to create, such as
myswppolicy
.Enter a description of the policy, such as
My new swp policy
.In the Regions list, select the region where you want to create the policy.
Click Create.
Cloud Shell
Use your preferred text editor to create the file
POLICY_FILE
.yaml. ReplacePOLICY_FILE
with the filename that you want for the policy file.Add the following to the YAML file that you created:
name: projects/PROJECT_NAME/locations/REGION/gatewaySecurityPolicies/POLICY_NAME description: POLICY_DESCRIPTION
Replace the following:
PROJECT_NAME
: the name of your projectREGION
: the region that this policy applies toPOLICY_NAME
: the name of the policy that you're creatingPOLICY_DESCRIPTION
: the description of the policy that you're creating
Import the security policy:
gcloud network-security gateway-security-policies import POLICY_NAME \ --source=POLICY_FILE.yaml \ --location=REGION
Create a web proxy
Console
In the Google Cloud console, go to the Network Security page.
Click Secure Web Proxy.
Click Set up a web proxy.
Enter a name for the web proxy that you want to create, such as
myswp
.Enter a description of the web proxy, such as
My new swp
.In the Regions list, select the region where you want to create the web proxy.
In the Network list, select the network where you want to create the web proxy.
In the Subnetwork list, select the subnetwork where you want to create the web proxy.
Enter the web proxy IP address.
In the Certificate list, select the certificate that you want to use to create the web proxy.
In the Policy list, select the policy that you created to associate the web proxy with.
Click Create.
Cloud Shell
Use your preferred text editor to create the file
GATEWAY_FILE
.yaml. ReplaceGATEWAY_FILE
with the filename that you want for the web proxy file.Add the following to the YAML file that you created:
name: projects/PROJECT_NAME/locations/REGION/gateways/GATEWAY_NAME type: SECURE_WEB_GATEWAY ports: [GATEWAY_PORT_NUMBERS] certificateUrls: [CERTIFICATE_URLS] gatewaySecurityPolicy: projects/PROJECT_NAME/locations/REGION/gatewaySecurityPolicies/POLICY_NAME network: projects/PROJECT_NAME/global/networks/NETWORK_NAME subnetwork: projects/PROJECT_NAME/regions/REGION/subnetworks/SUBNET_NAME addresses: [GATEWAY_IP_ADDRESS] scope: samplescope
Replace the following:
GATEWAY_NAME
: the name for this instanceGATEWAY_PORT_NUMBERS
: a list of port numbers for this gateway, such as[80,443]
CERTIFICATE_URLS
: a list of SSL certificate URLsSUBNET_NAME
: the name of the subnet that containsGATEWAY_IP_ADDRESS
GATEWAY_IP_ADDRESS
: an optional list of IP addresses for your Secure Web Proxy instances within the proxy subnets previously created in the initial setup stepsIf you choose not to list IP addresses, omit the field to have the web proxy choose an IP address for you.
Create a Secure Web Proxy instance:
gcloud network-services gateways import GATEWAY_NAME \ --source=GATEWAY_FILE.yaml \ --location=REGION
Test connectivity
To test connectivity, use the curl
command from any VM within your
Virtual Private Cloud (VPC) network:
curl -x https://GATEWAY_IP_ADDRESS:PORT_NUMBER https://www.example.com --proxy-insecure
A 403 Forbidden
error is expected.
Create a URL list
To create a URL list and add a rule, complete the tasks in the following sections.
Create and configure a URL list
Console
In the Google Cloud console, go to the Network Security page.
Click Secure Web Proxy.
Click the URL lists tab.
Click Create a URL list.
Enter a name for the URL list that you want to create, such as
myurllist
.Enter a description of the URL list, such as
My new URL list
.In the Regions list, select the region where you want to create the URL list.
Click Upload lists to upload the list of hosts, URLs, or patterns to match. For more information, see the UrlList syntax reference.
Click Create.
Cloud Shell
Use your preferred text editor to create the file URL_LIST_FILE
.yaml. Replace
URL_LIST_FILE` with your desired filename.name: projects/PROJECT_ID/locations/REGION/urlLists/URL_LIST_NAME values: URL_LIST
Replace the following:
PROJECT_ID
: your project numberREGION
: the region this URL list applies toURL_LIST_NAME
: a name for the URL list that you're creatingURL_LIST
: the list of hosts, URLs, or patterns to match
For more information, see UrlList syntax reference.
The following is an example URL list rule file:
name: projects/PROJECT_ID/locations/REGION/urlLists/example-org-allowed-list values: - www.example.com - about.example.com - "*.google.com" - "github.com/example-org/*"
The asterisk (
*
) character has a special meaning in YAML. Therefore, you must add quotation marks around URLs that include an*
character.Add the URL list so that it can be referenced by a Secure Web Proxy rule:
gcloud network-security url-lists import URL_LIST_NAME \ --location=REGION \ --project=PROJECT_ID \ --source=URL_LIST_FILE.yaml
Add a rule
Console
In the Google Cloud console, go to the Network Security page.
Click Secure Web Proxy.
In the project selector menu, select your organization ID or the folder that contains your policy.
Click the name of your policy.
Click Add rule.
Populate the rule fields:
- Name
- Description
- Status
- Priority: the numeric evaluation order of the rule. The rules are
evaluated from highest to lowest priority where
0
is the highest priority. - In the Action section, specify whether connections that match the rule are allowed (Allow) or denied (Deny).
In the Session Match section, specify the name of the URL list that you created previously. For example:
sessionMatcher: "inUrlList(host(), 'projects/PROJECT_ID/locations/REGION/urlLists/URL_LIST_NAME')"
To enable TLS inspection, select Enable TLS inspection.
In the Application Match section, specify the criteria for matching the request.
Click Create.
Click Add rule to add another rule.
Click Create to create the policy.
Cloud Shell
Use your preferred text editor to create the file
RULE_FILE
.yaml. ReplaceRULE_FILE
with your desired filename.name: projects/PROJECT_ID/locations/REGION/gatewaySecurityPolicies/POLICY_NAME/rules/RULE_NAME basicProfile: ALLOW enabled: true priority: PRIORITY_VALUE description: RULE_DESCRIPTION sessionMatcher: SESSION_CEL_EXPRESSION applicationMatcher: APPLICATION_CEL_EXPRESSION
Replace the following:
PROJECT_ID
: your project numberREGION
: the region this rule applies toPOLICY_NAME
: the name of an existingGatewaySecurityPolicy
used by your Secure Web Proxy instanceRULE_NAME
: a name for theGatewaySecurityPolicyRule
that you're creatingPRIORITY_VALUE
: a priority value for this rule; lower numbers correspond to higher prioritiesRULE_DESCRIPTION
: a description for the policy that you're creatingSESSION_CEL_EXPRESSION
: a Common Expression Language (CEL) expression for the sessionAPPLICATION_CEL_EXPRESSION
: a CEL expression for the application
The following is an example rule file:
name: projects/PROJECT_ID/locations/REGION/urlLists/allow-repos basicProfile: ALLOW enabled: true priority: 100 description: Allow access to our list of known code repos. sessionMatcher: "inUrlList(host(), 'projects/PROJECT_ID/locations/REGION/urlLists/URL_LIST_NAME')"
Add a Secure Web Proxy rule by using the URL list that you previously created:
gcloud network-security gateway-security-policies rules import RULE_NAME \ --location=REGION \ --project=PROJECT_ID \ --source=RULE_FILE.yaml \ --gateway-security-policy=POLICY_NAME
Test connectivity
To test connectivity, use the following curl
command:
curl -x https://SWP_IP_ADDRESS:SWP_PORT_NUMBER HTTP_TEST_ADDRESS
--proxy-insecure
Replace the following:
SWP_IP_ADDRESS
: the IP address to your web proxySWP_PORT_NUMBER
: the port number for your web proxy, such as443
HTTP_TEST_ADDRESS
: an address to test, such ashttps://www.example.com
, that matches a host or URL entry in yourURL_LIST
The request should return a successful response.