2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-22 01:59:26 +00:00

45 Commits

Author SHA1 Message Date
Matthijs Mekking
c000cf70cb Test manual-mode with CSK algorithm rollover
Update check_rollover_step to return the found keys. This can be used
to test that keymgr-manual-mode messages are correctly logged.

Parametrize each test case and in case of manual-mode, execute
additional checks. First a keymgr run should not change the existing
key state (with exceptions of timing events such as moving from
RUMOURED to OMNIPRESENT, and from UNRETENTIVE to HIDDEN). Appropriate
messages must be logged.

After enforcing the next step with 'rndc dnssec -step', the key state
should be the same as if the step were to be taken automatically.
2025-08-21 16:09:55 +02:00
Matthijs Mekking
927c249711 Add manual-mode parameter to isctest.kasp
Key state transitions may be blocked by manual-mode, meaning key
timing metadata may not be respected and can be inaccurate. For these
tests use the state values to determine whether the DNSKEY/CDS/CDNSKEY
RRset must be published or not.
2025-08-21 16:09:55 +02:00
Matthijs Mekking
89e90c30f8 Allow for lifetime not set in state file
When migrating to dnssec-policy, keys that do not match will not have
a lifetime set. Adjust the test code to allow for that. Setting '-'
in a key properties string signals lifetime is expected not to be set.
2025-08-19 14:07:12 +00:00
Matthijs Mekking
1a8cbf11fe Update set_expected_keytimes for migrate case
If we are migrating keys, we should take the existing key timing
metadata to initialise the state values. These tests will only setup
keys with Publish/Activate/SyncPublish times, because the Retire and
Remove timings will still need to be adjusted to the DNSSEC policy.
2025-08-19 14:07:12 +00:00
Nicki Křížek
64143ea077 Use isctest.query.create across system tests
Rather than using the dnspython's facilities and defaults to create the
queries, use the isctest.query.create function in all the cases that
don't require special handling to have consistent defaults.
2025-07-29 12:13:11 -07:00
Nicki Křížek
467b826162 Add wait_for_keymgr_done() util function to tests
The kasp test cases assume that keymgr operations on the zone under test
have been completed before the test is executed. These are typically
quite fast, but the logs need to be explicitly checked for the messages,
otherwise there's a possibility of race conditions causing the
kasp/rollover tests to become unstable.

Call the wait function in all the kasp/rollover tests where it is
expected (which is generally in each test, unless we're dealing with
unsigned zones).
2025-07-18 14:37:32 +02:00
Nicki Křížek
d6dffe6603 Use common test functions for three-is-a-crowd test
Previously, a lot of the checking was re-implemented and duplicated from
check_rollover_step(). Use that function where possible and only
override the needed checks.
2025-07-18 13:37:58 +02:00
Nicki Křížek
b410710354 Move shared test code into isctest.kasp module
Move key calculations and rollover step checks into the shared
isctest.kasp module. Deduplicate the key interval calculations.
2025-07-18 13:37:58 +02:00
Nicki Křížek
9f3f6ec38e Log command stdout when using isctest.run.cmd()
The command's stdout may provide useful debug info, so make sure we log
it by default. It doesn't seem to have a significant impact on the log
size.
2025-06-27 16:31:49 +02:00
Nicki Křížek
620c884133 Improve logging from isctest.run.retry_with_timeout
Allow use of exception (and by extension, assert statements) in the
called function in order to extract essential debug information about
the type of failure that was encountered.

In case the called function fails to succeed on the last retry and
raised an exception, log it as error and set it as the assert message to
propagate it through the pytest framework.
2025-06-19 14:11:27 +02:00
Mark Andrews
e687710dc7 Add PRIVATEOIDs for RSASHA256 and RSASHA512
Use the existing RSASHA256 and RSASHA512 implementation to provide
working PRIVATEOID example implementations.  We are using the OID
values normally associated with RSASHA256 (1.2.840.113549.1.1.11)
and RSASHA512 (1.2.840.113549.1.1.13).
2025-06-19 07:15:20 +10:00
Mark Andrews
e6f1363964 Make system test changes needed for PRIVATEOID/PRIVATEDNS
- When the algorithm value for a DNSSEC key is set to PRIVATEOID
  or PRIVATEDNS, that's a placeholder value indicating that the
  real algorithm identifier is encoded into the key or signature
  data.  That means the DNSKEY algorithm value and the DST algorithm
  value may not be identical, so we must now add environment variables
  DEFAULT_ALGORITHM_DST_NUMBER, ALTERNATIVE_ALGORITHM_DST_NUMBER
  and DISABLED_ALGORITHM_DST_NUMBER to the test suite, with support
  for mapping from DST algorithm value to PRIVATEDNS or PRIVATEOID.

- Some test cases use RRSIGs that have been modified to force
  validation to fail. When making those modifications, we now
  preserve the first part of the signature, so that PRIVATEDNS and
  PRIVATEOID algorithm identifier values will still work.  (This
  assumes that the identifiers are short and fit into the first
  base64 block.)
2025-06-19 07:00:53 +10:00
Matthijs Mekking
b1d8217d1a Convert going insecure kasp test to pytest
When going insecure, we publish CDS and CDNSKEY DELETE records. Update
the check_apex function to test this.

Also, skip some tests in the 'check_rollover_step()' function. If
we change the DNSSEC Policy, keys that no longer match the policy will
be retired. When this exactly happens is hard to determine, as it
happens on the reconfigure. So for these tests, we skip the key timing
metadata checks.

Also, the zone becomes unsigned, so don't call 'check_zone_is_signed'
in those cases.
2025-06-18 10:01:24 +02:00
Matthijs Mekking
9ff7609614 Convert ksk rollover test case to pytest
Move the 'ksk-doubleksk' zones to the rollover test dir and convert KSK
rollover test to pytest.

Since the 'ksk-doubleksk' policy publishes different CDNSKEY/CDS RRsets,
update the 'check_rollover_step' to check which CDNSKEY/CDS RRsets should
be published and which should be prohibited. Update 'isctest.kasp'
accordingly.

We are changing the ZSK lifetime to unlimited in this test case as it
is of no importance (this actually discovered a bug in setting the
next time the keymgr should run).
2025-06-02 09:21:06 +00:00
Matthijs Mekking
bd6c70bd67 Convert zsk rollover test case to pytest
Move the 'zsk-prepub' zones to the rollover test dir and convert ZSK
rollover test to pytest.

We need a way to signal a smooth rollover is going on. Signatures are
being replaced gradually during a ZSK rollover, so the existing
signatures of the predecessor ZSK are still being used. Add a smooth
operator to set the right expectations on what signatures are being
used.

Setting expected key relationships is a bit crude: a list of two
elements where the first element is the index of the expected keys that
is the predecessor, and the second element is the index of the expected
keys that is the successor.

We are changing the KSK lifetime to unlimited in this test case as it
is of no importance.
2025-06-02 09:21:06 +00:00
Matthijs Mekking
233fdb8d52 Convert enable dnssec test case to pytest
Move the 'enable-dnssec' to the rollover test dir and convert to pytest.

This requires new test functionality to check that "CDS is published"
messages are logged (or prohibited).

The setup part is slightly adapted such that it no longer needs to
set the '-P sync' value in most cases (this is then set by 'named'),
and to adjust for the inappropriate safety intervals fix.
2025-06-02 09:21:06 +00:00
Matthijs Mekking
8ee02190a5 Convert kasp multi-signer tests to pytest
Move the multi-signer test scenarios to the rollover directory and
convert tests to pytest.

- If the KeyProperties set the "legacy" to True, don't set expected
  key times, nor check them. Also, when a matching key is found, set
  key.external to True.
- External keys don't show up in the 'rndc dnssec -status' output so
  skip them in the 'check_dnssecstatus' function. External keys never
  sign RRsets, so also skip those keys in the '_check_signatures'
  function.
- Key properties strings now can set expected key tag ranges, and if
  KeyProperties have tag ranges set, they are checked.
