Accept engine sources from Gitea servers #16

Merged
claude merged 2 commits from gitea-sources into master 2026-11-15 00:46:00 +01:00
Collaborator

Tests, tunes and datagen could only use https://github.com/<user>/<repo>. Gitea servers listed under gitea_hosts in Config/config.json are now accepted too, starting with https://gitea.rektdie.com.

How it works

  • OpenBench/git_hosts.py holds all host logic: repo validation, API base, resolving a branch, tag or sha, compare counts, diff links and source URLs. Github code paths keep their old behaviour.
  • API access: the server calls the Gitea API (/api/v1/repos/<owner>/<repo>/commits?sha=<ref>) with the token from Config/credentials.gitea. The token only goes to configured Gitea hosts, and Github requests never get it.
  • Source downloads: gitea.rektdie.com answers anonymous requests with a redirect to the login page, archives included, so workers cannot download sources themselves.
    • The server stores a /giteaSource/?repo=…&sha=…&sig=… link as the test source, and the view streams the .zip from the Gitea API.
    • Workers keep doing a plain GET, so no client change and no client version bump.
  • Signing: the link carries an HMAC of repo and commit keyed with the Gitea token, not Django's SECRET_KEY.
    • OpenSite/settings.py is in this public repo, so a SECRET_KEY signature could be forged to read any repository the token can see.
    • Without a token, Gitea tests are refused at creation and no link validates.
    • Replacing the token invalidates the source links of tests created before it.
  • UI: diff links (compare/base...dev, commit/<sha> for SPSA), the out-of-date check and the profile page handle Gitea repos. The repo fields of the forms accept every configured prefix. Static version bumped to v5 because default_text.js changed.
  • Private engines stay Github-only, because they depend on Github Actions artifacts. A Gitea repo on a private engine gets a clear error.

Deploying

  1. Create a Gitea access token with read:repository scope for an account that can read the engine repos, and write it as the only line of Config/credentials.gitea on the server. credentials.* is already gitignored.
  2. Restart the server.

Tested

Run locally against this branch with Django 4.2 and SQLite, Gitea API responses mocked in the shape of this server's own swagger.v1.json (version 28.1.0). All 36 checks pass:

  • Repo validation: Gitea and Github repos are accepted. Unknown hosts, lookalike hosts (gitea.rektdie.com.evil.com) and deep paths are rejected.
  • Test creation with a Gitea branch: the sha and the bench from the commit message are resolved. The token goes only to Gitea, and the source becomes a signed proxy link.
  • /giteaSource/:
    • Returns the zip, fetched with the token.
    • Gets 403 for another sha, another repo, a bad signature, missing parameters, or a signature made with SECRET_KEY.
  • Without a token: test creation is refused and links are refused. They work again once the token is back.
  • Links and checks: the out-of-date check and diff links work for both hosts. A private engine with a Gitea repo is refused.
  • Github regression: same archive URL (tree sha) and bench, no token leaks to Github, same diff link.
  • Pages: /newTest/ renders with both prefixes.
  • Not tested: the real Gitea API with a real token, since I have none. That needs a first test after deploying.

manage.py check reports no issues.

🤖 Generated with Claude Code

