-
Notifications
You must be signed in to change notification settings - Fork 274
Multiple-create: Authorization #1943
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
Multiple-create: Authorization #1943
Conversation
…hether entity is linking or not
src/Core/Resolvers/Sql Query Structures/BaseSqlQueryStructure.cs
Outdated
Show resolved
Hide resolved
src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs
Outdated
Show resolved
Hide resolved
…h/AuthZForNestedInsertions
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
Azure Pipelines successfully started running 2 pipeline(s). |
The PR description example doesn't touch on authorization of "multiple mutations." Yes, there is a relationship field in the mutation, but your example doesn't demonstrate authorization of fields/entities defined by that relationship field. |
src/Core/Resolvers/Sql Query Structures/BaseSqlQueryStructure.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far. I'd say only thing that this PR would benefit from is testing authz of sub-entity fields. Unless i missed it, i only saw tests for Top-level entity and fields and sub-entity (no fields)
src/Service.Tests/Authorization/GraphQL/CreateMutationAuthorizationTests.cs
Outdated
Show resolved
Hide resolved
src/Service.Tests/Authorization/GraphQL/CreateMutationAuthorizationTests.cs
Outdated
Show resolved
Hide resolved
src/Service.Tests/Authorization/GraphQL/CreateMutationAuthorizationTests.cs
Show resolved
Hide resolved
src/Service.Tests/Authorization/GraphQL/CreateMutationAuthorizationTests.cs
Show resolved
Hide resolved
/azp run |
Azure Pipelines successfully started running 2 pipeline(s). |
## Why make this change? - All code changes for **Multiple Create** feature was being merged into `dev/NestedMutations` branch. - This PR attempts to merge all these changes to the `main` branch in preparation for the `0.12.* rc1` release ## What is this change? - Right now, `dev/NestedMutations` branch contains the code changes for the following components of Multiple Create feature - Schema Generation - #1902 - AuthZ - #1943 - Feature flag - CLI changes #1983 - Feature flag - Re-naming changes #2103 - Feature flag - Engine changes #2116 - Each specified PR was reviewed before merging into `dev/NestedMutations` branch. - This PR aims to merge all the changes into `main` branch ## How was this tested? - [x] Unit, Integration and Manual tests were performed on each PR before merging into `dev/NestedMutations` --------- Co-authored-by: Shyam Sundar J <[email protected]> Co-authored-by: Sean Leonard <[email protected]>
Why make this change?
Since GraphQL insertions now support nested insertions, we need to authorize entity and fields not only for the top-level entity in the insertion, but also the nested entities and fields. This PR aims to address that logic of collecting all the unique entities and fields belonging to those entities in a data structure, and then sequentially iterate over all entities and fields to check whether the given role is authorized to perform the action (here nested insertion).
What is this change?
SqlMutationEngine.ExecuteAsync()
method. This logic determines whether the input argument name isitem
(for point mutation) oritems
(for insert many).SqlMutationEngine.AuthorizeEntityAndFieldsForMutation()
is added. The name is kept generic (instead of using 'Insertion') because the same method can be used later for nested updates as well. As the name indicates, this method iterates over all the entities and fields and does the required authorization checks.SqlMutationEngine.PopulateMutationFieldsToAuthorize()
whose job is to populate all the unique entities referred in the mutation and their corresponding fields into a data structure of the format:Dictionary<string, HashSet<string>> entityAndFieldsToAuthorize
- where for each entry in the dictionary:-> Key represents the entity name
-> Value represents the unique set of fields referenced from the entity
SqlMutationEngine.PopulateMutationFieldsToAuthorize()
recursively calls itself for nested entities based on different criteria explained in code comments.SqlMutationEngine.ProcessObjectFieldNodesForAuthZ()
which sequentially goes over all the fields and add it to the list of fields to be authorized. Since a field might represent a relationship- and hence a nested entity, this method again calls its parent caller i.e.SqlMutationEngine.PopulateMutationFieldsToAuthorize()
.SqlMutationEngine.ProcessObjectFieldNodesForAuthZ()
contains the logic to ensure that the fields belonging to linking tables are not added to the list of fields to be authorized.GetRoleOfGraphQLRequest()
fromCosmos
/SqlMutationEngine
toAuthorizationResolver
.How was this tested?
To be added.
Sample Request(s)
Config:


Request/Response - AuthZ failure because

piecesAvailable
field is not accessible totest_role_with_excluded_fields_on_create
role.Request/Response: Removing
piecesAvailable
field from request body leads to successful authz checks (request fails during query generation).