fix(ci): redact the key's own body lines from notarytool diagnostics

The preflight logs notarytool's output on both the error and the warning
path after removing complete PEM blocks and the exact key ID and issuer.
Key material echoed without its BEGIN/END markers matched neither, so it
would have reached the public job log.

Redact each body line of the key file the preflight already read, so the
rest of notarytool's message stays as the diagnostic (it is the only
clue on the warn-and-continue path, which is why the output is kept
rather than dropped). The test echoes the body lines without markers on
HTTP 401 and on HTTP 500; the previous helper leaked them on 401.

Found by a gpt-6.2-sol review round.
This commit is contained in:
BearHuddleston
2026-11-22 01:49:15 +00:00
parent 06ecdea621
commit 5a93368019
2 changed files with 16 additions and 1 deletions

View File

@@ -284,7 +284,9 @@ def check_notary_auth(
return PreflightResult(PreflightStatus.OK, _success_message(proc.stdout or ""))
raw_output = "\n".join(part for part in (proc.stderr or "", proc.stdout or "") if part.strip())
redacted = redact_secrets(raw_output, (clean_key_id, clean_issuer))
# Key material echoed without its PEM markers would escape the block pattern.
body = [line.strip() for line in pem_text.splitlines() if line.strip() and not line.strip().startswith("-----")]
redacted = redact_secrets(raw_output, (*body, clean_key_id, clean_issuer))
status, message = classify_notarytool_failure(redacted)
return PreflightResult(status, message, detail=redacted)

View File

@@ -234,6 +234,19 @@ def test_check_notary_auth_handles_success_timeout_oserror_and_redacts_secrets(t
assert issuer not in combined
assert _PEM_BEGIN not in combined
body_lines = pem.splitlines()[1:-1]
for code, expected in ((401, PreflightStatus.AUTH_FAILED), (500, PreflightStatus.TRANSIENT)):
def body_echo_runner(argv: list[str], timeout: float, code: int = code) -> subprocess.CompletedProcess[str]:
return subprocess.CompletedProcess(
argv, 1, stdout="", stderr=f"Error: HTTP status code: {code}.\nkey:\n" + "\n".join(body_lines),
)
echoed = check_notary_auth(str(key_file), key_id, issuer, runner=body_echo_runner)
assert echoed.status is expected
assert "HTTP status code" in echoed.detail
leaked = [line for line in body_lines if line in f"{echoed.message}\n{echoed.detail}"]
assert not leaked, f"key body lines reached the log on HTTP {code}"
def timeout_runner(argv: list[str], timeout: float) -> subprocess.CompletedProcess[str]:
raise subprocess.TimeoutExpired(argv, timeout)