Skip to content
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

Server: Remote relationships permissions #6125

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
123 commits
Select commit Hold shift + click to select a range
eec029b
[WIP] add the `add_remote_schema_permissions` API
codingkarthik Sep 22, 2020
e3c772a
add validation for directives, enums and input objects
codingkarthik Sep 23, 2020
68f0dfa
add validation for interfaces, unions and object types
codingkarthik Sep 24, 2020
1d77539
integrate all validations into validateRemoteSchema
codingkarthik Sep 24, 2020
170e664
refactor CustomRemoteSchema to RoleBasedSchema
codingkarthik Sep 24, 2020
9600a9c
add function to format the errors
codingkarthik Sep 24, 2020
27e53ce
integrate role based remote schema validation into the API
codingkarthik Sep 25, 2020
f57f6c3
check for duplicate type names among the types
codingkarthik Sep 25, 2020
34a5ed9
fix object implementing interfaces validation
codingkarthik Sep 25, 2020
b16f6bf
add duplicate checks for args, fields and directives
codingkarthik Sep 25, 2020
a2e3624
add documentation to some of the functions in Validate module
codingkarthik Sep 25, 2020
4ceb271
build remote schema context with permissions
codingkarthik Sep 29, 2020
7ddc6e9
modify the schema cache to include remote schema with perms
codingkarthik Sep 29, 2020
aa51c23
generate role based schema for each role
codingkarthik Sep 29, 2020
56f7a43
[not compiling] delete remote schema perms metadata obj
codingkarthik Sep 29, 2020
4f16e46
enable lenses for 'RemoteSchemaCtxWithPermissions' type
rakeshkky Sep 29, 2020
3e1f857
add drop_remote_schema_permissions api and include dependencies
codingkarthik Sep 29, 2020
77d061e
Refactor SchemaDocumentTypeDefinitions to PartitionedTypeDefinitions
codingkarthik Sep 30, 2020
c328d3a
minor refactoring of the RemoteSchema/Validate.hs module
codingkarthik Sep 30, 2020
9d594e7
move ParitionedTypeDefinitions to Types/RemoteSchema.hs
codingkarthik Sep 30, 2020
4d1e47a
add remote schema permissions docs
codingkarthik Sep 30, 2020
b71a541
add feature flag to enable remote schema permissions
codingkarthik Sep 30, 2020
2f23019
don't expose remotes in unauthenticated context
codingkarthik Sep 30, 2020
56a2041
add remote schema permissions in import and export metadata
codingkarthik Sep 30, 2020
89d5929
fix the haskell tests
codingkarthik Sep 30, 2020
9a8a845
change permissions to be Maybe while exporting metadata
codingkarthik Oct 1, 2020
9e5dd5d
drop the related permissions while removing a remote schema
codingkarthik Oct 1, 2020
c9b11de
restrict adding remote schema permissions when permissions are not en…
codingkarthik Oct 1, 2020
73066a5
add a note about enabling remote schema permissions
codingkarthik Oct 1, 2020
a31fc86
add CHANGELOG
codingkarthik Oct 1, 2020
b96a932
report only non permission dependent objects while removing remote sc…
codingkarthik Oct 1, 2020
e4752dc
throw error when all non-nullable arguments to a field aren't provided
codingkarthik Oct 1, 2020
7d25284
compare only the names of the non nullable input args
codingkarthik Oct 1, 2020
4b3bd3a
add some validation tests for remote schema permissions
codingkarthik Oct 1, 2020
13e9f52
add more tests
codingkarthik Oct 1, 2020
9e100cb
add validation for object types
codingkarthik Oct 1, 2020
90f0f96
run remote schema permissions test in test-server.sh
codingkarthik Oct 1, 2020
3b70eb1
unset remote schema permsissions after testing
codingkarthik Oct 2, 2020
90b2aba
change the location of the remote schema permissions test
codingkarthik Oct 2, 2020
1f9e945
remove --hge-webhook flag from remote schema permissions tests
codingkarthik Oct 2, 2020
59c35b0
add failing remote schema permissions execution test
codingkarthik Oct 5, 2020
adecd5a
Merge branch 'master' into remote-schema-perms
codingkarthik Oct 13, 2020
fb1e93d
Merge branch 'master' into remote-schema-perms
codingkarthik Oct 13, 2020
e2cc299
add/modify some of the role-based remote schema tests
codingkarthik Oct 13, 2020
9c4df90
remove -fdefer-typed-holes from cabal.project
codingkarthik Oct 13, 2020
5a2e188
include directives for InputValueDefinition in appropriate places
codingkarthik Oct 13, 2020
e6621bb
add validation for preset directives
codingkarthik Oct 13, 2020
43f458a
use the correct tag of graphql-parser-hs
codingkarthik Oct 13, 2020
05ff97e
adjust the code after modifying G.InputValueDefinition
codingkarthik Oct 13, 2020
9c317df
add documentation to some of the function in RemoteSchema/Validate.hs
codingkarthik Oct 15, 2020
e78552b
change the type of RemoteField
codingkarthik Oct 15, 2020
d2fdf38
argument presets only for static values and arguments of field
codingkarthik Oct 15, 2020
6fd4aff
fix the arguments of `mkFieldParserWithSelectionSet`
codingkarthik Oct 15, 2020
17ecffd
compare the directives of input object field's arguments as well
codingkarthik Oct 15, 2020
d45511d
undo the static_preset and session_preset
codingkarthik Oct 16, 2020
61a9fe5
accomodate the changes after parametrizing G.TypeDefinition
codingkarthik Oct 16, 2020
e1d69fe
incorporate changes made after parametrizing G.InputObjectTypeDefinition
codingkarthik Oct 16, 2020
387adc6
[WIP] make modifications in remote schema stuff after changing G.Type…
codingkarthik Oct 16, 2020
1e85d81
[WIP] accomodate changes made in the remote schema introspection type
codingkarthik Oct 19, 2020
f5bce71
accomodate the changes after changing order of args in TypeDefinition
codingkarthik Oct 19, 2020
c0831c9
save the graphQL type with every variable value
codingkarthik Oct 19, 2020
6f7bfb6
[WIP] Change the return type of parsePresetDirective
codingkarthik Oct 19, 2020
23339cb
return a G.Value Variable instead of RemoteSchemaPresetArguments
codingkarthik Oct 20, 2020
a7bf820
implement presets for input object fields!!
codingkarthik Oct 21, 2020
3fb5d99
minor changes in the parsePresetDirective function
codingkarthik Oct 22, 2020
95736d2
add relationships between remote_schemas and remote_schema_permission
codingkarthik Oct 22, 2020
51fb4f7
Merge branch 'remote-schema-perms' into remote-schema-args-preset-inp…
codingkarthik Oct 22, 2020
23d3490
finish off remote schema session preset argument presets
codingkarthik Oct 22, 2020
378f5aa
validate the preset value
codingkarthik Oct 23, 2020
6efa3ce
minor refactorings in the remote schema validate file
codingkarthik Oct 23, 2020
b20ce33
throw error when trying to set session variable to list type
codingkarthik Oct 23, 2020
fff892c
rename validatePresetValue to parsePresetValue
codingkarthik Oct 23, 2020
468bdba
rename RemoteSchema/Validate.hs to RemoteSchema/Permission.hs
codingkarthik Oct 23, 2020
bbd6145
refactor RemoteSchemaCtxWithPermissions to RemoteSchemaCtx
codingkarthik Oct 23, 2020
0f88c19
Merge branch 'master' into remote-schema-args-preset-inp-obj-presets
codingkarthik Oct 26, 2020
ee15971
use the Printer instance of G.SchemaDocument in the ToJSON instance
codingkarthik Oct 26, 2020
5b8da91
use the appropriate env flag in parseEnabelRemoteSchemaPerms
codingkarthik Oct 27, 2020
ad8df34
apply hlint suggestions
codingkarthik Oct 27, 2020
f8a4ccb
handle static session variables values
codingkarthik Oct 27, 2020
965931d
remove graphql-engine +developer -profiling from cabal.project.freeze
codingkarthik Oct 27, 2020
1190014
Merge branch 'master' into remote-schema-args-preset-inp-obj-presets
codingkarthik Oct 27, 2020
b34e1b8
fix mutation bug, use G.OperationTypeMutation in mutation exec
codingkarthik Oct 27, 2020
c12e871
handle nullability for remote input objects
codingkarthik Oct 28, 2020
0e25ac5
fix failing role based remote schema tests
codingkarthik Oct 28, 2020
a66dde1
update tag of graphql-parser-hs with latest commit
codingkarthik Oct 28, 2020
35a3d7d
add RS permissions static argument preset tests
codingkarthik Oct 28, 2020
da77b8b
add some session arguments preset execution tests
codingkarthik Oct 28, 2020
8aa3801
document the mergeValue function in Remote.hs
codingkarthik Oct 28, 2020
a5d79fd
minor refactoring
codingkarthik Oct 28, 2020
16d2aed
document the argumentsParser function
codingkarthik Oct 28, 2020
aecf172
when schema definition is not provided, parse with default query root…
codingkarthik Oct 29, 2020
515186e
add some validation tests for preset arguments
codingkarthik Oct 29, 2020
f1b4491
change invalid-role-based-remote-schema to invalid-custom-remote-sche…
codingkarthik Oct 29, 2020
2539989
improve the mergeValue function to avoid partiality
codingkarthik Oct 29, 2020
aee1341
Merge branch 'master' into remote-schema-args-preset-inp-obj-presets
codingkarthik Oct 29, 2020
13ba1a4
use G.InputValueDefinition instead of RemoteSchemaInputValueDefinition
codingkarthik Oct 30, 2020
39de82b
add module documentation for `RemoteSchema/Permission.hs`
codingkarthik Oct 31, 2020
8cef016
add a separator to make the variable names distinct
codingkarthik Nov 2, 2020
13aab63
undo a unnecessary change and fix a TODO
codingkarthik Nov 2, 2020
4b8ab27
apply changes suggested in the docs
codingkarthik Nov 2, 2020
37b20f5
add docs about preset arguments in remote schema permissions docs
codingkarthik Nov 2, 2020
3f8a949
modify a failing test
codingkarthik Nov 2, 2020
26616b9
remove stray TODOs
codingkarthik Nov 2, 2020
4263ce0
[WIP] first step towards remote join permissions
codingkarthik Nov 2, 2020
4776c61
use the remote schema configured for the role instead of admin remotes
codingkarthik Nov 3, 2020
c41df70
derive remote schema permissions
codingkarthik Nov 3, 2020
1bba34f
add tests for remote join permissions
codingkarthik Nov 3, 2020
8c8cc49
Merge branch 'master' into remote-relationships-permissions
codingkarthik Nov 3, 2020
0cfb93f
move the remote relationship validation logic to remoteRelationshipField
codingkarthik Nov 3, 2020
4b7361a
[WIP] Deep parsing of remote join queries
codingkarthik Nov 4, 2020
3be4b7e
use the role's configured introspection instead of the upstream one
codingkarthik Nov 4, 2020
2366831
apply hlint suggestions
codingkarthik Nov 4, 2020
3011020
server: refactor the fetchRemoteJoinFields function
codingkarthik Nov 4, 2020
4f08afd
fix remote relationships when remote schema permissions were not enabled
codingkarthik Nov 4, 2020
4843ee2
Merge branch 'master' into remote-relationships-permissions
codingkarthik Nov 4, 2020
a25bafa
don't ignore presets for the non-joining arguments of the remote reln…
codingkarthik Nov 5, 2020
4be883e
get the variable infos from the selection set of the field as well
codingkarthik Nov 5, 2020
6bb0b1d
add tests for remote relationship permissions
codingkarthik Nov 5, 2020
7fde85b
add documentation for Remote Relationship Permissions
codingkarthik Nov 5, 2020
545acb4
Merge branch 'master' into remote-relationships-permissions
codingkarthik Nov 5, 2020
c13a051
apply hlint suggestions
codingkarthik Nov 5, 2020
7850c48
Merge branch 'master' into remote-relationships-permissions
codingkarthik Dec 22, 2020
900c9f7
Merge branch 'master' into remote-relationships-permissions
codingkarthik Dec 22, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge branch 'master' into remote-relationships-permissions
  • Loading branch information
codingkarthik committed Nov 4, 2020
commit 4843ee2ade410f2dc252d5e4e9fa9110bdee25d5
414 changes: 226 additions & 188 deletions server/src-lib/Hasura/GraphQL/Schema.hs

Large diffs are not rendered by default.

102 changes: 5 additions & 97 deletions server/src-lib/Hasura/RQL/DDL/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,88 +76,8 @@ runClearMetadata _ = do
buildSchemaCacheStrict
return successMsg

applyQP1
:: (QErrM m)
=> ReplaceMetadata -> m ()
applyQP1 (ReplaceMetadata _ tables functionsMeta remoteSchemas
collections
allowlist _ actions
cronTriggers) = do
withPathK "tables" $ do

checkMultipleDecls "tables" $ map _tmTable tables

-- process each table
void $ indexedForM tables $ \table -> withTableName (table ^. tmTable) $ do
let allRels = map Relationship.rdName (table ^. tmObjectRelationships) <>
map Relationship.rdName (table ^. tmArrayRelationships)

insPerms = map Permission.pdRole $ table ^. tmInsertPermissions
selPerms = map Permission.pdRole $ table ^. tmSelectPermissions
updPerms = map Permission.pdRole $ table ^. tmUpdatePermissions
delPerms = map Permission.pdRole $ table ^. tmDeletePermissions
eventTriggers = map etcName $ table ^. tmEventTriggers
computedFields = map _cfmName $ table ^. tmComputedFields
remoteRelationships = map _rrmName $ table ^. tmRemoteRelationships

checkMultipleDecls "relationships" allRels
checkMultipleDecls "insert permissions" insPerms
checkMultipleDecls "select permissions" selPerms
checkMultipleDecls "update permissions" updPerms
checkMultipleDecls "delete permissions" delPerms
checkMultipleDecls "event triggers" eventTriggers
checkMultipleDecls "computed fields" computedFields
checkMultipleDecls "remote relationships" remoteRelationships

withPathK "functions" $
case functionsMeta of
FMVersion1 qualifiedFunctions ->
checkMultipleDecls "functions" qualifiedFunctions
FMVersion2 functionsV2 ->
checkMultipleDecls "functions" $ map Schema._tfv2Function functionsV2

withPathK "remote_schemas" $ do

checkMultipleDecls "remote schemas" $ map _rsmName remoteSchemas

void $ indexedForM remoteSchemas $ \(RemoteSchemaMeta _ _ _ perms) ->
onJust perms $ (checkMultipleDecls "remote schema permissions" . map _rspmRole)

withPathK "query_collections" $
checkMultipleDecls "query collections" $ map Collection._ccName collections

withPathK "allowlist" $
checkMultipleDecls "allow list" $ map Collection._crCollection allowlist

withPathK "actions" $
checkMultipleDecls "actions" $ map _amName actions

