Entry offers (CRA-Check, SBOM-Erstellung, CVE-Scan) are paid at booking
outside the ERP. Staff grant them with POST /v1/admin/tenants/{id}/entry-offer
(named staff member, audited, cloud only): Prüfwerk with source "entry",
SKU CRA-CSA-CLD-EIN, the order's included targets (1..10) and an end date
that is sent again at delivery (90 days after it).
- Plan "einstieg": no monthly quota and a Prüftag cap of 0 whatever the
workspace saved, so only support scans (never counted) and change scans
of the included targets run. Any subscription plan SKU wins over it; no
plan SKU at all stays Standard, so trials and previews are unchanged.
- cap_applies is false on the entry plan, as on Enterprise.
- A trial workspace becomes active (no trial banner).
- recomputeEntitlements does not halt a workspace while an entry grant
runs; once it has ended the old rule applies.
- Refused for a workspace that booked Prüfwerk (subscription, ERP or
activation grant) or is neither trial nor active.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
## What
- **Codes:** two workspaces connect by code. One administrator creates a code; another workspace's administrator enters it, and the two are connected at once. Each side sees only the other's display name.
- **Ending:** either side can end a connection. Archiving a workspace ends all of its connections. When a workspace is purged, the other side keeps the ended connection under the name it knew.
- **Product routes:** products (Prüfwerk's supplier SBOM releases first) list a tenant's active connections and check one before each delivery, under a new route group `connections.read`.
## Why
Closes#138. This is phase 4 of platform/pruefwerk#1028. Prüfwerk's agent is on stage and already calls the two internal routes; without them the release screen warns that connections can't be read (see the comment on #138).
Linked milestone: **n/a** (Prüfwerk #1028, phase 4)
## How
**Routes:**
| Call | Group | Answer |
|---|---|---|
| `POST /v1/tenants/{id}/connection-invites` | tenants.write | `201 {id, code, created_at, expires_at}`; the code is in this answer only |
| `GET /v1/tenants/{id}/connection-invites` | tenants.read | open codes, without the codes |
| `DELETE /v1/tenants/{id}/connection-invites/{invite}` | tenants.write | `204`, withdraws an unused code |
| `POST /v1/tenants/{id}/connections` `{code}` | tenants.write | `201 {id, peer_name, state, created_at, ended_by_us}` |
| `GET /v1/tenants/{id}/connections` | tenants.read | `{items: [...]}`, newest first |
| `POST /v1/tenants/{id}/connections/{connection}/end` | tenants.write | `200`; ending one that has ended answers it unchanged |
| `GET /v1/internal/tenants/{id}/connections?state=active` | **connections.read** | `{items: [{id, peer_tenant_id, peer_name}]}`; 404 for an unknown tenant |
| `GET /v1/internal/connections/{connection}` | **connections.read** | `{active, tenant_ids}`; 404 for an unknown id |
The two internal answers match what `compliance-agent/src/registry.rs` reads. A test pins the `items` key, because the agent defaults a missing key to "no connections".
**Codes:**
- 160 random bits (`crypto/rand`), shown as eight groups of four base32 letters.
- Stored as SHA-256 only, looked up by hash; case, spaces and dashes don't matter.
- Valid for 14 days, single use, at most 20 open per workspace.
- Every code that doesn't work gets the same 404 `invalid_code`: unknown, used, expired, withdrawn, the workspace's own, or either workspace archived.
- 409 `already_connected` when the two are connected already; the code then stays open.
- Entering codes is limited to 20 per hour per workspace, and per person when the call names one (`keyRateLimiter` now takes its limit as an argument; CI licences keep theirs). A call from the portal's own client that names nobody has only the workspace limit. Otherwise every workspace would share one limit through that client. **portal#201 must send `X-Portal-User-Subject`.**
**Redeeming** is one transaction. `SELECT … FOR UPDATE` on the code, insert the connection, then mark the code used. A partial unique index allows at most one connection per pair of workspaces that hasn't ended. A race test has two workspaces enter one code at the same time: exactly one connects.
**Active** is derived on every read: not ended, both workspaces exist, and neither is archived. So no delivery can go to an archived workspace, even if writing the end failed.
**Ending on archive:** every status change passes through `syncTenantStatus`, which now ends an archived workspace's connections. The admin purge calls the same step again before `DeleteTenant`, as a safety net. The foreign keys are `ON DELETE SET NULL`, with name snapshots, so the other side keeps its history.
**Audit:** `connection.invite_created`, `connection.invite_withdrawn`, `connection.created` and `connection.ended` go into both workspaces' logs.
- The acting side's entry names the actor.
- The other side's entry is a system entry with `by: peer`: no person, IP or user agent, only the connection id and the acting side's display name.
- Ends caused by archiving carry `reason: tenant_archived`.
**Product routes refuse user tokens** (403 `FORBIDDEN_CLIENT`), whatever groups the token's client holds, because they carry the peer's tenant id.
**Who may:** user tokens need IT_ADMIN or OWNER in their own workspace (the existing team gate, `IsTenantAdmin`). Another workspace's administrator gets a 404. The portal calls as its service client, naming the person in `X-Portal-User-*`.
**Side fix:** the Postgres `GetTenant` now answers a non-UUID id as not found (404), as the memory store does. It was a 500, which the new internal route hit.
## Test plan
- [x] Unit tests: route groups in `authz_test`, roles and cross-tenant scoping in `connections_scope_test`, and the OpenAPI contract cases.
- [x] Integration tests on memory **and Postgres (testcontainers)** in `connections_test.go`, run locally:
- connect, list, product view, check, and the re-connect after end;
- every invalid code gives the same answer, including expiry with an injected clock;
- archive, then purge;
- unknown ids;
- the rate limit;
- the redeem race.
- [x] The whole `internal/server` suite runs against Postgres locally (`go test -count=1 ./internal/server/`, 236 s, green). `-race` is green on the connection tests. `go vet` and `golangci-lint` v2.12.2: 0 issues.
- [ ] Playwright e2e: n/a, there's no UI here (portal#201).
- [ ] Manual smoke on stage after deploy, once `AUTHZ_RULES` carries the grant below. Prüfwerk's release screen should then show no warning.
## Risk
**Blast radius:** new tables and routes only. Existing routes change in two small ways: the `GetTenant` 500→404 for non-UUID ids, and the archive path now also ends connections.
**What could break:**
- **Migration number:** `0032` is also used by the open onprem PRs (#142/#143, `0032_werkpilot_description`). Whichever merges second must renumber. A duplicate version fails the migrations test loudly. I didn't pick 0033, because golang-migrate would silently skip a 0032 that merges after it.
- **Deployment grant:** the new group needs a grant in stage and prod `AUTHZ_RULES`. That config isn't in this repo: `pruefwerk-svc-stage:…,connections.read`, and the same for prod. Until it's added, Prüfwerk keeps getting 403.
**Rollback plan:** revert the PR and redeploy. The down migration drops both tables.
## Decided (2026-11-20, by the product owner)
- **Archived only** ends connections. A `halted` workspace keeps them, so a returning customer finds them again. Active stays false while a side is archived.
- **IT_ADMIN or OWNER** may create, enter and end, using the existing team gate rather than a new catalogue right.
## Open points for review
1. **Retention:** a purged workspace's display name stays visible to its former peers through the name snapshot, with no time limit. Should it be dropped after a while?
2. **Additions to the sketch:** the create answer now carries the invite `id`, which the withdraw route needs, and there's a list of open codes, without the codes.
## Checklist
- [x] Docs updated: the OpenAPI spec and the package doc in `connections.go` (no separate docs page for registry routes)
- [x] Audit events emitted for state changes
- [x] Secrets via Infisical, never in repo (none involved)
- [x] Migration is forward-only (new tables; down drops them)
- [x] Tenant scoping enforced on every DB query
- [x] OpenAPI spec updated
- [ ] `featureFlags.evaluate()`: n/a (nothing toggleable)
- [ ] CHANGELOG entry: n/a (generated by git-cliff on release)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
Co-authored-by: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com>
Reviewed-on: #145
With WinAnsi encoding, names like "Michał", "Yılmaz" or "Łódź" fell back to "staff fill it in", a path nobody watches yet. The value is now set as glyph ids of the embedded Geist Regular (Type0 / CIDFontType2, Identity-H) with a ToUnicode map, so any character the font has works and the text still extracts as written. Only control characters and characters without a glyph (e.g. CJK) are refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A workspace whose company profile is submitted and whose Geschäftsleitung is named (Verantwortliche) now sees its AVV filled in: name with legal form, address, "Vertreten durch" and, as the owner decided, "Geschäftsleitung" on the Weisung line. The new package internal/legal/avvfill writes the details onto the released master as one incremental PDF update: the two content streams holding the blank lines are replaced, the underscores dropped and the value set in their place in Geist Regular at body size, inside the line's marked content. The master's bytes stay an untouched prefix, so its pin still holds; the result is deterministic and cached by master and details digest. Layouts are pinned per master SHA-256; a test makes every released AVV master have one.
Until then the master is listed with "missing" (profile, company_name, address, management) for the portal's hint; details that do not fit the form or the Windows-1252 character set give "manual" and a log line without the values. A staff upload still wins (filled_from: staff). The admin avv-values answer uses the same derivation; its Weisung is now "Geschäftsleitung" only. The legal form is no longer appended twice when the name writes it without spaces ("UG(haftungsbeschränkt)").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The owner released the AVV on 19.11.2026: Arbeitsstand 06, without a signature block (it is concluded with the main contract, § 12(1)), Stand 17.11.2026. The PDF is byte for byte the one in its release record FREIGABE_1.0.0.json (sha256 623aa518…). It is listed between AGB and TOM for every workspace; a workspace's own filled AVV still takes its place. The AVV contract status stays "not_concluded": listing the master concludes nothing.
Tests: released set and order, the master in the overview and as PDF, and the own-AVV-without-master path now on a catalogue without the master.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
pgx reports an invalid UUID from rows.Err, not from Query, so GET /v1/usage/events?tenant_id=not-a-uuid answered 500 on Postgres and 200 on the memory store. It now returns an empty list on both.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TestSeed_canInsertAndQuery deleted a tenant that had intake reports, which 0030 forbids on purpose (reports outlive their workspace). The intake rows now sit on a workspace of their own; the test checks that its delete is refused and the rows stay, and the cascade check keeps the other tenant.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The late-payment ladder (#134) reads Dunnings, which ERPNext lets only the Accounts roles read. The registry's API user holds Sales User only. erpsetup now adds a level-0 read rule for Sales User on Dunning through Frappe's permission manager (which first copies the standard rules, as the Role Permissions Manager UI does) and cuts a broader rule back to read only. The spec.go comment no longer claims Accounts User. Live ERP: the same rule was added by hand on 17.11.; the next run reports it as existing.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The first sentinel looked like an API key to gitleaks' generic rule. It
is a test value; its fingerprint goes into .gitleaksignore since the
commit is already pushed.
Refs: t81
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Daily Europe/Berlin job: Managed Git = members signed in to the tenant's
active instances; Werkpilot/Firmwerk = people with their own licence in
use in the month. Staff PUT for the Gitea admin token, staff and tenant
reads of the month's counts, POST /v1/internal/module-users/count on
demand (route group module-users). No invoicing yet (t72).
Refs: t81
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GET /api/v1/admin/users with a read:admin token in the Authorization
header, paged until an empty page. Errors carry no body, URL or token.
Refs: t81
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The portal's 30-day views folded at most 1000 events from the usage list,
so busy tenants saw figures that were too low. The summary aggregates
every matching event in the store (GROUP BY in Postgres, the same fold in
Memory): counts, quantity sums and the latest occurred_at per product and
metric, and counts and sums per UTC day and metric.
Same filters, tenant pinning for user tokens and route group (usage.read)
as GET /v1/usage/events, so the portal's service client needs no new
AUTHZ grant. Both stores share the filter (usageWhere / matches).
Refs: t80
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AGB § 10 allows restricting access only "trotz Mahnung und angemessener
Nachfrist". The ladder counted from the due date (restricted after 14,
halted after 30 days overdue) and escalated any warning after 14 days.
Now an overdue invoice alone means warning. The reconcile pass reads the
customer's submitted, unresolved ERPNext Dunnings; the earliest one that
names a still-open invoice sets the clock: restricted 14 days after its
posting date, halted a further 14 days after the restriction. A Mahnung
never halts directly, so a late-seen one errs in the customer's favour.
A failed Dunning read keeps the tenant on warning and is reported.
ERP_HALT_AFTER_DAYS defaults to 28 (was 30), so an expired trial is
read-only for 14 days instead of 16 before it is halted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The contracts overview reported the TOMs as "pending" unconditionally,
from before the TOM was released, so the portal showed "Wird
bereitgestellt" above the released TOM 1.0.0 on stage. The status is
now "available" when a TOM document is listed for the tenant (i.e.
released and CONTRACT_DOCUMENTS on), and stays "pending" otherwise.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Released by the owner on 16.11.2026 (AGB SaaS AS06, TOM AS08, both
Stand 09.11.2026). The PDFs are byte for byte the released working
versions (release records FREIGABE_1.0.0.json next to them in the
document store); their SHA-256 are pinned in the table. They apply to
every workspace and are listed first, before the Leistungsbeschreibungen.
The AVV master stays out: it is on hold until the signature block and
§12(1) are decided internally.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Catalogue r1-2026-11-16.1 adds the functions owner decision Nr. 2
(docgen#6 17878, 18011) names and that no R1 function already covers:
CVD-Verantwortung and Veröffentlichungsverantwortung (R5), Meldefreigabe,
Fristführung, Vorabprüfung, Weitergabe von Informationen and
Datenschutzfunktion (R2), and the R1 functions Erstzuordnung, Eskalation
and Einsichtsprotokollkontrolle. External holders as proposed in 18110
K-4. The safety check and product measures wait for the owner (K-1, K-2).
GET /role-dataset now names the current catalogue as catalogue_version
and the stored one as stored_catalogue_version. It named the stored one,
which the portal sends back on save: after any catalogue change every
save of an existing dataset was refused as catalogue_outdated, and
reloading answered the same version again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
docgen#4 Nr. 31 (AK-R3-030): the role dataset gets an optional section
company_rules with separate_approval ("Festlegung und Freigabe durch
verschiedene Personen"). Not set counts as off.
- The rule is maintained by whoever maintains the dataset (AM-3),
stamped from the writer's token, and historised with the revisions.
- Older datasets decode unchanged and store no section.
- GET /v1/tenants/{id}/role-dataset/rules answers the rules now for
Werkmeister (tenants.read) or a member of the tenant.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
The slug "breakpilot" was reserved (#32) so no customer could pose as
Breakpilot. Sharang decided (12.11.) that the company's own workspace
is app.breakpilot.com/breakpilot. Staff (a named staff member on the
admin client) may now create exactly this slug; everyone else, and
the trial offer's slug choice, still get reserved_slug. The other
reserved slugs stay closed to staff too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Purging an archived workspace deleted its intake reports with it: every
intake table cascaded from tenants. Benjamin's decision Nr. 17 (docgen#6
17878, V-g): no automatic deletion of the reports when a workspace is
deleted.
The purge now refuses first, before any file or account is removed:
409 intake_retained while the workspace has reports. Migration 0030 makes
the database refuse as well (intake_reports → tenants ON DELETE RESTRICT),
and DeleteTenant maps that to ErrConflict. CountIntakeReports on both
stores.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
With the runner's test cache, packages marked "(cached)" left their
share out of cover.out and the total fell under the 70% gate, while the
same code passed on a run without cached results (main dd94763: every
package run, gate passed; PR #126: six packages cached, gate failed
twice with the same per-package numbers). -count=1 runs them all.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
The catalogue named CXO "Geschäftsleitung" and OWNER "Inhaber des
Arbeitsbereichs", while the portal shows "Geschäftsführung" and
"Inhaberschaft". The catalogue now takes the portal's names (version
2026-11-12.1), which also keeps the role "Geschäftsführung" apart from
the company function "Geschäftsleitung" of the role dataset.
The last-admin refusal named only IT_ADMIN; the guard holds for OWNER
too, so the message now says "the last administrator (IT_ADMIN or
OWNER)".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
GET /v1/tenants/{id}/contracts carries street, postcode, city and
country of the trial offer, so the company profile can suggest the
registration address as the master data (portal#159, item 3; read
by portal#161). Only for the tenant's own activated offer, as the
rest of the trial block.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The page that sent the offer waits for the e-mail confirmation. When
the link is opened on another device (a phone), that page stayed put
(portal#159, item 1). The status read lets it follow: the state and,
once active, the workspace slug and the trial dates. No e-mail or
company data in the answer; the offer id, which only the sending
browser has, is the key. Same authz group as the other offer routes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
GET /v1/tenants/{id}/role-dataset/holders?function=…[&scope] answers
who holds a role-dataset function now: the holders in the scope, the
effective deputies of the function and open/filled/not applicable.
Werkmeister reads it (tenants.read) when a step names a function.
It shares the matching with /resolve, which now goes through it; for a
decision type, only deputies covering it count, as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
PSIRT, DEVELOPMENT, QUALITY, PRIVACY, PURCHASING, AUDITOR and EXTERNAL
can be given to a member (catalogue 2026-11-11.1). Invitations and role
changes accept exactly the catalogue's assignable bundles.
The registry's own checks read the catalogue instead of role lists:
notification recipients, managed services and Prüfwerk settings. For
today's six bundles nothing changes (pinned against the 2026-11-10
tables); AUDITOR now reads managed services, and the new bundles get
the mails their capabilities name. Individual capabilities still do not
count in the registry.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf