使用自訂限制條件管理 Cloud Load Balancing 資源

Google Cloud 機構政策可讓您透過程式以集中方式控管機構的資源。身為機構政策管理員,您可以定義機構政策,也就是一組稱為限制的限制,適用於Google Cloud 資源和Google Cloud 資源階層中這些資源的子系。您可以在機構、資料夾或專案層級強制執行機構政策。

機構政策提供各種Google Cloud 服務的預先定義限制。不過,如要進一步自訂組織政策中受限制的特定欄位,也可以建立自訂限制,並在自訂組織政策中使用這些限制。

下列負載平衡元件支援自訂限制:

Compute Engine 資源 (例如執行個體群組) 和 VPC 資源 (例如 VPC 網路和子網路) 也支援自訂限制。

優點

  • 成本管理:使用自訂機構政策,限制健康狀態檢查探測頻率。
  • 安全性、法規遵循與管理:您可以透過自訂機構政策強制執行政策。例如:

    • 強制使用特定健康狀態檢查通訊協定或通訊埠範圍
    • 禁止使用特定後端流量通訊協定
    • 規定後端 bucket 必須啟用 Cloud CDN
    • 要求轉送規則使用特定網路服務層級

Cloud Load Balancing 支援的資源

對於 Cloud Load Balancing,您可以對下列資源和欄位設定自訂限制。

後端 bucket

後端值區compute.googleapis.com/BackendBucket

  • resource.name
  • resource.description
  • resource.bucketName
  • resource.enableCdn
  • resource.cdnPolicy
    • resource.cdnPolicy.bypassCacheOnRequestHeaders
      • resource.cdnPolicy.bypassCacheOnRequestHeaders.headerName
    • resource.cdnPolicy.cacheKeyPolicy
      • resource.cdnPolicy.cacheKeyPolicy.includeHttpHeaders
      • resource.cdnPolicy.cacheKeyPolicy.queryStringWhitelist
      • resource.cdnPolicy.signedUrlCacheMaxAgeSec
    • resource.compressionMode
    • resource.customResponseHeaders

後端服務

後端服務compute.googleapis.com/BackendService

  • resource.name
  • resource.description
  • resource.port
  • resource.portName
  • resource.protocol
  • resource.backends
    • resource.backends.balancingMode
    • resource.backends.capacityScaler
    • resource.backends.description
    • resource.backends.failover
    • resource.backends.maxConnections
    • resource.backends.maxConnectionsPerEndpoint
    • resource.backends.maxConnectionsPerInstance
    • resource.backends.maxRate
    • resource.backends.maxRatePerEndpoint
    • resource.backends.maxRatePerInstance
    • resource.backends.maxUtilization
    • resource.backends.preference
  • resource.enableCDN
  • resource.cdnPolicy
    • resource.cdnPolicy.bypassCacheOnRequestHeaders
      • resource.cdnPolicy.bypassCacheOnRequestHeaders.headerName
    • resource.cdnPolicy.cacheKeyPolicy
      • resource.cdnPolicy.cacheKeyPolicy.includeHost
      • resource.cdnPolicy.cacheKeyPolicy.includeHttpHeaders
      • resource.cdnPolicy.cacheKeyPolicy.includeNamedCookies
      • resource.cdnPolicy.cacheKeyPolicy.includeProtocol
      • resource.cdnPolicy.cacheKeyPolicy.includeQueryString
      • resource.cdnPolicy.cacheKeyPolicy.queryStringBlacklist
      • resource.cdnPolicy.cacheKeyPolicy.queryStringWhitelist
    • resource.cdnPolicy.cacheMode
    • resource.cdnPolicy.clientTtl
    • resource.cdnPolicy.defaultTtl
    • resource.cdnPolicy.maxTtl
    • resource.cdnPolicy.negativeCaching
    • resource.cdnPolicy.negativeCachingPolicy
      • resource.cdnPolicy.negativeCachingPolicy.code
      • resource.cdnPolicy.negativeCachingPolicy.ttl
    • resource.cdnPolicy.requestCoalescing
    • resource.cdnPolicy.serveWhileStale
    • resource.cdnPolicy.signedUrlCacheMaxAgeSec
  • resource.circuitBreakers
    • resource.circuitBreakers.maxConnections
    • resource.circuitBreakers.maxPendingRequests
    • resource.circuitBreakers.maxRequests
    • resource.circuitBreakers.maxRequestsPerConnection
    • resource.circuitBreakers.maxRetries
  • resource.compressionMode
  • resource.connectionDraining
    • resource.connectionDraining.drainingTimeoutSec
  • resource.connectionTrackingPolicy
    • resource.connectionTrackingPolicy.connectionPersistenceOnUnhealthyBackends
    • resource.connectionTrackingPolicy.enableStrongAffinity
    • resource.connectionTrackingPolicy.idleTimeoutSec
    • resource.connectionTrackingPolicy.trackingMode
  • resource.consistentHash
    • resource.consistentHash.httpCookie
    • resource.consistentHash.httpCookie.name
    • resource.consistentHash.httpCookie.path
    • resource.consistentHash.httpCookie.ttl
      • resource.consistentHash.httpCookie.ttl.nanos
      • resource.consistentHash.httpCookie.ttl.seconds
    • resource.consistentHash.minimumRingSize
  • resource.customRequestHeaders
  • resource.customResponseHeaders
  • resource.affinityCookieTtlSec
  • resource.failoverPolicy
    • resource.failoverPolicy.disableConnectionDrainOnFailover
    • resource.failoverPolicy.dropTrafficIfUnhealthy
    • resource.failoverPolicy.failoverRatio
  • resource.iap
    • resource.iap.enabled
    • resource.iap.oauth2ClientId
  • resource.ipAddressSelectionPolicy
  • resource.loadBalancingScheme
  • resource.localityLbPolicies
    • resource.localityLbPolicies.customPolicy
    • resource.localityLbPolicies.customPolicy.data
    • resource.localityLbPolicies.customPolicy.name
    • resource.localityLbPolicies.policy
    • resource.localityLbPolicies.policy.name
  • resource.logConfig
    • resource.logConfig.enable
    • resource.logConfig.optionalFields
    • resource.logConfig.optionalMode
    • resource.logConfig.sampleRate
  • resource.maxStreamDuration
    • resource.maxStreamDuration.nanos
    • resource.maxStreamDuration.seconds
  • resource.outlierDetection
    • resource.outlierDetection.baseEjectionTime
    • resource.outlierDetection.baseEjectionTime.nanos
    • resource.outlierDetection.baseEjectionTime.seconds
    • resource.outlierDetection.consecutiveGatewayFailure
    • resource.outlierDetection.enforcingConsecutiveErrors
    • resource.outlierDetection.enforcingConsecutiveGatewayFailure
    • resource.outlierDetection.enforcingSuccessRate
    • resource.outlierDetection.maxEjectionPercent
    • resource.outlierDetection.successRateMinimumHosts
    • resource.outlierDetection.successRateRequestVolume
    • resource.outlierDetection.successRateStdevFactor
  • resource.securitySettings
    • resource.securitySettings.awsV4Authentication
    • resource.securitySettings.awsV4Authentication.accessKeyId
    • resource.securitySettings.awsV4Authentication.accessKeyVersion
    • resource.securitySettings.subjectAltNames
  • resource.sessionAffinity
  • resource.subsetting
    • resource.subsetting.policy
  • resource.timeoutSec
  • resource.strongSessionAffinityCookie
    • resource.strongSessionAffinityCookie.name
    • resource.strongSessionAffinityCookie.path
    • resource.strongSessionAffinityCookie.ttl
    • resource.strongSessionAffinityCookie.ttl.nanos
    • resource.strongSessionAffinityCookie.ttl.seconds

