First part of #439 (stories 1–3, 5, 7): a tenant's managed Gitea organisation becomes a git source. Every repository in it becomes a target, is scanned on push to the default branch, and gets its findings as labelled issues.
Platform API (service token, like the other /api/v1/platform/* routes)
PUT /api/v1/platform/tenants/{id}/git-source
body {base_url, org, bot_token?, enabled? (default true), rotate_webhook_secret? (default false)}. base_url must be https://<host> with no port, path or credentials, and the host must match GIT_SOURCE_HOST_PATTERN (anchored; default ^[a-z0-9-]+\.code(-stage)?\.breakpilot\.com$). bot_token is required the first time; if you leave it out later, the stored token stays. The response is the source without secrets plus webhook_url and webhook_secret. The secret is only included when it is issued (on the first PUT or with rotate_webhook_secret), otherwise it is null, so a retried PUT doesn't break the registered webhook. A new token is also written onto the existing managed targets. A sync starts right away.
removes the source and archives its targets (targets_archived).
Customer API: GET /api/v1/git-source (read-only, for IT_ADMIN or support), no dashboard UI yet.
Webhook
POST /webhook/{tenant_id}/gitea-source (webhook server, port 3002). Register it in Gitea as an org or system webhook of type Gitea, content type JSON, with the events Repository and Push.
X-Gitea-Signature = hex HMAC-SHA256 of the body under the source's secret. Missing or wrong → 401. No enabled source → 404. The source is read through for_existing_tenant_id, so nothing is created before the signature has been verified.
repository / created → a target is created (clone URL built from the source origin, never taken from the payload; credentials are the bot token, the issue tracker is Gitea on the same repo; type from detect_target). Then the first scan, unless the repo is empty, in which case the first push triggers it. deleted → the target is archived (archived_at).
push to refs/heads/<default_branch> → scan, creating the target first if it's missing. Pushes to other branches, tags and branch deletions are ignored.
Repos outside the configured org, and all other events (including pull_request), → 200 and ignored.
Before any write, entitlement and the status ladder are checked the same way as for scheduled work (allowed && !read_only && scheduler_runs_for(status); without a registry only outside hardened deployments) → 403. Usage events go through the usual paths (target.added, scan.completed).
Idempotent: a unique partial index on (source_repo.base_url, source_repo.repo_id) plus a re-read on duplicate key. Concurrent deliveries create one target (covered by a test). Renames and changes of the default branch update the existing target, and if the repo shows up again its target is unarchived.
Sync
A scheduler job runs every GIT_SOURCE_SYNC_MINUTES (default 30) for every runnable tenant that has an enabled source. It lists /api/v1/orgs/{org}/repos page by page through the guarded client, creates missing targets, refreshes renamed ones, archives targets whose repo is gone, and sets last_sync_at. The scheduled scan now skips archived targets.
Issues
On managed targets the Gitea tracker ensures the labels pruefwerk, cra:annex-i and severity:critical|high|medium|low once per run and attaches them by id. If that fails, the issue is still created, with the label names in the body as before. The issue body (same format for all trackers) now adds **CRA:** cra-ai-N — <title> (Annex I) from control_refs, and managed issues link to DASHBOARD_PUBLIC_URL/findings?target=…. Trackers that users configured themselves are unchanged.
Env
GIT_SOURCE_HOST_PATTERN, GIT_SOURCE_SYNC_MINUTES and WEBHOOK_PUBLIC_URL. The last one is the public origin of the webhook server, used for webhook_url; without it only the path is returned. A malformed value refuses startup. All three are documented in .env.example.
Docs
docs/guide/managed-git.md (DE) and managed-git-en.md (EN) cover the workflow, the bot user pruefwerk with minimal rights (a team with Code: read and Issues: write; token scopes read:organization, read:repository, write:issue; no admin) and the operator steps.
Tests
Unit tests: signature (valid, invalid, missing, tampered, prefixed), host allowlist (default and env, anchoring), event routing (created, deleted, push to default/other branch, tags, branch deletion, other org, unknown event, bad payload), target construction and idempotent refresh, sync diffing, pagination against a fake Gitea, label ensure against a fake Gitea, issue body with CWE and CRA.
tests/git_source.rs (needs Mongo, skips without it): PUT/GET/DELETE, sealed storage, the secret shown only once, webhook 401/404, concurrent created → one target, other org ignored, deleted → archived, sync with a mocked listing.
Lifecycle (auto-close and reopen, accepted risk → label and close), PR review comments from the org webhook, a dashboard view of the source, the pilot run on git.breakpilot.com. Deployment also needs a public route to the webhook port, WEBHOOK_PUBLIC_URL, and Gitea's ALLOWED_HOST_LIST.
First part of #439 (stories 1–3, 5, 7): a tenant's managed Gitea organisation becomes a **git source**. Every repository in it becomes a target, is scanned on push to the default branch, and gets its findings as labelled issues.
## Platform API (service token, like the other `/api/v1/platform/*` routes)
| | |
|---|---|
| `PUT /api/v1/platform/tenants/{id}/git-source` | body `{base_url, org, bot_token?, enabled? (default true), rotate_webhook_secret? (default false)}`. `base_url` must be `https://<host>` with no port, path or credentials, and the host must match `GIT_SOURCE_HOST_PATTERN` (anchored; default `^[a-z0-9-]+\.code(-stage)?\.breakpilot\.com$`). `bot_token` is required the first time; if you leave it out later, the stored token stays. The response is the source without secrets plus `webhook_url` and `webhook_secret`. The secret is only included when it is issued (on the first PUT or with `rotate_webhook_secret`), otherwise it is `null`, so a retried PUT doesn't break the registered webhook. A new token is also written onto the existing managed targets. A sync starts right away. |
| `GET …/git-source` | `{base_url, org, enabled, has_bot_token, has_webhook_secret, created_at, updated_at, last_sync_at, webhook_url, webhook_secret: null}` |
| `DELETE …/git-source` | removes the source and archives its targets (`targets_archived`). |
Customer API: `GET /api/v1/git-source` (read-only, for IT_ADMIN or support), no dashboard UI yet.
## Webhook
`POST /webhook/{tenant_id}/gitea-source` (webhook server, port 3002). Register it in Gitea as an org or system webhook of type Gitea, content type JSON, with the events **Repository** and **Push**.
- `X-Gitea-Signature` = hex HMAC-SHA256 of the body under the source's secret. Missing or wrong → 401. No enabled source → 404. The source is read through `for_existing_tenant_id`, so nothing is created before the signature has been verified.
- `repository` / `created` → a target is created (clone URL built from the source origin, never taken from the payload; credentials are the bot token, the issue tracker is Gitea on the same repo; type from `detect_target`). Then the first scan, unless the repo is empty, in which case the first push triggers it. `deleted` → the target is archived (`archived_at`).
- `push` to `refs/heads/<default_branch>` → scan, creating the target first if it's missing. Pushes to other branches, tags and branch deletions are ignored.
- Repos outside the configured org, and all other events (including `pull_request`), → 200 and ignored.
- Before any write, entitlement and the status ladder are checked the same way as for scheduled work (`allowed && !read_only && scheduler_runs_for(status)`; without a registry only outside hardened deployments) → 403. Usage events go through the usual paths (`target.added`, `scan.completed`).
- Idempotent: a unique partial index on `(source_repo.base_url, source_repo.repo_id)` plus a re-read on duplicate key. Concurrent deliveries create one target (covered by a test). Renames and changes of the default branch update the existing target, and if the repo shows up again its target is unarchived.
## Sync
A scheduler job runs every `GIT_SOURCE_SYNC_MINUTES` (default 30) for every runnable tenant that has an enabled source. It lists `/api/v1/orgs/{org}/repos` page by page through the guarded client, creates missing targets, refreshes renamed ones, archives targets whose repo is gone, and sets `last_sync_at`. The scheduled scan now skips archived targets.
## Issues
On managed targets the Gitea tracker ensures the labels `pruefwerk`, `cra:annex-i` and `severity:critical|high|medium|low` once per run and attaches them by id. If that fails, the issue is still created, with the label names in the body as before. The issue body (same format for all trackers) now adds `**CRA:** cra-ai-N — <title> (Annex I)` from `control_refs`, and managed issues link to `DASHBOARD_PUBLIC_URL/findings?target=…`. Trackers that users configured themselves are unchanged.
## Env
`GIT_SOURCE_HOST_PATTERN`, `GIT_SOURCE_SYNC_MINUTES` and `WEBHOOK_PUBLIC_URL`. The last one is the public origin of the webhook server, used for `webhook_url`; without it only the path is returned. A malformed value refuses startup. All three are documented in `.env.example`.
## Docs
`docs/guide/managed-git.md` (DE) and `managed-git-en.md` (EN) cover the workflow, the bot user `pruefwerk` with minimal rights (a team with Code: read and Issues: write; token scopes `read:organization`, `read:repository`, `write:issue`; no admin) and the operator steps.
## Tests
- Unit tests: signature (valid, invalid, missing, tampered, prefixed), host allowlist (default and env, anchoring), event routing (created, deleted, push to default/other branch, tags, branch deletion, other org, unknown event, bad payload), target construction and idempotent refresh, sync diffing, pagination against a fake Gitea, label ensure against a fake Gitea, issue body with CWE and CRA.
- `tests/git_source.rs` (needs Mongo, skips without it): PUT/GET/DELETE, sealed storage, the secret shown only once, webhook 401/404, concurrent `created` → one target, other org ignored, deleted → archived, sync with a mocked listing.
## Not in this PR (rest of #439)
Lifecycle (auto-close and reopen, accepted risk → label and close), PR review comments from the org webhook, a dashboard view of the source, the pilot run on git.breakpilot.com. Deployment also needs a public route to the webhook port, `WEBHOOK_PUBLIC_URL`, and Gitea's `ALLOWED_HOST_LIST`.
No version bump.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
A tenant's managed Gitea organisation becomes a git source: every
repository in it is a target, scanned on push, with findings as
labelled issues.
- Git source per tenant (`git_sources`, one doc): https base URL whose
host must match GIT_SOURCE_HOST_PATTERN, org, bot token and webhook
secret sealed like other credentials. Platform API
PUT/GET/DELETE /api/v1/platform/tenants/{id}/git-source; the secret
is returned only when issued (first PUT or rotate_webhook_secret).
Read-only GET /api/v1/git-source for IT admins and support.
- POST /webhook/{tenant_id}/gitea-source on the webhook server,
X-Gitea-Signature checked before anything is created. repository
created -> target (clone URL built from the source origin, bot token,
Gitea tracker, type from detection) and first scan unless empty;
deleted -> target archived; push to the default branch -> scan,
creating the target if missing. Other orgs are ignored. Entitlement
and ladder are checked as for scheduled work; usage events as usual.
- Targets get source_repo (unique per instance + repo id, so racing
deliveries make one target) and archived_at; the scheduler skips
archived targets.
- Sync job every GIT_SOURCE_SYNC_MINUTES (default 30): lists the org's
repos (paginated), creates missing, refreshes renamed, archives gone.
- Managed repos get the labels pruefwerk, cra:annex-i and
severity:* ensured once per run and attached by id; issue bodies name
the CRA requirement(s) and link into Prüfwerk. User-configured
trackers behave as before.
- Docs (DE/EN): connecting Managed Git and the bot's minimal rights.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
A Gitea with MAX_RESPONSE_ITEMS below 50 returns short pages; taking
the first short page for the last one would have made the sync archive
every repository after it. Same for the label listing. A token renewal
skips git artifacts without credentials instead of failing, and the
guides say the source is readable through the API (no UI yet).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
sharang
merged commit 260d07c783 into main2026-10-05 10:39:20 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
First part of #439 (stories 1–3, 5, 7): a tenant's managed Gitea organisation becomes a git source. Every repository in it becomes a target, is scanned on push to the default branch, and gets its findings as labelled issues.
Platform API (service token, like the other
/api/v1/platform/*routes)PUT /api/v1/platform/tenants/{id}/git-source{base_url, org, bot_token?, enabled? (default true), rotate_webhook_secret? (default false)}.base_urlmust behttps://<host>with no port, path or credentials, and the host must matchGIT_SOURCE_HOST_PATTERN(anchored; default^[a-z0-9-]+\.code(-stage)?\.breakpilot\.com$).bot_tokenis required the first time; if you leave it out later, the stored token stays. The response is the source without secrets pluswebhook_urlandwebhook_secret. The secret is only included when it is issued (on the first PUT or withrotate_webhook_secret), otherwise it isnull, so a retried PUT doesn't break the registered webhook. A new token is also written onto the existing managed targets. A sync starts right away.GET …/git-source{base_url, org, enabled, has_bot_token, has_webhook_secret, created_at, updated_at, last_sync_at, webhook_url, webhook_secret: null}DELETE …/git-sourcetargets_archived).Customer API:
GET /api/v1/git-source(read-only, for IT_ADMIN or support), no dashboard UI yet.Webhook
POST /webhook/{tenant_id}/gitea-source(webhook server, port 3002). Register it in Gitea as an org or system webhook of type Gitea, content type JSON, with the events Repository and Push.X-Gitea-Signature= hex HMAC-SHA256 of the body under the source's secret. Missing or wrong → 401. No enabled source → 404. The source is read throughfor_existing_tenant_id, so nothing is created before the signature has been verified.repository/created→ a target is created (clone URL built from the source origin, never taken from the payload; credentials are the bot token, the issue tracker is Gitea on the same repo; type fromdetect_target). Then the first scan, unless the repo is empty, in which case the first push triggers it.deleted→ the target is archived (archived_at).pushtorefs/heads/<default_branch>→ scan, creating the target first if it's missing. Pushes to other branches, tags and branch deletions are ignored.pull_request), → 200 and ignored.allowed && !read_only && scheduler_runs_for(status); without a registry only outside hardened deployments) → 403. Usage events go through the usual paths (target.added,scan.completed).(source_repo.base_url, source_repo.repo_id)plus a re-read on duplicate key. Concurrent deliveries create one target (covered by a test). Renames and changes of the default branch update the existing target, and if the repo shows up again its target is unarchived.Sync
A scheduler job runs every
GIT_SOURCE_SYNC_MINUTES(default 30) for every runnable tenant that has an enabled source. It lists/api/v1/orgs/{org}/repospage by page through the guarded client, creates missing targets, refreshes renamed ones, archives targets whose repo is gone, and setslast_sync_at. The scheduled scan now skips archived targets.Issues
On managed targets the Gitea tracker ensures the labels
pruefwerk,cra:annex-iandseverity:critical|high|medium|lowonce per run and attaches them by id. If that fails, the issue is still created, with the label names in the body as before. The issue body (same format for all trackers) now adds**CRA:** cra-ai-N — <title> (Annex I)fromcontrol_refs, and managed issues link toDASHBOARD_PUBLIC_URL/findings?target=…. Trackers that users configured themselves are unchanged.Env
GIT_SOURCE_HOST_PATTERN,GIT_SOURCE_SYNC_MINUTESandWEBHOOK_PUBLIC_URL. The last one is the public origin of the webhook server, used forwebhook_url; without it only the path is returned. A malformed value refuses startup. All three are documented in.env.example.Docs
docs/guide/managed-git.md(DE) andmanaged-git-en.md(EN) cover the workflow, the bot userpruefwerkwith minimal rights (a team with Code: read and Issues: write; token scopesread:organization,read:repository,write:issue; no admin) and the operator steps.Tests
tests/git_source.rs(needs Mongo, skips without it): PUT/GET/DELETE, sealed storage, the secret shown only once, webhook 401/404, concurrentcreated→ one target, other org ignored, deleted → archived, sync with a mocked listing.Not in this PR (rest of #439)
Lifecycle (auto-close and reopen, accepted risk → label and close), PR review comments from the org webhook, a dashboard view of the source, the pilot run on git.breakpilot.com. Deployment also needs a public route to the webhook port,
WEBHOOK_PUBLIC_URL, and Gitea'sALLOWED_HOST_LIST.No version bump.
🤖 Generated with Claude Code
https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
A tenant's managed Gitea organisation becomes a git source: every repository in it is a target, scanned on push, with findings as labelled issues. - Git source per tenant (`git_sources`, one doc): https base URL whose host must match GIT_SOURCE_HOST_PATTERN, org, bot token and webhook secret sealed like other credentials. Platform API PUT/GET/DELETE /api/v1/platform/tenants/{id}/git-source; the secret is returned only when issued (first PUT or rotate_webhook_secret). Read-only GET /api/v1/git-source for IT admins and support. - POST /webhook/{tenant_id}/gitea-source on the webhook server, X-Gitea-Signature checked before anything is created. repository created -> target (clone URL built from the source origin, bot token, Gitea tracker, type from detection) and first scan unless empty; deleted -> target archived; push to the default branch -> scan, creating the target if missing. Other orgs are ignored. Entitlement and ladder are checked as for scheduled work; usage events as usual. - Targets get source_repo (unique per instance + repo id, so racing deliveries make one target) and archived_at; the scheduler skips archived targets. - Sync job every GIT_SOURCE_SYNC_MINUTES (default 30): lists the org's repos (paginated), creates missing, refreshes renamed, archives gone. - Managed repos get the labels pruefwerk, cra:annex-i and severity:* ensured once per run and attached by id; issue bodies name the CRA requirement(s) and link into Prüfwerk. User-configured trackers behave as before. - Docs (DE/EN): connecting Managed Git and the bot's minimal rights. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB