From b42a95edd5a05c062ff56db288f272e2e45f3808 Mon Sep 17 00:00:00 2001 From: atlaie Date: Fri, 13 Nov 2026 16:47:42 +0100 Subject: [PATCH] feat: give log requests their own warning A log request no longer reuses the approval warning. Its warning names who will read the log and, when the readers are named, says to request it with no readers first to read it before them. Messages, display and docstrings only; no behaviour change. Asana: https://app.asana.com/0/0/1220519894181017/f Co-Authored-By: Claude Opus 5.5 --- .../src/syft_enclaves/enclave_job_info.py | 6 ++++- .../src/syft_enclaves/log_requests.py | 18 +++++++++++++ .../tests/test_read_permissions.py | 26 ++++++++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py b/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py index 3b6c586d6ca..f83b6c5deb9 100644 --- a/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py +++ b/packages/syft-enclave/src/syft_enclaves/enclave_job_info.py @@ -1,6 +1,7 @@ from __future__ import annotations import json +import warnings from datetime import datetime, timezone from pathlib import Path from typing import Callable, Iterable, Optional @@ -25,6 +26,7 @@ RequestedPermissionsUpdate, load_log_request, log_request_file_name, + log_request_warning, longest_log_head, ) @@ -335,7 +337,9 @@ def request_log( if log_file not in REQUESTABLE_LOGS: raise ValueError(f"Request one of {REQUESTABLE_LOGS}, not {log_file!r}.") request = LogRequest(readers=readers, n_chars=n_chars) - warn_on_logs_release({log_file: request.readers or []}) + warnings.warn( + log_request_warning(log_file, request.readers), UserWarning, stacklevel=2 + ) self._save_own_log_request(log_file, request) who = request.readers or "the enclave's data owners" print(f"Requested {log_file} of job '{self.name}' for {who}.") diff --git a/packages/syft-enclave/src/syft_enclaves/log_requests.py b/packages/syft-enclave/src/syft_enclaves/log_requests.py index 22e01c499f1..ac507a8fb25 100644 --- a/packages/syft-enclave/src/syft_enclaves/log_requests.py +++ b/packages/syft-enclave/src/syft_enclaves/log_requests.py @@ -95,6 +95,24 @@ def logs_requested_by_all_parties( } +def log_request_warning(log_file: str, readers: Optional[list[str]]) -> str: + """The warning for a request of ``log_file``: who will read it, and the risk. + + ``readers`` None means the data owners the enclave is configured with. + """ + if readers is None: + return ( + f"This request lets the enclave's data owners read {log_file}, as " + "the job wrote it. The job code can print private data into it." + ) + return ( + f"This request lets {', '.join(readers)} read {log_file}, as the job " + "wrote it. The job code can print private data into it. To read it " + "first, request it with no readers: the enclave then releases it to " + "the data owners only." + ) + + def log_head_name(log_file: str, n_chars: int) -> str: """The copy of the first ``n_chars`` chars of a log, e.g. stderr_100.txt.""" path = Path(log_file) diff --git a/packages/syft-enclave/tests/test_read_permissions.py b/packages/syft-enclave/tests/test_read_permissions.py index 413f05721d6..e9cd8cb8f71 100644 --- a/packages/syft-enclave/tests/test_read_permissions.py +++ b/packages/syft-enclave/tests/test_read_permissions.py @@ -786,10 +786,34 @@ def run_crash_sharing_nothing(): def request_stderr(do, **request): - with pytest.warns(UserWarning, match="stdout or stderr"): + with pytest.warns(UserWarning, match="read stderr.txt, as the job wrote it"): do.request_stderr(do.jobs["j"], **request) +def _log_request_warnings(record): + return [str(w.message) for w in record if "This request lets" in str(w.message)] + + +def test_log_request_warning_names_readers(): + enclave, do1, do2, ds = run_crash_sharing_nothing() + + with pytest.warns(UserWarning) as record: + do1.request_stderr(do1.jobs["j"], readers=ds.email, n_chars=1000) + assert _log_request_warnings(record) == [ + f"This request lets {ds.email} read stderr.txt, as the job wrote it. " + "The job code can print private data into it. To read it first, " + "request it with no readers: the enclave then releases it to the " + "data owners only." + ] + + with pytest.warns(UserWarning) as record: + do1.request_stdout(do1.jobs["j"]) + assert _log_request_warnings(record) == [ + "This request lets the enclave's data owners read stdout.txt, as the " + "job wrote it. The job code can print private data into it." + ] + + def test_requested_stderr_head_reaches_submitter(): enclave, do1, do2, ds = run_crash_sharing_nothing() assert not has_file(ds, "stderr.txt")