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
add feature flag to enable remote schema permissions
  • Loading branch information
codingkarthik committed Sep 30, 2020
commit b71a541a866b0d5ee479ccb47b9c28f77bd42ec5
12 changes: 7 additions & 5 deletions server/src-exec/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ runApp env (HGEOptionsG rci hgeCmd) =
withVersion $$(getVersionFromEnvironment) $ case hgeCmd of
HCServe serveOptions -> do
(initCtx, initTime) <- initialiseCtx env hgeCmd rci

ekgStore <- liftIO do
s <- EKG.newStore
EKG.registerGcMetrics s

let getTimeMs :: IO Int64
getTimeMs = (round . (* 1000)) `fmap` getPOSIXTime

EKG.registerCounter "ekg.server_timestamp_ms" getTimeMs s
pure s

let shutdownApp = return ()
-- Catches the SIGTERM signal and initiates a graceful shutdown.
-- Graceful shutdown for regular HTTP requests is already implemented in
Expand All @@ -81,7 +81,8 @@ runApp env (HGEOptionsG rci hgeCmd) =
(InitCtx{..}, _) <- initialiseCtx env hgeCmd rci
queryBs <- liftIO BL.getContents
let sqlGenCtx = SQLGenCtx False
res <- runAsAdmin _icPgPool sqlGenCtx _icHttpManager $ do
enableRSPermsCtx = EnableRemoteSchemaPermsCtx False
res <- runAsAdmin _icPgPool sqlGenCtx enableRSPermsCtx _icHttpManager $ do
schemaCache <- buildRebuildableSchemaCache env
execQuery env queryBs
& Tracing.runTraceTWithReporter Tracing.noReporter "execute"
Expand All @@ -93,8 +94,9 @@ runApp env (HGEOptionsG rci hgeCmd) =
HCDowngrade opts -> do
(InitCtx{..}, initTime) <- initialiseCtx env hgeCmd rci
let sqlGenCtx = SQLGenCtx False
enableRSPermsCtx = EnableRemoteSchemaPermsCtx False
res <- downgradeCatalog opts initTime
& runAsAdmin _icPgPool sqlGenCtx _icHttpManager
& runAsAdmin _icPgPool sqlGenCtx enableRSPermsCtx _icHttpManager
either (printErrJExit DowngradeProcessError) (liftIO . print) res

HCVersion -> liftIO $ putStrLn $ "Hasura GraphQL Engine: " ++ convertText currentVersion
Expand Down
26 changes: 16 additions & 10 deletions server/src-lib/Hasura/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import Hasura.RQL.Types (CacheRWM, Code (..),
HasSQLGenCtx, HasSystemDefined,
QErr (..), SQLGenCtx (..),
SchemaCache (..), UserInfoM,
EnableRemoteSchemaPermsCtx(..),
buildSchemaCacheStrict, decodeValue,
throw400, withPathK)
import Hasura.RQL.Types.Run
Expand Down Expand Up @@ -199,7 +200,7 @@ initialiseCtx env hgeCmd rci = do
instanceId <- liftIO generateInstanceId
connInfo <- liftIO procConnInfo
latch <- liftIO newShutdownLatch
(loggers, pool, sqlGenCtx) <- case hgeCmd of
(loggers, pool, sqlGenCtx, enableRSPermsCtx) <- case hgeCmd of
-- for the @serve@ command generate a regular PG pool
HCServe so@ServeOptions{..} -> do
l@(Loggers _ logger pgLogger) <- mkLoggers soEnabledLogTypes soLogLevel
Expand All @@ -208,16 +209,17 @@ initialiseCtx env hgeCmd rci = do
-- log postgres connection info
unLogger logger $ connInfoToLog connInfo
pool <- liftIO $ Q.initPGPool connInfo soConnParams pgLogger
pure (l, pool, SQLGenCtx soStringifyNum)
let remoteSchemaPermsCtx = EnableRemoteSchemaPermsCtx soEnableRemoteSchemaPermissions
pure (l, pool, SQLGenCtx soStringifyNum, remoteSchemaPermsCtx)

