Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⚡️ filtered resources:
microsoft.users
& microsoft.roles
When writing policies that require fetching huge amount of data only to search or filter for specific resources, we fetch all resources and then we apply the filters using the builtin functions `where()` `any()` and more. An example of a policy check that uses these patterns is: ``` // search for emergency accounts microsoft.users.any(displayName == /emergency/) // emrgIds holds the ids which match the above criteria emrgID = microsoft.users.where(displayName == /emergency/).map(id) // check if at least one of the accounts identified as such is attached to the "Global Administrator" role microsoft.rolemanagement.roleDefinitions.where(displayName == "Global Administrator").all(assignments.any(principalId == emrgID)) ``` To improve these resources, I am proposing a new pattern, similar to the one used at #5156, but with the difference that it doesn't override builtin functions, instead it leverages list resources which are natively supported in MQL with additional query parameters `filter` and `search`. These query parameters will be used directly when executing API requests against Microsoft Graph API. These query parameters are documented at: https://learn.microsoft.com/en-us/graph/filter-query-parameter?tabs=http#filter-using-lambda-operators The above example can be rewritten using these two new filtered resources like: ``` // search for emergency accounts microsoft.users(search: "displayName:emergency").any() // emrgIds holds the ids which match the above criteria emrgID = microsoft.users(search: "displayName:emergency").map(id) // check if at least one of the accounts identified as such is attached to the "Global Administrator" role microsoft.roles(filter: "displayName eq 'Global Administrator'").all(assignments.any(principalId == emrgID)) ``` Additionally, since these query parameters are directly passed to Microsoft API's, we can write very complex filters for these two new resources. A couple examples are: ``` microsoft.roles(filter: "isBuiltIn eq true and startswith(displayName, 'Global')") microsoft.users(filter: "accountEnabled eq true AND userType eq 'Member'", search: "officeLocation:berlin") ``` Closes #5110 Signed-off-by: Salim Afiune Maya <[email protected]>
- Loading branch information