2025-06-02 09:21:06 +00:00
Matthijs Mekking
7a31fd57e2 Fix intermittent kasp pytest failures
The pytest cases checks if a zone is signed by looking at the NSEC
record at the apex. If that has an RRSIG record, it is considered
signed. But 'named' signs zones incrementally (in batches) and so
the zone may still lack some signatures. In other words, the tests
may consider a zone signed while in fact signing is not yet complete,
then performs additional checks such as is a subdomain signed with the
right key. If this check happens before the zone is actually fully
signed, the check will fail.

Fix this by using 'check_dnssec_verify' instead of
'check_is_zone_signed'. We were already doing this check, but we now
move it up. This will transfer the zone and then run 'dnssec-verify'
on the response. If the zone is partially signed, the check will fail,
and it will retry for up to ten times.
2025-05-29 11:44:56 +00:00
Matthijs Mekking
7d670b7fe7 Parametrize the default kasp test cases
Make use of pytest.mark.parametrize to split up the many default kasp
test cases into separate tests.
2025-04-23 15:22:04 +00:00
Matthijs Mekking
5f23f750c2 Convert more kasp test cases to pytest
These test cases follow the same pattern as many other, but all require
some additional checks. These are set in "additional-tests".

The "zsk-missing.autosign" zone is special handled, as it expects the
KSK to sign the SOA RRset (because the ZSK is unavailable).

The kasp/ns3/setup.sh script is updated so the SyncPublish is not set
(named will initialize it correctly). For the test zones that have
missing private key files we do need to set the expected key timing
metadata.

Remove the counterparts for the newly added test from the kasp shell
tests script.
2025-04-23 15:22:04 +00:00
Matthijs Mekking
fddf9f778b Update kasp check_signatures for dnssec-policy
The check_signatures code was initially created to be suitable for
the ksr system test, to test the Offline KSK feature. For that, a
key is expected to be signing if the current time is between
the timing metadata Active and Retired.

With dnssec-policy, the key timing metadata is indicative, the key
states determine the actual signing behavior.

Update the check_signatures function so that by default the signing
is derived from the key states (ksigning and zsigning). Add an
argument 'offline_ksk', if set the make sure that the zsigning is set
if the current time is between the Active and Retired timing metadata,
and for ksigning we just use the timing metadata (as the key is offline,
we cannot check the key states).

Another (upcoming) test case is where key files are missing. When the
ZSK private key file is missing, the KSK takes over. Add an argument
'zsk_missing', when set to True the expected zone signing (zsigning)
is reversed.
2025-04-23 15:22:04 +00:00
Matthijs Mekking
62a6b9faa7 Fix bugs in isctest.kasp
isctest.util was not imported so file_contents_contain could not be
found. And rename verify_keys to check_keys because it asserts in
isctest.run.retry_with_timeout.
2025-04-17 13:50:49 +02:00
Matthijs Mekking
07ac0e6036 Convert some special kasp test cases to pytest
This converts a special characters test case, a max-zone-ttl error
check, and two cases of insecure zones.

We no longer assert for having more than one DNSKEY and/or RRSIG
records. If the zone is insecure, this is no longer always true. And
we already check for the expected number of records in the
check_dnskeys/check_signatures functions.
2025-04-17 13:50:49 +02:00
Matthijs Mekking
4e22b019f5 Convert kasp default test cases to pytest
This commit deals with converting the test cases related to the default
dnssec-policy.

This requires a new method 'check_update_is_signed'. This method will
be used in future tests as well, and checks if an expected record is
in the zone and is properly signed.

Remove the counterparts for the newly added test from the kasp shell
tests script.
2025-04-17 13:50:49 +02:00
Matthijs Mekking
00ea2c2564 Convert kasp dnssectools tests to pytest
Convert the first couple of tests from 'kasp/tests.sh' to
'kasp/tests_kasp.py', those are test cases related to 'dnssec-keygen'
and 'dnssec-settime'.