-- for other commands generate a minimal PG pool
_ -> do
l@(Loggers _ _ pgLogger) <- mkLoggers defaultEnabledLogTypes LevelInfo
pool <- getMinimalPool pgLogger connInfo
pure (l, pool, SQLGenCtx False)
pure (l, pool, SQLGenCtx False, EnableRemoteSchemaPermsCtx False)

res <- flip onException (flushLogger (_lsLoggerCtx loggers)) $
migrateCatalogSchema env (_lsLogger loggers) pool httpManager sqlGenCtx
migrateCatalogSchema env (_lsLogger loggers) pool httpManager sqlGenCtx enableRSPermsCtx
pure (InitCtx httpManager instanceId loggers connInfo pool latch res, initTime)
where
procConnInfo =
Expand All @@ -237,10 +239,11 @@ initialiseCtx env hgeCmd rci = do
migrateCatalogSchema
:: (HasVersion, MonadIO m)
=> Env.Environment -> Logger Hasura -> Q.PGPool -> HTTP.Manager -> SQLGenCtx
-> EnableRemoteSchemaPermsCtx
-> m (RebuildableSchemaCache Run, Maybe UTCTime)
migrateCatalogSchema env logger pool httpManager sqlGenCtx = do
migrateCatalogSchema env logger pool httpManager sqlGenCtx enableRSPermsCtx = do
let pgExecCtx = mkPGExecCtx Q.Serializable pool
adminRunCtx = RunCtx adminUserInfo httpManager sqlGenCtx
adminRunCtx = RunCtx adminUserInfo httpManager sqlGenCtx enableRSPermsCtx
currentTime <- liftIO Clock.getCurrentTime
initialiseResult <- runExceptT $ peelRun adminRunCtx pgExecCtx Q.ReadWrite Nothing $
(,) <$> migrateCatalog env currentTime <*> liftTx fetchLastUpdate
Expand Down Expand Up @@ -330,6 +333,7 @@ runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp pos
#endif

let sqlGenCtx = SQLGenCtx soStringifyNum
enableRSPermsCtx = EnableRemoteSchemaPermsCtx soEnableRemoteSchemaPermissions
Loggers loggerCtx logger _ = _icLoggers

authModeRes <- runExceptT $ setupAuthMode soAdminSecret soAuthHook soJwtSecret soUnAuthRole
Expand Down Expand Up @@ -363,6 +367,7 @@ runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp pos
postPollHook
_icSchemaCache
ekgStore
enableRSPermsCtx

-- log inconsistent schema objects
inconsObjs <- scInconsistentObjs <$> liftIO (getSCFromRef cacheRef)
Expand All @@ -371,7 +376,7 @@ runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp pos
-- start background threads for schema sync
(schemaSyncListenerThread, schemaSyncProcessorThread) <-
startSchemaSyncThreads sqlGenCtx _icPgPool logger _icHttpManager
cacheRef _icInstanceId cacheInitTime
cacheRef _icInstanceId cacheInitTime enableRSPermsCtx

let
maxEvThrds = fromMaybe defaultMaxEventThreads soEventsHttpPoolSize
Expand Down Expand Up @@ -443,7 +448,7 @@ runHGEServer env ServeOptions{..} InitCtx{..} pgExecCtx initTime shutdownApp pos

where
-- | prepareScheduledEvents is a function to unlock all the scheduled trigger
-- events that are locked and unprocessed, which is called while hasura is
-- events that are locked and unprocessed, which is called while hasura is
-- started.
--
-- Locked and unprocessed events can occur in 2 ways
Expand Down Expand Up @@ -587,11 +592,12 @@ runAsAdmin
:: (MonadIO m)
=> Q.PGPool
-> SQLGenCtx
-> EnableRemoteSchemaPermsCtx
-> HTTP.Manager
-> Run a
-> m (Either QErr a)
runAsAdmin pool sqlGenCtx httpManager m = do
let runCtx = RunCtx adminUserInfo httpManager sqlGenCtx
runAsAdmin pool sqlGenCtx enableRSPermsCtx httpManager m = do
let runCtx = RunCtx adminUserInfo httpManager sqlGenCtx enableRSPermsCtx
pgCtx = mkPGExecCtx Q.Serializable pool
runExceptT $ peelRun runCtx pgCtx Q.ReadWrite Nothing m