轉送規則

轉送規則compute.googleapis.com/ForwardingRule

  • resource.name
  • resource.description
  • resource.allowGlobalAccess
  • resource.allowPscGlobalAccess
  • resource.allPorts
  • resource.IPProtocol
  • resource.ipVersion
  • resource.isMirroringCollector
  • resource.loadBalancingScheme
  • resource.metadataFilters
    • resource.metadataFilters.filterLabels
    • resource.metadataFilters.filterLabels.name
    • resource.metadataFilters.filterLabels.value
    • resource.metadataFilters.filterMatchCriteria
  • resource.networkTier
  • resource.noAutomateDnsZone
  • resource.portRange
  • resource.ports
  • resource.serviceDirectoryRegistrations
    • resource.serviceDirectoryRegistrations.namespace
    • resource.serviceDirectoryRegistrations.service
    • resource.serviceDirectoryRegistrations.serviceDirectoryRegion
  • resource.serviceLabel
  • resource.sourceIpRanges

健康狀態檢查

健康檢查compute.googleapis.com/HealthCheck

  • resource.name
  • resource.description
  • resource.checkIntervalSec
  • resource.timeoutSec
  • resource.unhealthyThreshold
  • resource.healthyThreshold
  • resource.type
  • TCP 健康狀態檢查:
    • resource.tcpHealthCheck.port
    • resource.tcpHealthCheck.request
    • resource.tcpHealthCheck.response
    • resource.tcpHealthCheck.proxyHeader
    • resource.tcpHealthCheck.portSpecification
  • SSL 健康狀態檢查:
    • resource.sslHealthCheck.port
    • resource.sslHealthCheck.request
    • resource.sslHealthCheck.response
    • resource.sslHealthCheck.proxyHeader
    • resource.sslHealthCheck.portSpecification
  • HTTP 健康狀態檢查:
    • resource.httpHealthCheck.port
    • resource.httpHealthCheck.host
    • resource.httpHealthCheck.requestPath
    • resource.httpHealthCheck.proxyHeader
    • resource.httpHealthCheck.response
    • resource.httpHealthCheck.portSpecification
  • HTTPS 健康狀態檢查:
    • resource.httpsHealthCheck.port
    • resource.httpsHealthCheck.host
    • resource.httpsHealthCheck.requestPath
    • resource.httpsHealthCheck.proxyHeader
    • resource.httpsHealthCheck.response
    • resource.httpsHealthCheck.portSpecification
  • HTTP/2 健康狀態檢查:
    • resource.http2HealthCheck.port
    • resource.http2HealthCheck.host
    • resource.http2HealthCheck.requestPath
    • resource.http2HealthCheck.proxyHeader
    • resource.http2HealthCheck.response
    • resource.http2HealthCheck.portSpecification
  • gRPC 健康狀態檢查:
    • resource.grpcHealthCheck.port
    • resource.grpcHealthCheck.grpcServiceName
    • resource.grpcHealthCheck.portSpecification
  • resource.sourceRegions
  • resource.logConfig
    • resource.logConfig.enable

網路端點群組

網路端點群組compute.googleapis.com/NetworkEndpointGroup

  • resource.annotations
  • resource.appEngine.service
  • resource.appEngine.urlMask
  • resource.appEngine.version
  • resource.cloudFunction.function
  • resource.cloudFunction.urlMask
  • resource.cloudRun.service
  • resource.cloudRun.tag
  • resource.cloudRun.urlMask
  • resource.defaultPort
  • resource.description
  • resource.name
  • resource.network
  • resource.networkEndpointType
  • resource.pscData.producerPort
  • resource.pscTargetService
  • resource.subnetwork

服務負載平衡政策

服務負載平衡政策networkservices.googleapis.com/ServiceLbPolicy

  • resource.autoCapacityDrain.enable
  • resource.description
  • resource.failoverConfig.failoverHealthThreshold
  • resource.loadBalancingAlgorithm
  • resource.name

安全資料傳輸層 (SSL) 政策

SSL 政策compute.googleapis.com/SslPolicy

  • resource.profile
  • resource.name
  • resource.description
  • resource.minTlsVersion
  • resource.customFeatures

目標執行個體

目標執行個體compute.googleapis.com/TargetInstance

  • resource.name
  • resource.description
  • resource.natPolicy

目標集區

目標集區compute.googleapis.com/TargetPool

  • resource.name
  • resource.description
  • resource.sessionAffinity
  • resource.failoverRatio

目標 Proxy

目標 TCP Proxycompute.googleapis.com/TargetTcpProxy

  • resource.name
  • resource.description
  • resource.proxyBind
  • resource.proxyHeader

目標 SSL Proxycompute.googleapis.com/TargetSslProxy

  • resource.name
  • resource.description
  • resource.proxyHeader

目標 HTTP Proxycompute.googleapis.com/TargetHttpProxy

  • resource.name
  • resource.description
  • resource.proxyBind
  • resource.httpKeepAliveTimeoutSec

目標 HTTPS Proxy 伺服器compute.googleapis.com/TargetHttpsProxy

  • resource.name
  • resource.description
  • resource.proxyBind
  • resource.httpKeepAliveTimeoutSec
  • resource.quicOverride
  • resource.tlsEarlyData

目標 gRPC Proxycompute.googleapis.com/TargetGrpcProxy

  • resource.name
  • resource.description
  • resource.validateForProxyless

網址對應