For this, we also add a new KeyProperties method,
'policy_to_properties', that takes a list of strings which represent
the keys according to the dnssec-policy and the expected key states.
2025-04-17 13:50:49 +02:00
Matthijs Mekking
0a6cc42914 Update _check_dnskeys function
In the kasp system test there are cases that the SyncPublish is not
set, nor it is required to do so. Update the _check_dnskeys function
accordingly.
2025-04-10 15:44:31 -05:00
Matthijs Mekking
9cb287afa0 Add support for TSIG in isctest.kasp
For some kasp test we are going to need TSIG based queries to
differentiate between views.
2025-04-10 15:44:31 -05:00
Matthijs Mekking
12e57eb222 Introduce pytest check_next_key_event, get_keyids
For the kasp tests we need a new utility that can retrieve a list of
Keys from a given directory, belonging to a specific zone. This is
'keydir_to_keylist' and is the replacement of 'kasp.sh:get_keyids()'.

'next_key_event_eqauls' is a method to check when the next key event is
scheduled, needed for the rollover tests, and is the equivalent of shell
script 'check_next_key_event'.
2025-04-10 15:44:31 -05:00
Matthijs Mekking
44ff63a50d Introduce pytest verify_keys and check_keytimes
This commit introduces replacements for the 'check_keys' and
'check_keytimes' from the shell test library. 'check_keys' is renamed
to 'verify_keys' because it does not assert.

For that, we introduce more functions for the class Key. The
'match_properties' function is used in 'verify_keys' to see if a set of
KeyProperties match the Key. This speficially ignores timing metadata.
The function resembles what is in 'kasp.sh:check_key()'.

