-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix and test IdM related parsers and combiners (#4178)
* fix(parsr): do not auto-create magic methods in __getattr__ The previous code would just provide any attribute, including the magic methods. Especially __deepcopy__ method that breaks deepcopy(parser_object). Signed-off-by: Pavel Březina <[email protected]> * fix(identity_domain): use correct SSSD realm option SSSD does not have krb5_domain, but krb5_realm. Signed-off-by: Pavel Březina <[email protected]> * fix(identity_domain): do not add realm twice This realm could have been already added as SSSD domain. Signed-off-by: Pavel Březina <[email protected]> * fix(sssd): refactor the code, fix issues and add SSSDConfAll Existing implementation of SSSD configuration parser did not consinder SSSD's include directory and other new functionality. * Add support for sssd.conf and conf.d include folder * Add SSSDConfAll combiner that merge all configuration files together * Add support for [domain/$dom]/enabled in addition to [sssd]/domain * Refactor the code to follow naming convention of other parsers/combiners Signed-off-by: Pavel Březina <[email protected]> * fix(ipa): simplify code and logic The current IPA combiner logic was quite complex, difficult to test and prone to errors. * It is sufficient to only test the SSSD configuration in order to get the server mode, other checks are redundant. * It is sufficient if there is any SSSD domain with ipa provider to get the client mode * SSSD domain name may differ from the IPA domain name, even though this is not the default setup, it can be changed. * Release information was removed, it make testing unnecessarily more complex. * It is possible to configure SSSD as IPA client without the freeipa-client package if one does not use ipa-client-install or realm command. Checking if SSSD package is there and IPA domain is configured is sufficient. Signed-off-by: Pavel Březina <[email protected]> * fix(identity_domain): write extensive tests ...and make krb5 configuration deterministic. Signed-off-by: Pavel Březina <[email protected]> --------- Signed-off-by: Pavel Březina <[email protected]>
- Loading branch information
Showing
13 changed files
with
1,196 additions
and
441 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.. automodule:: insights.combiners.sssd_conf | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
""" | ||
SSSD Configuration | ||
================== | ||
Provides access to complete SSSD configuration: /etc/sssd/sssd.conf with merged | ||
configuration snippets from /etc/sssd/conf.d. | ||
""" | ||
|
||
from copy import deepcopy | ||
|
||
from insights.core.plugins import combiner | ||
from insights.parsers.sssd_conf import SSSDConf, SSSDConfd | ||
|
||
|
||
@combiner(SSSDConf, SSSDConfd) | ||
class SSSDConfAll(object): | ||
""" | ||
Provides access to complete SSSD configuration: /etc/sssd/sssd.conf with | ||
merged configuration snippets from /etc/sssd/conf.d. | ||
""" | ||
def __init__(self, sssd_conf, sssd_conf_d): | ||
self.config = deepcopy(sssd_conf) | ||
|
||
for parser in sorted(sssd_conf_d, key=lambda x: x.file_name): | ||
if parser.file_name.startswith("."): | ||
continue | ||
|
||
for section in parser.sections(): | ||
for key, value in parser.items(section).items(): | ||
self.config._set(section, key, value) | ||
|
||
self._enabled_domains = None | ||
|
||
@property | ||
def enabled_domains(self): | ||
""" | ||
Returns the list of enabled domains. | ||
Domains can be enabled either using the ``domains`` option in the | ||
``sssd`` section of the configuration file or using the ``enabled`` | ||
option in the domain configuration. | ||
[sssd] | ||
domains = a, b | ||
[domain/a] | ||
... | ||
[domain/b] | ||
... | ||
[domain/c] | ||
enabled = true | ||
""" | ||
if self._enabled_domains is None: | ||
enabled_domains = [] | ||
|
||
if self.config.has_option("sssd", "domains"): | ||
domains = self.config.get("sssd", "domains") | ||
enabled_domains = [domain.strip() for domain in domains.split(",")] | ||
|
||
prefix = "domain/" | ||
for section in self.config.sections(): | ||
# Ignore if this is not a domain configuration | ||
if not section.startswith(prefix): | ||
continue | ||
|
||
name = section[len(prefix):].strip() | ||
if not name: | ||
# Invalid configuration | ||
continue | ||
|
||
# Ignore if this is a subdomain configuration | ||
# `domain/$dom/$subdom` | ||
if "/" in name: | ||
continue | ||
|
||
if self.config.has_option(section, "enabled"): | ||
enabled = self.config.getboolean(section, "enabled") | ||
|
||
if enabled and name not in enabled_domains: | ||
enabled_domains.append(name) | ||
elif not enabled and name in enabled_domains: | ||
enabled_domains.remove(name) | ||
|
||
self._enabled_domains = enabled_domains | ||
|
||
return self._enabled_domains | ||
|
||
def domain_config(self, domain): | ||
""" | ||
Return the configuration dictionary for a specific domain, given as | ||
the raw name as listed in the 'domains' property of the sssd section. | ||
This then looks for the equivalent 'domain/{domain}' section of the | ||
config file. | ||
""" | ||
full_domain = self.domain_section(domain) | ||
if full_domain not in self.config: | ||
return {} | ||
|
||
return self.config.items(full_domain) | ||
|
||
def domain_section(self, domain): | ||
""" | ||
Transform plain SSSD domain name into a configuration section. | ||
ipa.test -> domain/ipa.test | ||
Args: | ||
domain (str): SSSD domain name. | ||
Returns: | ||
str: Returns the configuration section. | ||
""" | ||
return "domain/" + domain | ||
|
||
def domain_get(self, domain, option, default=None): | ||
""" | ||
Lookup option in domain. | ||
Args: | ||
domain (str): The SSSD domain name. | ||
option (str): The option str to search for. | ||
default (any): Default value if the option is not found. | ||
Returns: | ||
str: Returns the value of the option in the specified section. | ||
""" | ||
section = self.domain_section(domain) | ||
|
||
if not self.config.has_option(section, option): | ||
return default | ||
|
||
return self.config.get(section, option) | ||
|
||
def domain_getboolean(self, domain, option, default=None): | ||
""" | ||
Lookup boolean option in domain. | ||
Args: | ||
domain (str): The SSSD domain name. | ||
option (str): The option str to search for. | ||
default (any): Default value if the option is not found. | ||
Returns: | ||
bool: Returns boolean form based on the data from get. | ||
""" | ||
section = self.domain_section(domain) | ||
|
||
if not self.config.has_option(section, option): | ||
return default | ||
|
||
return self.config.getboolean(section, option) |
Oops, something went wrong.