Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1c4a51d
feat: add the DS's storage on Drive for what it received from each DO
pjwerneck Nov 3, 2026
ebca5a0
feat: save and load the DS's state for each DO through the router, en…
pjwerneck Nov 3, 2026
330ead1
feat: restore a DS's files and cursor for each DO from its own Drive …
pjwerneck Nov 3, 2026
8402930
refactor: remove the DS's local -event-messages cache, now that Drive…
pjwerneck Nov 3, 2026
f54b85f
refactor: keep the DS's watcher state unencrypted and reuse the DO's …
pjwerneck Nov 4, 2026
7fd99f7
fix: drop a DO change that has no content or no hash when it arrives
pjwerneck Nov 4, 2026
2d3823a
refactor: share the file content and checkpoint merge code between th…
pjwerneck Nov 4, 2026
ff407d1
fix: refuse file content that is not valid base64
pjwerneck Nov 4, 2026
30347d8
refactor: read the checkpoint threshold from one constant
pjwerneck Nov 4, 2026
2e13bb9
fix: give the Drive watcher store its own Drive client in another thread
pjwerneck Nov 4, 2026
4319633
refactor: name the watcher store and cache helpers after what they ha…
pjwerneck Nov 4, 2026
d369c28
test: restore the DS from its own saved state in the deletion-reload …
pjwerneck Nov 4, 2026
928ddec
Merge branch 'pjwerneck/ds-spool' into pjwerneck/ds-watcher-storage
pjwerneck Nov 10, 2026
a0e19ed
refactor: restore the checkpoint and the rolling state of a DO in two…
pjwerneck Nov 10, 2026
ed7b0f7
refactor: name the in-memory rolling state of a DO _rolling_state_loc…
pjwerneck Nov 10, 2026
86700c1
perf: cache the Drive ids of the DS's watcher folders and files
pjwerneck Nov 10, 2026
c79c51b
refactor: refuse a change without content in FileChangeEvent, not in …
pjwerneck Nov 10, 2026
b45bcd3
refactor: keep the content of a checkpoint file as bytes
pjwerneck Nov 10, 2026
eb43610
feat: encrypt the DS's watcher state, and let an enclave keep none
pjwerneck Nov 10, 2026
0d7d9f1
fix: refuse two watcher folders for one DO again
pjwerneck Nov 11, 2026
dde6d12
refactor: share the text-to-bytes helper and ContentType through file…
pjwerneck Nov 11, 2026
35c100f
Merge branch 'pjwerneck/ds-spool' into pjwerneck/ds-watcher-storage
pjwerneck Nov 11, 2026
0cc48d2
refactor: replace the pre_write_filter callback with a config flag
pjwerneck Nov 13, 2026
25e3aea
refactor: name each check in _write_denied and say what was refused
koenvanderveen Nov 24, 2026
43e1399
docs: say why _write_denied exists
koenvanderveen Nov 24, 2026
a19c3c0
docs: say who turns freeze_private_datasets on
koenvanderveen Nov 24, 2026
100721d
refactor: freeze private datasets by default
koenvanderveen Nov 24, 2026
f704bd1
fix: read a version 1 checkpoint, which held text content
koenvanderveen Nov 24, 2026
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
21 changes: 7 additions & 14 deletions packages/syft-enclave/src/syft_enclaves/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
PartyApprovalStatus,
enclave_approval_file_name,
)
from syft_enclaves.immutability import (
make_private_dataset_immutability_filter,
)
from syft_enclaves.receipt.writer import (
ReceiptSettings,
mark_started,
Expand Down Expand Up @@ -794,13 +791,6 @@ def from_config(
"""
rds = SyftRDSClient.from_config(config, connections)
rds.job_client = EnclaveJobClient(rds.job_client)

sync_engine = rds.sync_engine
if sync_engine.datasite_watcher_syncer:
sync_engine.datasite_watcher_syncer.datasite_watcher_cache.pre_write_filter = make_private_dataset_immutability_filter(
sync_engine.syftbox_folder
)

return cls(rds, data_owners=data_owners)

@classmethod
Expand All @@ -819,10 +809,11 @@ def for_enclave(
email: The enclave datasite's email address.
token_path: Path to a pre-authorized Google Drive OAuth token.
data_owners: Emails whose approval gates every job on this enclave.
persist_owner_state: Keep the owner-only state used to restore
this datasite later (event log, rolling state, checkpoints).
Off by default - an enclave gets ephemeral keys and wipes its
state on boot, so there is never anything to restore.
persist_owner_state: Keep the state used to restore this datasite
later: the owner's event log, rolling state and checkpoints,
and the watcher state of its DS role. Off by default - an
enclave gets ephemeral keys and wipes its state on boot, so
there is never anything to restore.
"""
config = SyftRDSClientConfig.for_jupyter(
email=email,
Expand All @@ -831,6 +822,8 @@ def for_enclave(
token_path=Path(token_path) if token_path is not None else None,
encryption=True,
persist_owner_state=persist_owner_state,
persist_watcher_state=persist_owner_state,
freeze_private_datasets=True,
)

# Note: We do not currently provide the ability to load encryption keys passed during creation of enclave.
Expand Down
52 changes: 0 additions & 52 deletions packages/syft-enclave/src/syft_enclaves/immutability.py

This file was deleted.

2 changes: 2 additions & 0 deletions packages/syft-enclave/src/syft_enclaves/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def _login(
has_ds_role=has_ds_role,
encryption=encryption,
skip_peer_on_patch_version_diff=skip_peer_on_patch_version_diff,
freeze_private_datasets=True,
)
else:
config = SyftRDSClientConfig.for_jupyter(
Expand All @@ -59,6 +60,7 @@ def _login(
token_path=Path(token_path) if token_path is not None else None,
encryption=encryption,
skip_peer_on_patch_version_diff=skip_peer_on_patch_version_diff,
freeze_private_datasets=True,
)

_import_key_file(key_file, config.sync.syftbox_folder, email)
Expand Down
7 changes: 4 additions & 3 deletions packages/syft-enclave/src/syft_enclaves/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ def _split_data_owners(cls, v: object) -> object:
persist_owner_state: bool = Field(
default=False,
description=(
"Keep the owner-only state that exists solely to restore this "
"datasite later: the append-only event log, the rolling state and "
"the checkpoints. Off by default because an enclave can never "
"Keep the state that exists solely to restore this datasite later: "
"the owner's append-only event log, rolling state and checkpoints, "
"and the watcher state of its DS role on Drive. Off by default "
"because an enclave can never "
"restore — it gets an ephemeral keypair each boot and wipes its "
"state under fresh_state — so those writes only spend Drive API "
"calls inside the poll loop. Peer-facing state (outbox, "
Expand Down
5 changes: 5 additions & 0 deletions packages/syft-enclave/src/syft_enclaves/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,32 @@ def create_configs(
has_ds_role=True,
use_in_memory_cache=use_in_memory_cache,
persist_owner_state=enclave_persist_owner_state,
persist_watcher_state=enclave_persist_owner_state,
encryption_policy=enclave_policy,
freeze_private_datasets=True,
)
do1_config = SyftRDSClientConfig._base_config_for_testing(
email=do1_email,
has_do_role=True,
has_ds_role=True,
use_in_memory_cache=use_in_memory_cache,
encryption_policy=do1_policy,
freeze_private_datasets=True,
)
do2_config = SyftRDSClientConfig._base_config_for_testing(
email=do2_email,
has_do_role=True,
has_ds_role=True,
use_in_memory_cache=use_in_memory_cache,
encryption_policy=do2_policy,
freeze_private_datasets=True,
)
ds_config = SyftRDSClientConfig._base_config_for_testing(
email=ds_email,
has_ds_role=True,
use_in_memory_cache=use_in_memory_cache,
encryption_policy=ds_policy,
freeze_private_datasets=True,
)
return enclave_config, do1_config, do2_config, ds_config

Expand Down
94 changes: 0 additions & 94 deletions packages/syft-enclave/tests/test_immutability.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,100 +5,6 @@
os.environ["PRE_SYNC"] = "false"

from syft_enclaves import SyftEnclaveClient
from syft_enclaves.immutability import (
is_private_dataset_path,
make_private_dataset_immutability_filter,
)


# --- Unit tests for is_private_dataset_path ---


def test_is_private_dataset_path_positive():
assert is_private_dataset_path(
"do@example.com/private/syft_datasets/my_ds/data.csv"
)


def test_is_private_dataset_path_versioned_layout():
# A protocol copy holds its files under a v<n> segment. The filter must
# protect that layout too, and not only the flat one of protocol 0.
assert is_private_dataset_path(
"do@example.com/private/syft_datasets/v1/my_ds/data.csv"
)


def test_is_private_dataset_path_public():
assert not is_private_dataset_path(
"do@example.com/public/syft_datasets/my_ds/data.csv"
)


def test_is_private_dataset_path_wrong_subdir():
assert not is_private_dataset_path("do@example.com/private/other/file.txt")


def test_is_private_dataset_path_too_short():
# Missing the file component — just the dataset dir itself
assert not is_private_dataset_path("do@example.com/private/syft_datasets/my_ds")


# --- Unit tests for the filter ---


def test_filter_allows_first_write(tmp_path):
f = make_private_dataset_immutability_filter(tmp_path)
path = "do@example.com/private/syft_datasets/my_ds/data.csv"
assert f(path, False) is True


def test_filter_blocks_overwrite(tmp_path):
f = make_private_dataset_immutability_filter(tmp_path)
path = "do@example.com/private/syft_datasets/my_ds/data.csv"

full_path = tmp_path / path
full_path.parent.mkdir(parents=True, exist_ok=True)
full_path.write_text("original data")

assert f(path, False) is False


def test_filter_blocks_delete(tmp_path):
f = make_private_dataset_immutability_filter(tmp_path)
path = "do@example.com/private/syft_datasets/my_ds/data.csv"

full_path = tmp_path / path
full_path.parent.mkdir(parents=True, exist_ok=True)
full_path.write_text("original data")

assert f(path, True) is False


def test_filter_allows_non_dataset_paths(tmp_path):
f = make_private_dataset_immutability_filter(tmp_path)

assert f("do@example.com/public/syft_datasets/ds/file.csv", False) is True
assert f("do@example.com/app_data/job/inbox/ds/job1/run.sh", False) is True


def test_filter_allows_remaining_files_in_batch(tmp_path):
"""First file creates the dir; other files in the same dataset should still be allowed."""
f = make_private_dataset_immutability_filter(tmp_path)
base = "do@example.com/private/syft_datasets/my_ds"

# Simulate first file already written
first = tmp_path / base / "data.csv"
first.parent.mkdir(parents=True, exist_ok=True)
first.write_text("data")

# Second file doesn't exist yet — allowed
assert f(f"{base}/metadata.yaml", False) is True

# First file exists — blocked
assert f(f"{base}/data.csv", False) is False


# --- Integration test ---


def _create_tmp_dataset_files():
Expand Down
21 changes: 21 additions & 0 deletions packages/syft-enclave/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pydantic import ValidationError

from syft_enclaves import EnclaveSettings
from syft_enclaves.client import SyftEnclaveClient
from syft_rds.config import SyftRDSClientConfig


Expand Down Expand Up @@ -138,3 +139,23 @@ def test_persist_owner_state_reaches_do_syncer_config():
has_ds_role=True,
)
assert default.sync.datasite_owner_syncer_config.persist_owner_state is True


def test_for_enclave_keeps_no_watcher_state_by_default(monkeypatch):
"""An enclave gets a new key at each boot and cannot read its saved
watcher state, so by default it keeps none."""
built = []
monkeypatch.setattr(
SyftEnclaveClient,
"from_config",
classmethod(lambda cls, config, data_owners=None: built.append(config)),
)

SyftEnclaveClient.for_enclave("enclave@openmined.org")

[config] = built
watcher_syncer_config = config.sync.datasite_watcher_syncer_config
assert (
watcher_syncer_config.datasite_watcher_cache_config.persist_watcher_state
is False
)
Loading
Loading