Common Expression Language (CEL) is an
open source non-Turing complete language that implements common semantics for
expression evaluation. Secure Web Proxy uses a subset of CEL conditions to make
boolean authorization decisions based on attribute data. In general, a condition
expression consists of one or more statements that are joined by logical
operators (&&, ||, or !). Each statement expresses an attribute-based
control rule that applies to the role binding and ultimately determines whether
access is allowed.
Attributes
Use session attributes and application attributes while defining Secure Web Proxy policies to describe either the session attributes or the application attributes that a policy applies to.
Session attributes, described by SessionMatcher, apply to session-specific
attributes such as the source IP address, hosts, and IP range. Application
attributes, described by ApplicationMatcher, apply to application attributes
such as request headers, request method, and request path.
Attributes available to SessionMatcher and ApplicationMatcher
The following table describes attributes that apply to both SessionMatcher and
ApplicationMatcher.
| Attribute | Attribute type | Description | 
|---|---|---|
| source.ip | string | IP address of the client that sent the request. | 
| source.port | integer | Client port that sent the request. | 
| destination.port | integer | Upstream port to which your Secure Web Proxy instance sends the traffic. | 
| host() | string | Host value used for DNS resolution and upstream connections.
        This doesn't include the port.
        The value of **host()** is determined by the following: 
 | 
| source.matchTag(SECURE_TAG) | boolean | 
 The argument is the permanent ID of the secure tag, such as
           | 
| source.matchServiceAccount(SERVICE_ACCOUNT) | boolean | True, if the source is associated withSERVICE_ACCOUNT, such assource.matchServiceAccount('[email protected]'). | 
| inUrlList(HOST_OR_URL, NAMED_LIST) | boolean | 
 
 When a  | 
| inIpRange(IP_ADDRESS, | boolean | True, ifIP_ADDRESSis contained
        within theIP_RANGE, such asinIpRange(source.ip, '1.2.3.0/24'). Subnet masks for IPv6
        addresses can't be larger than /64. | 
Attributes available only to ApplicationMatcher
The following table describes attributes that apply only to
ApplicationMatcher.
| Attribute | Attribute type | Description | 
|---|---|---|
| request.headers | map | String-to-string map of the request headers. If a header contains multiple values, then the value in this map is a comma-separated string of all the values of the header. All keys in this map are in lowercase. | 
| request.method | string | Request method, such as GET or POST. | 
| request.host | string | Convenience equivalent to  We recommend that you use  | 
| request.path | string | Requested URL path. | 
| request.query | string | URL query in the format of
         No decoding is performed. | 
| request.scheme | string | URL scheme, such as HTTP or HTTPS. All values of this attribute are in lowercase. | 
| request.url() | string | Convenience for  This doesn't include the port and uses a host value that might differ from the host header. | 
| request.useragent() | string | Convenience equivalent to request.headers['user-agent']. | 
Operators
Secure Web Proxy supports several operators that can be used to build complex
logic expressions from simple expression statements. Secure Web Proxy supports
logical operators, such as &&, ||, and !, and string manipulation
operators, such as x.contains('y').
The logical operators let you verify multiple variables in a conditional
expression. For example,
request.method == 'GET' && host().matches('.*\.example.com') joins two
statements and requires both statements to be True to produce an
overall result of True.
The string manipulation operators match strings or substrings that you define, and let you develop rules to control access to resources without listing every possible combination.
Logical operators
The following table describes the logical operators that Secure Web Proxy supports.
| Example expression | Description | 
|---|---|
| x == "foo" | Returns Trueifxis equal to the constant
        string literal argument. | 
| x == R"fo'o" | Returns Trueifxis equal to the given raw
        string literal that does not interpret escape sequences. Raw string
        literals are convenient for expressing strings that the code must
        use to escape sequence characters. | 
| x == y | Returns Trueifxis equal toy. | 
|  x != y  | Returns Trueifxis not equal toy. | 
|  x && y  | Returns Trueif bothxandyareTrue. | 
|  x || y  | Returns Trueifx,y, or both
        areTrue. | 
|  !x  | Returns Trueif the boolean valuexisFalse. Otherwise, it returnsFalseif the
        boolean valuexisTrue. | 
|  m['k']  | If key kis present, returns the value at keykin the string-to-string mapm. If keykis not present, it returns an error that
        causes the rule under evaluation to not match. | 
String manipulation operators
The following table describes the string manipulation operators that Secure Web Proxy supports.
| Expression | Description | 
|---|---|
|  x.contains(y)  | Returns Trueif the stringxcontains the
        substringy. | 
|  x.startsWith(y)  | Returns Trueif the stringxbegins with the
        substringy. | 
|  x.endsWith(y)  | Returns Trueif the stringxends with the
        substringy. | 
|  x.matches(y)  | Returns  The RE2 pattern is compiled by using the RE2::Latin1 option that disables Unicode features. | 
|  x.lower()  | Returns the lowercase value of the string x. | 
|  x.upper()  | Returns the uppercase value of the string x. | 
|  x + y  | Returns the concatenated string xy. | 
|  int(x)  | Converts the string result of xto aninttype. You can use the converted string to compare integers with
        standard arithmetic operators such as>and<=. This works only for integer values. |