Skip to content

Commit

Permalink
Prepare directory services cache for IPA changes (#13924)
Browse files Browse the repository at this point in the history
This commit creates a generic directory-service agnostic user
and group cache in perparation for adding IPA directory service
integration. It also includes opportunistic API cleanups by
removing the TDB plugin that was initially written for clustering
support in favor of shifting TDB wrappers into a utils file with
direct CI tests.
  • Loading branch information
anodos325 authored Jun 27, 2024
1 parent 592f745 commit eb1f1a3
Show file tree
Hide file tree
Showing 30 changed files with 1,477 additions and 1,471 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
SHELL=/bin/sh
PATH=/etc:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

30 3 * * * root midclt call dscache.refresh > /dev/null 2>&1
30 3 * * * root midclt call directoryservices.cache.refresh_impl > /dev/null 2>&1
45 3 * * * root midclt call config.backup >/dev/null 2>&1

45 3 * * * root midclt call pool.scrub.run ${boot_pool} ${system_advanced['boot_scrub']} > /dev/null 2>&1
Expand Down
4 changes: 2 additions & 2 deletions src/middlewared/middlewared/plugins/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ async def query(self, filters, options):
if dssearch:
ds_state = await self.middleware.call('directoryservices.get_state')
if ds_state['activedirectory'] == 'HEALTHY' or ds_state['ldap'] == 'HEALTHY':
ds_users = await self.middleware.call('directoryservices.cache.query', 'USERS', filters, options.copy())
ds_users = await self.middleware.call('directoryservices.cache.query', 'USER', filters, options.copy())
# For AD users, we will not have 2FA attribute normalized so let's do that
ad_users_2fa_mapping = await self.middleware.call('auth.twofactor.get_ad_users')
for index, user in enumerate(filter(
Expand Down Expand Up @@ -1741,7 +1741,7 @@ async def query(self, filters, options):
if dssearch:
ds_state = await self.middleware.call('directoryservices.get_state')
if ds_state['activedirectory'] == 'HEALTHY' or ds_state['ldap'] == 'HEALTHY':
ds_groups = await self.middleware.call('directoryservices.cache.query', 'GROUPS', filters, options)
ds_groups = await self.middleware.call('directoryservices.cache.query', 'GROUP', filters, options)

if 'SMB' in additional_information:
try:
Expand Down
5 changes: 3 additions & 2 deletions src/middlewared/middlewared/plugins/activedirectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,8 @@ async def __start(self, job):
if ret == neterr.JOINED:
await self.set_state(DSStatus['HEALTHY'].name)
job.set_progress(90, 'Restarting dependent services.')
await self.middleware.call('service.start', 'dscache')
cache_fill = await self.middleware.call('directoryservices.cache.refresh_impl')
await cache_fill.wait()
await self.middleware.call('directoryservices.restart_dependent_services')
if ad['verbose_logging']:
self.logger.debug('Successfully started AD service for [%s].', ad['domainname'])
Expand Down Expand Up @@ -890,7 +891,7 @@ async def __stop(self, job, config):
await self.middleware.call('etc.generate', 'nss')
await self.set_state(DSStatus['DISABLED'].name)
job.set_progress(60, 'clearing caches.')
await self.middleware.call('service.stop', 'dscache')
await self.middleware.call('directoryservices.cache.abort_refresh')
await self.middleware.call('service.start', 'cifs')
await self.set_state(DSStatus['DISABLED'].name)
job.set_progress(100, 'Active Directory stop completed.')
Expand Down
154 changes: 0 additions & 154 deletions src/middlewared/middlewared/plugins/activedirectory_/cache.py

This file was deleted.

14 changes: 7 additions & 7 deletions src/middlewared/middlewared/plugins/directoryservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ async def status(self):
# status more directly and deprecate the `get_state` method.
state = await self.get_state()
for ds in DSType:
if (status := state.get(ds.value, 'DISABLED')) == DSStatus.DISABLED.name:
if (status := state.get(ds.value.lower(), 'DISABLED')) == DSStatus.DISABLED.name:
continue

return {
'type': ds.value.upper(),
'type': ds.value,
'status': status
}

Expand Down Expand Up @@ -89,8 +89,8 @@ async def get_state(self):
# TODO: IPA join not implemented yet
continue
try:
res = await self.middleware.call(f'{srv.value}.started')
ds_state[srv.value] = DSStatus.HEALTHY.name if res else DSStatus.DISABLED.name
res = await self.middleware.call(f'{srv.value.lower()}.started')
ds_state[srv.value.lower()] = DSStatus.HEALTHY.name if res else DSStatus.DISABLED.name

except CallError as e:
if e.errno == errno.EINVAL:
Expand Down Expand Up @@ -124,7 +124,7 @@ async def set_state(self, new):
return await self.middleware.call('cache.put', 'DS_STATE', ds_state)

@accepts()
@job()
@job(lock="directoryservices_refresh_cache", lock_queue_size=1)
async def cache_refresh(self, job):
"""
This method refreshes the directory services cache for users and groups that is
Expand All @@ -139,7 +139,7 @@ async def cache_refresh(self, job):
permissions and ACL related methods. Likewise, a cache refresh will not resolve issues
with users being unable to authenticate to shares.
"""
return await job.wrap(await self.middleware.call('directoryservices.cache.refresh'))
return await job.wrap(await self.middleware.call('directoryservices.cache.refresh_impl'))

@private
@returns(List(
Expand Down Expand Up @@ -176,7 +176,7 @@ async def sasl_wrapping_choices(self, dstype):
name='nss_info_choices'
))
async def nss_info_choices(self, dstype):
ds = DSType(dstype.lower())
ds = DSType(dstype)
ret = []

for x in list(NSS_Info):
Expand Down
Loading

0 comments on commit eb1f1a3

Please sign in to comment.