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
generate role based schema for each role
  • Loading branch information
codingkarthik committed Sep 29, 2020
commit aa51c230a321daa72be826420e314aa56ece24a1
60 changes: 50 additions & 10 deletions server/src-lib/Hasura/GraphQL/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Hasura.GraphQL.Schema.Introspect
import Hasura.GraphQL.Schema.Mutation
import Hasura.GraphQL.Schema.Select
import Hasura.GraphQL.Schema.Table
import Hasura.GraphQL.Schema.Remote (buildRemoteParser)
import Hasura.RQL.DDL.Schema.Cache.Common
import Hasura.RQL.Types
import Hasura.Session
Expand All @@ -39,6 +40,8 @@ import Hasura.SQL.Types
-- | Whether the request is sent with `x-hasura-use-backend-only-permissions` set to `true`.
data Scenario = Backend | Frontend deriving (Enum, Show, Eq)

type RemoteSchemaCache = HashMap RemoteSchemaName (RemoteSchemaCtxWithPermissions, MetadataObject)

buildGQLContext
:: forall arr m
. ( ArrowChoice arr
Expand All @@ -52,7 +55,7 @@ buildGQLContext
=> ( GraphQLQueryType
, TableCache
, FunctionCache
, HashMap RemoteSchemaName (RemoteSchemaCtxWithPermissions, MetadataObject)
, RemoteSchemaCache
, ActionCache
, NonObjectTypeMap
)
Expand All @@ -65,9 +68,11 @@ buildGQLContext =

-- Scroll down a few pages for the actual body...

let allRoles = Set.insert adminRoleName $
let remoteSchemasRoles = concatMap (Map.keys . rscpPermissions . fst . snd) $ Map.toList allRemoteSchemas
allRoles = Set.insert adminRoleName $
(allTables ^.. folded.tiRolePermInfoMap.to Map.keys.folded)
<> (allActionInfos ^.. folded.aiPermissions.to Map.keys.folded)
<> (Set.fromList remoteSchemasRoles)

tableFilter = not . isSystemDefined . _tciSystemDefined
functionFilter = not . isSystemDefined . fiSystemDefined
Expand Down Expand Up @@ -151,29 +156,64 @@ buildGQLContext =
Just _ -> returnA -< (newSchemaName, rscParsed $ rscpContext newSchemaContext):okSchemas
) |) [] (Map.toList allRemoteSchemas)

-- TODO: I think this will need to change, we'll have to read the unauthenticated role from the server options
-- and then use the remote schema defined for that role!
let unauthenticatedContext :: m GQLContext
unauthenticatedContext = P.runSchemaT do
ucQueries <- finalizeParser <$> unauthenticatedQueryWithIntrospection queryRemotes mutationRemotes
ucMutations <- fmap finalizeParser <$> unauthenticatedMutation mutationRemotes
ucQueries <- finalizeParser <$> unauthenticatedQueryWithIntrospection adminQueryRemotes adminMutationRemotes
ucMutations <- fmap finalizeParser <$> unauthenticatedMutation adminMutationRemotes
pure $ GQLContext ucQueries ucMutations

buildRoleBasedRemoteSchemaParser :: RoleName -> RemoteSchemaCache -> m [ParsedIntrospection]
buildRoleBasedRemoteSchemaParser role remoteSchemaCache = do
let remoteSchemaIntroInfos = map fst $ toList remoteSchemaCache
remoteSchemaPerms <-
flip traverse remoteSchemaIntroInfos $ \(RemoteSchemaCtxWithPermissions _ ctx perms) ->
case Map.lookup role perms of
Nothing -> return Nothing
Just introspectRes -> do
(queryParsers, mutationParsers, subscriptionParsers) <-
P.runSchemaT @m @(P.ParseT Identity) $ buildRemoteParser introspectRes $ rscInfo ctx
return $ Just $ ParsedIntrospection queryParsers mutationParsers subscriptionParsers
return $ catMaybes remoteSchemaPerms

-- | The 'query' type of the remotes. TODO: also expose mutation
-- remotes. NOT TODO: subscriptions, as we do not yet aim to support
-- these.
queryRemotes = concatMap (piQuery . snd) remotes
mutationRemotes = concatMap (concat . piMutation . snd) remotes
queryHasuraOrRelay = case queryType of
adminQueryRemotes = concatMap (piQuery . snd) remotes
adminMutationRemotes = concatMap (concat . piMutation . snd) remotes

