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
34 changes: 34 additions & 0 deletions backend/tests/deployment/test_cron_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,40 @@ def test_host_layout_grants_cron_traversal_and_drops_production_group(monkeypatc
]


def test_host_layout_shares_only_the_trace_spool_with_cron(monkeypatch):
import deploy.install_host_layout as host_layout

calls: list[list[str]] = []
directories: list[tuple[str, str, str, int]] = []
monkeypatch.setattr(
host_layout.subprocess, "run", lambda command, check: calls.append(command)
)
monkeypatch.setattr(
host_layout,
"ensure_dir",
lambda path, user, group, mode: directories.append(
(str(path), user, group, mode)
),
)

host_layout.share_curation_trace_spool()

spool = "/var/lib/paperswithcode/production/recovery-spool"
assert directories == [
(f"{spool}/curation-traces", "pwc-production", "pwc-production", 0o700)
]
assert calls == [
["setfacl", "--modify", "user:pwc-cron:--x", spool],
[
"setfacl",
"--modify",
"user:pwc-cron:rwx,default:user:pwc-cron:rw-,"
"default:user:pwc-production:rw-",
f"{spool}/curation-traces",
],
]


def test_launcher_hides_its_environment_from_same_user_jobs(tmp_path: Path):
script = tmp_path / "probe.py"
script.write_text(
Expand Down
26 changes: 26 additions & 0 deletions deploy/install_host_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,31 @@ def restrict_cron_access() -> None:
)


def share_curation_trace_spool() -> None:
"""Let the CRON operator re-finalize curation traces the backend spooled.

`pwc-cron enqueue_hf_daily_paper_curation --retry-trace` runs as pwc-cron,
but the backend writes trace-finalization payloads as pwc-production. Grant
pwc-cron traversal of the recovery spool and access to its trace directory
only; the rest of the spool and production state stay private.
"""

spool = STATE_ROOT / "production" / "recovery-spool"
traces = spool / "curation-traces"
ensure_dir(traces, "pwc-production", "pwc-production", 0o700)
subprocess.run(["setfacl", "--modify", "user:pwc-cron:--x", str(spool)], check=True)
subprocess.run(
[
"setfacl",
"--modify",
"user:pwc-cron:rwx,default:user:pwc-cron:rw-,"
"default:user:pwc-production:rw-",
str(traces),
],
check=True,
)


def main() -> int:
if os.geteuid() != 0:
raise SystemExit("run through sudo")
Expand Down Expand Up @@ -371,6 +396,7 @@ def main() -> int:
STATE_ROOT / "production" / "chat-recovery-spool",
):
ensure_dir(path, "pwc-production", "pwc-production", 0o700)
share_curation_trace_spool()

repository = APP_ROOT / "repository.git"
if not repository.exists():
Expand Down
5 changes: 5 additions & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,11 @@ sandbox credentials (`APP_ONLY_SECRET_KEYS` in `deploy/cron_launcher.py`).
`production.env` directly. systemd loads the environment files as root, and a
`user:pwc-cron:--x` ACL lets jobs traverse `/var/lib/paperswithcode/production`
to their own directories (`install_host_layout.restrict_cron_access`).
The only production app state they share is the curation trace spool
(`recovery-spool/curation-traces`), so `pwc-cron enqueue_hf_daily_paper_curation
--retry-trace` can re-upload traces the backend spooled
(`install_host_layout.share_curation_trace_spool`). Rerun
`sudo python3 deploy/install_host_layout.py` after changing these grants.

```bash
sudo pwc-cron status
Expand Down
Loading