dnssec: fix ipa-ods-exporter crash when master key missing

When a master key is missing from the local HSM, ipa-ods-exporter crashes.
This can happen when the DNSSEC master role is moved from one node to
another with the following scenario:
- install server1 with dns + dnssec
- install server2 without dns
- disable dnssec from server1
- install dns + dnssec on server2

With the above scenario, server2 never had the opportunity to get
the master key (this happens only when the replica is already
configured as DNS server and has put its public replica key in LDAP +
the current DNSSEC master wraps its master key with the replica key).

ipa-ods-exporter can only log an error instead of crashing.

Related: https://pagure.io/freeipa/issue/8654
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
This commit is contained in:
Florence Blanc-Renaud 2021-03-05 14:58:53 +01:00
parent a6b4871304
commit 3b1a56f588

View File

@ -375,7 +375,18 @@ def master2ldap_master_keys_sync(ldapkeydb, localhsm):
str_hexlify(mkey_id), hex_set(new_replica_keys))
# wrap master key with new replica keys
mkey_local = localhsm.find_keys(id=mkey_id).popitem()[1]
try:
mkey_local = localhsm.find_keys(id=mkey_id).popitem()[1]
except KeyError:
# The master key is present in LDAP but could not be found
# in the local HSM. Let's hope it's not the active key,
# log an error and process the next master key
logger.error("master key 0x%s missing in local HSM, "
"will not be able to add master key wrapped with "
"replica keys",
str_hexlify(mkey_id))
continue
for replica_key_id in new_replica_keys:
logger.info('adding master key 0x%s wrapped with replica key 0x%s',
str_hexlify(mkey_id), str_hexlify(replica_key_id))