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")