gcloud alpha compute security-policies rules update Stay organized with collections Save and categorize content based on your preferences.
- NAME
- gcloud alpha compute security-policies rules update - update a Compute Engine security policy rule
- SYNOPSIS
gcloud alpha compute security-policies rules updatePRIORITY[--action=ACTION][--ban-duration-sec=BAN_DURATION_SEC][--ban-threshold-count=BAN_THRESHOLD_COUNT][--ban-threshold-interval-sec=BAN_THRESHOLD_INTERVAL_SEC][--conform-action=CONFORM_ACTION][--description=DESCRIPTION][--enforce-on-key=ENFORCE_ON_KEY][--enforce-on-key-configs=[[all],[ip],[xff-ip],[http-cookie=HTTP_COOKIE],[http-header=HTTP_HEADER],[http-path],[sni],[region-code],[tls-ja3-fingerprint],[user-ip],[tls-ja4-fingerprint]],[…]][--enforce-on-key-name=ENFORCE_ON_KEY_NAME][--exceed-action=EXCEED_ACTION][--exceed-action-rpc-status-code=EXCEED_ACTION_RPC_STATUS_CODE][--exceed-action-rpc-status-message=EXCEED_ACTION_RPC_STATUS_MESSAGE][--exceed-redirect-target=EXCEED_REDIRECT_TARGET][--exceed-redirect-type=EXCEED_REDIRECT_TYPE][--[no-]preview][--rate-limit-threshold-count=RATE_LIMIT_THRESHOLD_COUNT][--rate-limit-threshold-interval-sec=RATE_LIMIT_THRESHOLD_INTERVAL_SEC][--recaptcha-action-site-keys=[SITE_KEY,…]][--recaptcha-session-site-keys=[SITE_KEY,…]][--redirect-target=REDIRECT_TARGET][--redirect-type=REDIRECT_TYPE][--region=REGION][--request-headers-to-add=[REQUEST_HEADERS_TO_ADD,…]][--security-policy=SECURITY_POLICY][--expression=EXPRESSION--network-dest-ip-ranges=[DEST_IP_RANGE,…]--network-dest-ports=[DEST_PORT,…]--network-ip-protocols=[IP_PROTOCOL,…]--network-src-asns=[SRC_ASN,…]--network-src-ip-ranges=[SRC_IP_RANGE,…]--network-src-ports=[SRC_PORT,…]--network-src-region-codes=[SRC_REGION_CODE,…]--network-user-defined-fields=[NAME;VALUE:VALUE:…,…]--src-ip-ranges=[SRC_IP_RANGE,…]][GCLOUD_WIDE_FLAG …]
- DESCRIPTION
(ALPHA)gcloud alpha compute security-policies rulesupdateis used to update security policy rules.- EXAMPLES
- To update the description and IP ranges of a rule at priority 1000, run:
gcloudalphacomputesecurity-policiesrulesupdate1000--security-policy=my-policy--description="block 1.2.3.4/32"--src-ip-ranges=1.2.3.4/32 - POSITIONAL ARGUMENTS
PRIORITY- The priority of the rule to update. Rules are evaluated in order from highestpriority to lowest priority where 0 is the highest priority and 2147483647 isthe lowest priority.
- FLAGS
--action=ACTION- The action to take if the request matches the match condition.
ACTIONmust be one of:allow- Allows the request from HTTP(S) Load Balancing.
deny- Denies the request from TCP/SSL Proxy and Network Load Balancing.
deny-403- Denies the request from HTTP(S) Load Balancing, with an HTTP response statuscode of 403.
deny-404- Denies the request from HTTP(S) Load Balancing, with an HTTP response statuscode of 404.
deny-502- Denies the request from HTTP(S) Load Balancing, with an HTTP response statuscode of 502.
fairshare- When traffic reaches the threshold limit, requests from the clients matchingthis rule begin to be rate-limited using the Fair Share algorithm.
rate-based-ban- Enforces rate-based ban action from HTTP(S) Load Balancing, based on rate limitoptions.
redirect- Redirects the request from HTTP(S) Load Balancing, based on redirect options.
redirect-to-recaptcha- (DEPRECATED) Redirects the request from HTTP(S) Load Balancing, for reCAPTCHAEnterprise assessment. This flag choice is deprecated. Use --action=redirect and--redirect-type=google-recaptcha instead.
throttle- Enforces throttle action from HTTP(S) Load Balancing, based on rate limitoptions.
--ban-duration-sec=BAN_DURATION_SEC- Can only be specified if the action for the rule is
. If specified, determinesthe time (in seconds) the traffic will continue to be banned by the rate limitafter the rate falls below the threshold.rate-based-ban --ban-threshold-count=BAN_THRESHOLD_COUNT- Number of HTTP(S) requests for calculating the threshold for banning requests.Can only be specified if the action for the rule is
. If specified, the key willbe banned for the configuredrate-based-banwhen the number ofrequests that exceed theBAN_DURATION_SECalso exceed thisRATE_LIMIT_THRESHOLD_COUNT.BAN_THRESHOLD_COUNT --ban-threshold-interval-sec=BAN_THRESHOLD_INTERVAL_SEC- Interval over which the threshold for banning requests is computed. Can only bespecified if the action for the rule is
. If specified, the key willbe banned for the configuredrate-based-banwhen the number ofrequests that exceed theBAN_DURATION_SECalso exceed thisRATE_LIMIT_THRESHOLD_COUNT.BAN_THRESHOLD_COUNT --conform-action=CONFORM_ACTION- Action to take when requests are under the given threshold. When requests arethrottled, this is also the action for all requests which are not dropped.
CONFORM_ACTIONmust be (only one value is supported):allow. --description=DESCRIPTION- An optional, textual description for the rule.
--enforce-on-key=ENFORCE_ON_KEY- Different key types available to enforce the rate limit threshold limit on:
: each client IP address has this limitenforced separatelyip: a single limit is applied to allrequests matching this ruleall: key type takes the value ofthe HTTP header configured in enforce-on-key-name as the key valuehttp-header: takes the original IP addressspecified in the X-Forwarded-For header as the keyxff-ip: key type takes the value ofthe HTTP cookie configured in enforce-on-key-name as the key valuehttp-cookie: key type takes the value of theURL path in the requesthttp-path: key type takes the value of the servername indication from the TLS session of the HTTPS requestsni: key type takes the value ofthe region code from which the request originatesregion-code: key type takes thevalue of JA3 TLS/SSL fingerprint if the client connects using HTTPS, HTTP/2 orHTTP/3tls-ja3-fingerprint: key type takes the IP address ofthe originating client, which is resolved based on user-ip-request-headersconfigured with the security policyuser-ip: key type takes thevalue of JA4 TLS/SSL fingerprint if the client connects using HTTPS, HTTP/2 orHTTP/3tls-ja4-fingerprint
ENFORCE_ON_KEYmust be one of:ip,all,http-header,xff-ip,http-cookie,http-path,sni,region-code,tls-ja3-fingerprint,user-ip,tls-ja4-fingerprint. --enforce-on-key-configs=[[all],[ip],[xff-ip],[http-cookie=HTTP_COOKIE],[http-header=HTTP_HEADER],[http-path],[sni],[region-code],[tls-ja3-fingerprint],[user-ip],[tls-ja4-fingerprint]],[…]- Specify up to 3 key type/name pairs to rate limit. Valid key types are:
: each client IP address has this limitenforced separatelyip: a single limit is applied to allrequests matching this ruleall: key type takes the value ofthe HTTP header configured in enforce-on-key-name as the key valuehttp-header: takes the original IP addressspecified in the X-Forwarded-For header as the keyxff-ip: key type takes the value ofthe HTTP cookie configured in enforce-on-key-name as the key valuehttp-cookie: key type takes the value of theURL path in the requesthttp-path: key type takes the value of the servername indication from the TLS session of the HTTPS requestsni: key type takes the value ofthe region code from which the request originatesregion-code: key type takes thevalue of JA3 TLS/SSL fingerprint if the client connects using HTTPS, HTTP/2 orHTTP/3tls-ja3-fingerprint: key type takes the IP address ofthe originating client, which is resolved based on user-ip-request-headersconfigured with the security policyuser-ip: key type takes thevalue of JA4 TLS/SSL fingerprint if the client connects using HTTPS, HTTP/2 orHTTP/3tls-ja4-fingerprint
Key names are only applicable to the following key types:
- http-header: The name of the HTTP header whose value is taken as the key value.
- http-cookie: The name of the HTTP cookie whose value is taken as the key value.
--enforce-on-key-name=ENFORCE_ON_KEY_NAME- Determines the key name for the rate limit key. Applicable only for thefollowing rate limit key types:
- http-header: The name of the HTTP header whose value is taken as the key value.
- http-cookie: The name of the HTTP cookie whose value is taken as the key value.
--exceed-action=EXCEED_ACTION- Action to take when requests are above the given threshold. When a request isdenied, return the specified HTTP response code. When a request is redirected,use the redirect options based on --exceed-redirect-type and--exceed-redirect-target below.
EXCEED_ACTIONmust beone of:deny-403,deny-404,deny-429,deny-502,deny,redirect. --exceed-action-rpc-status-code=EXCEED_ACTION_RPC_STATUS_CODE- Status code, which should be an enum value of [google.rpc.Code]
--exceed-action-rpc-status-message=EXCEED_ACTION_RPC_STATUS_MESSAGE- Developer-facing error message, should be in English.
--exceed-redirect-target=EXCEED_REDIRECT_TARGET- URL target for the redirect action that is configured as the exceed action whenthe redirect type is
.external-302 --exceed-redirect-type=EXCEED_REDIRECT_TYPE- Type for the redirect action that is configured as the exceed action.
EXCEED_REDIRECT_TYPEmust be one of:google-recaptcha,external-302. --[no-]preview- If specified, the action will not be enforced. Use
--previewtoenable and--no-previewto disable. --rate-limit-threshold-count=RATE_LIMIT_THRESHOLD_COUNT- Number of HTTP(S) requests for calculating the threshold for rate limitingrequests.
--rate-limit-threshold-interval-sec=RATE_LIMIT_THRESHOLD_INTERVAL_SEC- Interval over which the threshold for rate limiting requests is computed.
--recaptcha-action-site-keys=[SITE_KEY,…]- A comma-separated list of site keys to be used during the validation ofreCAPTCHA action-tokens. The provided site keys need to be created from thereCAPTCHA API under the same project where the security policy is created.
--recaptcha-session-site-keys=[SITE_KEY,…]- A comma-separated list of site keys to be used during the validation ofreCAPTCHA session-tokens. The provided site keys need to be created from thereCAPTCHA API under the same project where the security policy is created.
--redirect-target=REDIRECT_TARGET- URL target for the redirect action. Must be specified if the redirect type is
. Cannot be specified if theredirect type isexternal-302.google-recaptcha --redirect-type=REDIRECT_TYPE- Type for the redirect action. Default to
if unspecified while--redirect-target is given.external-302REDIRECT_TYPEmust be oneof:google-recaptcha,external-302. --region=REGION- Region of the security policy to update. If not specified, you might be promptedto select a region (interactive mode only).
A list of regions can be fetched by running:
gcloudcomputeregionslistOverrides the default
compute/regionproperty value for thiscommand invocation. --request-headers-to-add=[REQUEST_HEADERS_TO_ADD,…]- A comma-separated list of header names and header values to add to requests thatmatch this rule.
--security-policy=SECURITY_POLICY- The security policy that this rule belongs to.
- Security policy rule matcher.
--expression=EXPRESSION- The Cloud Armor rules language expression to match for this rule.
--network-dest-ip-ranges=[DEST_IP_RANGE,…]- The destination IPs/IP ranges to match for this rule. To match all IPs specify*.
--network-dest-ports=[DEST_PORT,…]- The destination ports to match for this rule. Each element can be an 16-bitunsigned decimal number (e.g. "80") or range (e.g."0-1023"), To match alldestination ports specify *.
--network-ip-protocols=[IP_PROTOCOL,…]- The IP protocols to match for this rule. Each element can be an 8-bit unsigneddecimal number (e.g. "6"), range (e.g."253-254"), or one of the followingprotocol names: "tcp", "udp", "icmp", "esp", "ah", "ipip", or "sctp". To matchall protocols specify *.
--network-src-asns=[SRC_ASN,…]- BGP Autonomous System Number associated with the source IP address to match forthis rule.
--network-src-ip-ranges=[SRC_IP_RANGE,…]- The source IPs/IP ranges to match for this rule. To match all IPs specify *.
--network-src-ports=[SRC_PORT,…]- The source ports to match for this rule. Each element can be an 16-bit unsigneddecimal number (e.g. "80") or range (e.g."0-1023"), To match all source portsspecify *.
--network-src-region-codes=[SRC_REGION_CODE,…]- The two letter ISO 3166-1 alpha-2 country code associated with the source IPaddress to match for this rule. To match all region codes specify *.
--network-user-defined-fields=[NAME;VALUE:VALUE:…,…]- Each element names a defined field and lists the matching values for that field.
--src-ip-ranges=[SRC_IP_RANGE,…]- The source IPs/IP ranges to match for this rule. To match all IPs specify *.
- GCLOUD WIDE FLAGS
- These flags are available to all commands:
--access-token-file,--account,--billing-project,--configuration,--flags-file,--flatten,--format,--help,--impersonate-service-account,--log-http,--project,--quiet,--trace-token,--user-output-enabled,--verbosity.Run
$gcloud helpfor details. - NOTES
- This command is currently in alpha and might change without notice. If thiscommand fails with API permission errors despite specifying the correct project,you might be trying to access an API with an invitation-only early accessallowlist. These variants are also available:
gcloudcomputesecurity-policiesrulesupdategcloudbetacomputesecurity-policiesrulesupdate
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-09-03 UTC.