Skip to content

Commit bc669fb

Browse files
Merge pull request #9613 from OpenMined/pjwerneck/ds-watcher-storage
feat: keep the DS's watcher state on its own Drive and restore it at startup
2 parents a34ed6f + f704bd1 commit bc669fb

33 files changed

Lines changed: 1211 additions & 526 deletions

‎packages/syft-enclave/src/syft_enclaves/client.py‎

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
PartyApprovalStatus,
3434
enclave_approval_file_name,
3535
)
36-
from syft_enclaves.immutability import (
37-
make_private_dataset_immutability_filter,
38-
)
3936
from syft_enclaves.receipt.writer import (
4037
ReceiptSettings,
4138
mark_started,
@@ -794,13 +791,6 @@ def from_config(
794791
"""
795792
rds = SyftRDSClient.from_config(config, connections)
796793
rds.job_client = EnclaveJobClient(rds.job_client)
797-
798-
sync_engine = rds.sync_engine
799-
if sync_engine.datasite_watcher_syncer:
800-
sync_engine.datasite_watcher_syncer.datasite_watcher_cache.pre_write_filter = make_private_dataset_immutability_filter(
801-
sync_engine.syftbox_folder
802-
)
803-
804794
return cls(rds, data_owners=data_owners)
805795

806796
@classmethod
@@ -819,10 +809,11 @@ def for_enclave(
819809
email: The enclave datasite's email address.
820810
token_path: Path to a pre-authorized Google Drive OAuth token.
821811
data_owners: Emails whose approval gates every job on this enclave.
822-
persist_owner_state: Keep the owner-only state used to restore
823-
this datasite later (event log, rolling state, checkpoints).
824-
Off by default - an enclave gets ephemeral keys and wipes its
825-
state on boot, so there is never anything to restore.
812+
persist_owner_state: Keep the state used to restore this datasite
813+
later: the owner's event log, rolling state and checkpoints,
814+
and the watcher state of its DS role. Off by default - an
815+
enclave gets ephemeral keys and wipes its state on boot, so
816+
there is never anything to restore.
826817
"""
827818
config = SyftRDSClientConfig.for_jupyter(
828819
email=email,
@@ -831,6 +822,8 @@ def for_enclave(
831822
token_path=Path(token_path) if token_path is not None else None,
832823
encryption=True,
833824
persist_owner_state=persist_owner_state,
825+
persist_watcher_state=persist_owner_state,
826+
freeze_private_datasets=True,
834827
)
835828

836829
# Note: We do not currently provide the ability to load encryption keys passed during creation of enclave.

‎packages/syft-enclave/src/syft_enclaves/immutability.py‎

Lines changed: 0 additions & 52 deletions
This file was deleted.

‎packages/syft-enclave/src/syft_enclaves/login.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def _login(
5050
has_ds_role=has_ds_role,
5151
encryption=encryption,
5252
skip_peer_on_patch_version_diff=skip_peer_on_patch_version_diff,
53+
freeze_private_datasets=True,
5354
)
5455
else:
5556
config = SyftRDSClientConfig.for_jupyter(
@@ -59,6 +60,7 @@ def _login(
5960
token_path=Path(token_path) if token_path is not None else None,
6061
encryption=encryption,
6162
skip_peer_on_patch_version_diff=skip_peer_on_patch_version_diff,
63+
freeze_private_datasets=True,
6264
)
6365

6466
_import_key_file(key_file, config.sync.syftbox_folder, email)

‎packages/syft-enclave/src/syft_enclaves/settings.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,10 @@ def _split_data_owners(cls, v: object) -> object:
153153
persist_owner_state: bool = Field(
154154
default=False,
155155
description=(
156-
"Keep the owner-only state that exists solely to restore this "
157-
"datasite later: the append-only event log, the rolling state and "
158-
"the checkpoints. Off by default because an enclave can never "
156+
"Keep the state that exists solely to restore this datasite later: "
157+
"the owner's append-only event log, rolling state and checkpoints, "
158+
"and the watcher state of its DS role on Drive. Off by default "
159+
"because an enclave can never "
159160
"restore — it gets an ephemeral keypair each boot and wipes its "
160161
"state under fresh_state — so those writes only spend Drive API "
161162
"calls inside the poll loop. Peer-facing state (outbox, "

‎packages/syft-enclave/src/syft_enclaves/utils.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,32 @@ def create_configs(
2525
has_ds_role=True,
2626
use_in_memory_cache=use_in_memory_cache,
2727
persist_owner_state=enclave_persist_owner_state,
28+
persist_watcher_state=enclave_persist_owner_state,
2829
encryption_policy=enclave_policy,
30+
freeze_private_datasets=True,
2931
)
3032
do1_config = SyftRDSClientConfig._base_config_for_testing(
3133
email=do1_email,
3234
has_do_role=True,
3335
has_ds_role=True,
3436
use_in_memory_cache=use_in_memory_cache,
3537
encryption_policy=do1_policy,
38+
freeze_private_datasets=True,
3639
)
3740
do2_config = SyftRDSClientConfig._base_config_for_testing(
3841
email=do2_email,
3942
has_do_role=True,
4043
has_ds_role=True,
4144
use_in_memory_cache=use_in_memory_cache,
4245
encryption_policy=do2_policy,
46+
freeze_private_datasets=True,
4347
)
4448
ds_config = SyftRDSClientConfig._base_config_for_testing(
4549
email=ds_email,
4650
has_ds_role=True,
4751
use_in_memory_cache=use_in_memory_cache,
4852
encryption_policy=ds_policy,
53+
freeze_private_datasets=True,
4954
)
5055
return enclave_config, do1_config, do2_config, ds_config
5156

‎packages/syft-enclave/tests/test_immutability.py‎

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -5,100 +5,6 @@
55
os.environ["PRE_SYNC"] = "false"
66

77
from syft_enclaves import SyftEnclaveClient
8-
from syft_enclaves.immutability import (
9-
is_private_dataset_path,
10-
make_private_dataset_immutability_filter,
11-
)
12-
13-
14-
# --- Unit tests for is_private_dataset_path ---
15-
16-
17-
def test_is_private_dataset_path_positive():
18-
assert is_private_dataset_path(
19-
"do@example.com/private/syft_datasets/my_ds/data.csv"
20-
)
21-
22-
23-
def test_is_private_dataset_path_versioned_layout():
24-
# A protocol copy holds its files under a v<n> segment. The filter must
25-
# protect that layout too, and not only the flat one of protocol 0.
26-
assert is_private_dataset_path(
27-
"do@example.com/private/syft_datasets/v1/my_ds/data.csv"
28-
)
29-
30-
31-
def test_is_private_dataset_path_public():
32-
assert not is_private_dataset_path(
33-
"do@example.com/public/syft_datasets/my_ds/data.csv"
34-
)
35-
36-
37-
def test_is_private_dataset_path_wrong_subdir():
38-
assert not is_private_dataset_path("do@example.com/private/other/file.txt")
39-
40-
41-
def test_is_private_dataset_path_too_short():
42-
# Missing the file component — just the dataset dir itself
43-
assert not is_private_dataset_path("do@example.com/private/syft_datasets/my_ds")
44-
45-
46-
# --- Unit tests for the filter ---
47-
48-
49-
def test_filter_allows_first_write(tmp_path):
50-
f = make_private_dataset_immutability_filter(tmp_path)
51-
path = "do@example.com/private/syft_datasets/my_ds/data.csv"
52-
assert f(path, False) is True
53-
54-
55-
def test_filter_blocks_overwrite(tmp_path):
56-
f = make_private_dataset_immutability_filter(tmp_path)
57-
path = "do@example.com/private/syft_datasets/my_ds/data.csv"
58-
59-
full_path = tmp_path / path
60-
full_path.parent.mkdir(parents=True, exist_ok=True)
61-
full_path.write_text("original data")
62-
63-
assert f(path, False) is False
64-
65-
66-
def test_filter_blocks_delete(tmp_path):
67-
f = make_private_dataset_immutability_filter(tmp_path)
68-
path = "do@example.com/private/syft_datasets/my_ds/data.csv"
69-
70-
full_path = tmp_path / path
71-
full_path.parent.mkdir(parents=True, exist_ok=True)
72-
full_path.write_text("original data")
73-
74-
assert f(path, True) is False
75-
76-
77-
def test_filter_allows_non_dataset_paths(tmp_path):
78-
f = make_private_dataset_immutability_filter(tmp_path)
79-
80-
assert f("do@example.com/public/syft_datasets/ds/file.csv", False) is True
81-
assert f("do@example.com/app_data/job/inbox/ds/job1/run.sh", False) is True
82-
83-
84-
def test_filter_allows_remaining_files_in_batch(tmp_path):
85-
"""First file creates the dir; other files in the same dataset should still be allowed."""
86-
f = make_private_dataset_immutability_filter(tmp_path)
87-
base = "do@example.com/private/syft_datasets/my_ds"
88-
89-
# Simulate first file already written
90-
first = tmp_path / base / "data.csv"
91-
first.parent.mkdir(parents=True, exist_ok=True)
92-
first.write_text("data")
93-
94-
# Second file doesn't exist yet — allowed
95-
assert f(f"{base}/metadata.yaml", False) is True
96-
97-
# First file exists — blocked
98-
assert f(f"{base}/data.csv", False) is False
99-
100-
101-
# --- Integration test ---
1028

1039

10410
def _create_tmp_dataset_files():

‎packages/syft-enclave/tests/test_settings.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pydantic import ValidationError
88

99
from syft_enclaves import EnclaveSettings
10+
from syft_enclaves.client import SyftEnclaveClient
1011
from syft_rds.config import SyftRDSClientConfig
1112

1213

@@ -138,3 +139,23 @@ def test_persist_owner_state_reaches_do_syncer_config():
138139
has_ds_role=True,
139140
)
140141
assert default.sync.datasite_owner_syncer_config.persist_owner_state is True
142+
143+
144+
def test_for_enclave_keeps_no_watcher_state_by_default(monkeypatch):
145+
"""An enclave gets a new key at each boot and cannot read its saved
146+
watcher state, so by default it keeps none."""
147+
built = []
148+
monkeypatch.setattr(
149+
SyftEnclaveClient,
150+
"from_config",
151+
classmethod(lambda cls, config, data_owners=None: built.append(config)),
152+
)
153+
154+
SyftEnclaveClient.for_enclave("enclave@openmined.org")
155+
156+
[config] = built
157+
watcher_syncer_config = config.sync.datasite_watcher_syncer_config
158+
assert (
159+
watcher_syncer_config.datasite_watcher_cache_config.persist_watcher_state
160+
is False
161+
)

0 commit comments

Comments
 (0)