網址對應compute.googleapis.com/UrlMap

  • resource.name
  • resource.description
  • resource.defaultCustomErrorResponsePolicy
    • resource.defaultCustomErrorResponsePolicy.errorResponseRules
      • resource.defaultCustomErrorResponsePolicy.errorResponseRules.matchResponseCodes
      • resource.defaultCustomErrorResponsePolicy.errorResponseRules.overrideResponseCode
      • resource.defaultCustomErrorResponsePolicy.errorResponseRules.path
  • resource.defaultRouteAction
    • resource.defaultRouteAction.corsPolicy
    • resource.defaultRouteAction.corsPolicy.allowCredentials
    • resource.defaultRouteAction.corsPolicy.allowHeaders
    • resource.defaultRouteAction.corsPolicy.allowMethods
    • resource.defaultRouteAction.corsPolicy.allowOrigins
    • resource.defaultRouteAction.corsPolicy.allowOriginRegexes
    • resource.defaultRouteAction.corsPolicy.disabled
    • resource.defaultRouteAction.corsPolicy.exposeHeaders
    • resource.defaultRouteAction.corsPolicy.maxAge
    • resource.defaultRouteAction.faultInjectionPolicy
    • resource.defaultRouteAction.faultInjectionPolicy.abort
      • resource.defaultRouteAction.faultInjectionPolicy.abort.httpStatus
      • resource.defaultRouteAction.faultInjectionPolicy.abort.percentage
    • resource.defaultRouteAction.faultInjectionPolicy.delay
      • resource.defaultRouteAction.faultInjectionPolicy.delay.percentage
      • resource.defaultRouteAction.faultInjectionPolicy.delay.fixedDelay
      • resource.defaultRouteAction.faultInjectionPolicy.delay.fixedDelay.nanos
      • resource.defaultRouteAction.faultInjectionPolicy.delay.fixedDelay.seconds
    • resource.defaultRouteAction.maxStreamDuration
    • resource.defaultRouteAction.maxStreamDuration.nanos
    • resource.defaultRouteAction.maxStreamDuration.seconds
    • resource.defaultRouteAction.requestMirrorPolicy
    • resource.defaultRouteAction.retryPolicy
    • resource.defaultRouteAction.retryPolicy.numRetries
    • resource.defaultRouteAction.retryPolicy.perTryTimeout
      • resource.defaultRouteAction.retryPolicy.perTryTimeout.nanos
      • resource.defaultRouteAction.retryPolicy.perTryTimeout.seconds
    • resource.defaultRouteAction.retryPolicy.retryConditions
    • resource.defaultRouteAction.timeout
    • resource.defaultRouteAction.timeout.nanos
    • resource.defaultRouteAction.timeout.seconds
    • resource.defaultRouteAction.urlRewrite
    • resource.defaultRouteAction.urlRewrite.hostRewrite
    • resource.defaultRouteAction.urlRewrite.pathPrefixRewrite
    • resource.defaultRouteAction.urlRewrite.pathTemplateRewrite
    • resource.defaultRouteAction.weightedBackendServices
    • resource.defaultRouteAction.weightedBackendServices.headerAction
      • resource.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToAdd
      • resource.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToAdd.headerName
      • resource.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToAdd.headerValue
      • resource.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToAdd.replace
      • resource.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToRemove
      • resource.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToAdd
      • resource.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToAdd.headerName
      • resource.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToAdd.headerValue
      • resource.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToAdd.replace
      • resource.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToRemove
    • resource.defaultRouteAction.weightedBackendServices.weight
  • resource.defaultUrlRedirect
    • resource.defaultUrlRedirect.hostRedirect
    • resource.defaultUrlRedirect.httpsRedirect
    • resource.defaultUrlRedirect.pathRedirect
    • resource.defaultUrlRedirect.prefixRedirect
    • resource.defaultUrlRedirect.redirectResponseCode
    • resource.defaultUrlRedirect.stripQuery
  • resource.headerAction
    • resource.headerAction.requestHeadersToAdd
    • resource.headerAction.requestHeadersToAdd.headerName
    • resource.headerAction.requestHeadersToAdd.headerValue
    • resource.headerAction.requestHeadersToAdd.replace
    • resource.headerAction.requestHeadersToRemove
    • resource.headerAction.responseHeadersToAdd
    • resource.headerAction.responseHeadersToAdd.headerName
    • resource.headerAction.responseHeadersToAdd.headerValue
    • resource.headerAction.responseHeadersToAdd.replace
    • resource.headerAction.responseHeadersToRemove
  • resource.hostRules
    • resource.hostRules.description
    • resource.hostRules.hosts
    • resource.hostRules.pathMatcher
  • resource.pathMatchers
    • resource.pathMatchers.name
    • resource.pathMatchers.description
    • resource.pathMatchers.defaultCustomErrorResponsePolicy
    • resource.pathMatchers.defaultCustomErrorResponsePolicy.errorResponseRules
      • resource.pathMatchers.defaultCustomErrorResponsePolicy.errorResponseRules.matchResponseCodes
      • resource.pathMatchers.defaultCustomErrorResponsePolicy.errorResponseRules.overrideResponseCode
      • resource.pathMatchers.defaultCustomErrorResponsePolicy.errorResponseRules.path
    • resource.pathMatchers.defaultRouteAction
    • resource.pathMatchers.defaultRouteAction.corsPolicy
      • resource.pathMatchers.defaultRouteAction.corsPolicy.allowCredentials
      • resource.pathMatchers.defaultRouteAction.corsPolicy.allowHeaders
      • resource.pathMatchers.defaultRouteAction.corsPolicy.allowMethods
      • resource.pathMatchers.defaultRouteAction.corsPolicy.allowOrigins
      • resource.pathMatchers.defaultRouteAction.corsPolicy.allowOriginRegexes
      • resource.pathMatchers.defaultRouteAction.corsPolicy.disabled
      • resource.pathMatchers.defaultRouteAction.corsPolicy.exposeHeaders
      • resource.pathMatchers.defaultRouteAction.corsPolicy.maxAge
    • resource.pathMatchers.defaultRouteAction.faultInjectionPolicy
      • resource.pathMatchers.defaultRouteAction.faultInjectionPolicy.abort
      • resource.pathMatchers.defaultRouteAction.faultInjectionPolicy.abort.httpStatus
      • resource.pathMatchers.defaultRouteAction.faultInjectionPolicy.abort.percentage
      • resource.pathMatchers.defaultRouteAction.faultInjectionPolicy.delay
      • resource.pathMatchers.defaultRouteAction.faultInjectionPolicy.delay.percentage
      • resource.pathMatchers.defaultRouteAction.faultInjectionPolicy.delay.fixedDelay
        • resource.pathMatchers.defaultRouteAction.faultInjectionPolicy.delay.fixedDelay.nanos
        • resource.pathMatchers.defaultRouteAction.faultInjectionPolicy.delay.fixedDelay.seconds
    • resource.pathMatchers.defaultRouteAction.maxStreamDuration
      • resource.pathMatchers.defaultRouteAction.maxStreamDuration.nanos
      • resource.pathMatchers.defaultRouteAction.maxStreamDuration.seconds
    • resource.pathMatchers.defaultRouteAction.requestMirrorPolicy
    • resource.pathMatchers.defaultRouteAction.retryPolicy
      • resource.pathMatchers.defaultRouteAction.retryPolicy.numRetries
      • resource.pathMatchers.defaultRouteAction.retryPolicy.perTryTimeout
      • resource.pathMatchers.defaultRouteAction.retryPolicy.perTryTimeout.nanos
      • resource.pathMatchers.defaultRouteAction.retryPolicy.perTryTimeout.seconds
      • resource.pathMatchers.defaultRouteAction.retryPolicy.retryConditions
    • resource.pathMatchers.defaultRouteAction.timeout
      • resource.pathMatchers.defaultRouteAction.timeout.nanos
      • resource.pathMatchers.defaultRouteAction.timeout.seconds
    • resource.pathMatchers.defaultRouteAction.urlRewrite
      • resource.pathMatchers.defaultRouteAction.urlRewrite.hostRewrite
      • resource.pathMatchers.defaultRouteAction.urlRewrite.pathPrefixRewrite
      • resource.pathMatchers.defaultRouteAction.urlRewrite.pathTemplateRewrite
    • resource.pathMatchers.defaultRouteAction.weightedBackendServices
      • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction
      • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToAdd
        • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToAdd.headerName
        • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToAdd.headerValue
        • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToAdd.replace
      • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.requestHeadersToRemove
      • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToAdd
        • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToAdd.headerName
        • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToAdd.headerValue
        • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToAdd.replace
      • resource.pathMatchers.defaultRouteAction.weightedBackendServices.headerAction.responseHeadersToRemove
      • resource.pathMatchers.defaultRouteAction.weightedBackendServices.weight
    • resource.pathMatchers.defaultUrlRedirect
    • resource.pathMatchers.defaultUrlRedirect.hostRedirect
    • resource.pathMatchers.defaultUrlRedirect.httpsRedirect
    • resource.pathMatchers.defaultUrlRedirect.pathRedirect
    • resource.pathMatchers.defaultUrlRedirect.prefixRedirect
    • resource.pathMatchers.defaultUrlRedirect.redirectResponseCode
    • resource.pathMatchers.defaultUrlRedirect.stripQuery
    • resource.pathMatchers.headerAction
    • resource.pathMatchers.headerAction.requestHeadersToAdd
    • resource.pathMatchers.headerAction.requestHeadersToAdd.headerName
    • resource.pathMatchers.headerAction.requestHeadersToAdd.headerValue
    • resource.pathMatchers.headerAction.requestHeadersToAdd.replace
    • resource.pathMatchers.headerAction.requestHeadersToRemove
    • resource.pathMatchers.headerAction.responseHeadersToAdd
    • resource.pathMatchers.headerAction.responseHeadersToAdd.headerName
    • resource.pathMatchers.headerAction.responseHeadersToAdd.headerValue
    • resource.pathMatchers.headerAction.responseHeadersToAdd.replace
    • resource.pathMatchers.headerAction.responseHeadersToRemove
    • resource.pathMatchers.pathRules
    • resource.pathMatchers.pathRules.paths
    • resource.pathMatchers.pathRules.customErrorResponsePolicy
      • resource.pathMatchers.pathRules.customErrorResponsePolicy.errorResponseRules
      • resource.pathMatchers.pathRules.customErrorResponsePolicy.errorResponseRules.matchResponseCodes
      • resource.pathMatchers.pathRules.customErrorResponsePolicy.errorResponseRules.overrideResponseCode
      • resource.pathMatchers.pathRules.customErrorResponsePolicy.errorResponseRules.path
    • resource.pathMatchers.pathRules.routeAction
      • resource.pathMatchers.pathRules.routeAction.corsPolicy
      • resource.pathMatchers.pathRules.routeAction.corsPolicy.allowCredentials
      • resource.pathMatchers.pathRules.routeAction.corsPolicy.allowHeaders
      • resource.pathMatchers.pathRules.routeAction.corsPolicy.allowMethods
      • resource.pathMatchers.pathRules.routeAction.corsPolicy.allowOrigins
      • resource.pathMatchers.pathRules.routeAction.corsPolicy.allowOriginRegexes
      • resource.pathMatchers.pathRules.routeAction.corsPolicy.disabled
      • resource.pathMatchers.pathRules.routeAction.corsPolicy.exposeHeaders
      • resource.pathMatchers.pathRules.routeAction.corsPolicy.maxAge
      • resource.pathMatchers.pathRules.routeAction.faultInjectionPolicy
      • resource.pathMatchers.pathRules.routeAction.faultInjectionPolicy.abort
        • resource.pathMatchers.pathRules.routeAction.faultInjectionPolicy.abort.httpStatus
        • resource.pathMatchers.pathRules.routeAction.faultInjectionPolicy.abort.percentage
      • resource.pathMatchers.pathRules.routeAction.faultInjectionPolicy.delay
        • resource.pathMatchers.pathRules.routeAction.faultInjectionPolicy.delay.percentage
        • resource.pathMatchers.pathRules.routeAction.faultInjectionPolicy.delay.fixedDelay
        • resource.pathMatchers.pathRules.routeAction.faultInjectionPolicy.delay.fixedDelay.nanos
        • resource.pathMatchers.pathRules.routeAction.faultInjectionPolicy.delay.fixedDelay.seconds
      • resource.pathMatchers.pathRules.routeAction.maxStreamDuration
      • resource.pathMatchers.pathRules.routeAction.maxStreamDuration.nanos
      • resource.pathMatchers.pathRules.routeAction.maxStreamDuration.seconds
      • resource.pathMatchers.pathRules.routeAction.requestMirrorPolicy
      • resource.pathMatchers.pathRules.routeAction.retryPolicy
      • resource.pathMatchers.pathRules.routeAction.retryPolicy.numRetries
      • resource.pathMatchers.pathRules.routeAction.retryPolicy.perTryTimeout
        • resource.pathMatchers.pathRules.routeAction.retryPolicy.perTryTimeout.nanos
        • resource.pathMatchers.pathRules.routeAction.retryPolicy.perTryTimeout.seconds
      • resource.pathMatchers.pathRules.routeAction.retryPolicy.retryConditions
      • resource.pathMatchers.pathRules.routeAction.timeout
      • resource.pathMatchers.pathRules.routeAction.timeout.nanos
      • resource.pathMatchers.pathRules.routeAction.timeout.seconds
      • resource.pathMatchers.pathRules.routeAction.urlRewrite
      • resource.pathMatchers.pathRules.routeAction.urlRewrite.hostRewrite
      • resource.pathMatchers.pathRules.routeAction.urlRewrite.pathPrefixRewrite
      • resource.pathMatchers.pathRules.routeAction.urlRewrite.pathTemplateRewrite
      • resource.pathMatchers.pathRules.routeAction.weightedBackendServices
      • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.requestHeadersToAdd
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.requestHeadersToAdd.headerName
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.requestHeadersToAdd.headerValue
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.requestHeadersToAdd.replace
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.requestHeadersToRemove
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.responseHeadersToAdd
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.responseHeadersToAdd.headerName
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.responseHeadersToAdd.headerValue
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.responseHeadersToAdd.replace
        • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.headerAction.responseHeadersToRemove
      • resource.pathMatchers.pathRules.routeAction.weightedBackendServices.weight
    • resource.pathMatchers.pathRules.urlRedirect
      • resource.pathMatchers.pathRules.urlRedirect.hostRedirect
      • resource.pathMatchers.pathRules.urlRedirect.httpsRedirect
      • resource.pathMatchers.pathRules.urlRedirect.pathRedirect
      • resource.pathMatchers.pathRules.urlRedirect.prefixRedirect
      • resource.pathMatchers.pathRules.urlRedirect.redirectResponseCode
      • resource.pathMatchers.pathRules.urlRedirect.stripQuery
    • resource.pathMatchers.routeRules
    • resource.pathMatchers.routeRules.description
    • resource.pathMatchers.routeRules.priority
    • resource.pathMatchers.routeRules.customErrorResponsePolicy
      • resource.pathMatchers.routeRules.customErrorResponsePolicy.errorResponseRules
      • resource.pathMatchers.routeRules.customErrorResponsePolicy.errorResponseRules.matchResponseCodes
      • resource.pathMatchers.routeRules.customErrorResponsePolicy.errorResponseRules.overrideResponseCode
      • resource.pathMatchers.routeRules.customErrorResponsePolicy.errorResponseRules.path
    • resource.pathMatchers.routeRules.headerAction
      • resource.pathMatchers.routeRules.headerAction.requestHeadersToAdd
      • resource.pathMatchers.routeRules.headerAction.requestHeadersToAdd.headerName
      • resource.pathMatchers.routeRules.headerAction.requestHeadersToAdd.headerValue
      • resource.pathMatchers.routeRules.headerAction.requestHeadersToAdd.replace
      • resource.pathMatchers.routeRules.headerAction.requestHeadersToRemove
      • resource.pathMatchers.routeRules.headerAction.responseHeadersToAdd
      • resource.pathMatchers.routeRules.headerAction.responseHeadersToAdd.headerName
      • resource.pathMatchers.routeRules.headerAction.responseHeadersToAdd.headerValue
      • resource.pathMatchers.routeRules.headerAction.responseHeadersToAdd.replace
      • resource.pathMatchers.routeRules.headerAction.responseHeadersToRemove
    • resource.pathMatchers.routeRules.matchRules
      • resource.pathMatchers.routeRules.matchRules.fullPathMatch
      • resource.pathMatchers.routeRules.matchRules.headerMatches
      • resource.pathMatchers.routeRules.matchRules.headerMatches.exactMatch
      • resource.pathMatchers.routeRules.matchRules.headerMatches.headerName
      • resource.pathMatchers.routeRules.matchRules.headerMatches.invertMatch
      • resource.pathMatchers.routeRules.matchRules.headerMatches.prefixMatch
      • resource.pathMatchers.routeRules.matchRules.headerMatches.presentMatch
      • resource.pathMatchers.routeRules.matchRules.headerMatches.rangeMatch
        • resource.pathMatchers.routeRules.matchRules.headerMatches.rangeMatch.rangeStart
        • resource.pathMatchers.routeRules.matchRules.headerMatches.rangeMatch.rangeEnd
      • resource.pathMatchers.routeRules.matchRules.headerMatches.regexMatch
      • resource.pathMatchers.routeRules.matchRules.headerMatches.suffixMatch
      • resource.pathMatchers.routeRules.matchRules.ignoreCase
      • resource.pathMatchers.routeRules.matchRules.metadataFilters
      • resource.pathMatchers.routeRules.matchRules.metadataFilters.filterLabels
        • resource.pathMatchers.routeRules.matchRules.metadataFilters.filterLabels.name
        • resource.pathMatchers.routeRules.matchRules.metadataFilters.filterLabels.value
      • resource.pathMatchers.routeRules.matchRules.metadataFilters.filterMatchCriteria
      • resource.pathMatchers.routeRules.matchRules.pathTemplateMatch
      • resource.pathMatchers.routeRules.matchRules.prefixMatch
      • resource.pathMatchers.routeRules.matchRules.queryParameterMatches
      • resource.pathMatchers.routeRules.matchRules.queryParameterMatches.name
      • resource.pathMatchers.routeRules.matchRules.queryParameterMatches.exactMatch
      • resource.pathMatchers.routeRules.matchRules.queryParameterMatches.presentMatch
      • resource.pathMatchers.routeRules.matchRules.queryParameterMatches.regexMatch
      • resource.pathMatchers.routeRules.matchRules.regexMatch
    • resource.pathMatchers.routeRules.routeAction
      • resource.pathMatchers.routeRules.routeAction.corsPolicy
      • resource.pathMatchers.routeRules.routeAction.corsPolicy.allowCredentials
      • resource.pathMatchers.routeRules.routeAction.corsPolicy.allowHeaders
      • resource.pathMatchers.routeRules.routeAction.corsPolicy.allowMethods
      • resource.pathMatchers.routeRules.routeAction.corsPolicy.allowOrigins
      • resource.pathMatchers.routeRules.routeAction.corsPolicy.allowOriginRegexes
      • resource.pathMatchers.routeRules.routeAction.corsPolicy.disabled
      • resource.pathMatchers.routeRules.routeAction.corsPolicy.exposeHeaders
      • resource.pathMatchers.routeRules.routeAction.corsPolicy.maxAge
      • resource.pathMatchers.routeRules.routeAction.faultInjectionPolicy
      • resource.pathMatchers.routeRules.routeAction.faultInjectionPolicy.abort
        • resource.pathMatchers.routeRules.routeAction.faultInjectionPolicy.abort.httpStatus
        • resource.pathMatchers.routeRules.routeAction.faultInjectionPolicy.abort.percentage
      • resource.pathMatchers.routeRules.routeAction.faultInjectionPolicy.delay
        • resource.pathMatchers.routeRules.routeAction.faultInjectionPolicy.delay.percentage
        • resource.pathMatchers.routeRules.routeAction.faultInjectionPolicy.delay.fixedDelay
        • resource.pathMatchers.routeRules.routeAction.faultInjectionPolicy.delay.fixedDelay.nanos
        • resource.pathMatchers.routeRules.routeAction.faultInjectionPolicy.delay.fixedDelay.seconds
      • resource.pathMatchers.routeRules.routeAction.maxStreamDuration
      • resource.pathMatchers.routeRules.routeAction.maxStreamDuration.nanos
      • resource.pathMatchers.routeRules.routeAction.maxStreamDuration.seconds
      • resource.pathMatchers.routeRules.routeAction.requestMirrorPolicy
      • resource.pathMatchers.routeRules.routeAction.retryPolicy
      • resource.pathMatchers.routeRules.routeAction.retryPolicy.numRetries
      • resource.pathMatchers.routeRules.routeAction.retryPolicy.perTryTimeout
        • resource.pathMatchers.routeRules.routeAction.retryPolicy.perTryTimeout.nanos
        • resource.pathMatchers.routeRules.routeAction.retryPolicy.perTryTimeout.seconds
      • resource.pathMatchers.routeRules.routeAction.retryPolicy.retryConditions
      • resource.pathMatchers.routeRules.routeAction.timeout
      • resource.pathMatchers.routeRules.routeAction.timeout.nanos
      • resource.pathMatchers.routeRules.routeAction.timeout.seconds
      • resource.pathMatchers.routeRules.routeAction.urlRewrite
      • resource.pathMatchers.routeRules.routeAction.urlRewrite.hostRewrite
      • resource.pathMatchers.routeRules.routeAction.urlRewrite.pathPrefixRewrite
      • resource.pathMatchers.routeRules.routeAction.urlRewrite.pathTemplateRewrite
      • resource.pathMatchers.routeRules.routeAction.weightedBackendServices
      • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.requestHeadersToAdd
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.requestHeadersToAdd.headerName
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.requestHeadersToAdd.headerValue
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.requestHeadersToAdd.replace
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.requestHeadersToRemove
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.responseHeadersToAdd
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.responseHeadersToAdd.headerName
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.responseHeadersToAdd.headerValue
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.responseHeadersToAdd.replace
        • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.headerAction.responseHeadersToRemove
      • resource.pathMatchers.routeRules.routeAction.weightedBackendServices.weight
    • resource.pathMatchers.routeRules.urlRedirect
      • resource.pathMatchers.routeRules.urlRedirect.hostRedirect
      • resource.pathMatchers.routeRules.urlRedirect.httpsRedirect
      • resource.pathMatchers.routeRules.urlRedirect.pathRedirect
      • resource.pathMatchers.routeRules.urlRedirect.prefixRedirect
      • resource.pathMatchers.routeRules.urlRedirect.redirectResponseCode
      • resource.pathMatchers.routeRules.urlRedirect.stripQuery
  • resource.tests
    • resource.tests.description
    • resource.tests.expectedOutputUrl
    • resource.tests.expectedRedirectResponseCode
    • resource.tests.headers
    • resource.tests.headers.name
    • resource.tests.headers.value
    • resource.tests.host
    • resource.tests.path