Tests, tunes and datagen could only use `https://github.com/<user>/<repo>`. Gitea servers listed under `gitea_hosts` in `Config/config.json` are now accepted too, starting with `https://gitea.rektdie.com`. ## How it works - **`OpenBench/git_hosts.py`** holds all host logic: repo validation, API base, resolving a branch, tag or sha, compare counts, diff links and source URLs. Github code paths keep their old behaviour. - **API access:** the server calls the Gitea API (`/api/v1/repos/<owner>/<repo>/commits?sha=<ref>`) with the token from `Config/credentials.gitea`. The token only goes to configured Gitea hosts, and Github requests never get it. - **Source downloads:** gitea.rektdie.com answers anonymous requests with a redirect to the login page, archives included, so workers cannot download sources themselves. - The server stores a `/giteaSource/?repo=…&sha=…&sig=…` link as the test source, and the view streams the `.zip` from the Gitea API. - Workers keep doing a plain GET, so **no client change and no client version bump**. - **Signing:** the link carries an HMAC of repo and commit keyed with **the Gitea token**, not Django's `SECRET_KEY`. - `OpenSite/settings.py` is in this public repo, so a `SECRET_KEY` signature could be forged to read any repository the token can see. - Without a token, Gitea tests are refused at creation and no link validates. - Replacing the token invalidates the source links of tests created before it. - **UI:** diff links (`compare/base...dev`, `commit/<sha>` for SPSA), the out-of-date check and the profile page handle Gitea repos. The repo fields of the forms accept every configured prefix. Static version bumped to `v5` because `default_text.js` changed. - **Private engines** stay Github-only, because they depend on Github Actions artifacts. A Gitea repo on a private engine gets a clear error. ## Deploying 1. Create a Gitea access token with **read:repository** scope for an account that can read the engine repos, and write it as the only line of `Config/credentials.gitea` on the server. `credentials.*` is already gitignored. 2. Restart the server. ## Tested Run locally against this branch with Django 4.2 and SQLite, Gitea API responses mocked in the shape of this server's own `swagger.v1.json` (version 28.1.0). All 36 checks pass: - **Repo validation:** Gitea and Github repos are accepted. Unknown hosts, lookalike hosts (`gitea.rektdie.com.evil.com`) and deep paths are rejected. - **Test creation with a Gitea branch:** the sha and the bench from the commit message are resolved. The token goes only to Gitea, and the source becomes a signed proxy link. - **`/giteaSource/`:** - Returns the zip, fetched with the token. - Gets 403 for another sha, another repo, a bad signature, missing parameters, or a signature made with `SECRET_KEY`. - **Without a token:** test creation is refused and links are refused. They work again once the token is back. - **Links and checks:** the out-of-date check and diff links work for both hosts. A private engine with a Gitea repo is refused. - **Github regression:** same archive URL (tree sha) and bench, no token leaks to Github, same diff link. - **Pages:** `/newTest/` renders with both prefixes. - **Not tested:** the real Gitea API with a real token, since I have none. That needs a first test after deploying. `manage.py check` reports no issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
claude added 1 commit 2026-11-15 00:42:50 +01:00
Tests, tunes and datagen could only use https://github.com/<user>/<repo>.
Gitea servers listed under "gitea_hosts" in Config/config.json are now
accepted too, starting with https://gitea.rektdie.com.

- OpenBench/git_hosts.py holds all host logic: repo validation, API base,
  resolving a branch/tag/sha, compare counts, diff links and source URLs.
- The server talks to Gitea with the token in Config/credentials.gitea and
  sends it nowhere else; Github requests stay unchanged.
- Gitea may require a login even to read, so workers cannot download the
  archive themselves. The server gives them a /giteaSource/ link signed with
  an HMAC of repo and commit (SECRET_KEY), and streams the archive from the
  Gitea API. No client change, no client version bump.
- Diff links, the out-of-date check and the profile page handle Gitea repos;
  the repo fields of the forms accept every configured prefix.
- Private engines stay Github-only, they depend on Github Actions artifacts.
- Static version bumped to v5 for the changed default_text.js.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rektdie added 1 commit 2026-11-15 00:45:02 +01:00
settings.py, SECRET_KEY included, is part of the public repository, so
links signed with it could be forged to read any repository the token can
see. The token in Config/credentials.gitea is gitignored and is now the
signing key. Without a token, Gitea tests are refused at creation and no
link validates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude merged commit f915c30f02 into master 2026-11-15 00:46:00 +01:00
claude deleted branch gitea-sources 2026-11-15 00:46:00 +01:00
Sign in to join this conversation.