Expand Down
14 changes: 6 additions & 8 deletions server/src-lib/Hasura/GraphQL/Schema.hs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ buildGQLContext
, MonadIO m
, MonadUnique m
, HasSQLGenCtx m
, HasEnableRemoteSchemaPermsCtx m
)
=> ( GraphQLQueryType
, TableCache
Expand All @@ -66,13 +67,14 @@ buildGQLContext
buildGQLContext =
proc (queryType, allTables, allFunctions, allRemoteSchemas, allActions, nonObjectCustomTypes) -> do

isEnabledRemoteSchemaPerms <- bindA -< enableRemoteSchemaPerms <$> askEnableRemoteSchemaPermsCtx
-- Scroll down a few pages for the actual body...

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)
-- include the new roles only if remote schema permissions are enabled
<> (Set.fromList $ (bool mempty remoteSchemasRoles $ isEnabledRemoteSchemaPerms))

tableFilter = not . isSystemDefined . _tciSystemDefined
functionFilter = not . isSystemDefined . fiSystemDefined
Expand Down Expand Up @@ -205,12 +207,8 @@ buildGQLContext =
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
if | (roleName == adminRoleName) || (not isEnabledRemoteSchemaPerms) -> pure $ map snd remotes
| otherwise -> buildRoleBasedRemoteSchemaParser roleName allRemoteSchemas
let qRemotes = queryRemotes roleBasedRemoteSchemas
mRemotes = mutationRemotes roleBasedRemoteSchemas
let gqlContext = GQLContext
Expand Down
11 changes: 9 additions & 2 deletions server/src-lib/Hasura/RQL/DDL/Schema/Cache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,14 @@ import Hasura.SQL.Types
import Hasura.Session

buildRebuildableSchemaCache
:: (HasVersion, MonadIO m, MonadUnique m, MonadTx m, HasHttpManager m, HasSQLGenCtx m)
:: ( HasVersion
, MonadIO m
, MonadUnique m
, MonadTx m
, HasHttpManager m
, HasSQLGenCtx m
, HasEnableRemoteSchemaPermsCtx m
)
=> Env.Environment
-> m (RebuildableSchemaCache m)
buildRebuildableSchemaCache env = do
Expand Down Expand Up @@ -117,7 +124,7 @@ buildSchemaCacheRule
-- what we want!
:: ( HasVersion, ArrowChoice arr, Inc.ArrowDistribute arr, Inc.ArrowCache m arr
, MonadIO m, MonadUnique m, MonadTx m
, MonadReader BuildReason m, HasHttpManager m, HasSQLGenCtx m )
, MonadReader BuildReason m, HasHttpManager m, HasSQLGenCtx m, HasEnableRemoteSchemaPermsCtx m)
=> Env.Environment
-> (CatalogMetadata, InvalidationKeys) `arr` SchemaCache
buildSchemaCacheRule env = proc (catalogMetadata, invalidationKeys) -> do
Expand Down
27 changes: 27 additions & 0 deletions server/src-lib/Hasura/RQL/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ module Hasura.RQL.Types
, SQLGenCtx(..)
, HasSQLGenCtx(..)

, EnableRemoteSchemaPermsCtx(..)
, HasEnableRemoteSchemaPermsCtx(..)

, HasSystemDefined(..)
, HasSystemDefinedT
, runHasSystemDefinedT
Expand Down Expand Up @@ -151,6 +154,30 @@ instance (HasHttpManager m) => HasHttpManager (TraceT m) where
-- instance (Monoid w, HasGCtxMap m) => HasGCtxMap (WriterT w m) where
-- askGCtxMap = lift askGCtxMap

newtype EnableRemoteSchemaPermsCtx
= EnableRemoteSchemaPermsCtx
{ enableRemoteSchemaPerms :: Bool
} deriving (Show, Eq)

class (Monad m) => HasEnableRemoteSchemaPermsCtx m where
askEnableRemoteSchemaPermsCtx :: m EnableRemoteSchemaPermsCtx

