strato_check_dns: klarer Status (match, local_override, mismatch, not_resolvable, not_in_zone)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cd734a6de2
commit
c1391cfb69
2 files changed
+45
-10
No files matched your search
+32
-10
@@ -242,25 +242,47 @@ def strato_check_dns(name: str) -> str:
|
||||
except OSError as exc:
|
||||
resolved = {"error": f"not resolvable: {exc.strerror or exc}"}
|
||||
target = expected[0].value.rstrip(".").lower() if expected else None
|
||||
matches: bool | None = None
|
||||
if target and "addresses" in resolved:
|
||||
names = [resolved["canonical_name"], *resolved["aliases"]]
|
||||
matches = any(n.rstrip(".").lower() == target for n in names) or _resolves_same(
|
||||
target, resolved["addresses"]
|
||||
)
|
||||
elif target:
|
||||
matches = False
|
||||
if not target:
|
||||
status = "not_in_zone"
|
||||
elif "addresses" not in resolved:
|
||||
status = "not_resolvable"
|
||||
elif any(n.rstrip(".").lower() == target for n in [resolved["canonical_name"], *resolved["aliases"]]):
|
||||
status = "match"
|
||||
elif _resolves_same(target, resolved["addresses"]):
|
||||
status = "match"
|
||||
elif all(_is_private(ip) for ip in resolved["addresses"]):
|
||||
status = "local_override"
|
||||
else:
|
||||
status = "mismatch"
|
||||
return _json({
|
||||
"name": host,
|
||||
"zone_cname_target": target,
|
||||
"resolver": resolved,
|
||||
"matches_zone": matches,
|
||||
"note": "Uses the MCP host's resolver; local DNS overrides or caches can differ from public DNS.",
|
||||
"status": status,
|
||||
"explanation": {
|
||||
"match": "The resolver follows the STRATO CNAME.",
|
||||
"local_override": (
|
||||
"The resolver answers with a private address instead of following the CNAME "
|
||||
"(local DNS / split-horizon). Public resolution cannot be judged from here."
|
||||
),
|
||||
"mismatch": "The resolver returns something else than the STRATO CNAME (cache/TTL or wrong record).",
|
||||
"not_resolvable": "The name does not resolve (yet).",
|
||||
"not_in_zone": "There is no CNAME for this name in the STRATO zone.",
|
||||
}[status],
|
||||
})
|
||||
except Exception as exc:
|
||||
raise _fail(exc) from None
|
||||
|
||||
|
||||
def _is_private(address: str) -> bool:
|
||||
import ipaddress
|
||||
|
||||
try:
|
||||
return ipaddress.ip_address(address).is_private
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
|
||||
def _resolves_same(target: str, addresses: list[str]) -> bool:
|
||||
try:
|
||||
return bool(set(socket.gethostbyname_ex(target)[2]) & set(addresses))
|
||||
|
||||
Reference in new issue
Block a user