withPathK "cron_triggers" $
checkMultipleDecls "cron triggers" $ map ctName cronTriggers

where
withTableName qt = withPathK (qualifiedObjectToText qt)

checkMultipleDecls t l = do
let dups = getDups l
unless (null dups) $
throw400 AlreadyExists $ "multiple declarations exist for the following " <> t <> " : "
<> T.pack (show dups)

getDups l =
l L.\\ HS.toList (HS.fromList l)

applyQP2
:: (CacheRWM m, MonadTx m, HasSystemDefined m, HasEnableRemoteSchemaPermsCtx m)
=> ReplaceMetadata -> m EncJSON
applyQP2 replaceMetadata = do
clearUserMetadata
saveMetadata replaceMetadata
buildSchemaCacheStrict
pure successMsg

saveMetadata :: (MonadTx m, HasSystemDefined m, HasEnableRemoteSchemaPermsCtx m) => ReplaceMetadata -> m ()
saveMetadata (ReplaceMetadata _ tables functionsMeta
saveMetadata :: (MonadTx m, HasSystemDefined m, HasEnableRemoteSchemaPermsCtx m) => Metadata -> m ()
saveMetadata (Metadata tables functions
remoteSchemas collections allowlist customTypes actions cronTriggers) = do

withPathK "tables" $ do
Expand Down Expand Up @@ -214,7 +134,7 @@ saveMetadata (ReplaceMetadata _ tables functionsMeta

-- remote schemas
withPathK "remote_schemas" $
indexedForM_ remoteSchemas $ \(RemoteSchemaMeta name defn comment mPermissions) -> do
indexedForM_ remoteSchemas $ \(RemoteSchemaMetadata name defn comment mPermissions) -> do
liftTx $ addRemoteSchemaToCatalog $ AddRemoteSchemaQuery name defn comment
onJust mPermissions $ \permissions ->
withPathK (unNonEmptyText $ unRemoteSchemaName name) $ do
Expand All @@ -227,7 +147,7 @@ saveMetadata (ReplaceMetadata _ tables functionsMeta
throw400 ConstraintViolation
$ "remote schema permissions can only be added when "
<> "remote schema permissions are enabled in the graphql-engine"
indexedForM_ permissions $ \(RemoteSchemaPermissionMeta role permDefn permComment) ->
indexedForM_ permissions $ \(RemoteSchemaPermissionMetadata role permDefn permComment) ->
liftTx $ RemoteSchema.addRemoteSchemaPermissionsToCatalog
$ AddRemoteSchemaPermissions name role permDefn permComment

Expand Down Expand Up @@ -317,7 +237,7 @@ fetchMetadataFromHdbTables = liftTx do
functions <- Q.catchE defaultTxErrorHandler fetchFunctions

-- fetch all remote schemas
remoteSchemas <- oMapFromL _arsqName <$> fetchRemoteSchemas
remoteSchemas <- oMapFromL _rsmName <$> fetchRemoteSchemas

-- fetch all collections
collections <- oMapFromL _ccName <$> fetchCollections
Expand Down Expand Up @@ -400,18 +320,6 @@ fetchMetadataFromHdbTables = liftTx do
flip map l $ \(sn, fn, Q.AltJ config) ->
FunctionMetadata (QualifiedObject sn fn) config

fetchRemoteSchemas =
map fromRow <$> Q.listQE defaultTxErrorHandler
[Q.sql|
SELECT name, definition, comment
FROM hdb_catalog.remote_schemas
ORDER BY name ASC
|] () True
where
fromRow (name, Q.AltJ def, comment) =
AddRemoteSchemaQuery name def comment


fetchCollections =
map fromRow <$> Q.listQE defaultTxErrorHandler [Q.sql|
SELECT collection_name, collection_defn::json, comment
Expand Down
4 changes: 2 additions & 2 deletions server/src-lib/Hasura/RQL/DDL/Metadata/Generator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,10 @@ instance Arbitrary G.SchemaDocument where
instance Arbitrary RemoteSchemaPermissionDefinition where
arbitrary = genericArbitrary

instance Arbitrary RemoteSchemaPermissionMeta where
instance Arbitrary RemoteSchemaPermissionMetadata where
arbitrary = genericArbitrary

instance Arbitrary RemoteSchemaMeta where
instance Arbitrary RemoteSchemaMetadata where
arbitrary = genericArbitrary

sampleCronSchedules :: [CronSchedule]
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.