instance (HasEnableRemoteSchemaPermsCtx m)
=> HasEnableRemoteSchemaPermsCtx (ReaderT r m) where
askEnableRemoteSchemaPermsCtx = lift askEnableRemoteSchemaPermsCtx
instance (HasEnableRemoteSchemaPermsCtx m)
=> HasEnableRemoteSchemaPermsCtx (StateT s m) where
askEnableRemoteSchemaPermsCtx = lift askEnableRemoteSchemaPermsCtx
instance (Monoid w, HasEnableRemoteSchemaPermsCtx m)
=> HasEnableRemoteSchemaPermsCtx (WriterT w m) where
askEnableRemoteSchemaPermsCtx = lift askEnableRemoteSchemaPermsCtx
instance (HasEnableRemoteSchemaPermsCtx m)
=> HasEnableRemoteSchemaPermsCtx (TableCoreCacheRT m) where
askEnableRemoteSchemaPermsCtx = lift askEnableRemoteSchemaPermsCtx
instance (HasEnableRemoteSchemaPermsCtx m)
=> HasEnableRemoteSchemaPermsCtx (TraceT m) where
askEnableRemoteSchemaPermsCtx = lift askEnableRemoteSchemaPermsCtx

newtype SQLGenCtx
= SQLGenCtx
{ stringifyNum :: Bool
Expand Down
12 changes: 8 additions & 4 deletions server/src-lib/Hasura/RQL/Types/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import qualified Hasura.Tracing as Tracing

data RunCtx
= RunCtx
{ _rcUserInfo :: !UserInfo
, _rcHttpMgr :: !HTTP.Manager
, _rcSqlGenCtx :: !SQLGenCtx
{ _rcUserInfo :: !UserInfo
, _rcHttpMgr :: !HTTP.Manager
, _rcSqlGenCtx :: !SQLGenCtx
, _rcEnableRemoteSchemaPermsCtx :: !EnableRemoteSchemaPermsCtx
}

newtype Run a
Expand All @@ -46,6 +47,9 @@ instance HasHttpManager Run where
instance HasSQLGenCtx Run where
askSQLGenCtx = asks _rcSqlGenCtx

instance HasEnableRemoteSchemaPermsCtx Run where
askEnableRemoteSchemaPermsCtx = asks _rcEnableRemoteSchemaPermsCtx

peelRun
:: (MonadIO m)
=> RunCtx
Expand All @@ -54,5 +58,5 @@ peelRun
-> Maybe Tracing.TraceContext
-> Run a
-> ExceptT QErr m a
peelRun runCtx@(RunCtx userInfo _ _) pgExecCtx txAccess ctx (Run m) =
peelRun runCtx@(RunCtx userInfo _ _ _) pgExecCtx txAccess ctx (Run m) =
runLazyTx pgExecCtx txAccess $ maybe id withTraceContext ctx $ withUserInfo userInfo $ runReaderT m runCtx
7 changes: 4 additions & 3 deletions server/src-lib/Hasura/Server/API/Query.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ runQuery
:: (HasVersion, MonadIO m, MonadError QErr m, Tracing.MonadTrace m)
=> Env.Environment -> PGExecCtx -> InstanceId
-> UserInfo -> RebuildableSchemaCache Run -> HTTP.Manager
-> SQLGenCtx -> SystemDefined -> RQLQuery -> m (EncJSON, RebuildableSchemaCache Run)
runQuery env pgExecCtx instanceId userInfo sc hMgr sqlGenCtx systemDefined query = do
-> SQLGenCtx -> EnableRemoteSchemaPermsCtx -> SystemDefined
-> RQLQuery -> m (EncJSON, RebuildableSchemaCache Run)
runQuery env pgExecCtx instanceId userInfo sc hMgr sqlGenCtx enableRSPermsCtx systemDefined query = do
accessMode <- getQueryAccessMode query
traceCtx <- Tracing.currentContext
resE <- runQueryM env query & Tracing.interpTraceT \x -> do
Expand All @@ -214,7 +215,7 @@ runQuery env pgExecCtx instanceId userInfo sc hMgr sqlGenCtx systemDefined query
(\((js, meta), rsc, ci) -> (Right (js, rsc, ci), meta)) a)
either throwError withReload resE
where
runCtx = RunCtx userInfo hMgr sqlGenCtx
runCtx = RunCtx userInfo hMgr sqlGenCtx enableRSPermsCtx
withReload (result, updatedCache, invalidations) = do
when (queryModifiesSchemaCache query) $ do
e <- liftIO $ runExceptT $ runLazyTx pgExecCtx Q.ReadWrite $ liftTx $
Expand Down
29 changes: 16 additions & 13 deletions server/src-lib/Hasura/Server/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ data ServerCtx
, scEkgStore :: !EKG.Store
, scResponseInternalErrorsConfig :: !ResponseInternalErrorsConfig
, scEnvironment :: !Env.Environment
, scEnableRemoteSchemaPermsCtx :: !EnableRemoteSchemaPermsCtx
}