queryRemotes
:: [ParsedIntrospection]
-> [P.FieldParser (P.ParseT Identity) (RemoteSchemaInfo, G.Field G.NoFragments P.Variable)]
queryRemotes = concatMap piQuery

mutationRemotes
:: [ParsedIntrospection]
-> [P.FieldParser (P.ParseT Identity) (RemoteSchemaInfo, G.Field G.NoFragments P.Variable)]
mutationRemotes = concatMap (concat . piMutation)

queryHasuraOrRelay (qRemotes, mRemotes) = case queryType of
QueryHasura -> queryWithIntrospection (Set.fromMap $ validTables $> ())
validFunctions queryRemotes mutationRemotes
validFunctions qRemotes mRemotes
allActionInfos nonObjectCustomTypes
QueryRelay -> relayWithIntrospection (Set.fromMap $ validTables $> ()) validFunctions

buildContextForRoleAndScenario :: RoleName -> Scenario -> m GQLContext
buildContextForRoleAndScenario roleName scenario = do
SQLGenCtx{ stringifyNum } <- askSQLGenCtx
roleBasedRemoteSchemas <-
case roleName == adminRoleName of
-- The admin role will have full access to the remote schema, so
-- we just re-use the `ParsedIntrospection` we already have in the
-- `remotes` object
True -> pure $ map snd remotes
False -> buildRoleBasedRemoteSchemaParser roleName allRemoteSchemas
let qRemotes = queryRemotes roleBasedRemoteSchemas
mRemotes = mutationRemotes roleBasedRemoteSchemas
let gqlContext = GQLContext
<$> (finalizeParser <$> queryHasuraOrRelay)
<*> (fmap finalizeParser <$> mutation (Set.fromList $ Map.keys validTables) mutationRemotes
<$> (finalizeParser <$> queryHasuraOrRelay (qRemotes,mRemotes))
<*> (fmap finalizeParser <$> mutation (Set.fromList $ Map.keys validTables) adminMutationRemotes
allActionInfos nonObjectCustomTypes)
flip runReaderT (roleName, validTables, scenario, QueryContext stringifyNum queryType queryRemotesMap) $
P.runSchemaT gqlContext
Expand Down
3 changes: 2 additions & 1 deletion server/src-lib/Hasura/RQL/DDL/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Hasura.RQL.DDL.EventTrigger (delEventTriggerFromCatalog,
import Hasura.RQL.DDL.Metadata.Types
import Hasura.RQL.DDL.Permission.Internal (dropPermFromCatalog)
import Hasura.RQL.DDL.RemoteSchema (addRemoteSchemaToCatalog, fetchRemoteSchemas,
removeRemoteSchemaFromCatalog)
removeRemoteSchemaFromCatalog, dropRemoteSchemaPermFromCatalog)
import Hasura.RQL.DDL.ScheduledTrigger (addCronTriggerToCatalog,
deleteCronTriggerFromCatalog)
import Hasura.RQL.DDL.Schema.Catalog (saveTableToCatalog)
Expand Down Expand Up @@ -537,6 +537,7 @@ purgeMetadataObj = liftTx . \case
MOTable qt -> Schema.deleteTableFromCatalog qt
MOFunction qf -> Schema.delFunctionFromCatalog qf
MORemoteSchema rsn -> removeRemoteSchemaFromCatalog rsn
MORemoteSchemaPermissions rsName role -> dropRemoteSchemaPermFromCatalog rsName role
MOTableObj qt (MTORel rn _) -> Relationship.delRelFromCatalog qt rn
MOTableObj qt (MTOPerm rn pt) -> dropPermFromCatalog qt rn pt
MOTableObj _ (MTOTrigger trn) -> delEventTriggerFromCatalog trn
Expand Down
24 changes: 15 additions & 9 deletions server/src-lib/Hasura/RQL/DDL/RemoteSchema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Hasura.RQL.DDL.RemoteSchema
, addRemoteSchemaToCatalog
, addRemoteSchemaPermissionsToCatalog
, runAddRemoteSchemaPermissions
, dropRemoteSchemaPermFromCatalog
) where

import Control.Monad.Unique
Expand All @@ -34,6 +35,8 @@ import Hasura.SQL.Types

import qualified Data.Environment as Env

import Hasura.Session

