Issue 8407 - Support changelog integration into main database
Description: Add support for both the old and new replication changelogs.
First try to get and update the new entry, if it's not found
then we know we need to update the old global changelog entry.
Fixes: https://pagure.io/freeipa/issue/8407
Signed-off-by: Mark Reynolds <mreynolds@redhat.com>
Fix missing self, and missing arg
Fix copy/paste error
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
1 parent
a26e0ba558
commit
44259e8e68
5 files changed
+139
-32
No files matched your search
@@ -1,5 +1,6 @@
|
||||
# first
|
||||
plugin: update_managed_post_first
|
||||
plugin: update_changelog_maxage
|
||||
|
||||
# middle
|
||||
plugin: update_replica_attribute_lists
|
||||
|
||||
@@ -62,7 +62,3 @@ default: nsslapd-plugin-depends-on-named: Multimaster Replication Plugin
|
||||
default: nsslapd-pluginVersion: 1.0
|
||||
default: nsslapd-pluginVendor: none
|
||||
default: nsslapd-pluginDescription: none
|
||||
|
||||
# Set replication changelog limit (#5086)
|
||||
dn: cn=changelog5,cn=config
|
||||
addifnew: nsslapd-changelogmaxage: 7d
|
||||
@@ -0,0 +1,51 @@
|
||||
#
|
||||
# Copyright (C) 2020 FreeIPA Contributors see COPYING for license
|
||||
#
|
||||
import logging
|
||||
from ipalib import Registry, errors
|
||||
from ipalib import Updater
|
||||
from ipapython.dn import DN
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
register = Registry()
|
||||
|
||||
|
||||
@register()
|
||||
class update_changelog_maxage(Updater):
|
||||
"""
|
||||
Update the changelog maxage if it is not set
|
||||
"""
|
||||
|
||||
def update_entry(self, cl_entry, conn):
|
||||
maxage = cl_entry.single_value.get('nsslapd-changelogmaxage')
|
||||
if maxage is None:
|
||||
cl_entry['nsslapd-changelogmaxage'] = '7d'
|
||||
conn.update_entry(cl_entry)
|
||||
|
||||
def execute(self, **options):
|
||||
ldap = self.api.Backend.ldap2
|
||||
|
||||
for backend in ('userroot', 'ipaca'):
|
||||
dn = DN(
|
||||
('cn', 'changelog'),
|
||||
('cn', backend),
|
||||
('cn', 'ldbm database'),
|
||||
('cn', 'plugins'),
|
||||
('cn', 'config'))
|
||||
try:
|
||||
cl_entry = ldap.get_entry(dn, ['nsslapd-changelogmaxage'])
|
||||
self.update_entry(cl_entry, ldap)
|
||||
except errors.NotFound:
|
||||
# Try the old global changelog, and return
|
||||
dn = DN(
|
||||
('cn', 'changelog5'),
|
||||
('cn', 'config'))
|
||||
try:
|
||||
cl_entry = ldap.get_entry(dn, ['nsslapd-changelogmaxage'])
|
||||
self.update_entry(cl_entry, ldap)
|
||||
except errors.NotFound:
|
||||
logger.warning('Error retrieving: %s', str(dn))
|
||||
return False, []
|
||||
|
||||
return False, []
|
||||
@@ -78,22 +78,47 @@ class update_unhashed_password(Updater):
|
||||
# We are running in a winsync environment
|
||||
# Log a warning that changelog will contain sensitive data
|
||||
try:
|
||||
cldb_e = ldap.get_entry(
|
||||
DN(('cn', 'changelog5'),
|
||||
# Check if the new per-backend changelog exists...
|
||||
cldb = ldap.get_entry(
|
||||
DN(('cn', 'changelog'),
|
||||
('cn', 'userRoot'),
|
||||
('cn', 'ldbm database'),
|
||||
('cn', 'plugins'),
|
||||
('cn', 'config')))
|
||||
|
||||
# We have a backend changelog so get the db dir in this case
|
||||
db_entry = ldap.get_entry(
|
||||
DN(('cn', 'userRoot'),
|
||||
('cn', 'ldbm database'),
|
||||
('cn', 'plugins'),
|
||||
('cn', 'config')),
|
||||
['nsslapd-changelogdir'])
|
||||
cldb = cldb_e.single_value.get("nsslapd-changelogdir")
|
||||
['nsslapd-directory'])
|
||||
cldb = db_entry.single_value.get("nsslapd-directory")
|
||||
logger.warning("This server is configured for winsync, "
|
||||
"the changelog files under %s "
|
||||
"may contain clear text passwords.\n"
|
||||
"Please ensure that these files can be accessed"
|
||||
" only by trusted accounts.\n", cldb)
|
||||
except errors.NotFound:
|
||||
logger.warning("This server is configured for winsync, "
|
||||
"the changelog files may contain "
|
||||
"clear text passwords.\n"
|
||||
"Please ensure that these files can be accessed"
|
||||
" only by trusted accounts.\n")
|
||||
# Did not find backend changelog, check the global changelog
|
||||
try:
|
||||
cldb_e = ldap.get_entry(
|
||||
DN(('cn', 'changelog5'),
|
||||
('cn', 'config')),
|
||||
['nsslapd-changelogdir'])
|
||||
cldb = cldb_e.single_value.get("nsslapd-changelogdir")
|
||||
logger.warning("This server is configured for winsync, "
|
||||
"the changelog files under %s "
|
||||
"may contain clear text passwords.\n"
|
||||
"Please ensure that these files can be "
|
||||
"accessed only by trusted accounts.\n",
|
||||
cldb)
|
||||
except errors.NotFound:
|
||||
logger.warning("This server is configured for winsync, "
|
||||
"the changelog files may contain "
|
||||
"clear text passwords.\n"
|
||||
"Please ensure that these files can be "
|
||||
"accessed only by trusted accounts.\n")
|
||||
if toggle.lower() == 'on':
|
||||
# The current DS configuration already logs the
|
||||
# unhashed password
|
||||
|
||||
@@ -478,6 +478,15 @@ class ReplicationManager:
|
||||
return DN(('cn', 'replica'), ('cn', self.db_suffix),
|
||||
('cn', 'mapping tree'), ('cn', 'config'))
|
||||
|
||||
def get_be_name(self, conn):
|
||||
# Get the backend name for this suffix
|
||||
suffix_entry = conn.get_entry(
|
||||
DN(('cn', self.db_suffix),
|
||||
('cn', 'mapping tree'),
|
||||
('cn', 'config')),
|
||||
['nsslapd-backend'])
|
||||
return suffix_entry.single_value.get('nsslapd-backend')
|
||||
|
||||
def _set_replica_binddngroup(self, r_conn, entry):
|
||||
"""
|
||||
Set nsds5replicabinddngroup attribute on remote master's replica entry.
|
||||
@@ -566,26 +575,51 @@ class ReplicationManager:
|
||||
return entry
|
||||
|
||||
def setup_changelog(self, conn):
|
||||
ent = conn.get_entry(
|
||||
DN(
|
||||
('cn', 'config'), ('cn', 'ldbm database'),
|
||||
('cn', 'plugins'), ('cn', 'config')),
|
||||
['nsslapd-directory'])
|
||||
dbdir = os.path.dirname(ent.single_value.get('nsslapd-directory'))
|
||||
|
||||
entry = conn.make_entry(
|
||||
DN(('cn', 'changelog5'), ('cn', 'config')),
|
||||
{
|
||||
'objectclass': ["top", "extensibleobject"],
|
||||
'cn': ["changelog5"],
|
||||
'nsslapd-changelogdir': [os.path.join(dbdir, "cldb")],
|
||||
'nsslapd-changelogmaxage': ['7d'],
|
||||
}
|
||||
)
|
||||
try:
|
||||
conn.add_entry(entry)
|
||||
except errors.DuplicateEntry:
|
||||
return
|
||||
"""Check if we have the new per backend changelog, and set
|
||||
the trimming max-age setting. If the new changelog entry
|
||||
is not found then we are still using the old global changelog.
|
||||
"""
|
||||
cl_dn = DN(
|
||||
('cn', 'changelog'),
|
||||
('cn', self.get_be_name(conn)),
|
||||
('cn', 'ldbm database'),
|
||||
('cn', 'plugins'),
|
||||
('cn', 'config'))
|
||||
cl_entry = conn.get_entry(cl_dn)
|
||||
except errors.NotFound:
|
||||
"""Did not find a per-backend changelog, so add the global
|
||||
changelog entry. First get the database directory to build
|
||||
the changelog directory location from.
|
||||
"""
|
||||
ent = conn.get_entry(
|
||||
DN(
|
||||
('cn', 'config'),
|
||||
('cn', 'ldbm database'),
|
||||
('cn', 'plugins'),
|
||||
('cn', 'config')),
|
||||
['nsslapd-directory'])
|
||||
dbdir = os.path.dirname(ent.single_value.get('nsslapd-directory'))
|
||||
|
||||
entry = conn.make_entry(
|
||||
DN(
|
||||
('cn', 'changelog5'),
|
||||
('cn', 'config')),
|
||||
{
|
||||
'objectclass': ["top", "extensibleobject"],
|
||||
'cn': ["changelog5"],
|
||||
'nsslapd-changelogdir': [os.path.join(dbdir, "cldb")],
|
||||
'nsslapd-changelogmaxage': ['7d'],
|
||||
}
|
||||
)
|
||||
try:
|
||||
conn.add_entry(entry)
|
||||
except errors.DuplicateEntry:
|
||||
return
|
||||
else:
|
||||
# Set the changelog trimming
|
||||
cl_entry['nsslapd-changelogmaxage'] = '7d'
|
||||
conn.update_entry(cl_entry)
|
||||
|
||||
def _finalize_replica_settings(self, conn):
|
||||
"""Change replica settings to final values
|
||||
|
||||
Reference in new issue
Block a user