如需其他支援的運算資源,請參閱 Compute Engine 自訂限制頁面

政策繼承

根據預設,機構政策會由您強制執行政策的資源子系繼承。舉例來說,如果您對資料夾強制執行政策, Google Cloud 系統會對該資料夾中的所有專案強制執行政策。如要進一步瞭解這項行為及如何變更,請參閱「階層評估規則」。

事前準備

  • 如果尚未設定驗證,請先完成設定。 「驗證」是指驗證身分的程序,確認您有權存取 Google Cloud 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:

    Select the tab for how you plan to use the samples on this page:

    Console

    When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.

    gcloud

    1. 安裝 Google Cloud CLI。 安裝完成後,執行下列指令初始化 Google Cloud CLI:

      gcloud init

      如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

    2. Set a default region and zone.

必要的角色

如要取得管理 Cloud Load Balancing 資源機構政策所需的權限,請要求管理員授予下列 IAM 角色:

  • 機構政策管理員 (roles/orgpolicy.policyAdmin) 機構資源類型
  • 如要測試負載平衡資源的限制,請在專案資源上啟用「Compute Load Balancer Admin (v1)」 (roles/compute.loadBalancerAdmin.v1)。

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

這些預先定義的角色具備管理 Cloud Load Balancing 資源組織政策所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:

所需權限

如要管理 Cloud Load Balancing 資源的組織政策,必須具備下列權限:

  • orgpolicy.constraints.list
  • orgpolicy.policies.create
  • orgpolicy.policies.delete
  • orgpolicy.policies.list
  • orgpolicy.policies.update
  • orgpolicy.policy.get
  • orgpolicy.policy.set

您或許還可透過自訂角色或其他預先定義的角色取得這些權限。

設定自訂限制

自訂限制是由資源、方法、條件和動作所定義,這些項目受到您要強制執行機構政策的服務支援。自訂限制的條件是使用一般運算語言 (CEL) 定義。如要進一步瞭解如何使用 CEL 在自訂限制中建立條件,請參閱「建立及管理自訂機構組織政策」的 CEL 一節。

您可以使用 Google Cloud 控制台或 gcloud CLI 建立自訂限制,並設定在機構政策中使用。

控制台

  1. 前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。

    前往「機構政策」

  2. 選取頁面頂端的專案挑選器。

  3. 在「選取資源」視窗中,選取要建立自訂限制的機構。

  4. 按一下「自訂限制」

  5. 在「顯示名稱」方塊中,輸入容易理解的限制名稱。這個欄位的長度上限為 200 個字元。 請勿在限制名稱中輸入 PII 或機密資料,因為錯誤訊息可能會顯示上述資訊。

  6. 在「Constraint ID」(限制條件 ID) 方塊中,輸入新自訂限制條件的名稱。自訂限制必須以 custom. 開頭,且只能包含大寫英文字母、小寫英文字母或數字,例如 custom.enforceTCPHealthCheckPort1024。這個欄位的長度上限為 70 個字元,不含前置字元,例如 organizations/123456789/customConstraints/custom.

  7. 在「Description」方塊中,輸入限制的易讀說明,違反政策時會以錯誤訊息形式顯示。 這個欄位的長度上限為 2000 個字元。

  8. 在「Resource type」方塊中,選取包含要限制物件和欄位的 Google Cloud REST 資源名稱。例如:compute.googleapis.com/HealthCheck

  9. 在「強制執行方式」下方,選取是否要對 REST CREATE 方法強制執行限制。

  10. 如要定義條件,請按一下「編輯條件」

    1. 在「新增條件」面板中,建立參照支援服務資源的 CEL 條件,例如 resource.tcpHealthCheck.port >= 1024。這個欄位的長度上限為 1000 個字元。

    2. 按一下 [儲存]

  11. 在「動作」下方,選取是否要在符合先前條件時允許或拒絕評估方法。

  12. 按一下「建立限制」

