|
1 | 1 | ---
|
2 |
| -# cSpell:ignore abac, gset, nxon |
| 2 | +# cSpell:ignore abac, gset, nxon, unvalidated |
3 | 3 |
|
4 | 4 | title: Authorization & Policy
|
5 | 5 | lang: en-US
|
@@ -126,17 +126,97 @@ Reapply policies as necessary to any route or namespace:
|
126 | 126 |
|
127 | 127 | ### Rego support
|
128 | 128 |
|
129 |
| -Pomerium Core and Enterprise support policies expressed in [Rego](https://www.openpolicyagent.org/docs/latest/#rego) for organizations that prefer to use [OPA](https://www.openpolicyagent.org/). |
| 129 | +Pomerium supports policies expressed in [Rego](https://www.openpolicyagent.org/docs/latest/#rego) for organizations that prefer to use [OPA](https://www.openpolicyagent.org/). |
130 | 130 |
|
131 |
| -For Enterprise customers, use the **Rego** tab to configure your policy: |
| 131 | +See the [Outputs](#outputs), [Inputs](#inputs), and [Functions](#functions) reference sections below to learn how they apply to policy evaluation. |
132 | 132 |
|
133 |
| - |
| 133 | +#### Outputs |
134 | 134 |
|
135 |
| -:::tip |
| 135 | +Authorization policy written in Rego is expected to return results in `allow` and/or `deny` rules: |
136 | 136 |
|
137 |
| -A policy can only support PPL or Rego. Once one is set, the other tab is disabled. |
| 137 | +```rego |
| 138 | +# a policy that always allows access |
| 139 | +allow := true |
| 140 | +``` |
138 | 141 |
|
139 |
| -::: |
| 142 | +```rego |
| 143 | +# a policy that always denies access |
| 144 | +deny := true |
| 145 | +``` |
| 146 | + |
| 147 | +Pomerium grants access according to the same rules as [PPL](/docs/capabilities/ppl#actions): |
| 148 | + |
| 149 | +> Only two actions are supported: allow and deny. deny takes precedence over allow. More precisely: a user will have access to a route if at least one allow rule matches and no deny rules match. |
| 150 | + |
| 151 | +`allow` and `deny` rules support four forms: |
| 152 | + |
| 153 | +1. A simple boolean: |
| 154 | + |
| 155 | +```rego |
| 156 | +allow := true |
| 157 | +``` |
| 158 | + |
| 159 | +2. An array with a single boolean value: |
| 160 | + |
| 161 | +```rego |
| 162 | +deny := [true] |
| 163 | +``` |
| 164 | + |
| 165 | +3. An array with two values: a boolean and a **reason**: |
| 166 | + |
| 167 | +```rego |
| 168 | +allow := [false, "user-unauthorized"] |
| 169 | +``` |
| 170 | + |
| 171 | +4. An array with three values: a boolean, a reason, and additional data: |
| 172 | + |
| 173 | +```rego |
| 174 | +allow := [false, "user-unauthorized", { "key": "value" }] |
| 175 | +``` |
| 176 | + |
| 177 | +The **reason** value is useful for debugging, since it appears in [authorization logs](/docs/reference/authorize-log-fields#find-authorize-logs). There are two special reasons that trigger functionality in Pomerium: |
| 178 | + |
| 179 | +- `user-unauthenticated` indicates that the user needs to sign in, and results in a redirect to the Authenticate service |
| 180 | +- `device-unauthenticated` indicates that the user needs to register a new device |
| 181 | + |
| 182 | +#### Inputs |
| 183 | + |
| 184 | +Rego scripts are evaluated with inputs available on the `input` object: |
| 185 | + |
| 186 | +```rego |
| 187 | +allow if input.http.method == "POST" |
| 188 | +``` |
| 189 | + |
| 190 | +Rego defines the following inputs: |
| 191 | + |
| 192 | +| **Input name** | **Type** | **Description** | |
| 193 | +| :-- | :-- | :-- | |
| 194 | +| `http` | Object | Represents the HTTP request | |
| 195 | +| `http.method` | String | The method used in the HTTP request | |
| 196 | +| `http.hostname` | String | The hostname in the HTTP request | |
| 197 | +| `http.path` | String | The path in the HTTP request | |
| 198 | +| `http.url` | String | The full URL in the HTTP request | |
| 199 | +| `http.headers` | Object | The headers in the HTTP request | |
| 200 | +| `http.client_certificate` | Object | The client certificate details | |
| 201 | +| `http.client_certificate.presented` | Boolean | `true` if the client presented a certificate | |
| 202 | +| `http.client_certificate.leaf` | String | The leaf certificated provided by the client (unvalidated) | |
| 203 | +| `http.client_certificate.intermediates` | String | The remainder of the client certificate chain | |
| 204 | +| `http.ip` | String | The user's IP address | |
| 205 | +| `http.session` | Object | Represents the user's session | |
| 206 | +| `http.session.id` | String | The session ID | |
| 207 | +| `http.is_valid_client_certificate` | Boolean | `true` if the presented client certificate is valid | |
| 208 | + |
| 209 | +#### Functions |
| 210 | + |
| 211 | +The function below is available in Rego scripts: |
| 212 | + |
| 213 | +- `get_databroker_record(record_type, record_id)`: Returns data from the Databroker service. |
| 214 | + |
| 215 | +For example: |
| 216 | + |
| 217 | +```rego |
| 218 | +session := get_databroker_record("type.googleapis.com/session.Session", input.session.id) |
| 219 | +``` |
140 | 220 |
|
141 | 221 | <details>
|
142 | 222 | <summary>Example Rego Policy</summary>
|
@@ -192,6 +272,20 @@ This example pulls session data from the Databroker service using `type.googleap
|
192 | 272 | </div>
|
193 | 273 | </details>
|
194 | 274 |
|
| 275 | +::::enterprise |
| 276 | + |
| 277 | +In the [**Enterprise Console**](/docs/deploy/enterprise), you can write policies in Rego with the PPL builder: |
| 278 | + |
| 279 | + |
| 280 | + |
| 281 | +:::note |
| 282 | + |
| 283 | +A policy can only support PPL or Rego. Once one is set, the other tab is disabled. |
| 284 | + |
| 285 | +::: |
| 286 | + |
| 287 | +:::: |
| 288 | + |
195 | 289 | ### Policy overrides
|
196 | 290 |
|
197 | 291 | Pomerium Core and Enterprise offer the following options for overriding your authorization policy:
|
|
0 commit comments