mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-01-11 00:31:56 -06:00
server-del: harden check for last roles
The current implementation of check for last CA/DNS server and DNSSec key master in `server-del` is quite fragile and wroks with quite a few assumptions which may not be always true (CA and DNS is always configured etc.). This patch hardens the check so that it does not break when the above assuptions do not hold. https://fedorahosted.org/freeipa/ticket/5960 Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
parent
5ffd7ef7c4
commit
be3ad1ed7a
@ -469,7 +469,6 @@ class server_del(LDAPDelete):
|
|||||||
raise errors.ServerRemovalError(reason=_(msg))
|
raise errors.ServerRemovalError(reason=_(msg))
|
||||||
|
|
||||||
ipa_config = self.api.Command.config_show()['result']
|
ipa_config = self.api.Command.config_show()['result']
|
||||||
dns_config = self.api.Command.dnsconfig_show()['result']
|
|
||||||
|
|
||||||
ipa_masters = ipa_config['ipa_master_server']
|
ipa_masters = ipa_config['ipa_master_server']
|
||||||
|
|
||||||
@ -477,26 +476,43 @@ class server_del(LDAPDelete):
|
|||||||
if ipa_masters == [hostname]:
|
if ipa_masters == [hostname]:
|
||||||
return
|
return
|
||||||
|
|
||||||
ca_servers = ipa_config['ca_server_server']
|
if self.api.Command.dns_is_enabled()['result']:
|
||||||
ca_renewal_master = ipa_config['ca_renewal_master_server']
|
dns_config = self.api.Command.dnsconfig_show()['result']
|
||||||
dns_servers = dns_config['dns_server_server']
|
|
||||||
dnssec_keymaster = dns_config['dnssec_key_master_server']
|
|
||||||
|
|
||||||
if ca_servers == [hostname]:
|
dns_servers = dns_config.get('dns_server_server', [])
|
||||||
raise errors.ServerRemovalError(
|
dnssec_keymaster = dns_config.get('dnssec_key_master_server', [])
|
||||||
reason=_("Deleting this server is not allowed as it would "
|
|
||||||
"leave your installation without a CA."))
|
|
||||||
|
|
||||||
if dnssec_keymaster == hostname:
|
if dnssec_keymaster == hostname:
|
||||||
handler(
|
handler(
|
||||||
_("Replica is active DNSSEC key master. Uninstall "
|
_("Replica is active DNSSEC key master. Uninstall "
|
||||||
"could break your DNS system. Please disable or "
|
"could break your DNS system. Please disable or "
|
||||||
"replace DNSSEC key master first."), ignore_last_of_role)
|
"replace DNSSEC key master first."), ignore_last_of_role)
|
||||||
|
|
||||||
if dns_servers == [hostname]:
|
if dns_servers == [hostname]:
|
||||||
handler(
|
handler(
|
||||||
_("Deleting this server will leave your installation "
|
_("Deleting this server will leave your installation "
|
||||||
"without a DNS."), ignore_last_of_role)
|
"without a DNS."), ignore_last_of_role)
|
||||||
|
|
||||||
|
if self.api.Command.ca_is_enabled()['result']:
|
||||||
|
ca_servers = ipa_config.get('ca_server_server', [])
|
||||||
|
ca_renewal_master = ipa_config.get(
|
||||||
|
'ca_renewal_master_server', [])
|
||||||
|
|
||||||
|
if ca_servers == [hostname]:
|
||||||
|
raise errors.ServerRemovalError(
|
||||||
|
reason=_("Deleting this server is not allowed as it would "
|
||||||
|
"leave your installation without a CA."))
|
||||||
|
|
||||||
|
if ca_renewal_master == hostname:
|
||||||
|
other_cas = [ca for ca in ca_servers if ca != hostname]
|
||||||
|
|
||||||
|
# if this is the last CA there is no other server to become
|
||||||
|
# renewal master
|
||||||
|
if not other_cas:
|
||||||
|
return
|
||||||
|
|
||||||
|
self.api.Command.config_mod(
|
||||||
|
ca_renewal_master_server=other_cas[0])
|
||||||
|
|
||||||
if ignore_last_of_role:
|
if ignore_last_of_role:
|
||||||
self.add_message(
|
self.add_message(
|
||||||
@ -504,16 +520,6 @@ class server_del(LDAPDelete):
|
|||||||
message=_("Ignoring these warnings and proceeding with "
|
message=_("Ignoring these warnings and proceeding with "
|
||||||
"removal")))
|
"removal")))
|
||||||
|
|
||||||
if ca_renewal_master == hostname:
|
|
||||||
other_cas = [ca for ca in ca_servers if ca != hostname]
|
|
||||||
|
|
||||||
# if this is the last CA there is no other server to become renewal
|
|
||||||
# master
|
|
||||||
if not other_cas:
|
|
||||||
return
|
|
||||||
|
|
||||||
self.api.Command.config_mod(ca_renewal_master_server=other_cas[0])
|
|
||||||
|
|
||||||
def _check_topology_connectivity(self, topology_connectivity, master_cn):
|
def _check_topology_connectivity(self, topology_connectivity, master_cn):
|
||||||
try:
|
try:
|
||||||
topology_connectivity.check_current_state()
|
topology_connectivity.check_current_state()
|
||||||
|
Loading…
Reference in New Issue
Block a user