在每個欄位中輸入值後,右側會顯示這個自訂限制的對等 YAML 設定。

gcloud

如要使用 gcloud CLI 建立自訂限制,請建立自訂限制的 YAML 檔案:

name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
resource_types:
- compute.googleapis.com/RESOURCE_NAME
method_types:
- CREATE
- UPDATE
condition: CONDITION
action_type: ACTION
display_name: DISPLAY_NAME
description: DESCRIPTION

更改下列內容:

  • ORGANIZATION_ID:您的機構 ID,例如 123456789

  • CONSTRAINT_NAME:新自訂限制的名稱。自訂限制條件必須以 custom. 開頭,且只能包含大寫英文字母、小寫英文字母或數字。例如,custom.enforceTCPHealthCheckPort1024。這個欄位的長度上限為 70 個字元,不含前置字元 (例如 organizations/123456789/customConstraints/custom.)。

  • RESOURCE_NAME:包含要限制物件和欄位的 Compute Engine API REST 資源名稱 (而非 URI)。例如:HealthCheck

  • CONDITION:針對支援服務資源的代表項目編寫的 CEL 條件。這個欄位的長度上限為 1000 個字元。如要進一步瞭解可編寫條件的資源,請參閱「支援的資源」。例如:"resource.tcpHealthCheck.port >= 1024"

  • ACTION:如果符合 condition,則要採取的動作。可以是 ALLOWDENY

  • DISPLAY_NAME:限制條件的易記名稱。這個欄位的長度上限為 200 個字元。

  • DESCRIPTION:違反政策時,要以錯誤訊息形式顯示的限制說明。這個欄位的長度上限為 2000 個字元。

如要進一步瞭解如何建立自訂限制,請參閱「建立及管理自訂機構政策」。

為新的自訂限制建立 YAML 檔案後,您必須進行設定,才能在貴機構的機構政策中使用該檔案。如要設定自訂限制,請使用 gcloud org-policies set-custom-constraint 指令:
gcloud org-policies set-custom-constraint CONSTRAINT_PATH
CONSTRAINT_PATH 替換為自訂限制檔案的完整路徑。例如:/home/user/customconstraint.yaml。 完成後,自訂限制就會顯示在 Google Cloud 機構政策清單中,做為機構政策使用。如要確認自訂限制存在,請使用 gcloud org-policies list-custom-constraints 指令:
gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID
ORGANIZATION_ID 替換為機構資源的 ID。 詳情請參閱「查看組織政策」。

強制執行自訂限制

如要強制執行限制,請建立參照該限制的機構政策,然後將該政策套用至 Google Cloud 資源。

控制台

  1. 前往 Google Cloud 控制台的「Organization policies」(組織政策) 頁面。

    前往「機構政策」

  2. 在專案選擇工具中,選取要設定機構政策的專案。
  3. 在「Organization policies」(機構政策) 頁面上的清單中選取限制條件,即可查看該限制條件的「Policy details」(政策詳情) 頁面。
  4. 如要設定這項資源的機構政策,請按一下「管理政策」
  5. 在「編輯政策」頁面中,選取「覆寫上層政策」
  6. 按一下「新增規則」
  7. 在「Enforcement」(強制執行) 區段中,選取是否要強制執行這項機構政策。
  8. 選用:如要根據標記設定機構政策條件,請按一下「新增條件」。請注意,如果為組織政策新增條件式規則,您必須至少新增一項無條件規則,否則無法儲存政策。詳情請參閱「使用標記設定組織政策」。
  9. 按一下「測試變更」,模擬機構政策的影響。舊版受管理限制不支援政策模擬。詳情請參閱「 使用 Policy Simulator 測試組織政策變更」。
  10. 如要完成並套用機構政策,請按一下「設定政策」。這項政策最多需要 15 分鐘才會生效。

gcloud

如要建立含有布林值規則的機構政策,請建立參照限制的政策 YAML 檔案:

      name: projects/PROJECT_ID/policies/CONSTRAINT_NAME
      spec:
        rules:
        - enforce: true
    

取代下列項目:

  • PROJECT_ID:要強制執行限制的專案。
  • CONSTRAINT_NAME:您為自訂限制定義的名稱。例如:custom.enforceTCPHealthCheckPort1024

如要強制執行包含限制的機構政策,請執行下列指令:

    gcloud org-policies set-policy POLICY_PATH
    

POLICY_PATH 替換為機構政策 YAML 檔案的完整路徑。這項政策最多需要 15 分鐘才會生效。

範例:使用自訂限制來限制 TLS 功能

如要使用自訂限制,限制支援的負載平衡器的 TLS 功能,請在機構中定義使用預先定義 constraints/compute.requireSslPolicy 限制的政策。定義政策後,請按照下列步驟設定及使用自訂限制。

  1. 為預先定義的限制建立 YAML 檔案。

    name: organizations/ORGANIZATION_ID/customConstraints/custom.CONSTRAINT_NAME
    resource_types: compute.googleapis.com/SslPolicy
    methodTypes:
    - CREATE
    - UPDATE
    condition: resource.FIELD_NAME == VALUE
    action_type: ACTION
    display_name: DISPLAY_NAME
    description: DESCRIPTION
    

    以下範例將最低 TLS 版本限制為 1.2:

    name: organizations/012345678901/customConstraints/custom.restrictLbTlsVersion
    resource_types: compute.googleapis.com/SslPolicy
    methodTypes:
    - CREATE
    - UPDATE
    condition: resource.minTlsVersion == "TLS_1_2"
    action_type: ALLOW
    display_name: Restrict Load Balancing TLS version to 1.2
    description: Only allow SSL policies to be created or updated if the minimum TLS version is 1.2 where this custom constraint is enforced.
    

    以下是另一個自訂限制範例,只有在符合下列條件時,才允許建立 SSL 資源:

    • 最低 TLS 版本設為 1.2。
    • SSL 政策提供 CUSTOM 設定檔,可讓您個別選取 SSL 功能。
    • SSL 政策未包含 ChaCha20-Poly1305 密碼套件。
    name: organizations/ORGANIZATION_ID/customConstraints/custom.restrictLbTlsCapabilities
    resourceTypes:
    - compute.googleapis.com/SslPolicy
    methodTypes:
    - CREATE
    - UPDATE
    condition: resource.minTlsVersion == "TLS_1_2" && resource.profile ==
    "CUSTOM" && !resource.customFeatures.exists(feature, feature.contains("CHACHA20_POLY1305"))
    actionType: ALLOW
    displayName: Restrict Load Balancing TLS Capabilities
    description: Only allow SSL Policy resources to be created or updated if the minimum TLS version is 1.2, profile is CUSTOM, and no ChaCha20-Poly1305 cipher suite is used where this custom constraint is enforced.
    
  2. 將自訂限制新增至貴機構。

    gcloud org-policies set-custom-constraint PATH_TO_FILE
    
  3. 確認機構中存在自訂限制。

    gcloud org-policies list-custom-constraints \
        --organization=ORGANIZATION_ID
    
  4. 為限制建立政策檔案。

    name: projects/PROJECT_ID/policies/custom.CONSTRAINT_NAME
    spec:
      rules:
    enforce: true

    更改下列內容:

    • PROJECT_ID:您的 Google Cloud 專案 ID
    • CONSTRAINT_NAME:限制名稱
  5. 強制執行政策。

    gcloud org-policies set-policy PATH_TO_POLICY_FILE
    

    PATH_TO_POLICY_FILE 替換為政策檔案的完整路徑。

  6. 假設您已建立 YAML 檔案,將最低 TLS 版本限制為 1.2,請建立 SSL 政策並將 minTlsVersion 設為 TLS_1_0,藉此測試限制:

    gcloud compute ssl-policies create SSL_POLICY_NAME \
        --min-tls-version=1.0 \
        --project=PROJECT_ID
    

    輸出結果會與下列內容相似:

    ERROR: (gcloud.compute.ssl-policies.update) HTTPError 412: Operation
    denied by custom org policy: [customConstraints/custom.
    restrictLbTlsVersion] : Only allow SSL policy resources to be created or
    updated if the minimum TLS version is 1.2 where this custom constraint
    is enforced.
    

範例:建立限制,將 TCP 健康狀態檢查通訊埠設為至少 1024

以下範例會建立自訂限制和政策,將 TCP 健康狀態檢查通訊埠號碼限制為至少 1024

開始之前,請先瞭解下列事項:

  • 您的機構 ID
  • 專案 ID

