-
Notifications
You must be signed in to change notification settings - Fork 258
feat(iam): conditions MTA-5686 #4532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
98d80bc
fix(iam): conditions pt1
ldecarvalho-doc 262308f
fix(iam): conditions pt2
ldecarvalho-doc e7e7a37
fix(iam): review ro
ldecarvalho-doc 921b6e6
fix(iam): review ro
ldecarvalho-doc cf3badc
fix(iam): retours
ldecarvalho-doc c81bef6
fix(iam): review
ldecarvalho-doc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
pages/iam/reference-content/understanding-policy-conditions.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| --- | ||
| meta: | ||
| title: Understanding policy conditions | ||
| description: Detailed information on policy conditions within Scaleway IAM. | ||
| content: | ||
| h1: Understanding policy conditions | ||
| paragraph: Learn how to use policy conditions to fine-tune access control within Scaleway IAM. | ||
| tags: iam | ||
| dates: | ||
| validation: 2025-03-03 | ||
| categories: | ||
| - iam | ||
| - console | ||
| --- | ||
|
|
||
| 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. | ||
|
|
||
| At Scaleway, IAM conditions are defined using Common Expression Language (CEL) expressions. | ||
|
|
||
| <Message type="tip"> | ||
| 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. | ||
| </Message> | ||
|
|
||
| ## Condition expressions | ||
|
|
||
| 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. | ||
|
|
||
| Condition expressions are composed of one or several statements that declare a rule based on attributes. Attributes are like characteristics or properties of a request, resource or a user. For example, an attribute might be a given date or time, or an IP address. | ||
|
|
||
| <Message type="note"> | ||
| Currently only request-based conditions are available with Scaleway IAM. | ||
| </Message> | ||
|
|
||
| Expressions at Scaleway are defined in CEL, which provides a human-readable and flexible method of creating conditions. | ||
|
|
||
| ## Common Expression Language | ||
|
|
||
| Common Expression Language is used to specify a IAM condition expression. | ||
|
|
||
| Expressions consist of one or more statements that declare an attribute-based control rule, and determine whether a permission applies. | ||
|
|
||
| IAM conditions use the following CEL features: | ||
| - Variables | ||
| - Operators and Logical Operators | ||
| - Functions | ||
|
|
||
| ### Variables | ||
|
|
||
| Conditions use variables to express attributes. Variables are populated with values based on the context at runtime. | ||
|
|
||
| | Name | Type | Description | | ||
| | ------------ | ------------------- | ------ | | ||
| | `request.ip` | String | The IP address of the request. | | ||
| | `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).| | ||
| | `request.user_agent` | String | The user-agent of the request. Truncated at 255 characters max.| | ||
|
|
||
| ### Operators | ||
|
|
||
| Every data type, such as `timestamp` or `string`, supports a set of operators that can be used to create a logic expression. | ||
|
|
||
| Most commonly, operators are used to compare the value contained in a variable with a literal value. | ||
|
|
||
| For example, `==` is the operator in the following statement: | ||
|
|
||
| ``` | ||
| request.time == "2025-03-03T14:30:00.000Z" | ||
| ``` | ||
|
|
||
| Refer to the official [CEL syntax specification](https://github.com/google/cel-spec/blob/master/doc/langdef.md#syntax) for list of supported operators. | ||
|
|
||
| #### Logical operators | ||
|
|
||
| Conditions support three logical operators that can be used to build complex logic expressions from basic expression statements: | ||
|
|
||
| | Logical operator | Description | Example | | ||
| | -- | ------------------- | ------ | | ||
| | `&&` (AND) | Evaluates to true if both expressions are true. | `request.time.getFullYear() < 2020 && request.ip == '10.154.3.1'` | | ||
| | `\|\|` (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'` | | ||
| | `!` (NOT) | Evaluates to true if the expression is false, and false if the expression is true. | `!(request.time.getFullYear() < 2020)` | | ||
|
|
||
|
|
||
| ### Functions | ||
|
|
||
| A function is a compound operator for data types, that supports more complex operations. In condition expressions, predefined functions can be used with a given data type. | ||
ldecarvalho-doc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| All standard CEL functions are supported, as well as the following custom Scaleway IAM function(s): | ||
|
|
||
| | Function | Description | Parameters | | ||
| | ------------ | ------------------- | ------ | | ||
| | `inIpRange(IP: string, Subnet: string)` | Checks if the IP address is included in the IP subnet. | **IP**: (String) The IP address to check. | | ||
| | | | **Subnet**: (String) The IP subnet to check against. | | ||
|
|
||
|
|
||
| ## Important considerations | ||
|
|
||
| ### Multiple policies | ||
| 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. | ||
|
|
||
| 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. | ||
ldecarvalho-doc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
ldecarvalho-doc marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Timezones | ||
|
|
||
| We recommend that you specify timezones when creating time-based conditions. | ||
|
|
||
| Refer to the official [CEL specification](https://github.com/google/cel-spec/blob/master/doc/langdef.md#timezones) for the correct syntax to express timezones in conditions. | ||
|
|
||
| ### Timestamps | ||
|
|
||
| Conditions based on timestamps might take up to a minute to be applied. | ||
|
|
||
| For example, if a user has permission to perform an action until 11am, they may be able to perform it until 11:01am. | ||
|
|
||
| ### IAM condition limitations | ||
|
|
||
| Currently it is only possible to edit conditions in the console using the **Advanced** expression editor. | ||
|
|
||
| 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. | ||
|
|
||
| ## Expression examples | ||
|
|
||
| ### User-agent conditions | ||
|
|
||
| In the example below we check if the user-agent contains the term "Terraform": | ||
| ``` | ||
| request.user_agent.contains("terraform/") | ||
| ``` | ||
|
|
||
| ### Time conditions | ||
|
|
||
| To only allow actions within a specific timeslot you can use the following expression. In this example, use weekdays from 9am to 5pm as a timestamp. | ||
| ``` | ||
| request.time.getDayOfWeek() != 0 && request.time.getDayOfWeek() != 6 | ||
| && request.time.getHours("Europe/Paris") < 17 | ||
| && request.time.getHours("Europe/Paris") > 8 | ||
| ``` | ||
|
|
||
| To only allow requests that were performed over the weekend, you can use the expression below: | ||
| ``` | ||
| request.time.getDayOfWeek() != 0 && request.time.getDayOfWeek() != 6 | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.