Skip to content

Commit 262308f

Browse files
fix(iam): conditions pt2
1 parent 98d80bc commit 262308f

File tree

6 files changed

+150
-11
lines changed

6 files changed

+150
-11
lines changed

pages/iam/concepts.mdx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ With the introduction of IAM, an API key is now associated with an IAM [user](#u
3434

3535
## Common Expression Language (CEL)
3636

37-
Common Expression Language (CEL) is the expression language used to specify an expression in [conditions](#conditions) within an IAM policy. The language helps express attribute-based logic expressions. In general, a condition expression consists of one or more statements. Each statement expresses an attribute-based control rule, and ultimately determines whether the permissions applies. IAM conditions use the following CEL features: **Variables**, **Operators**, **Functions** and **Logical Operators**. Refer to the [Understanding policy conditions]() documentation page for a detailed description of the supported CEL features.
37+
Common Expression Language (CEL) is the expression language used to specify an expression in [conditions](#conditions) within an IAM policy. The language helps express attribute-based logic expressions. In general, a condition expression consists of one or more statements. Each statement expresses an attribute-based control rule, and ultimately determines whether the permissions applies. IAM conditions use the following CEL features: **Variables**, **Operators**, **Functions** and **Logical Operators**. Refer to the [Understanding policy conditions](/iam/reference-content/understanding-policy-conditions) documentation page for a detailed description of the supported CEL features.
3838

3939
## Conditions
4040

41-
A condition is an additional layer of restrictions for your rule. You can allow access to specific user agents, IP addresses and on a given date or time. Conditions are defined through [CEL](#common-expression-language-cel) expressions, and can be set up and configured in the Scaleway console. Refer to the [Understanding policy conditions]() documentation page to learn how they are set up and how you can define them.
41+
A condition is an additional layer of restrictions for your rule. You can allow access to specific user agents, IP addresses and on a given date or time. Conditions are defined through [CEL](#common-expression-language-cel) expressions, and can be set up and configured in the Scaleway console. Refer to the [Understanding policy conditions](/iam/reference-content/understanding-policy-conditions) documentation page to learn how they are set up and how you can define them.
4242

4343
## Group
4444

@@ -99,8 +99,6 @@ Policies control user rights by defining one or more [rules](#rule) to apply to
9999

100100
For each policy rule, you specify one or more permission sets (e.g. "list all Instances") and their scope (e.g. "on Project A only"). This therefore defines the actions that the principles can carry out on resources within the scope.
101101

102-
<Lightbox src="scaleway-iam-policy.webp" alt="" />
103-
104102
## Preferred Project
105103

106104
You can carry out actions on Scaleway Object Storage resources either via the [Scaleway console](https://console.scaleway.com), or via a third-party API or CLI, such as [the AWS CLI](/object-storage/api-cli/object-storage-aws-cli/), [MinIOClient](/object-storage/api-cli/installing-minio-client/) or [Rclone](/object-storage/api-cli/installing-rclone/). While the Scaleway console gives you the option to specify the [Scaleway Project](/organizations-and-projects/concepts/#project) to carry out your Object Storage actions in, this option is not available via third-party API/CLI tools. These tools are based on a [standard Amazon S3 programming interface](https://en.wikipedia.org/wiki/Amazon_S3#S3_API_and_competing_services), which does not accept Project ID as a parameter. Therefore, when you create a Scaleway API key with IAM, you are prompted to specify the API key's **preferred Project for Object Storage**. This API key will always use this Project when carrying out Object Storage actions via any API/CLI. See our page on [using API keys with Object Storage](/iam/api-cli/using-api-key-object-storage/) for more information.

pages/iam/how-to/create-policy.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ An IAM [policy](/iam/reference-content/policy/) is used to define the permission
5252
9. Click **Validate**.
5353
10. (Optional) Click **+ Add new** to add one or more conditions. You can allow access to specific user agents, IP addresses and on a given date or time.
5454
<Message type="tip">
55-
Refer to the [Understanding policy conditions]() documentation page to find an exhaustive list of different conditions you can set up, as well as examples of conditions.
55+
Refer to the [Understanding policy conditions](/iam/reference-content/understanding-policy-conditions) documentation page for more details about how to write condition expressions, as well as examples of conditions.
5656
</Message>
5757
11. Click **Validate**. The rule, with its scope and permission sets, is added to the list of the policy's rules.
5858
12. Click **Add new rule** and repeat steps 6-8 as many times as required to add multiple rules to your policy.

pages/iam/how-to/manage-policies.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ From the policy's [Overview page](#how-to-access-the-policy-overview):
3838
## How to edit a policy's rules
3939

4040
1. From the policy's [Overview page](#how-to-access-the-policy-overview), scroll down to the **Rules** panel and click <Icon name="edit" /> next to the rule you want to edit.
41-
2. Edit the rule as required.
42-
<Message type="tip">
43-
You can edit the scope, the permission sets and the conditions. However, the conditions can only be edited using the **Advanced** editor. You must update [CEL]() expression in the editor to update the condition. Refer to the [Understanding policy conditions]() documentation page to find an exhaustive list of different conditions you can set up, as well as examples of conditions.
41+
2. Edit the rule as required. You can edit the scope, permission sets and conditions.
42+
<Message type="important">
43+
Conditions can only be edited using the **Advanced** editor. You must update the [CEL](/iam/concepts#common-expression-language-cel) expression in the editor to update the condition. Refer to the [Understanding policy conditions](/iam/reference-content/understanding-policy-conditions) documentation page for more details about how to write condition expressions, as well as examples of conditions.
4444
</Message>
4545
3. Click **Validate** to finish.
4646
<Message type="tip">

pages/iam/quickstart.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Users you have invited to your Organization, and applications you have created,
8080
9. Click **Validate**.
8181
10. (Optional) Click **+ Add new** to add one or more conditions. You can allow access to specific user agents, IP addresses and on a given date or time.
8282
<Message type="tip">
83-
Refer to the [Understanding policy conditions]() documentation page to find an exhaustive list of different conditions you can set up, as well as examples of conditions.
83+
Refer to the [Understanding policy conditions](/iam/reference-content/understanding-policy-conditions) documentation page for more details about how to write condition expressions, as well as examples of conditions.
8484
</Message>
8585
11. Click **Validate**. The rule, with its scope and permission sets, is added to the list of the policy's rules.
8686
12. Click **Add new rule** and repeat steps 6-8 as many times as required to add multiple rules to your policy.

pages/iam/reference-content/policy.mdx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ They are composed of:
1919

2020
- a [principal](#principal) - a user, group, or application,
2121
- one or more IAM rules - consisting of [permission sets](#permission-sets) bound to a [scope](#scope).
22-
23-
<Lightbox src="scaleway-iam-policy.webp" alt="" />
22+
- one or more IAM conditions - defined in Common Expression Language (CEL) expressions.
2423

2524
## Principal
2625

@@ -55,6 +54,14 @@ A permission set consists of one or multiple permissions to perform actions on r
5554
You can find a detailed list of all permission sets available at Scaleway in the permission sets [reference page](/iam/reference-content/permission-sets/).
5655
</Message>
5756

57+
### Conditions
58+
59+
A condition is an additional layer of restrictions for your rule. You can allow access to specific user agents, IP addresses and on a given date or time. Conditions are defined through [CEL](#common-expression-language-cel) expressions. In general, a condition expression consists of one or more statements that are joined by logical operators (`&&`, `||`, or `!`).
60+
61+
Conditions can be set up and configured in the Scaleway console.
62+
63+
Refer to the [Understanding policy conditions](/iam/reference-content/understanding-policy-conditions) documentation page to learn how they are set up and how you can define them.
64+
5865
### Example rule
5966

6067
The rule below defines various levels of access to different resources in Project A.
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
meta:
3+
title: Understanding policy conditions
4+
description: Detailed information on policy conditions within Scaleway IAM.
5+
content:
6+
h1: Understanding policy conditions
7+
paragraph: Learn how to use policy conditions to fine-tune access control within Scaleway IAM.
8+
tags: iam
9+
dates:
10+
validation: 2024-03-03
11+
categories:
12+
- iam
13+
- console
14+
---
15+
16+
A condition is an additional layer of restrictions for your rule. You can configure conditions in IAM policies to allow access to specific user agents, IP addresses and on a given date or time.
17+
18+
At Scaleway, IAM conditions are defined using Common Expression Language (CEL) expressions.
19+
20+
<Message type="tip">
21+
Refer to the [How to create a policy](/iam/how-to/create-policy/) and [How to manage policies](/iam/how-to/create-policy/) documentation pages to learn where and how to specify a condition.
22+
</Message>
23+
24+
## Condition expressions
25+
26+
An expression can be compared to a conditional statement in programming. It is a logical statement that evaluates to either true or false. The result determines whether the permission set defined in the rule is applied or not.
27+
28+
Condition expressions are composed of one or several statements that declare a rule based on attributes. Attributes are like characteristics or properties of a resource or a user. For example, an attribute might be a given date or time, or an IP address.
29+
30+
Expressions at Scaleway are defined in CEL, which provides a human-readable and flexible method of creating conditions.
31+
32+
## Common Expression Language
33+
34+
Common Expression Language is used to specify a IAM condition expression.
35+
36+
Expressions consist of one or more statements that declare an attribute-based control rule, and determines whether a permission applies.
37+
38+
IAM conditions use the following CEL features:
39+
- Variables
40+
- Operators and Logical Operators
41+
- Functions
42+
43+
### Variables
44+
45+
Conditions use variables to express attributes. Variables are populated with values based on the context at runtime.
46+
47+
| Name | Type | Description |
48+
| ------------ | ------------------- | ------ |
49+
| `request.ip` | String | The IP address of the request. |
50+
| `request.time` | `google.protobuf.Timestamp` | The time of the request. Represented as a Protobuf object, allowing usage with [associated functions](https://github.com/google/cel-spec/blob/master/doc/langdef.md#datetime-functions).|
51+
| `request.user_agent` | String | The user-agent of the request. Truncated at 255 characters max.|
52+
53+
### Operators
54+
55+
Every data type, such as `timestamp` or `string`, supports a set of operators that can be used to create a logic expression.
56+
57+
Most commonly, operators are used to compare the value contained in a variable with a literal value.
58+
59+
For example, `==` is the operator in the following statement:
60+
61+
```
62+
request.time == "2024-03-03T14:30:00.000Z"
63+
```
64+
65+
Refer to the official [CEL syntax specification](https://github.com/google/cel-spec/blob/master/doc/langdef.md#syntax) for list of supported operators.
66+
67+
#### Logical operators
68+
69+
Conditions supports three logical operators that can be used to build complex logic expressions from basic expression statements:
70+
71+
| Logical operator | Description | Example |
72+
| -- | ------------------- | ------ |
73+
| `&&` (AND) | Evaluates to true if both expressions are true. | `request.time.getFullYear() < 2020 && request.ip == '10.154.3.1'` |
74+
| `\|\|` (OR) | Evaluates to true if either expression is true. If the first expression is true, the second expression may not be evaluated. | `request.time.getFullYear() < 2020 \|\| request.ip == '10.154.3.1'` |
75+
| `!` (NOT) | Evaluates to true if the expression is false, and false if the expression is true. | `!(request.time.getFullYear() < 2020)` |
76+
77+
78+
### Functions
79+
80+
A function is a compound operator for data types that supports more complex operations. In condition expressions, there are predefined functions that can be used with a given data type.
81+
82+
| Function | Description | Parameters |
83+
| ------------ | ------------------- | ------ |
84+
| `inIpRange(IP: string, Subnet: string)` | Checks if the IP address is included in the IP subnet. | **IP**: (String) The IP address to check. |
85+
| | | **Subnet**: (String) The IP subnet to check against. |
86+
87+
88+
## Important considerations
89+
90+
### Multiple policies
91+
If multiple policies with different conditions apply to the same principal, the presence of a single policy with met conditions (or no conditions) will override any denying rules from other policies, allowing the action to be taken.
92+
93+
For example, if you set up a policy that grants access to a resource only on Monday while another policy grants access only on Tuesday, the action will still be permitted on Monday.
94+
95+
### Timezones
96+
97+
We recommend that you specify timezones when creating time-based conditions.
98+
99+
Refer to the official [CEL specification](https://github.com/google/cel-spec/blob/master/doc/langdef.md#timezones) for the correct grammar to express timezones in conditions.
100+
101+
### Timestamps
102+
103+
Conditions based on timestamps might take up to a minute to be applied.
104+
105+
For example, if a user has permission to perform an action until 11am, they may be able to perform it until 11:01am.
106+
107+
### IAM condition limitations
108+
109+
Currently it is only possible to edit conditions in the console using the **Advanced** expression editor.
110+
111+
When creating a policy, you can define a simple condition expression with the help of the console form. When editing, you must define the changes by writing them in CEL in the Advanced editor.
112+
113+
## Expression examples
114+
115+
### User-agent conditions
116+
117+
In the example below we check if the user-agent contains the term "Terraform":
118+
```
119+
request.user_agent.contains("terraform/")
120+
```
121+
122+
### Time conditions
123+
124+
To check if a request was performed at a specific timeslot you can use the following expression. In this example, use weekdays from 9am to 5pm as a timestamp.
125+
```
126+
request.time.getDayOfWeek() != 0 && request.time.getDayOfWeek() != 6
127+
&& request.time.getHours("Europe/Paris") < 17
128+
&& request.time.getHours("Europe/Paris") > 8
129+
```
130+
131+
To check if the request was performed over the weekend, you can use the expression below:
132+
```
133+
request.time.getDayOfWeek() != 0 && request.time.getDayOfWeek() != 6
134+
```

0 commit comments

Comments
 (0)