gcloud

  1. 建立包含下列資訊的 enforceTCPHealthCheckPort1024.yaml 限制檔案:

    name: organizations/ORGANIZATION_ID/customConstraints/custom.enforceTCPHealthCheckPort1024
    resource_types: compute.googleapis.com/HealthCheck
    condition: "resource.tcpHealthCheck.port >= 1024"
    method_types: CREATE UPDATE
    action_type: ALLOW
    display_name: Only TCP HealthCheck Port >= 1024 Allowed.
    description: Prevent TCP health checks on well-known ports.
  2. 設定自訂限制。

    gcloud org-policies set-custom-constraint enforceTCPHealthCheckPort1024.yaml
    
  3. 建立包含下列資訊的 enforceTCPHealthCheckPort1024-policy.yaml 政策檔案。 在本範例中,我們是在專案層級強制執行這項限制,但您也可以在機構或資料夾層級設定這項限制。將 PROJECT_ID 替換為您的專案 ID。

    name: projects/PROJECT_ID/policies/custom.enforceTCPHealthCheckPort1024
    spec:
      rules:
    enforce: true
  4. 強制執行政策。

    gcloud org-policies set-policy enforceTCPHealthCheckPort1024-policy.yaml
    
  5. 嘗試在不允許的通訊埠 80 上建立 TCP 健康狀態檢查,測試限制。

    gcloud compute health-checks create tcp my-tcp-health-check \
        --project=PROJECT_ID \
        --region=us-central1 \
        --port=80 \
        --check-interval=5s \
        --timeout=5s \
        --healthy-threshold=4 \
        --unhealthy-threshold=5 \
    
    

    輸出結果會與下列內容相似:

    ERROR: (gcloud.compute.healthChecks.create) Could not fetch resource:
    – Operation denied by custom org policies: [customConstraints/custom.enforceTCPHealthCheckPort1024]: Only TCP HealthCheck Port >= 1024 Allowed.
    

常見用途的更多範例

以下各節提供一些實用的自訂限制語法:

後端 bucket

用途 語法
要求所有後端 bucket 啟用 Cloud CDN
name: organizations/ORGANIZATION_ID/customConstraints/custom.backendBucketEnableCdn
resourceTypes:
- compute.googleapis.com/BackendBucket
methodTypes:
- CREATE
- UPDATE
condition: "resource.enableCdn == true"
actionType: ALLOW
displayName: Require all backend buckets to have Cloud CDN enabled
description: All backend buckets must have Cloud CDN enabled.

後端服務

用途 語法
禁止使用 HTTP 和 TCP 做為後端服務通訊協定
name: organizations/ORGANIZATION_ID/customConstraints/custom.backendBucketEnableCdn
resourceTypes:
- compute.googleapis.com/BackendService
methodTypes:
- CREATE
- UPDATE
condition: "resource.serviceProtocol == 'HTTP' || resource.serviceProtocol == 'TCP'"
actionType: DENY
displayName: Disallow the use of HTTP and TCP as backend service protocols
description: Backend services cannot configure HTTP or TCP as the backend service protocol.

轉送規則

用途 語法
使用標準級時必須提供轉送規則
name: organizations/ORGANIZATION_ID/customConstraints/custom.forwardingRulesStandardTier
resourceTypes:
- compute.googleapis.com/ForwardingRule
methodTypes:
- CREATE
- UPDATE
condition: "resource.networkTier == 'STANDARD'"
actionType: ALLOW
displayName: Require forwarding rules to use Standard Tier
description: Forwarding rules must use the Standard Network Service Tier.

健康狀態檢查

用途 語法
要求所有健康狀態檢查通訊協定都發生在通訊埠 1024 以上
name: organizations/ORGANIZATION_ID/customConstraints/custom.healthCheckPortMin1024
resourceTypes:
- compute.googleapis.com/HealthCheck
methodTypes:
- CREATE
- UPDATE
condition: "resource.tcpHealthCheck.port >= 1024 && resource.httpHealthCheck.port >= 1024 && resource.httpsHealthCheck.port >= 1024 && resource.sslHealthCheck.port >= 1024 && resource.sslHealthCheck.port >= 1024 &&resource.http2HealthCheck.port >= 1024 && resource.grpcHealthCheck.port >= 1024"
actionType: ALLOW
displayName: Require port 1024 or greater for all health checks
description: All health check protocols must use a port of 1024 or higher, to avoid well-known ports.
禁止 GRPC 健康狀態檢查
name: organizations/ORGANIZATION_ID/customConstraints/custom.disallowGRPCHealthChecks
resourceTypes:
- compute.googleapis.com/HealthCheck
methodTypes:
- CREATE
- UPDATE
condition: "resource.type == 'GRPC'"
actionType: DENY
displayName: Disallow GRPC health checks
description: Health checks aren't allowed to use GRPC.
防止高頻率健康狀態檢查探測要求
name: organizations/ORGANIZATION_ID/customConstraints/custom.minHealthCheckFrequency
resourceTypes:
- compute.googleapis.com/HealthCheck
methodTypes:
- CREATE
- UPDATE
condition: "resource.checkIntervalSec >= 30"
actionType: ALLOW
displayName: Disallow fast health check probes
description: Prevent health checks from having a probe frequency under 30 seconds.

目標 Proxy

用途 語法
禁止用戶端 HTTPS 保持運作逾時值超過 1000 秒
name: organizations/ORGANIZATION_ID/customConstraints/custom.clientHTTPSKeepalive1000Sec
resourceTypes:
- compute.googleapis.com/TargetHttpsProxy
methodTypes:
- CREATE
- UPDATE
condition: "resource.httpKeepAliveTimeoutSec > 1000"
actionType: DENY
displayName: Disallow client HTTPS keepalive timeout greater than 1000 seconds
description: Disallow client HTTPS keepalive timeout values greater than 1000 seconds.

網址對應

用途 語法
要求網址對應具有 HTTP 500 狀態碼的自訂錯誤回應政策
name: organizations/ORGANIZATION_ID/customConstraints/custom.urlMapCustomResponseHTTP500
resourceTypes:
- compute.googleapis.com/UrlMaps
methodTypes:
- CREATE
- UPDATE
condition: "resource.defaultCustomErrorResponsePolicy.errorResponseRule.exists(value, value.matchResponseCode == 500)"
actionType: ALLOW
displayName: Require URL maps to have a custom error response policy for HTTP 500 errors
description: URL maps must have a custom error response policy configured for HTTP 500 errors.

目標執行個體

用途 語法
要求目標執行個體的名稱開頭為「targetInstance」字串
name: organizations/ORGANIZATION_ID/customConstraints/custom.targetInstanceConstraint
resourceTypes:
- compute.googleapis.com/TargetInstance
methodTypes:
- CREATE
- UPDATE
condition: "resource.name.startsWith('targetInstance')"
actionType: ALLOW
displayName: Require target instances to have a name that starts with the string "targetInstance"
description: Target instances must have resource names that start with the string "targetInstance"

目標集區

用途 語法
要求目標集區具有 CLIENT_IP 工作階段相依性
name: organizations/ORGANIZATION_ID/customConstraints/custom.targetPoolConstraint
resourceTypes:
- compute.googleapis.com/TargetPool
methodTypes:
- CREATE
- UPDATE
condition: "resource.sessionAffinity == 'CLIENT_IP'"
actionType: ALLOW
displayName: Require target pools to use CLIENT_IP session affinity
description: Target pools must use CLIENT_IP session affinity

限制

  • 系統不支援舊版健康狀態檢查 (舊版全域 (HTTP)舊版全域 (HTTPS))。

  • 對於部分 Compute Engine 資源 (例如 Compute Engine SSL 政策資源),系統也會在 UPDATE 方法上強制執行自訂限制。

後續步驟