This page shows you how to set up authorization policies for Application Load Balancers.
Before you begin
- Familiarize yourself with the Authorization policy overview.
-
- Network Security API
- Network Services API
Set up the load balancer
If you haven't created a load balancer, see the following pages to set up your preferred Application Load Balancer:
- To create a global external Application Load Balancer, see Set up a global external Application Load Balancer with VM instance group backends.
To create a regional external Application Load Balancer, see Set up a regional external Application Load Balancer with VM instance group backends.
To create a regional internal Application Load Balancer, see Set up a regional internal Application Load Balancer with VM instance group backends.
- To create a cross-region internal Application Load Balancer, see Set up a cross-region internal Application Load Balancer with VM instance group backends.
Create an authorization policy
To create an authorization policy, you create a YAML file
defining the target and the rules, and then import the file using the
gcloud network-security authz-policies command.
This section provides instructions for creating authorization policies attached to the forwarding rule of Application Load Balancers.
To learn more about how to create an authorization policy for an Agent Gateway that delegates authorization using Service Extensions, see Delegate authorization with Service Extensions.
To learn more about how to create an authorization policy for a Secure Web Proxy, see Set up authorization policies for Secure Web Proxy.
Authorization policy to deny requests
This section provides authorization policy examples that denies requests based on certain request attributes.
Deny requests based on IP address ranges
This section provides an authorization policy example that denies requests based on requests originating from specific IP address ranges.
Global and cross-region
Define the authorization policy in a YAML file.
The following example creates an
authz-policy-deny.yamlfile for the forwarding ruleLB_FORWARDING_RULEin thegloballocation. The policy denies clients with IP addresses in the10.0.0.0/24range to access the/api/paymentsURL path.cat >authz-policy-deny.yaml <<EOF name: my-authz-policy-deny target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/forwardingRules/LB_FORWARDING_RULE" httpRules: - from: sources: - ipBlocks: - prefix: "10.0.0.0" length: 24 to: operations: - paths: - prefix: "/api/payments" action: DENY EOFReplace the following:
LB_SCHEME: the load balancing scheme. For global external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For cross-region internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-deny \ --source=authz-policy-deny.yaml \ --location=global
Regional
Define the authorization policy in a YAML file.
The following example creates an
authz-policy-deny.yamlfile for the forwarding ruleLB_FORWARDING_RULEin a Google Cloud region. The policy denies clients with IP addresses in the10.0.0.0/24range to access the/api/paymentsURL path.cat >authz-policy-deny.yaml <<EOF name: my-authz-policy-deny target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/LB_FORWARDING_RULE" httpRules: - from: sources: - ipBlocks: - prefix: "10.0.0.0" length: 24 to: operations: - paths: - prefix: "/api/payments" action: DENY EOFReplace the following:
LB_SCHEME: the load balancing scheme. For regional external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For regional internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LOCATION: your Google Cloud region.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-deny \ --source=authz-policy-deny.yaml \ --location=LOCATION
Deny requests based on client certificate principals
This section provides an authorization policy example that denies requests based on client certificate principals.
Global and cross-region
Define the authorization policy in a YAML file.
The following example creates an
authz-policy-deny.yamlfile for the forwarding ruleLB_FORWARDING_RULEin thegloballocation. The policy denies access to the/api/paymentsURL path to clients that havewww.example.comin their client certificate DNS name SANs.cat >authz-policy-deny.yaml <<EOF name: my-authz-policy-deny target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/forwardingRules/LB_FORWARDING_RULE" httpRules: - from: sources: - principals: - principalSelector: CLIENT_CERT_DNS_NAME_SAN principal: exact: "www.example.com" to: operations: - paths: - prefix: "/api/payments" action: DENY EOFReplace the following:
LB_SCHEME: the load balancing scheme. For global external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For cross-region internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-deny \ --source=authz-policy-deny.yaml \ --location=global
Regional
Define the authorization policy in a YAML file.
The following example creates an
authz-policy-deny.yamlfile for the forwarding ruleLB_FORWARDING_RULEin a Google Cloud region. The policy denies access to the/api/paymentsURL path to clients that havewww.example.comin their client certificate DNS name SANs.cat >authz-policy-deny.yaml <<EOF name: my-authz-policy-deny target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/LB_FORWARDING_RULE" policyProfile: REQUEST_AUTHZ httpRules: - from: sources: - principals: - principalSelector: CLIENT_CERT_DNS_NAME_SAN principal: exact: "www.example.com" to: operations: - paths: - prefix: "/api/payments" action: DENY EOFReplace the following:
LB_SCHEME: the load balancing scheme. For regional external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For regional internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LOCATION: your Google Cloud region.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-deny \ --source=authz-policy-deny.yaml \ --location=LOCATION
Authorization policy to allow requests
This section provides an authorization policy example that allows requests originating from specific IP address ranges.
Global and cross-region
If you're using a global external Application Load Balancer or a cross-region internal Application Load Balancer, follow these steps to create an authorization policy:
Define the authorization policy in a YAML file.
The following example creates an
authz-policy-allow.yamlfile for the forwarding ruleLB_FORWARDING_RULEin thegloballocation. The policy allows clients with IP addresses in the10.0.0.0/24range to access the/api/paymentsURL path.cat >authz-policy-allow.yaml <<EOF name: my-authz-policy-allow target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/forwardingRules/LB_FORWARDING_RULE" httpRules: - from: sources: - ipBlocks: - prefix: "10.0.0.0" length: 24 to: operations: - paths: - exact: "/api/payments" action: ALLOW EOFReplace the following:
LB_SCHEME: the load balancing scheme. For global external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For cross-region internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-allow \ --source=authz-policy-allow.yaml \ --location=global
Regional
If you're using a regional external Application Load Balancer or a regional internal Application Load Balancer, follow these steps to create and import an authorization policy:
Define the authorization policy in a YAML file.
The following example creates an
authz-policy-allow.yamlfile for the forwarding ruleLB_FORWARDING_RULEin a specific Google Cloud region. The policy allows clients with IP addresses in the10.0.0.0/24range to access the/api/paymentsURL path.cat >authz-policy-allow.yaml <<EOF name: my-authz-policy-allow target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/LB_FORWARDING_RULE" policyProfile: REQUEST_AUTHZ httpRules: - from: sources: - ipBlocks: - prefix: "10.0.0.0" length: 24 to: operations: - paths: - exact: "/api/payments" action: ALLOW EOFReplace the following:
LB_SCHEME: the load balancing scheme. For regional external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For regional internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LOCATION: your Google Cloud region.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-allow \ --source=authz-policy-allow.yaml \ --location=LOCATION
Authorization policy based on service accounts or tags
You can apply an authorization policy based on service accounts or secure tags attached to various Google Cloud resources.
This example assumes that you have done the following:
created a service account and attached it to a Google Cloud resource.
created a secure tag and attached it to a Google Cloud resource as a key-value pair. When you create the tag key, do one of the following:
- In the Google Cloud console, for Tag purpose, select Cloud NGFW.
- In the gcloud CLI, set the
--purposeflag toGCE_FIREWALL.
Authorization policies require this purpose to apply the tag.
Service account
Define the authorization policy in a YAML file.
The following example creates an
authz-policy-deny.yamlfile for the forwarding ruleLB_FORWARDING_RULEof a regional internal Application Load Balancer. The policy is configured to deny requests from a Google Cloud resource, such as a Compute Engine VM, with the service accountmy-sa-123@PROJECT_ID.iam.gserviceaccount.comto reach the/api/paymentspath.cat >authz-policy-deny.yaml <<EOF name: my-authz-policy-deny target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/LB_FORWARDING_RULE" policyProfile: REQUEST_AUTHZ httpRules: - from: sources: - resources: - iamServiceAccount: exact: "my-sa-123@PROJECT_ID.iam.gserviceaccount.com" to: operations: - paths: - prefix: "/api/payments" action: DENY EOFReplace the following:
LB_SCHEME: the load balancing scheme. For regional internal Application Load Balancers and cross-region internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LOCATION: your Google Cloud region.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-deny \ --source=authz-policy-deny.yaml \ --location=LOCATIONReplace
LOCATIONwith your Google Cloud region.
Tag
Define the authorization policy in a YAML file.
The following example creates an
authz-policy-allow.yamlfile for the forwarding ruleLB_FORWARDING_RULEof a regional internal Application Load Balancer. The policy only allows requests that originate from a Google Cloud resource, such as a Compute Engine VM, with a secure tag valueTAG_VALUE_PERMANENT_IDto access the/api/paymentsURL path.cat >authz-policy-allow.yaml <<EOF name: my-authz-policy-allow target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/LB_FORWARDING_RULE" policyProfile: REQUEST_AUTHZ httpRules: - from: sources: - resources: - tagValueIdSet: ids: - TAG_VALUE_PERMANENT_ID to: operations: - paths: - exact: "/api/payments" action: ALLOW EOFReplace the following:
LB_SCHEME: the load balancing scheme. For regional internal Application Load Balancers and cross-region internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LOCATION: your Google Cloud region.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.TAG_VALUE_PERMANENT_ID: the permanent ID of a tag value.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-allow \ --source=authz-policy-allow.yaml \ --location=LOCATIONReplace the following:
LOCATION: your Google Cloud region.
Authorization policy to delegate authorization decisions
The examples in this section create an authorization policy that delegate authorization decisions to the following services through Service Extensions:
- User-managed service
- Google-managed service
Delegate authorization decision to a user-managed service
You can configure an authorization policy to delegate the authorization decision to a user-managed service through Service Extensions, specifically an authorization extension.
For global and cross-region load balancers, the authorization extension can run on a user-managed Google Cloud backend service.
For regional load balancers, the authorization extension can run on both a user-managed Google Cloud backend service and an FQDN-based service.
This example setup assumes
that you have created a user-managed Google Cloud backend service,
also referred to as a callout backend service, named authz-service.
To learn more about how to create one, see
Configure a user-managed callout backend service.
For an FQDN-based service, this example setup assumes that the custom service is
deployed in your own VPC, supports the ext_authz protocol, and
is accessible by the fully qualified domain name
mycustomauthz.internal.net.
Global and cross-region
If you're using a global external Application Load Balancer or a cross-region internal Application Load Balancer, follow these steps to delegate the authorization decision to user-managed service.
Define the authorization extension in a YAML file. The authorization extension runs on a backend service (
authz-service) and supports theext_authzprotocol.cat >authz-extension.yaml <<EOF name: my-authz-ext authority: ext11.com loadBalancingScheme: LB_SCHEME service: https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/authz-service forwardHeaders: - Authorization failOpen: false timeout: "0.1s" wireFormat: EXT_AUTHZ_GRPC EOFCreate the authorization extension by importing the authorization extension YAML file using the
gcloud service-extensions authz-extensions importcommand.gcloud service-extensions authz-extensions import my-authz-ext \ --source=authz-extension.yaml \ --location=globalReplace the following:
LB_SCHEME: the load balancing scheme. For global external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For cross-region internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.
Define the authorization policy in a YAML file. The authorization policy delegates authorization to the authorization extension in the
customProviderfield.The policy calls the
my-authz-extauthorization extension for all traffic to theexample.com/api/paymentsURL path when the request contains a non-emptyAuthorizationheader.cat >authz-policy-custom.yaml <<EOF name: my-authz-policy-custom target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/forwardingRules/LB_FORWARDING_RULE" httpRules: - to: operations: - hosts: - exact: "example.com" - paths: - exact: "/api/payments" when: 'request.headers["Authorization"] != ""' action: CUSTOM customProvider: authzExtension: resources: - "projects/PROJECT_ID/locations/global/authzExtensions/my-authz-ext" EOFReplace the following:
LB_SCHEME: the load balancing scheme. For global external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For cross-region internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-custom \ --source=authz-policy-custom.yaml \ --location=global
Regional
If you're using a regional external Application Load Balancer or a regional internal Application Load Balancer, follow these steps to delegate the authorization decision to a user-managed service.
Define the authorization extension in a YAML file. The authorization extension can run on a backend service or an FQDN-based service.
cat >authz-extension.yaml <<EOF name: my-authz-ext authority: ext11.com loadBalancingScheme: LB_SCHEME service: BACKEND_SERVICE_URI_OR_FQDN forwardHeaders: - Authorization failOpen: false timeout: "0.1s" wireFormat: EXT_AUTHZ_GRPC EOFReplace the following:
LB_SCHEME: the load balancing scheme. For regional external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For regional internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.BACKEND_SERVICE_URI_OR_FQDN: the service can be either of the following:- a regional backend service resource URI of the form
https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/backendServices/authz-service. - a fully-qualified domain name
(for example,
mycustomauthz.extension.net) that can be resolved by Cloud DNS.
- a regional backend service resource URI of the form
Create the authorization extension by importing the authorization extension YAML file using the
gcloud service-extensions authz-extensions importcommand.gcloud service-extensions authz-extensions import my-authz-ext \ --source=authz-extension.yaml \ --location=LOCATIONReplace LOCATION with the Google Cloud region where the callout backend service is configured.
Define the authorization policy in a YAML file. The authorization policy delegates authorization to the authorization extension in the
customProviderfield.The policy calls the
my-authz-extauthorization extension for all traffic to theexample.com/api/paymentsURL path when the request contains a non-emptyAuthorizationheader.cat >authz-policy-custom.yaml <<EOF name: my-authz-policy-custom target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/LB_FORWARDING_RULE" policyProfile: REQUEST_AUTHZ httpRules: - to: operations: - paths: - exact: "/api/payments" when: 'request.headers["Authorization"] != ""' action: CUSTOM customProvider: authzExtension: resources: - "projects/PROJECT_ID/locations/LOCATION/authzExtensions/my-authz-ext" EOFReplace the following:
LB_SCHEME: the load balancing scheme. For regional external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For regional internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LOCATION: the Google Cloud region.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-custom \ --source=authz-policy-custom.yaml \ --location=LOCATIONReplace LOCATION with the Google Cloud region where the load balancer is configured.
For more information about authorization extensions, see Configure an authorization extension.
Delegate authorization decision to Model Armor
You can configure an authorization policy to delegate the authorization decision to Model Armor.
Before you begin, create a Model Armor template. In this example setup, the authorization policy points to an authorization extension, which in turn points to Model Armor.
If you're using a regional external Application Load Balancer or a regional internal Application Load Balancer, follow these steps to delegate the authorization decision to Model Armor.
Regional
Define the authorization extension in a YAML file. The authorization extension points to Model Armor request and response templates.
cat >authz-extension.yaml <<EOF name: my-authz-extension loadBalancingScheme: INTERNAL_MANAGED service: modelarmor.LOCATION.rep.googleapis.com metadata: model_armor_settings: '[ { "response_template_id": "projects/PROJECT_ID/locations/LOCATION/templates/RESPONSE_TEMPLATE_ID", "request_template_id": "projects/PROJECT_ID/locations/LOCATION/templates/REQUEST_TEMPLATE_ID" } ]' failOpen: true EOFReplace the following:
- LOCATION: the location of the template
- PROJECT_ID: the ID of the project that the template belongs to
- RESPONSE_TEMPLATE_ID: ID of the response template
- REQUEST_TEMPLATE_ID: the ID of the request template
Create the authorization extension by importing the authorization extension YAML file using the
gcloud service-extensions authz-extensions importcommand.gcloud service-extensions authz-extensions import my-authz-ext \ --source=authz-extension.yaml \ --location=LOCATION
Replace LOCATION with the Google Cloud region where the load balancer is located.
Define the authorization policy in a YAML file. The authorization policy delegates authorization to the authorization extension in the
customProviderfield.The value of the
policyProfileisCONTENT_AUTHZ.cat >authz-policy-custom.yaml <<EOF name: my-authz-policy-custom target: loadBalancingScheme: INTERNAL_MANAGED resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/LB_FORWARDING_RULE" policyProfile: CONTENT_AUTHZ action: CUSTOM customProvider: authzExtension: resources: - "projects/PROJECT_ID/locations/LOCATION/authzExtensions/my-authz-ext" EOFReplace the following:
PROJECT_ID: the ID of your Google Cloud project.LOCATION: the Google Cloud region.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-custom \ --source=authz-policy-custom.yaml \ --location=LOCATION
Replace LOCATION with the Google Cloud region where the load balancer is configured.
Delegate authorization decision to Identity-Aware Proxy
For global external Application Load Balancers and cross-region internal Application Load Balancers, you cannot delegate
the authorization decision to IAP through an authorization
extension. For these load balancers, you can delegate authorization decision to
IAP through the customProvider field on the authorization
policy resource.
For regional external Application Load Balancers and regional internal Application Load Balancers, you can configure an authorization policy to delegate the authorization decision to IAP through an authorization extension.
Global and cross-region
In the following example, all authorization decisions are delegated to
IAP for all requests originating from the 10.0.0.0/24
IP address block. If requests originate from any IP address outside of
10.0.0.0/24, they don't match this policy and aren't
evaluated by IAP under this specific rule.
Define the authorization policy in a YAML file. The authorization policy delegates authorization to IAP through the
customProviderfield.cat >authz-policy-iap.yaml <<EOF name: my-authz-policy-custom target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/forwardingRules/LB_FORWARDING_RULE" httpRules: - from: sources: - ipBlocks: - prefix: "10.0.0.0" length: 24 action: CUSTOM customProvider: cloudIap: {} EOFReplace the following:
LB_SCHEME: the load balancing scheme. For global external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For cross-region internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-custom \ --source=authz-policy-iap.yaml \ --location=global
Regional
If you're using a regional external Application Load Balancer or a regional internal Application Load Balancer, follow these steps to delegate the authorization decision to IAP using an authorization extension.
Define the authorization extension in a YAML file. The authorization extension points to IAP.
cat >authz-extension.yaml <<EOF name: my-authz-ext loadBalancingScheme: LB_SCHEME service: iap.googleapis.com failOpen: false EOFReplace the following:
- LB_SCHEME: the load balancing scheme.
For regional external Application Load Balancers, set the scheme to
EXTERNAL_MANAGED. For regional internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.
- LB_SCHEME: the load balancing scheme.
For regional external Application Load Balancers, set the scheme to
Create the authorization extension by importing the authorization extension YAML file using the
gcloud service-extensions authz-extensions importcommand.gcloud service-extensions authz-extensions import my-authz-ext \ --source=authz-extension.yaml \ --location=LOCATIONReplace LOCATION with the Google Cloud region where the authorization extension is configured.
Define the authorization policy in a YAML file. The authorization policy delegates authorization to the authorization extension in the
customProviderfield.cat >authz-policy-custom.yaml <<EOF name: my-authz-policy-custom target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/LB_FORWARDING_RULE" policyProfile: REQUEST_AUTHZ action: CUSTOM customProvider: authzExtension: resources: - "projects/PROJECT_ID/locations/LOCATION/authzExtensions/my-authz-ext" EOFReplace the following:
LB_SCHEME: the load balancing scheme. For regional external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For regional internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LOCATION: the Google Cloud region.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-custom \ --source=authz-policy-custom.yaml \ --location=LOCATIONReplace LOCATION with the Google Cloud region where the load balancer is configured.
Authorization policy to deny requests by default
An authorization policy with a DENY_BY_DEFAULT action enforces a secure
baseline on the target resource by blocking all requests unless explicitly
permitted by an ALLOW or CUSTOM policy. This ensures that your resource
remains protected even if no ALLOW policies are configured, such as when
relying only on CUSTOM policies (like IAP or
Service Extensions) or during policy maintenance when ALLOW policies
might be temporarily removed or updated.
The following steps show how to create a DENY_BY_DEFAULT authorization
policy.
Cross-region
Define the
DENY_BY_DEFAULTauthorization policy in a YAML file.The policy targets the load balancer's forwarding rule and blocks all requests not explicitly permitted by an
ALLOWorCUSTOMpolicy.cat >authz-policy-deny-by-default.yaml <<EOF name: my-authz-policy-deny-by-default target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/global/forwardingRules/LB_FORWARDING_RULE" action: DENY_BY_DEFAULT EOFReplace the following:
LB_SCHEME: the load balancing scheme. For cross-region internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-deny-by-default \ --source=authz-policy-deny-by-default.yaml \ --location=globalThis policy establishes a deny-by-default security baseline for your load balancer. To selectively allow or deny traffic, create separate
ALLOW,DENY, orCUSTOMpolicies.
Regional
Define the authorization policy in a YAML file.
The policy targets the load balancer's forwarding rule and blocks all requests not explicitly permitted by an
ALLOWorCUSTOMpolicy.cat >authz-policy-deny-by-default.yaml <<EOF name: my-authz-policy-deny-by-default target: loadBalancingScheme: LB_SCHEME resources: - "https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/LB_FORWARDING_RULE" action: DENY_BY_DEFAULT EOFReplace the following:
LB_SCHEME: the load balancing scheme. For regional external Application Load Balancers, set the scheme toEXTERNAL_MANAGED. For regional internal Application Load Balancers, set the scheme toINTERNAL_MANAGED.PROJECT_ID: the ID of your Google Cloud project.LOCATION: the Google Cloud region.LB_FORWARDING_RULE: the name of the load balancer's forwarding rule.
Create the authorization policy by importing the authorization policy YAML file using the
gcloud network-security authz-policies importcommand.gcloud network-security authz-policies import my-authz-policy-deny-by-default \ --source=authz-policy-deny-by-default.yaml \ --location=LOCATIONThis policy establishes a deny-by-default security baseline for your load balancer. To selectively allow or deny traffic, create separate
ALLOW,DENY, orCUSTOMpolicies.
Authorization policy logs in Cloud Logging
When an authorization policy is attached to a load balancer's forwarding
rule, the load balancer records authorization decisions in Cloud Logging under
the jsonPayload.authzPolicyInfo field.
If an authorization policy attached to the forwarding rule of a global external Application Load Balancer denies a request, the
jsonPayload.statusDetailsfield is set todenied_by_authz_policy.If an authorization policy attached to the forwarding rule of a regional internal Application Load Balancer, regional external Application Load Balancer, or cross-region internal Application Load Balancer denies a request, the
jsonPayload.proxyStatusfield is set todenied_by_authz_policy.
Log entries
The examples in this section show abbreviated log entries for HTTP requests that are evaluated by an authorization policy:
Request matches neither the ALLOW nor DENY policy
When a request does not match the DENY policy, the DENY policy stage allows
the request and logs it as allowed_as_no_deny_policies_matched_request. The
evaluation then proceeds to the ALLOW policy stage. Because the request does
not match the configured ALLOW policy, the request is denied and logged as
denied_as_no_allow_policies_matched_request.
Because the ALLOW stage denied the request, the overall result
(jsonPayload.authzPolicyInfo.result) is logged as DENIED.
{
jsonPayload: {
@type: "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"
authzPolicyInfo: {
policies: [
0: {
details: "allowed_as_no_deny_policies_matched_request"
result: "ALLOWED"
}
1: {
details: "denied_as_no_allow_policies_matched_request"
result: "DENIED"
}
]
result: "DENIED"
}
}
...
}
Request matches the DENY policy
When a request matches the DENY policy, the request is denied immediately
and the name of the policy that denied the request is logged.
{
jsonPayload: {
@type: "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"
authzPolicyInfo: {
policies: [
0: {
name: "projects/12345567/locations/global/authzPolicies/deny-authz-policy-test"
result: "DENIED"
}
]
result: "DENIED"
}
}
...
}
Request does not match the DENY policy, but matches the ALLOW policy
When a request does not match the DENY policy, the DENY
policy stage permits the request and logs it as
allowed_as_no_deny_policies_matched_request. The evaluation then proceeds to
the ALLOW policy stage. Because the request matches the ALLOW policy, the
ALLOW stage logs the resource name of the matching policy in
policies[1].name with the result as ALLOWED.
Because the ALLOW stage allowed the request, the overall result
(jsonPayload.authzPolicyInfo.result) is logged as ALLOWED.
{
jsonPayload: {
@type: "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"
authzPolicyInfo: {
policies: [
0: {
details: "allowed_as_no_deny_policies_matched_request"
result: "ALLOWED"
}
1: {
name: "projects/12345567/locations/global/authzPolicies/allow-authz-policy-test"
result: "ALLOWED"
}
]
result: "ALLOWED"
}
}
...
}
Request matches the DENY_BY_DEFAULT policy
When you configure a DENY_BY_DEFAULT policy on a load balancer's forwarding
rule and no ALLOW policy is configured (or no CUSTOM policy permitted the
request), the request reaches the default deny evaluation stage and is blocked.
This action is logged as denied_by_default.
{
jsonPayload: {
@type: "type.googleapis.com/google.cloud.loadbalancing.type.LoadBalancerLogEntry"
authzPolicyInfo: {
policies: [
{
details: "denied_by_default",
result: "DENIED"
}
],
result: "DENIED"
}
}
...
}
Configure log alerts
You can configure alerts for events that authorization policies write to Logging, such as traffic denials or specific policy matches. For general instructions on how to set up these alerts, see Configure log-based alerts.
This section provides examples of queries that you can use to configure alerts for specific authorization policy events. To learn more about the different log names and resource types for load balancers, see Cloud Load Balancing in Platform logs documentation.
The following table outlines the log name and resource type for different Application Load Balancers:
| Application Load Balancer type | Log name | Resource type |
|---|---|---|
| Global external Application Load Balancer | projects/PROJECT_ID/logs/requests |
http_load_balancer |
| Regional external Application Load Balancer | projects/PROJECT_ID/logs/loadbalancing.googleapis.com%2Fexternal_regional_requests |
http_external_regional_lb_rule |
| Regional internal Application Load Balancer and cross-region internal Application Load Balancer | projects/PROJECT_ID/logs/loadbalancing.googleapis.com%2Frequests
|
internal_http_lb_rule |
Alert for traffic that was denied by an authorization policy
Use the following query to trigger an alert when a request is denied at any stage of the authorization policy evaluation order.
logName: "projects/PROJECT_ID/logs/loadbalancing.googleapis.com%2Fexternal_regional_requests" resource.type="http_external_regional_lb_rule" jsonPayload.authzPolicyInfo.result="DENIED"
Alert for traffic that was denied because it didn't match any configured ALLOW policies
Use the following query to trigger an alert when a request is denied because it
didn't match any configured ALLOW policies:
logName: "projects/PROJECT_ID/logs/loadbalancing.googleapis.com%2Fexternal_regional_requests" resource.type="http_external_regional_lb_rule" jsonPayload.authzPolicyInfo.policies.details="denied_as_no_allow_policies_matched_request"
Alert for traffic denied by a DENY_BY_DEFAULT policy
Use the following query to trigger an alert when an authorization policy with
a DENY_BY_DEFAULT action denies a request:
logName: "projects/PROJECT_ID/logs/loadbalancing.googleapis.com%2Fexternal_regional_requests" resource.type="http_external_regional_lb_rule" (jsonPayload.authzPolicyInfo.policies.details="denied_by_default" OR jsonPayload.authzPolicyInfo.policies.details="denied_as_no_allow_policies_matched_request")