Skip to content

Commit c915e82

Browse files
committed
Update tests for k8s version policy to reflect new language in standard
Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud>
1 parent 287a5a5 commit c915e82

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

Tests/kaas/k8s-version-policy/k8s_version_policy.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646

4747
MINOR_VERSION_CADENCE = timedelta(days=120)
4848
PATCH_VERSION_CADENCE = timedelta(days=31)
49-
CVE_VERSION_CADENCE = timedelta(days=2)
49+
CVE_VERSION_CADENCE = timedelta(weeks=2)
50+
CVE_VERSION_CADENCE_WARN = timedelta(days=2)
5051
CVE_SEVERITY = 8 # CRITICAL
5152

5253
HERE = Path(__file__).parent
@@ -420,19 +421,19 @@ def check_k8s_version_recency(
420421
# whoops, the cluster should have been updated to this (or a higher version) already!
421422
return False
422423
ranges = [_range for _range in cve_affected_ranges if my_version in _range]
423-
if ranges and release.age > CVE_VERSION_CADENCE:
424-
# -- two FIXMEs:
425-
# (a) if the release still has the CVE, then there is no use if we updated to it?
426-
# (b) the standard says "time period MUST be even shorter ... it is RECOMMENDED that ...",
427-
# so what is it now, a requirement or a recommendation?
424+
if ranges and release.age > CVE_VERSION_CADENCE_WARN:
425+
# -- FIXME:
426+
# if the release still has the CVE, then there is no use if we updated to it?
428427
# shouldn't we check for CVEs of my_version and then check whether the new one still has them?
429428
# -- so, this has to be reworked in a major way, but for the time being, just emit an INFO
430429
# (unfortunately, the cluster name is not available here)
431-
logger.info(
430+
logger.warning(
432431
"Consider updating from %s to %s to avoid a CVE",
433432
my_version,
434433
release.version,
435434
)
435+
if release.age > CVE_VERSION_CADENCE:
436+
return False
436437
return True
437438

438439

Tests/kaas/k8s-version-policy/k8s_version_policy_test.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,11 @@ def test_check_version_recency_with_cve(caplog, release_data):
6565
# 2 days after release of patch for affected_version
6666
dt.now.return_value = datetime(2024, 1, 20)
6767
assert check_k8s_version_recency(affected_version, release_data, fake_ranges)
68-
assert len(caplog.records) == 1, "expected a log message"
69-
assert caplog.records[0].levelname == "INFO"
68+
# 2 weeks after the release
69+
dt.now.return_value = datetime(2024, 2, 1)
70+
assert not check_k8s_version_recency(affected_version, release_data, fake_ranges)
71+
assert len(caplog.records) >= 1, "expected a log message"
72+
assert caplog.records[0].levelname == "WARNING"
7073
assert "Consider updating from 1.28.5" in caplog.records[0].message
7174

7275

0 commit comments

Comments
 (0)