2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 05:57:52 +00:00

Only initialize goal on active keys

If we initialize goals on all keys, superfluous keys that match
the policy all desire to be active.  For example, there are six
keys available for a policy that needs just two, we only want to
set the goal state to OMNIPRESENT on two keys, not six.
This commit is contained in:
Matthijs Mekking 2020-04-01 16:35:06 +02:00
parent f47e697da3
commit 2389fcb4dc
6 changed files with 39 additions and 28 deletions

View File

@ -46,9 +46,9 @@ zone "migrate.kasp" {
update-check-ksk yes; update-check-ksk yes;
}; };
zone "migrate-nomatch.kasp" { zone "migrate-nomatch-alglen.kasp" {
type master; type master;
file "migrate-nomatch.kasp.db"; file "migrate-nomatch-alglen.kasp.db";
auto-dnssec maintain; auto-dnssec maintain;
allow-update { any; }; allow-update { any; };
dnssec-dnskey-kskonly yes; dnssec-dnskey-kskonly yes;

View File

@ -43,11 +43,11 @@ zone "migrate.kasp" {
dnssec-policy "migrate"; dnssec-policy "migrate";
}; };
zone "migrate-nomatch.kasp" { zone "migrate-nomatch-alglen.kasp" {
type master; type master;
file "migrate-nomatch.kasp.db"; file "migrate-nomatch-alglen.kasp.db";
allow-update { any; }; allow-update { any; };
dnssec-policy "migrate-nomatch"; dnssec-policy "migrate-nomatch-alglen";
}; };
/* /*

View File

@ -58,7 +58,11 @@ dnssec-policy "migrate" {
}; };
}; };
dnssec-policy "migrate-nomatch" { /*
* This policy tests migration from existing keys with 1024 bits RSASHA1 keys
* to 2048 bits RSASHA1 keys.
*/
dnssec-policy "migrate-nomatch-alglen" {
dnskey-ttl 300; dnskey-ttl 300;
keys { keys {

View File

@ -52,8 +52,10 @@ private_type_record $zone 5 "$ZSK" >> "$infile"
$SIGNER -S -x -s now-1h -e now+2w -o $zone -O full -f $zonefile $infile > signer.out.$zone.1 2>&1 $SIGNER -S -x -s now-1h -e now+2w -o $zone -O full -f $zonefile $infile > signer.out.$zone.1 2>&1
# Set up a zone with auto-dnssec maintain to migrate to dnssec-policy, but this # Set up a zone with auto-dnssec maintain to migrate to dnssec-policy, but this
# time the existing keys do not match the policy. # time the existing keys do not match the policy. The existing keys are
setup migrate-nomatch.kasp # 1024 bits RSASHA1 keys, and will be migrated to a dnssec-policy that
# dictates 2048 bits RSASHA1 keys.
setup migrate-nomatch-alglen.kasp
echo "$zone" >> zones echo "$zone" >> zones
KSK=$($KEYGEN -a RSASHA1 -b 1024 -f KSK -L 300 $zone 2> keygen.out.$zone.1) KSK=$($KEYGEN -a RSASHA1 -b 1024 -f KSK -L 300 $zone 2> keygen.out.$zone.1)
ZSK=$($KEYGEN -a RSASHA1 -b 1024 -L 300 $zone 2> keygen.out.$zone.2) ZSK=$($KEYGEN -a RSASHA1 -b 1024 -L 300 $zone 2> keygen.out.$zone.2)

View File

@ -2920,11 +2920,11 @@ _migrate_zsk=$(key_get KEY2 ID)
# #
# Testing migration with unmatched existing keys. # Testing migration with unmatched existing keys.
# #
set_zone "migrate-nomatch.kasp" set_zone "migrate-nomatch-alglen.kasp"
set_policy "none" "2" "300" set_policy "none" "2" "300"
set_server "ns6" "10.53.0.6" set_server "ns6" "10.53.0.6"
init_migration_nomatch() { init_migration_nomatch_alglen() {
key_clear "KEY1" key_clear "KEY1"
key_set "KEY1" "LEGACY" "yes" key_set "KEY1" "LEGACY" "yes"
set_keyrole "KEY1" "ksk" set_keyrole "KEY1" "ksk"
@ -2957,7 +2957,7 @@ init_migration_nomatch() {
set_keystate "KEY2" "STATE_DNSKEY" "omnipresent" set_keystate "KEY2" "STATE_DNSKEY" "omnipresent"
set_keystate "KEY2" "STATE_ZRRSIG" "omnipresent" set_keystate "KEY2" "STATE_ZRRSIG" "omnipresent"
} }
init_migration_nomatch init_migration_nomatch_alglen
# Make sure the zone is signed with legacy keys. # Make sure the zone is signed with legacy keys.
check_keys check_keys
@ -2966,8 +2966,8 @@ check_subdomain
dnssec_verify dnssec_verify
# Remember legacy key tags. # Remember legacy key tags.
_migratenomatch_ksk=$(key_get KEY1 ID) _migratenomatch_alglen_ksk=$(key_get KEY1 ID)
_migratenomatch_zsk=$(key_get KEY2 ID) _migratenomatch_alglen_zsk=$(key_get KEY2 ID)
# Reconfig dnssec-policy (triggering algorithm roll and other dnssec-policy # Reconfig dnssec-policy (triggering algorithm roll and other dnssec-policy
# changes). # changes).
@ -3033,13 +3033,13 @@ ret=0
status=$((status+ret)) status=$((status+ret))
# Test migration to dnssec-policy, existing keys do not match. # Test migration to dnssec-policy, existing keys do not match.
set_zone "migrate-nomatch.kasp" set_zone "migrate-nomatch-alglen.kasp"
set_policy "migrate-nomatch" "4" "300" set_policy "migrate-nomatch-alglen" "4" "300"
set_server "ns6" "10.53.0.6" set_server "ns6" "10.53.0.6"
# The legacy keys need to be retired, but otherwise stay present until the # The legacy keys need to be retired, but otherwise stay present until the
# new keys are omnipresent, and can be used to construct a chain of trust. # new keys are omnipresent, and can be used to construct a chain of trust.
init_migration_nomatch init_migration_nomatch_alglen
key_set "KEY1" "LEGACY" "no" key_set "KEY1" "LEGACY" "no"
set_keytime "KEY1" "RETIRED" "yes" set_keytime "KEY1" "RETIRED" "yes"
@ -3059,7 +3059,7 @@ set_keyrole "KEY4" "zsk"
set_keylifetime "KEY4" "5184000" set_keylifetime "KEY4" "5184000"
set_keyalgorithm "KEY4" "5" "RSASHA1" "2048" set_keyalgorithm "KEY4" "5" "RSASHA1" "2048"
set_keysigning "KEY4" "no" set_keysigning "KEY4" "no"
# This key is not active yet, first the DNSKEY needs to be omnipresent. # This key is considered to be prepublished, so it is not yet signing.
set_zonesigning "KEY4" "no" set_zonesigning "KEY4" "no"
set_keytime "KEY3" "PUBLISHED" "yes" set_keytime "KEY3" "PUBLISHED" "yes"
@ -3086,8 +3086,8 @@ dnssec_verify
n=$((n+1)) n=$((n+1))
echo_i "check that of zone ${ZONE} migration to dnssec-policy keeps existing keys ($n)" echo_i "check that of zone ${ZONE} migration to dnssec-policy keeps existing keys ($n)"
ret=0 ret=0
[ $_migratenomatch_ksk == $(key_get KEY1 ID) ] || log_error "mismatch ksk tag" [ $_migratenomatch_alglen_ksk == $(key_get KEY1 ID) ] || log_error "mismatch ksk tag"
[ $_migratenomatch_zsk == $(key_get KEY2 ID) ] || log_error "mismatch zsk tag" [ $_migratenomatch_alglen_zsk == $(key_get KEY2 ID) ] || log_error "mismatch zsk tag"
status=$((status+ret)) status=$((status+ret))
# #

View File

@ -1402,7 +1402,7 @@ dns_keymgr_run(const dns_name_t *origin, dns_rdataclass_t rdclass,
keystr, keymgr_keyrole(dkey->key), keystr, keymgr_keyrole(dkey->key),
dns_kasp_getname(kasp)); dns_kasp_getname(kasp));
/* Initialize lifetime and goal, if not set. */ /* Initialize lifetime if not set. */
uint32_t l; uint32_t l;
if (dst_key_getnum(dkey->key, DST_NUM_LIFETIME, if (dst_key_getnum(dkey->key, DST_NUM_LIFETIME,
&l) != ISC_R_SUCCESS) { &l) != ISC_R_SUCCESS) {
@ -1411,14 +1411,6 @@ dns_keymgr_run(const dns_name_t *origin, dns_rdataclass_t rdclass,
lifetime); lifetime);
} }
dst_key_state_t goal;
if (dst_key_getstate(dkey->key, DST_KEY_GOAL,
&goal) != ISC_R_SUCCESS) {
dst_key_setstate(dkey->key,
DST_KEY_GOAL,
OMNIPRESENT);
}
if (active_key) { if (active_key) {
/* We already have an active key that /* We already have an active key that
* matches the kasp policy. * matches the kasp policy.
@ -1442,6 +1434,19 @@ dns_keymgr_run(const dns_name_t *origin, dns_rdataclass_t rdclass,
continue; continue;
} }
/*
* This is possibly an active key created
* outside dnssec-policy. Initialize goal,
* if not set.
*/
dst_key_state_t goal;
if (dst_key_getstate(dkey->key, DST_KEY_GOAL,
&goal) != ISC_R_SUCCESS) {
dst_key_setstate(dkey->key,
DST_KEY_GOAL,
OMNIPRESENT);
}
/* /*
* Save the matched key only if it is active * Save the matched key only if it is active
* or desires to be active. * or desires to be active.