runAddRemoteSchema
:: ( HasVersion
, QErrM m
Expand All @@ -55,29 +58,25 @@ runAddRemoteSchema env q = do
name = _arsqName q

runAddRemoteSchemaPermissions
:: ( HasVersion
, QErrM m
:: ( QErrM m
, CacheRWM m
, MonadTx m
, MonadIO m
, MonadUnique m
, HasHttpManager m
)
=> AddRemoteSchemaPermissions
-> m EncJSON
runAddRemoteSchemaPermissions q = do
remoteSchemaMap <- scRemoteSchemas <$> askSchemaCache
upstreamRemoteSchema <-
onNothing (Map.lookup name remoteSchemaMap) $
throw400 NotExists "no such remote schema"
throw400 NotExists $ "remote schema " <> name <<> " doesn't exist"
resolveRoleBasedRemoteSchema providedSchemaDoc $ irDoc $ rscIntro $ rscpContext upstreamRemoteSchema
liftTx $ addRemoteSchemaPermissionsToCatalog q
-- buildSchemaCacheFor $ MORemoteSchema name
buildSchemaCacheFor $ MORemoteSchemaPermissions name role
pure successMsg
where
name = _arspRemoteSchema q
AddRemoteSchemaPermissions name role defn _ = q

providedSchemaDoc = _rspdSchema $ _arspDefinition q
providedSchemaDoc = _rspdSchema defn

addRemoteSchemaP1
:: (QErrM m, CacheRM m)
Expand Down Expand Up @@ -164,6 +163,13 @@ removeRemoteSchemaFromCatalog name =
WHERE name = $1
|] (Identity name) True

dropRemoteSchemaPermFromCatalog :: RemoteSchemaName -> RoleName -> Q.TxE QErr ()
dropRemoteSchemaPermFromCatalog name role =
Q.unitQE defaultTxErrorHandler [Q.sql|
DELETE FROM hdb_catalog.hdb_remote_schema_permission
WHERE remote_schema_name = $1 AND role_name = $2
|] (name, role) True

fetchRemoteSchemas :: Q.TxE QErr [AddRemoteSchemaQuery]
fetchRemoteSchemas =
map fromRow <$> Q.listQE defaultTxErrorHandler
Expand Down
7 changes: 5 additions & 2 deletions server/src-lib/Hasura/RQL/DDL/RemoteSchema/Validate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Control.Monad.Validate

import Hasura.Prelude
import Hasura.SQL.Types
import Hasura.RQL.Types hiding (GraphQLType)
import Hasura.RQL.Types hiding (GraphQLType, defaultScalars)
import Hasura.Server.Utils (englishList, duplicates)

import qualified Data.HashMap.Strict as Map
Expand Down Expand Up @@ -549,7 +549,7 @@ getSchemaDocIntrospection
-> (G.Name, Maybe G.Name, Maybe G.Name)
-> IntrospectionResult
getSchemaDocIntrospection schemaDocTypeDefs (queryRoot, mutationRoot, subscriptionRoot) =
let scalarTypeDefs = map G.TypeDefinitionScalar scalars
let scalarTypeDefs = map G.TypeDefinitionScalar $ scalars <> defaultScalars
objectTypeDefs = map G.TypeDefinitionObject objects
unionTypeDefs = map G.TypeDefinitionUnion unions
enumTypeDefs = map G.TypeDefinitionEnum enums
Expand All @@ -574,6 +574,9 @@ getSchemaDocIntrospection schemaDocTypeDefs (queryRoot, mutationRoot, subscripti
SchemaDocumentTypeDefinitions scalars objects interfaces
unions enums inpObjs _ = schemaDocTypeDefs

defaultScalars = map (\n -> G.ScalarTypeDefinition Nothing n [])
$ [intScalar, floatScalar, stringScalar, boolScalar, idScalar]

-- | validateRemoteSchema accepts two arguments, the `SchemaDocument` of
-- the role-based schema, that is provided by the user and the `SchemaIntrospection`
-- of the upstream remote schema. This function, in turn calls the other validation
Expand Down
3 changes: 1 addition & 2 deletions server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ import Hasura.RQL.DDL.Utils (clearHdbViews)
import Hasura.RQL.DDL.RemoteSchema.Validate (resolveRoleBasedRemoteSchema)
import Hasura.RQL.Types
import Hasura.RQL.Types.Catalog
import Hasura.RQL.Types.SchemaCacheTypes (RemoteSchemaPermObjId(..))
import Hasura.Server.Version (HasVersion)
import Hasura.SQL.Types

Expand Down Expand Up @@ -369,7 +368,7 @@ buildSchemaCacheRule env = proc (catalogMetadata, invalidationKeys) -> do
buildRemoteSchemaPermission = proc (remoteSchemaCtx, remoteSchemaPerm) -> do
let AddRemoteSchemaPermissions rsName roleName defn _ = remoteSchemaPerm
metadataObject = mkRemoteSchemaPermissionMetadataObject remoteSchemaPerm
schemaObject = SORemoteSchemaObj rsName $ RemoteSchemaPermObjId roleName
schemaObject = SORemoteSchemaPermission rsName roleName
upstreamSchemaIntrospection = irDoc $ rscIntro remoteSchemaCtx
providedSchemaDoc = _rspdSchema defn
addPermContext err = "in remote schema permission for role " <> roleName <<> ": " <> err
Expand Down
7 changes: 7 additions & 0 deletions server/src-lib/Hasura/RQL/DDL/Schema/Cache/Dependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ pruneDanglingDependents cache = fmap (M.filter (not . null)) . traverse do
Left $ "function " <> functionName <<> " is not tracked"
SORemoteSchema remoteSchemaName -> unless (remoteSchemaName `M.member` _boRemoteSchemas cache) $
Left $ "remote schema " <> remoteSchemaName <<> " is not found"
SORemoteSchemaPermission remoteSchemaName roleName -> do
remoteSchema <-
onNothing (M.lookup remoteSchemaName $ _boRemoteSchemas cache)
$ Left $ "remote schema " <> remoteSchemaName <<> " is not found"
unless (roleName `M.member` (rscpPermissions $ fst remoteSchema)) $
Left $ "no permission defined on remote schema " <> remoteSchemaName
<<> " for role " <>> roleName
SOTableObj tableName tableObjectId -> do
tableInfo <- resolveTable tableName
case tableObjectId of
Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/RQL/Types/SchemaCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ data RemoteSchemaCtxWithPermissions
instance ToJSON RemoteSchemaCtxWithPermissions where
toJSON (RemoteSchemaCtxWithPermissions name ctx _ ) =
object $
[ "name" .= name
[ "name" .= name
, "context" .= ctx
]

Expand Down
11 changes: 3 additions & 8 deletions server/src-lib/Hasura/RQL/Types/SchemaCacheTypes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@ data TableObjId
deriving (Show, Eq, Generic)
instance Hashable TableObjId

data RemoteSchemaPermObjId =
RemoteSchemaPermObjId !RoleName
deriving (Show, Eq, Generic)
instance Hashable RemoteSchemaPermObjId

data SchemaObjId
= SOTable !QualifiedTable
| SOTableObj !QualifiedTable !TableObjId
| SOFunction !QualifiedFunction
| SORemoteSchema !RemoteSchemaName
| SORemoteSchemaObj !RemoteSchemaName !RemoteSchemaPermObjId
| SORemoteSchemaPermission !RemoteSchemaName !RoleName
deriving (Eq, Generic)

instance Hashable SchemaObjId
Expand All @@ -63,10 +58,10 @@ reportSchemaObj (SOTableObj tn (TORemoteRel rn)) =
"remote relationship " <> qualObjectToText tn <> "." <> remoteRelationshipNameToText rn
reportSchemaObj (SORemoteSchema remoteSchemaName) =
"remote schema " <> unNonEmptyText (unRemoteSchemaName remoteSchemaName)
reportSchemaObj (SORemoteSchemaObj remoteSchemaName (RemoteSchemaPermObjId roleName)) =
reportSchemaObj (SORemoteSchemaPermission remoteSchemaName roleName) =
"remote schema permission "
<> unNonEmptyText (unRemoteSchemaName remoteSchemaName)
<> "." <> roleNameToTxt roleName
<> "." <>> roleName

instance Show SchemaObjId where
show soi = T.unpack $ reportSchemaObj soi
Expand Down
2 changes: 1 addition & 1 deletion server/src-lib/Hasura/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import qualified Network.HTTP.Types as HTTP
newtype RoleName
= RoleName {getRoleTxt :: NonEmptyText}
deriving ( Show, Eq, Ord, Hashable, FromJSONKey, ToJSONKey, FromJSON
, ToJSON, Q.FromCol, Q.ToPrepArg, Lift, Generic, Arbitrary, NFData, Cacheable )
, ToJSON, Q.FromCol, Q.ToPrepArg, Lift, Generic, Arbitrary, NFData, Cacheable)

instance DQuote RoleName where
dquoteTxt = roleNameToTxt
Expand Down