The 'match_timingmetadata' function is used in 'check_keytimes' to see
if the timing metadata of a set of KeyProperties match the Key. The
values are checked in all three key files (except if the private key is
not available (set with properties["private"]), or if it is a legacy key
(set with properties["legacy"]).

An additional check function is added, to check if the key relationships
are set correctly. It follows a similar pattern as 'check_keytimes'. If
"Predecessor" and/or "Successor" are expected to be set in the state
file, this function checks so, and also verifies that they are not set
if they should not be.
2025-04-10 15:44:31 -05:00
Matthijs Mekking
97f6b7ad11 Update class Key
Because we want to check the metadata in all three files, a new
value in the Key class is added: 'privatefile'. The 'get_metadata'
function is adapted so that we can also check metadata in other files.

Introduce methods to easily retrieve the TTL and public DNSKEY record
from the keyfile.

When checking if the CDS is equal to the expected value, use the DNSKEY
TTL instead of hardcoded 3600.
2025-04-10 15:31:21 -05:00
Matthijs Mekking
0b9fbca18e Introduce class KeyProperties
In isctest.kasp, introduce a new class 'KeyProperties' that can be used
to check if a Key matches expected properties. Properties are for the
time being divided in three parts: 'properties' that contain some
attributes of the expected properties (such as are we dealing with a
legacy key, is the private key available, and other things that do not
fit the metadata exactly), 'metadata' that contains expected metadata
(such as 'Algorithm', 'Lifetime', 'Length'), and 'timing', which is
metadata of the class KeyTimingMetadata.

The 'default()' method fills in the expected properties for the default
DNSSEC policy.

The 'set_expected_times()' sets the expected timing metadata, derived
from when the key was created. This method can take an offset to push
the expected timing metadata a duration in the future or back into the
past. If 'pregenerated=True', derive the expected timing metadata from
the 'Publish' metadata derived from the keyfile, rather than from the
'Created' metadata.

The calculations in the 'Ipub', 'IpubC' and 'Iret' methods are derived
from RFC 7583 DNSSEC Key Rollover Timing Considerations.
2025-04-10 15:31:21 -05:00
Matthijs Mekking
ee8e9f1ded Move test code that can be reused to isctest
This is the first step of converting the kasp system test to pytest.
Well, perhaps not the first, because earlier the ksr system test was
already converted to pytest and then the `isctest/kasp.py` library
was already introduced. Lots of this code can be reused for the kasp
pytest code.

First of all, 'check_file_contents_equal' is moved out of the ksr test
and into the 'check' library. This feels the most appropriate place
for this function to be reused in other tests. Then, 'keystr_to_keylist'
is moved to the 'kasp' library.

Introduce two new methods that are unused in this point of time, but
we are going to need them for the kasp system test. 'zone_contains'
will be used to check if a signature exists in the zonefile. This way
we can tell whether the signature has been reused or refreshed.
'file_contents_contain' will be used to check if the comment and public
DNSKEY record in the keyfile is correct.
2025-04-10 15:31:21 -05:00
Matthijs Mekking
708927e03d Allow empty CDNSKEY/CDS RRset in ksr system test
When the zone is initially signed, the CDNSKEY/CDS RRset is not
immediately published. The DNSKEY and signatures must propagate first.
Adjust the test to allow for this case.
2024-11-01 15:50:16 +01:00
Matthijs Mekking
795fcc9f80 Match algorithms when checking signatures
In the ksr system test, the test_ksr_twotone case may fail if there
are two keys with the same keytag (but different algorithms), because
one key is expected to be signing and the other is not.

Switch to regular expression matching and include the algorithm in the
search string.
2024-11-01 14:14:07 +01:00
Matthijs Mekking
d5f32f6990 Fix intermittent ksr test failure
The test_ksr_twotwone may fail if the key id is shorter than 5 digits.
Add a leading space to the expected strings which start with the key
tag to avoid the issue.
2024-10-24 14:30:51 +02:00
Nicki Křížek
f840deba33 Use UTC timezone when handling keys in kasp test library
When working with key timestamps, ensure we correctly set the UTC
timezone in order for the tests to work consistently regardless of the
local time setting.
2024-10-22 09:17:19 +02:00
Nicki Křížek
7639c58c48 Disable too-many/too-few pylint checks
Enforcing pylint standards and default for our test code seems
counter-productive. Since most of the newly added code are tests or is
test-related, encountering these checks rarely make us refactor the code
in other ways and we just disable these checks individually. Code that
is too complex or convoluted will be pointed out in reviews anyways.
2024-10-17 11:01:44 +02:00
Matthijs Mekking
b8b3df0676 Retry dnssec-verify in kasp test code
It is possible that the zone is not yet fully signed because it is
signed in batches. Retry the AXFR and verify command a couple of times.
2024-10-16 17:16:02 +02:00
Nicki Křížek
3c6124a093 Address pylint issues 2024-10-16 17:16:02 +02:00
Nicki Křížek
55ec9f94bc Use f-strings 2024-10-16 17:16:02 +02:00
Nicki Křížek
732a959d9a Simplify command invocation 2024-10-16 17:16:02 +02:00
Nicki Křížek
b5633462bf Remove unused isctest/kasp code 2024-10-16 17:16:02 +02:00
Nicki Křížek
67957d1f54 Rename kasp function to check_*
If a function is expected to assert / raise on failure (rather than
return boolean), its name should start with "check_".
2024-10-16 17:16:02 +02:00
Nicki Křížek
2b0a8fcfb5 Use convenience wrappers for kasp key operations 2024-10-16 17:16:02 +02:00
Matthijs Mekking
a3829990fd Introduce pytest kasp library
Write initial pytest kasp library. This contains everything that is
required for testing Offline KSK functionality with pytest.

This includes:
- addtime: adding a value to a timing metadata
- get_timing_metdata: retrieve timing metadata from keyfile
- get_metadata/get_keystate: retrieve metadata from statefile
- get_keytag: retrieve keytag from base keyfile string
- get_keyrole: get key role from statefile
- dnskey_equals: compare DNSKEY record from file against a string
- cds_equals: compare CDS derived from file against a string
- zone_is_signed: wait until a zone is completely signed
- dnssec_verify: verify a DNSSEC signed zone with dnssec-verify
- check_dnssecstatus: check rndc dnssec -status output
- check_signatures: check that signatures for a given RRset are correct
- check_dnskeys: check that the published DNSKEY RRset is correct
- check_cds: check that the published CDS RRset is correct
- check_apex: check SOA, DNSKEY, CDNSKEY, and CDS RRset
- check_subdomain: check an RRset below the apex
2024-10-16 17:16:02 +02:00