data HandlerCtx
Expand Down Expand Up @@ -352,20 +353,20 @@ v1QueryHandler query = do
authorizeMetadataApi query userInfo
scRef <- asks (scCacheRef . hcServerCtx)
logger <- asks (scLogger . hcServerCtx)
res <- bool (fst <$> dbAction) (withSCUpdate scRef logger dbAction) $ queryModifiesSchemaCache query
res <- bool (fst <$> action) (withSCUpdate scRef logger action) $ queryModifiesSchemaCache query
return $ HttpResponse res []
where
-- Hit postgres
dbAction = do
userInfo <- asks hcUser
scRef <- asks (scCacheRef . hcServerCtx)
schemaCache <- fmap fst $ liftIO $ readIORef $ _scrCache scRef
httpMgr <- asks (scManager . hcServerCtx)
sqlGenCtx <- asks (scSQLGenCtx . hcServerCtx)
pgExecCtx <- asks (scPGExecCtx . hcServerCtx)
instanceId <- asks (scInstanceId . hcServerCtx)
env <- asks (scEnvironment . hcServerCtx)
runQuery env pgExecCtx instanceId userInfo schemaCache httpMgr sqlGenCtx (SystemDefined False) query
action = do
userInfo <- asks hcUser
scRef <- asks (scCacheRef . hcServerCtx)
schemaCache <- fmap fst $ liftIO $ readIORef $ _scrCache scRef
httpMgr <- asks (scManager . hcServerCtx)
sqlGenCtx <- asks (scSQLGenCtx . hcServerCtx)
pgExecCtx <- asks (scPGExecCtx . hcServerCtx)
instanceId <- asks (scInstanceId . hcServerCtx)
env <- asks (scEnvironment . hcServerCtx)
enableRSPermsCtx <- asks (scEnableRemoteSchemaPermsCtx . hcServerCtx)
runQuery env pgExecCtx instanceId userInfo schemaCache httpMgr sqlGenCtx enableRSPermsCtx (SystemDefined False) query

v1Alpha1GQHandler
:: ( HasVersion
Expand Down Expand Up @@ -603,9 +604,10 @@ mkWaiApp
-> Maybe EL.LiveQueryPostPollHook
-> (RebuildableSchemaCache Run, Maybe UTCTime)
-> EKG.Store
-> EnableRemoteSchemaPermsCtx
-> m HasuraApp
mkWaiApp env isoLevel logger sqlGenCtx enableAL pool pgExecCtxCustom ci httpManager mode corsCfg enableConsole consoleAssetsDir
enableTelemetry instanceId apis lqOpts _ {- planCacheOptions -} responseErrorsConfig liveQueryHook (schemaCache, cacheBuiltTime) ekgStore = do
enableTelemetry instanceId apis lqOpts _ {- planCacheOptions -} responseErrorsConfig liveQueryHook (schemaCache, cacheBuiltTime) ekgStore enableRSPermsCtx = do

-- See Note [Temporarily disabling query plan caching]
-- (planCache, schemaCacheRef) <- initialiseCache
Expand Down Expand Up @@ -636,6 +638,7 @@ mkWaiApp env isoLevel logger sqlGenCtx enableAL pool pgExecCtxCustom ci httpMana
, scEkgStore = ekgStore
, scEnvironment = env
, scResponseInternalErrorsConfig = responseErrorsConfig
, scEnableRemoteSchemaPermsCtx = enableRSPermsCtx
}

spockApp <- liftWithStateless $ \lowerIO ->
Expand Down
Loading