Multiple-create: Authorization #1943
Merged
ayush3797 merged 132 commits intodev/NestedMutationsfrom Mar 21, 2024
Merged
Conversation
…hether entity is linking or not
src/Core/Resolvers/Sql Query Structures/BaseSqlQueryStructure.cs
Outdated
Show resolved
Hide resolved
seantleonard
reviewed
Jan 3, 2024
src/Service.Tests/Authorization/GraphQL/GraphQLMutationAuthorizationTests.cs
Outdated
Show resolved
Hide resolved
…h/AuthZForNestedInsertions
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Base automatically changed from
dev/agarwalayush/schemaGeneration
to
dev/NestedMutations
March 21, 2024 14:26
|
Azure Pipelines successfully started running 2 pipeline(s). |
Contributor
|
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
seantleonard
approved these changes
Mar 21, 2024
Contributor
seantleonard
left a comment
There was a problem hiding this comment.
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
Contributor
Author
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
1 task
severussundar
added a commit
that referenced
this pull request
Mar 29, 2024
## 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 <shyamsundarj@microsoft.com> Co-authored-by: Sean Leonard <sean.leonard@microsoft.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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/SqlMutationEnginetoAuthorizationResolver.How was this tested?
To be added.
Sample Request(s)
Config:


Request/Response - AuthZ failure because

piecesAvailablefield is not accessible totest_role_with_excluded_fields_on_createrole.Request/Response: Removing
piecesAvailablefield from request body leads to successful authz checks (request fails during query generation).