diff --git a/backend/tests/deployment/test_cron_environment.py b/backend/tests/deployment/test_cron_environment.py index ed6f19f77..f7ef17f1a 100644 --- a/backend/tests/deployment/test_cron_environment.py +++ b/backend/tests/deployment/test_cron_environment.py @@ -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( diff --git a/deploy/install_host_layout.py b/deploy/install_host_layout.py index 72a420fdf..388e0413c 100755 --- a/deploy/install_host_layout.py +++ b/deploy/install_host_layout.py @@ -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") @@ -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(): diff --git a/docs/deployment.md b/docs/deployment.md index e5871f6cb..9bede4715 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -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