Skip to content

Commit 8e5f2e8

Browse files
Axot017eliecharrapeterdeme
authored
Migrate examples to rego v1 (#1018)
* feat: add doc about space module permissions (#1002) * docs: Update changelog with new features and fixes for Terraform modules and telemetry improvements (#1006) * Migrate examples to rego v1 * Add rego version selector --------- Co-authored-by: Elie CHARRA <[email protected]> Co-authored-by: Peter Deme <[email protected]>
1 parent a989d37 commit 8e5f2e8

21 files changed

+3670
-1475
lines changed

docs/concepts/authorization/assigning-roles-api-keys.md

Lines changed: 327 additions & 135 deletions
Large diffs are not rendered by default.

docs/concepts/authorization/assigning-roles-groups.md

Lines changed: 324 additions & 129 deletions
Large diffs are not rendered by default.

docs/concepts/authorization/assigning-roles-stacks.md

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,25 @@ Policies can react to stack role attachments through the `stack.roles` field in
149149

150150
### Example: Reject Space Admin role usage
151151

152-
```rego
153-
package spacelift
154-
155-
reject_with_note["Don't use the Space Admin role!"] {
156-
role := input.stack.roles[_]
157-
role.id == "space-admin" # (1)
158-
}
159-
```
152+
=== "Rego v1"
153+
```rego
154+
package spacelift
155+
156+
reject_with_note contains "Don't use the Space Admin role!" if {
157+
some role in input.stack.roles
158+
role.id == "space-admin" # (1)
159+
}
160+
```
161+
162+
=== "Rego v0"
163+
```rego
164+
package spacelift
165+
166+
reject_with_note["Don't use the Space Admin role!"] {
167+
role := input.stack.roles[_]
168+
role.id == "space-admin" # (1)
169+
}
170+
```
160171

161172
1. Role slug. Use either "Copy Slug" button in the UI or the [`spacelift_role` data source](https://search.opentofu.org/provider/spacelift-io/spacelift/latest/docs/datasources/role){: rel="nofollow"} to retrieve it.
162173

@@ -294,19 +305,35 @@ After creating the role attachment, verify that the stack can perform the same o
294305

295306
If any of your policies reference the `stack.administrative` field, update them to use the `stack.roles` field instead. For example:
296307

297-
```rego
298-
# Old policy:
299-
deny["Administrative stacks are not allowed"] {
300-
stack := input.spacelift.stack
301-
stack.administrative == true
302-
}
303-
304-
# Would become:
305-
deny["Administrative stacks are not allowed"] {
306-
role := input.spacelift.stack.roles[_]
307-
role.id == "space-admin" # (1)
308-
}
309-
```
308+
=== "Rego v1"
309+
```rego
310+
# Old policy:
311+
deny contains "Administrative stacks are not allowed" if {
312+
stack := input.spacelift.stack
313+
stack.administrative == true
314+
}
315+
316+
# Would become:
317+
deny contains "Administrative stacks are not allowed" if {
318+
some role in input.spacelift.stack.roles
319+
role.id == "space-admin" # (1)
320+
}
321+
```
322+
323+
=== "Rego v0"
324+
```rego
325+
# Old policy:
326+
deny["Administrative stacks are not allowed"] {
327+
stack := input.spacelift.stack
328+
stack.administrative == true
329+
}
330+
331+
# Would become:
332+
deny["Administrative stacks are not allowed"] {
333+
role := input.spacelift.stack.roles[_]
334+
role.id == "space-admin" # (1)
335+
}
336+
```
310337

311338
1. Role slug. Use either "Copy Slug" button in the UI or the [`spacelift_role` data source](https://search.opentofu.org/provider/spacelift-io/spacelift/latest/docs/datasources/role){: rel="nofollow"} to retrieve it.
312339

0 commit comments

Comments
 (0)