-
Notifications
You must be signed in to change notification settings - Fork 279
Cosmos DB: Adds Item Level Auth support using DB Policy #2106
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 all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
5dd56aa
first draft
sourabh1007 d798895
wip
sourabh1007 d5164b0
fix test
sourabh1007 c195c89
clean up
sourabh1007 bc8a85e
rverted resolver file
sourabh1007 e1b025e
code refactor
sourabh1007 bd299f4
revert csproj
sourabh1007 61d16b2
fix config
sourabh1007 272806a
remove unused file
sourabh1007 64b1371
config change
sourabh1007 695a3e1
config changes
sourabh1007 9073c7d
Test fixes
sourabh1007 78b19d1
fix tests
sourabh1007 ce8d349
code refator
sourabh1007 2530bf6
fix formatting
sourabh1007 243f456
update config
sourabh1007 7d43c21
added doc
sourabh1007 bac9928
changed join to subquery and changed enetity join generation logic on…
sourabh1007 ce1f79c
fixed formatting
sourabh1007 67c02a3
Add documentation
sourabh1007 805b62e
remove join related code
sourabh1007 aff4c17
fix formattig issue
sourabh1007 60743fa
generate simple condition for non array node
sourabh1007 6cfd162
Update src/Core/Services/MetadataProviders/CosmosSqlMetadataProvider.cs
sourabh1007 4d79a28
Update src/Core/Services/MetadataProviders/CosmosSqlMetadataProvider.cs
sourabh1007 064ddd9
Update src/Core/Services/MetadataProviders/CosmosSqlMetadataProvider.cs
sourabh1007 74da73c
Update src/Core/Resolvers/BaseQueryStructure.cs
sourabh1007 e2cd56e
Update src/Core/Resolvers/AuthorizationPolicyHelpers.cs
sourabh1007 6ce1d7f
cosmetic changes
sourabh1007 22dcff4
addressed few comments
sourabh1007 072c910
improved codc
sourabh1007 9ff31da
fix error with multiple model
sourabh1007 a8c7048
fix formatting
sourabh1007 e924275
Merge branch 'main' into users/sourabhjain/itemlevelauthapproach3
sourabh1007 ae16644
Merge branch 'main' into users/sourabhjain/itemlevelauthapproach3
sourabh1007 f2e5b2e
Merge branch 'main' into users/sourabhjain/itemlevelauthapproach3
seantleonard df06b1d
Merge branch 'main' into users/sourabhjain/itemlevelauthapproach3
sourabh1007 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
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 |
---|---|---|
@@ -1,33 +1,48 @@ | ||
init --config "dab-config.CosmosDb_NoSql.json" --database-type "cosmosdb_nosql" --connection-string "AccountEndpoint=https://localhost:8081/;AccountKey=C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==" --cosmosdb_nosql-database "graphqldb" --cosmosdb_nosql-container "planet" --graphql-schema "schema.gql" --host-mode Development --cors-origin "http://localhost:5000" | ||
add Planet --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:create,read,update,delete" --graphql "Planet:Planets" | ||
update Planet --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "*" | ||
update Planet --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete" | ||
update Planet --config "dab-config.CosmosDb_NoSql.json" --permissions "limited-read-role:read" | ||
add PlanetAlias --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:create,read,update,delete" --graphql "Planet:Planets" | ||
update PlanetAlias --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "*" | ||
update PlanetAlias --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete" | ||
update PlanetAlias --config "dab-config.CosmosDb_NoSql.json" --permissions "limited-read-role:read" | ||
update PlanetAlias --config "dab-config.CosmosDb_NoSql.json" --permissions "item-level-permission-role:read" | ||
add Character --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:create,read,update,delete" --graphql "Character:Characters" | ||
add StarAlias --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:create,read,update,delete" --graphql "Star:Stars" | ||
update StarAlias --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "authenticated:create,read,update,delete" | ||
add TagAlias --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:create,read,update,delete" --graphql "Tag:Tags" | ||
update Character --config "dab-config.CosmosDb_NoSql.json" --permissions "item-level-permission-role:read" | ||
add Star --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:create,read,update,delete" --graphql "Star:Stars" | ||
update Star --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "authenticated:create,read,update,delete" | ||
add Tag --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:create,read,update,delete" --graphql "Tag:Tags" | ||
add Moon --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:create,read,update,delete" --graphql true | ||
update Moon --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "authenticated:create,read,update,delete" | ||
add Earth --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "field-mutation-with-read-permission:read" --graphql "Earth:Earths" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "field-mutation-with-read-permission:create" --fields.include "id" --fields.exclude "name" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "field-mutation-with-read-permission:delete" --fields.include "id,type" --fields.exclude "name" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "field-mutation-with-read-permission:update" --fields.include "id,type" --fields.exclude "name" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:create,update,delete" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "*" --fields.exclude "*" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "limited-read-role:read" --fields.include "id,type" --fields.exclude "name" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "wildcard-exclude-fields-role:create" --fields.exclude "*" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "wildcard-exclude-fields-role:update" --fields.exclude "*" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "wildcard-exclude-fields-role:delete" --fields.exclude "*" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "wildcard-exclude-fields-role:read" --fields.exclude "*" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "only-create-role:create" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "only-update-role:update" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "only-delete-role:delete" | ||
update Earth --config "dab-config.CosmosDb_NoSql.json" --permissions "item-level-permission-role:read" --policy-database "@item.type eq 'earth0'" | ||
add Sun --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:create,update,delete" --graphql true | ||
update Sun --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "*" --fields.exclude "name" | ||
add AdditionalAttribute --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:*" --graphql "AdditionalAttribute:AdditionalAttributes" | ||
update AdditionalAttribute --config "dab-config.CosmosDb_NoSql.json" --permissions "item-level-permission-role:read" --policy-database "@item.name eq 'volcano0'" | ||
add MoonAdditionalAttribute --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:*" --graphql "MoonAdditionalAttribute:MoonAdditionalAttributes" | ||
add MoreAttrAlias --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:delete" --graphql "MoreAttribute:MoreAttributes" | ||
update MoreAttrAlias --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:create" --fields.include "id" --fields.exclude "name" | ||
update MoreAttrAlias --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "id" --fields.exclude "name" | ||
update MoreAttrAlias --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:update" --fields.exclude "*" | ||
update MoreAttrAlias --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete" | ||
update MoonAdditionalAttribute --config "dab-config.CosmosDb_NoSql.json" --permissions "item-level-permission-role:read" --policy-database "@item.name eq 'moonattr0'" | ||
add MoreAttribute --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.planet" --permissions "anonymous:delete" --graphql "MoreAttribute:MoreAttributes" | ||
update MoreAttribute --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:create" --fields.include "id" --fields.exclude "name" | ||
update MoreAttribute --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "id" --fields.exclude "name" | ||
update MoreAttribute --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:update" --fields.exclude "*" | ||
update MoreAttribute --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete" | ||
add PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.newcontainer" --permissions "field-mutation-with-read-permission:read" --graphql "PlanetAgain:PlanetAgains" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "field-mutation-with-read-permission:create" --fields.include "id" --fields.exclude "name" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "field-mutation-with-read-permission:delete" --fields.include "id,type" --fields.exclude "name" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "field-mutation-with-read-permission:update" --fields.include "id,type" --fields.exclude "name" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "limited-read-role:read" --fields.include "id,type" --fields.exclude "name" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "wildcard-exclude-fields-role:create" --fields.exclude "*" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "wildcard-exclude-fields-role:update" --fields.exclude "*" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "wildcard-exclude-fields-role:delete" --fields.exclude "*" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "wildcard-exclude-fields-role:read" --fields.exclude "*" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "only-create-role:create" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "only-update-role:update" | ||
update PlanetAgain --config "dab-config.CosmosDb_NoSql.json" --permissions "only-delete-role:delete" | ||
add InvalidAuthModel --config "dab-config.CosmosDb_NoSql.json" --source "graphqldb.invalidAuthModelContainer" --permissions "anonymous:delete" --graphql "InvalidAuthModel:InvalidAuthModels" | ||
update InvalidAuthModel --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:create" --fields.include "id" --fields.exclude "name" | ||
update InvalidAuthModel --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:read" --fields.include "id" --fields.exclude "name" | ||
update InvalidAuthModel --config "dab-config.CosmosDb_NoSql.json" --permissions "anonymous:update" --fields.exclude "*" | ||
update InvalidAuthModel --config "dab-config.CosmosDb_NoSql.json" --permissions "authenticated:create,read,update,delete" |
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,53 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
namespace Azure.DataApiBuilder.Config.ObjectModel | ||
{ | ||
/// <summary> | ||
/// It contains Entity information along with Pre-Generated JOIN statements for all the entities using configured DB policy. | ||
/// So that, it can be used for generating CosmosDB SQL queries. | ||
/// </summary> | ||
public record EntityDbPolicyCosmosModel | ||
{ | ||
/// <summary> | ||
/// Path to the given entity with "." delimiter, it will be used as prefix while generating conditions for CosmosDB SQL queries. | ||
sourabh1007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// e.g. c.stars, c.earth.type | ||
/// </summary> | ||
public string Path { get; } | ||
|
||
/// <summary> | ||
/// Column name representation of the entity | ||
/// </summary> | ||
public string? ColumnName { get; } | ||
|
||
/// <summary> | ||
/// If entity is of array type then we would have a generated alias of the entity | ||
/// e.g table0, table1 etc | ||
/// </summary> | ||
public string? Alias { get; } | ||
|
||
/// <summary> | ||
/// Entity Name | ||
/// </summary> | ||
public string? EntityName { get; } | ||
|
||
/// <summary> | ||
/// Pre-generated (If define DB policies are available and entity type is array) JOIN statement for the entity | ||
/// </summary> | ||
public string? JoinStatement { get; set; } | ||
|
||
public EntityDbPolicyCosmosModel(string Path, string? EntityName, string? ColumnName = null, string? Alias = null) | ||
{ | ||
this.Path = Path; | ||
this.ColumnName = ColumnName; | ||
this.Alias = Alias; | ||
this.EntityName = EntityName; | ||
|
||
// Generate JOIN statement only when Alias is there | ||
if (!string.IsNullOrEmpty(Alias)) | ||
{ | ||
this.JoinStatement = $" {Alias} IN {Path}.{ColumnName}"; | ||
} | ||
} | ||
} | ||
} |
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
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.