Skip to content

Commit

Permalink
Add check for use of cortex authgate, warn when it is set via storm (…
Browse files Browse the repository at this point in the history
…SYN-7007)
  • Loading branch information
vEpiphyte committed Mar 26, 2024
1 parent bdf3f63 commit c0ab4ec
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
11 changes: 10 additions & 1 deletion synapse/cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,16 @@ async def initServiceStorage(self):
'multiqueue': self.multiqueue,
})

await self.auth.addAuthGate('cortex', 'cortex')
# TODO - Remove this in 3.0.0
ag = await self.auth.addAuthGate('cortex', 'cortex')
for (useriden, user) in ag.gateusers.items():
mesg = f'User {useriden} ({user.name}) has a rule on the "cortex" authgate. This authgate is not used ' \
f'for permission checks and will be removed in Synapse v3.0.0.'
logger.warning(mesg, extra=await self.getLogExtra(user=useriden, username=user.name))
for (roleiden, role) in ag.gateroles.items():
mesg = f'Role {roleiden} ({role.name}) has a rule on the "cortex" authgate. This authgate is not used ' \
f'for permission checks and will be removed in Synapse v3.0.0.'
logger.warning(mesg, extra=await self.getLogExtra(role=roleiden, rolename=role.name))

self._initVaults()

Expand Down
10 changes: 10 additions & 0 deletions synapse/lib/stormlib/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,11 @@ async def _methUserAddRule(self, rule, gateiden=None, indx=None):
indx = await s_stormtypes.toint(indx, noneok=True)
gateiden = await s_stormtypes.tostr(gateiden, noneok=True)
self.runt.confirm(('auth', 'user', 'set', 'rules'), gateiden=gateiden)
# TODO: Remove me in 3.0.0
if gateiden == 'cortex':
mesg = f'Adding rule on the "cortex" authgate. This authgate is not used ' \
f'for permission checks and will be removed in Synapse v3.0.0.'
await self.runt.snap.warn(mesg, log=False)
await self.runt.snap.core.addUserRule(self.valu, rule, indx=indx, gateiden=gateiden)

async def _methUserDelRule(self, rule, gateiden=None):
Expand Down Expand Up @@ -1480,6 +1485,11 @@ async def _methRoleAddRule(self, rule, gateiden=None, indx=None):
indx = await s_stormtypes.toint(indx, noneok=True)
gateiden = await s_stormtypes.tostr(gateiden, noneok=True)
self.runt.confirm(('auth', 'role', 'set', 'rules'), gateiden=gateiden)
# TODO: Remove me in 3.0.0
if gateiden == 'cortex':
mesg = f'Adding rule on the "cortex" authgate. This authgate is not used ' \
f'for permission checks and will be removed in Synapse v3.0.0.'
await self.runt.snap.warn(mesg, log=False)
await self.runt.snap.core.addRoleRule(self.valu, rule, indx=indx, gateiden=gateiden)

async def _methRoleDelRule(self, rule, gateiden=None):
Expand Down
30 changes: 30 additions & 0 deletions synapse/tests/test_cortex.py
Original file line number Diff line number Diff line change
Expand Up @@ -7984,3 +7984,33 @@ async def test_cortex_query_offload(self):

msgs = await alist(core01.storm('inet:asn=0', opts={'mirror': False}))
self.len(1, [m for m in msgs if m[0] == 'node'])

async def test_cortex_authgate(self):
# TODO - Remove this in 3.0.0
with self.getTestDir() as dirn:

async with self.getTestCore(dirn=dirn) as core: # type: s_cortex.Cortex

unfo = await core.addUser('lowuser')
lowuser = unfo.get('iden')

msgs = await core.stormlist('auth.user.addrule lowuser --gate cortex node')
self.stormIsInWarn('Adding rule on the "cortex" authgate. This authgate is not used', msgs)
msgs = await core.stormlist('auth.role.addrule all --gate cortex hehe')
self.stormIsInWarn('Adding rule on the "cortex" authgate. This authgate is not used', msgs)

aslow = {'user': lowuser}

# The cortex authgate does nothing
with self.raises(s_exc.AuthDeny) as cm:
await core.nodes('[test:str=hello]', opts=aslow)

with self.getAsyncLoggerStream('synapse.cortex') as stream:
async with self.getTestCore(dirn=dirn) as core: # type: s_cortex.Cortex
# The cortex authgate still does nothing
with self.raises(s_exc.AuthDeny) as cm:
await core.nodes('[test:str=hello]', opts=aslow)
stream.seek(0)
buf = stream.read()
self.isin('(lowuser) has a rule on the "cortex" authgate', buf)
self.isin('(all) has a rule on the "cortex" authgate', buf)

0 comments on commit c0ab4ec

Please sign in to comment.