Skip to content

Commit a50aef6

Browse files
ZPain8464github-actions[bot]
authored andcommitted
Adds rego docs (#1353)
* adds rego docs * fixes precommit failures * Adds anchor link
1 parent 3233e98 commit a50aef6

File tree

1 file changed

+101
-7
lines changed

1 file changed

+101
-7
lines changed

content/docs/capabilities/authorization.mdx

+101-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
# cSpell:ignore abac, gset, nxon
2+
# cSpell:ignore abac, gset, nxon, unvalidated
33

44
title: Authorization & Policy
55
lang: en-US
@@ -126,17 +126,97 @@ Reapply policies as necessary to any route or namespace:
126126

127127
### Rego support
128128

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/).
130130

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.
132132

133-
![Apply Rego in Console editor](./img/authorization/ppl-rego-policy.png)
133+
#### Outputs
134134

135-
:::tip
135+
Authorization policy written in Rego is expected to return results in `allow` and/or `deny` rules:
136136

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+
```
138141

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+
```
140220

141221
<details>
142222
<summary>Example Rego Policy</summary>
@@ -192,6 +272,20 @@ This example pulls session data from the Databroker service using `type.googleap
192272
</div>
193273
</details>
194274

275+
::::enterprise
276+
277+
In the [**Enterprise Console**](/docs/deploy/enterprise), you can write policies in Rego with the PPL builder:
278+
279+
![Apply Rego in Console editor](./img/authorization/ppl-rego-policy.png)
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+
195289
### Policy overrides
196290

197291
Pomerium Core and Enterprise offer the following options for overriding your authorization policy:

0 commit comments

Comments
 (0)