mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-05 09:18:53 +00:00
fix(web-app-xwiki): only trust the running-wiki probe when the superadmin answered
e5f3c52119lets a redeploy skip the bootstrap restarts when the running wiki already serves the pinned core and add-ons. Its probe GETs /rest/wikis/xwiki/spaces with the superadmin's basic auth and accepted any 200. XWiki answers a rejected basic auth as guest with 200 (seeb1dfff370a, tasks/03_administrator.yml reads the XWiki-User header for exactly that reason). Between PASS 1 and PASS 2 the harness rotates the credentials ("=== matrix-deploy: rotating credentials between passes ===", xwiki2.log:257549 of run 40625679270). PASS 2 then probed the container still running with PASS 1's password: XWiki logged "Authentication failure with login [superadmin]" 34 times, answered as guest with 200, and the add-on check PUT XWiki.CheckExtension as guest until it died on 401 after 31 attempts (XWiki#2, LDAP variant; the probe only runs with OIDC or LDAP on). The core-version read now also requires the XWiki-User response header to name the superadmin. A guest answer skips it, so the role takes the bootstrap path that recreates the container with the rotated password before any write. test_extensions_ready_probe evaluates the task's when list for a guest 200, a superadmin 200 and a skipped probe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a5de245bf9
commit
77504cec4f
2 files changed
+59
No files matched your search
@@ -0,0 +1,57 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from typing import Any
|
||||
|
||||
from jinja2 import Environment
|
||||
|
||||
from utils.cache.files import PROJECT_ROOT, read_text
|
||||
from utils.cache.yaml import load_yaml_str
|
||||
|
||||
PROBE = PROJECT_ROOT / "roles/web-app-xwiki/tasks/utils/extensions_ready.yml"
|
||||
CORE_READ_REGISTER = "_xwiki_running_core"
|
||||
SUPERADMIN = "superadmin"
|
||||
|
||||
|
||||
def core_read_runs(probe_result: dict[str, Any]) -> bool:
|
||||
"""Evaluate the core-version read's ``when`` list the way Ansible does.
|
||||
|
||||
Args:
|
||||
probe_result: the registered result of the superadmin probe.
|
||||
|
||||
Returns:
|
||||
``True`` when every condition holds, stopping at the first false one.
|
||||
"""
|
||||
tasks = load_yaml_str(read_text(str(PROBE)))
|
||||
task = next(t for t in tasks if t.get("register") == CORE_READ_REGISTER)
|
||||
env = Environment(autoescape=True)
|
||||
env.tests["skipped"] = lambda result: bool(result.get("skipped"))
|
||||
context = {
|
||||
"_xwiki_running": probe_result,
|
||||
"XWIKI_SUPERADMIN_USERNAME": SUPERADMIN,
|
||||
}
|
||||
return all(env.compile_expression(cond)(**context) for cond in task["when"])
|
||||
|
||||
|
||||
class TestExtensionsReadyProbe(unittest.TestCase):
|
||||
def test_a_guest_answer_does_not_count_as_the_superadmin(self) -> None:
|
||||
self.assertFalse(
|
||||
core_read_runs({"status": 200, "changed": False}),
|
||||
"XWiki answers a rejected basic auth as guest with 200, so after a "
|
||||
"credential rotation the running wiki would pass the probe and the "
|
||||
"add-on check would PUT as guest and die on 401 after 31 retries",
|
||||
)
|
||||
|
||||
def test_the_superadmin_answer_keeps_the_fast_path(self) -> None:
|
||||
self.assertTrue(
|
||||
core_read_runs({"status": 200, "xwiki_user": f"xwiki:XWiki.{SUPERADMIN}"}),
|
||||
"a probe XWiki answered as the superadmin must still reach the "
|
||||
"core-version read, or every unchanged redeploy pays two restarts",
|
||||
)
|
||||
|
||||
def test_a_skipped_probe_never_reads_the_core(self) -> None:
|
||||
self.assertFalse(core_read_runs({"skipped": True, "changed": False}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user