Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/syft-enclave/src/syft_enclaves/enclave_job_info.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -25,6 +26,7 @@
RequestedPermissionsUpdate,
load_log_request,
log_request_file_name,
log_request_warning,
longest_log_head,
)

Expand Down Expand Up @@ -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}.")
Expand Down
18 changes: 18 additions & 0 deletions packages/syft-enclave/src/syft_enclaves/log_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 25 additions & 1 deletion packages/syft-enclave/tests/test_read_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading