feat(onprem): APP_ENV=onprem with directory users and installation mail #146

Merged
sharang merged 8 commits from feat/onprem into main 2026-11-20 16:31:12 +00:00
Owner

Replaces #142, #143 and #144 (stacked) as one branch on today's main: the same six commits, cherry-picked in order, plus one fix. Since the stack was branched, main took migration 0032 for workspace connections (#145); ours is renumbered to 0033 (golang-migrate refuses two files with one version). Force-pushing the old branches was not an option, and merging main into them would put merge commits into the commitlint range.

Checked: the tree equals main + the stack merged and tested locally; go vet, gofmt, the CI test command (coverage 81.5 %) and the migration tests (up/down round trip) against Postgres 16 pass. Commits per part: #142 = a4fb318, b30b5e3; #143 = 90ae11a, 30cd577, 76b8366; #144 = afe62e4.


From #142: feat(onprem): APP_ENV=onprem for a customer's own node

On-prem blocker #1 from the test install (platform/onprem, testenv/results/gaps.md), plus gaps 2–5, 7 and 9. This adds APP_ENV=onprem, a mode for a registry running on a customer's own node.

Problem. Today the provisioning and launch URLs come from the migrations (*.breakpilot.com, keyed stage/prod). Activating a workspace on-prem would send its id, name and slug to our cloud, together with a service token.

What on-prem changes

  • Products and URLs: they come only from PRODUCTS and PRODUCT_LAUNCH_URLS / PRODUCT_PROVISION_URLS (key=url,…). A store decorator applies them to every product read, so catalog, activation, provisioning, entitlement checks and the Prüfwerk targets all agree. The URLs are checked at start.
  • No ERP: nothing goes into the outbox, and the webhook route is off.
  • No trial: a new workspace starts active, and the time ladder never escalates. The cloud still escalates, and a control test pins that.
  • Routes off: these answer 404 not_available:
    • trial offers and trial terms
    • catalog request and trial request
    • admin trial
    • ERP webhook
  • Start refused while a cloud or dev default is still in effect:
    • auth off
    • no authz rules
    • ephemeral licence key
    • portal, invite or sender not set
    • LLM gateway not set while an LLM key is
    • an ERP configured
    • contract documents on
  • Mail: a new setting SMTP_TLS=starttls|tls|none (plain internal relay). Credentials are never sent unencrypted.

Cloud. Without the new variables, stage and prod behave as before (TestLoad_cloudUnchangedWithoutTheNewVariables).

Migration 0032. The Werkpilot catalog text no longer names llm.breakpilot.com. It now says "the platform's language-model gateway". This applies to all environments, so the text on prod changes too.

Not in this PR:

  • Invites for directory (AD) users (gap 6). A federated user probably already exists in Keycloak, so POST /v1/tenants with admin_email answers email_taken. The next PR adds attaching an existing directory user.
  • Mail templates with our imprint.

Tests. go test ./... passes. The server and migration suites also pass with Postgres (testcontainers via podman). New tests: onprem_test.go (server, config) and plain_test.go (mail).


From #143: feat(onprem): directory users instead of invitations

Stacked on #142, so the base is feat/onprem-mode; merge #142 first. This closes on-prem gap 6.

Problem. On-prem, every account comes from the customer's AD through Keycloak's federation. Keycloak finds an AD user by e-mail even before their first sign-in, so creating the workspace with an AD admin answered email_taken, and nobody could enter it. Invitations would also have created local users and sent a set-password mail.

Directory mode in the Keycloak adapter. It is on with APP_ENV=onprem:

  • First admin and invited members are existing directory users, added to the organization with their role. No local user is created and no mail is sent. They sign in with their AD password. The invite status is added; the audit actions are user.added and keycloak.admin_added.
  • Unknown address, or one outside the AD groups that may use the platform: 404 not_in_directory. For the workspace admin this is checked before the workspace is created, and the adapter looks the user up before it creates the organization. Nothing is left behind.
  • Resend: 409 no_invite_mail. Directory members are never "pending".
  • Member list: Keycloak 26.8 lists a federated member with only its LDAP attributes, so the roles are now read from the user record.

Keycloak side (platform/onprem, package/keycloak/):

  • Read-only federation refuses every attribute write on AD users ("Federated storage is not writable"), but the platform keeps workspace and role in those attributes.
  • The package therefore runs the federation UNSYNCED, which never writes to AD.
  • realm-policy.sh:
    • turns Organizations on
    • lets admins edit attributes, as in the cloud realm
    • closes every user-facing way to set a password in Keycloak (reset mail, update-password action, account console); the registry never sets one either
    • residual: a Keycloak admin can still set a local password, which then bypasses AD, even for an account disabled there. That is the same trust level as any Keycloak admin, who can already impersonate users. The detective control is check-local-passwords.sh, tested both ways.
  • removeInvalidUsersEnabled=false: an account disabled in AD, or removed from the groups, can't sign in but keeps its membership.

Checked against Keycloak 26.8.1 and a Samba AD (the test VM):

  • Admin attached without mail, member added, an account outside the groups refused.
  • Roles listed correctly, resend refused, nobody pending.
  • Sign-in works with the AD password. Wrong password, disabled account and an account outside the groups are all refused, and attributes survive every case.
  • PurgeTenant removes only the Keycloak copies; the AD accounts stay.

Tests. go test ./... passes, including Postgres. New: internal/keycloak/directory_test.go (each test has a cloud control where it matters) and on-prem server tests in onprem_test.go.

Small cloud-side changes:

  • The workspace admin's e-mail is lowercased before it goes to Keycloak and into the audit rows. Keycloak already stores e-mails lowercase, and the tenant row was already lowercase.
  • The member list makes one extra user read per member whose list entry has no org_roles.
  • The admin's tenant_status stays trial in the cloud; only on-prem passes the workspace status. A test pins this.

Follow-up from the test install (1b821ba)

On an installation the realm also holds our local staff accounts (onprem keycloak/staff-account.sh). The directory lookup took any Keycloak user with the address, so a workspace admin could add our staff account to their team (201 added, workspace attributes and membership on the staff account). Now only a user with a federation link (from the AD) joins a workspace, as first admin or member; a local account answers not_in_directory. New test TestDirectory_localAccountIsNotADirectoryUser; checked in the VM (422 not_in_directory). #144 has this merged in.


From #144: feat(onprem): mails come from the installation, not from us

Stacked on #143 (which is on #142): merge those first, then retarget this to main.

What

On APP_ENV=onprem the registry's mails (new findings, published documents) come from the customer's installation, through their relay and from their address. Until now they carried our company signature (address, register entry, noreply@/kontakt@breakpilot.com) and our imprint and privacy links.

  • mail.View gets a Site. Its zero value is the cloud, so cloud mails are unchanged.
  • On-prem the signature is a short note that the installation sent the mail, plus MAIL_CONTACT (their IT) if set.
  • The legal line shows the customer's LEGAL_IMPRINT_URL / LEGAL_PRIVACY_URL, each only when set. The cloud keeps ours as defaults.
  • The legal line moved from each text template into signature.tmpl.
  • On-prem the registry refuses to start when MAIL_FROM, PORTAL_URL, INVITE_REDIRECT_URI or LEGAL_* point at breakpilot.com.
  • Spelling "Breakpilot" in the templates and the default MAIL_FROM_NAME.

Cloud impact

All eight cloud mails (4 kinds × de/en) were rendered with the old and the new templates. They are byte-identical except "BreakPilot" → "Breakpilot" (signature "Ihr Breakpilot-Team", the document text, the default sender name).

Tests

go test -short -race ./..., go vet, gofmt clean.

  • TestRender_onPrem: for both kinds and languages, no company data or breakpilot.com; the customer's contact (HTML-escaped) and links appear; without them, no legal line, no contact and no empty link.
  • TestRender_cloudLegalLinks: cloud defaults, and the override.
  • TestOnPrem_notificationMailIsTheInstallations: queue → drain → recorder, end to end.
  • Config: the four breakpilot.com refusals; on-prem defaults are empty.

🤖 Generated with Claude Code

Replaces #142, #143 and #144 (stacked) as one branch on today's main: the same six commits, cherry-picked in order, plus one fix. Since the stack was branched, main took migration **0032** for workspace connections (#145); ours is renumbered to **0033** (golang-migrate refuses two files with one version). Force-pushing the old branches was not an option, and merging main into them would put merge commits into the commitlint range. Checked: the tree equals main + the stack merged and tested locally; `go vet`, `gofmt`, the CI test command (coverage 81.5 %) and the migration tests (up/down round trip) against Postgres 16 pass. Commits per part: #142 = a4fb318, b30b5e3; #143 = 90ae11a, 30cd577, 76b8366; #144 = afe62e4. --- ## From #142: feat(onprem): APP_ENV=onprem for a customer's own node On-prem blocker #1 from the test install (`platform/onprem`, `testenv/results/gaps.md`), plus gaps 2–5, 7 and 9. This adds `APP_ENV=onprem`, a mode for a registry running on a customer's own node. **Problem.** Today the provisioning and launch URLs come from the migrations (`*.breakpilot.com`, keyed stage/prod). Activating a workspace on-prem would send its id, name and slug to our cloud, together with a service token. **What on-prem changes** - **Products and URLs:** they come only from `PRODUCTS` and `PRODUCT_LAUNCH_URLS` / `PRODUCT_PROVISION_URLS` (`key=url,…`). A store decorator applies them to every product read, so catalog, activation, provisioning, entitlement checks and the Prüfwerk targets all agree. The URLs are checked at start. - **No ERP:** nothing goes into the outbox, and the webhook route is off. - **No trial:** a new workspace starts `active`, and the time ladder never escalates. The cloud still escalates, and a control test pins that. - **Routes off:** these answer 404 `not_available`: - trial offers and trial terms - catalog request and trial request - admin trial - ERP webhook - **Start refused** while a cloud or dev default is still in effect: - auth off - no authz rules - ephemeral licence key - portal, invite or sender not set - LLM gateway not set while an LLM key is - an ERP configured - contract documents on - **Mail:** a new setting `SMTP_TLS=starttls|tls|none` (plain internal relay). Credentials are never sent unencrypted. **Cloud.** Without the new variables, stage and prod behave as before (`TestLoad_cloudUnchangedWithoutTheNewVariables`). **Migration 0032.** The Werkpilot catalog text no longer names `llm.breakpilot.com`. It now says "the platform's language-model gateway". This applies to all environments, so the text on prod changes too. **Not in this PR:** - Invites for directory (AD) users (gap 6). A federated user probably already exists in Keycloak, so `POST /v1/tenants` with `admin_email` answers `email_taken`. The next PR adds attaching an existing directory user. - Mail templates with our imprint. **Tests.** `go test ./...` passes. The server and migration suites also pass with Postgres (testcontainers via podman). New tests: `onprem_test.go` (server, config) and `plain_test.go` (mail). --- ## From #143: feat(onprem): directory users instead of invitations Stacked on #142, so the base is `feat/onprem-mode`; merge #142 first. This closes on-prem gap 6. **Problem.** On-prem, every account comes from the customer's AD through Keycloak's federation. Keycloak finds an AD user by e-mail even before their first sign-in, so creating the workspace with an AD admin answered `email_taken`, and nobody could enter it. Invitations would also have created local users and sent a set-password mail. **Directory mode in the Keycloak adapter.** It is on with `APP_ENV=onprem`: - **First admin and invited members** are existing directory users, added to the organization with their role. No local user is created and no mail is sent. They sign in with their AD password. The invite status is `added`; the audit actions are `user.added` and `keycloak.admin_added`. - **Unknown address,** or one outside the AD groups that may use the platform: 404 `not_in_directory`. For the workspace admin this is checked before the workspace is created, and the adapter looks the user up before it creates the organization. Nothing is left behind. - **Resend:** 409 `no_invite_mail`. Directory members are never "pending". - **Member list:** Keycloak 26.8 lists a federated member with only its LDAP attributes, so the roles are now read from the user record. **Keycloak side** (`platform/onprem`, `package/keycloak/`): - Read-only federation refuses every attribute write on AD users ("Federated storage is not writable"), but the platform keeps workspace and role in those attributes. - The package therefore runs the federation `UNSYNCED`, which never writes to AD. - `realm-policy.sh`: - turns Organizations on - lets admins edit attributes, as in the cloud realm - closes every user-facing way to set a password in Keycloak (reset mail, update-password action, account console); the registry never sets one either - residual: a **Keycloak admin** can still set a local password, which then bypasses AD, even for an account disabled there. That is the same trust level as any Keycloak admin, who can already impersonate users. The detective control is `check-local-passwords.sh`, tested both ways. - `removeInvalidUsersEnabled=false`: an account disabled in AD, or removed from the groups, can't sign in but keeps its membership. **Checked against Keycloak 26.8.1 and a Samba AD** (the test VM): - Admin attached without mail, member added, an account outside the groups refused. - Roles listed correctly, resend refused, nobody pending. - Sign-in works with the AD password. Wrong password, disabled account and an account outside the groups are all refused, and attributes survive every case. - `PurgeTenant` removes only the Keycloak copies; the AD accounts stay. **Tests.** `go test ./...` passes, including Postgres. New: `internal/keycloak/directory_test.go` (each test has a cloud control where it matters) and on-prem server tests in `onprem_test.go`. **Small cloud-side changes:** - The workspace admin's e-mail is lowercased before it goes to Keycloak and into the audit rows. Keycloak already stores e-mails lowercase, and the tenant row was already lowercase. - The member list makes one extra user read per member whose list entry has no `org_roles`. - The admin's `tenant_status` stays `trial` in the cloud; only on-prem passes the workspace status. A test pins this. ## Follow-up from the test install (1b821ba) On an installation the realm also holds our local staff accounts (`onprem` `keycloak/staff-account.sh`). The directory lookup took any Keycloak user with the address, so a workspace admin could add our staff account to their team (201 `added`, workspace attributes and membership on the staff account). Now only a user with a federation link (from the AD) joins a workspace, as first admin or member; a local account answers `not_in_directory`. New test `TestDirectory_localAccountIsNotADirectoryUser`; checked in the VM (422 `not_in_directory`). #144 has this merged in. --- ## From #144: feat(onprem): mails come from the installation, not from us Stacked on #143 (which is on #142): merge those first, then retarget this to `main`. ## What On `APP_ENV=onprem` the registry's mails (new findings, published documents) come from the customer's installation, through their relay and from their address. Until now they carried our company signature (address, register entry, `noreply@`/`kontakt@breakpilot.com`) and our imprint and privacy links. - `mail.View` gets a `Site`. Its zero value is the cloud, so cloud mails are unchanged. - On-prem the signature is a short note that the installation sent the mail, plus `MAIL_CONTACT` (their IT) if set. - The legal line shows the customer's `LEGAL_IMPRINT_URL` / `LEGAL_PRIVACY_URL`, each only when set. The cloud keeps ours as defaults. - The legal line moved from each text template into `signature.tmpl`. - On-prem the registry refuses to start when `MAIL_FROM`, `PORTAL_URL`, `INVITE_REDIRECT_URI` or `LEGAL_*` point at `breakpilot.com`. - Spelling "Breakpilot" in the templates and the default `MAIL_FROM_NAME`. ## Cloud impact All eight cloud mails (4 kinds × de/en) were rendered with the old and the new templates. They are byte-identical except "BreakPilot" → "Breakpilot" (signature "Ihr Breakpilot-Team", the document text, the default sender name). ## Tests `go test -short -race ./...`, `go vet`, `gofmt` clean. - `TestRender_onPrem`: for both kinds and languages, no company data or `breakpilot.com`; the customer's contact (HTML-escaped) and links appear; without them, no legal line, no contact and no empty link. - `TestRender_cloudLegalLinks`: cloud defaults, and the override. - `TestOnPrem_notificationMailIsTheInstallations`: queue → drain → recorder, end to end. - Config: the four `breakpilot.com` refusals; on-prem defaults are empty. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 7 commits 2026-11-20 16:16:04 +00:00
The registry on a customer's node must never reach a Breakpilot host and
must not run the cloud's commercial machinery.

- APP_ENV=onprem: no ERP (nothing queued, webhook off), no trial (new
  workspaces start active, the ladder never escalates by time), and the
  trial-offer, trial-terms, catalog/trial request and admin trial routes
  answer 404 not_available.
- PRODUCTS, PRODUCT_LAUNCH_URLS, PRODUCT_PROVISION_URLS: one store
  decorator applies the product list and URLs to every catalog read
  (catalog, activation, provisioning, entitlement checks). On-prem has no
  seeded URLs, so provisioning goes only to the local products. Checked at
  start ({id} in provision URLs, absolute http(s)).
- On-prem start fails when the values leave something to a cloud or dev
  default (auth off, no authz rules, ephemeral licence key, portal, invite,
  sender, LLM gateway) or set an ERP or contract documents.
- SMTP_TLS=starttls|tls|none: a plain relay inside the customer's network;
  no AUTH without encryption.
- Migration 0032: the Werkpilot text no longer names our LLM host.

Cloud behaviour is unchanged without the new variables (tested).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 2f6fa5f3e8)
- Start fails when PRODUCTS or a URL override names no catalog product.
- The on-prem catalog sets supports_trial=false (the portal hides the button).
- Test that seeded cloud provision URLs are never called on-prem, with a
  cloud control; the outbox test gets its cloud control too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 3e42b1ceb8)
On-prem every account comes from the customer's AD through Keycloak's
federation, so an AD admin answered email_taken and invitations asked for a
new password. The Keycloak adapter gets a directory mode (DirectoryUsers,
on with APP_ENV=onprem):

- The first admin and invited members are existing directory users,
  attached to the organization with their role. No local user is created,
  no execute-actions mail is sent (invite status "added", audit user.added /
  keycloak.admin_added).
- An unknown address (or one outside the admitted AD groups) answers 404
  not_in_directory. For the workspace's admin it is checked before the
  workspace is created, and the adapter looks the user up before creating
  the organization, so nothing is left behind.
- Resend answers 409 no_invite_mail; directory members are never pending.
- Member lists read the roles from the user when Keycloak lists a federated
  member with its LDAP attributes only (seen with Keycloak 26.8).
- The admin address is normalized once for lookup, store and Keycloak.

Checked against Keycloak 26.8.1 with a Samba AD (the test install in
platform/onprem, realm with UNSYNCED federation and realm-policy.sh).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit b8206c553f)
Only on-prem passes the workspace's status to Keycloak for its first admin;
a cloud demo workspace with an admin wrote demo instead of trial (pinned by
a test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit d8cb363d5c)
On APP_ENV=onprem the registry's mails (new findings, published documents)
no longer carry our company signature, address, register entry, contact
address or legal pages. They say the installation sent them, name the
customer's contact (MAIL_CONTACT) and link the customer's imprint and
privacy notice (LEGAL_IMPRINT_URL, LEGAL_PRIVACY_URL), each only when set.

mail.View gets a Site; the zero value is the cloud, so cloud mails stay as
they were (checked byte for byte against the previous templates) apart from
the spelling "Breakpilot", also in the default sender name. The legal line
moved from every text template into signature.tmpl.

On-prem the registry also refuses to start when MAIL_FROM, PORTAL_URL,
INVITE_REDIRECT_URI or LEGAL_* point at breakpilot.com.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 6058a94254)
In directory mode the registry attached any Keycloak user found by
e-mail. On an installation the realm also holds our local staff accounts
(onprem keycloak/staff-account.sh): a workspace admin could add one to
their team (201 added), giving our support account workspace attributes
and membership. Found in the test install.

Now only a user with a federation link (from the AD) counts, for the
first admin and for members; a local account answers not_in_directory
like an unknown address. The cloud is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 1b821baa7b)
fix(migrations): werkpilot description is 0033 (0032 is connections)
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Failing after 39s
ci / image (pull_request) Skipped
ebeed5f0cf
main took 0032 for tenant connections (#145) while the on-prem branch
had 0032 for the neutral Werkpilot text; golang-migrate refuses two
files with one version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CODEOWNERS rules requested review from Benjamin_Boenisch 2026-11-20 16:16:04 +00:00
sharang added 1 commit 2026-11-20 16:23:31 +00:00
fix(lint): tagged switch on the invite status; close checked in the relay test
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 7m16s
ci / image (pull_request) Skipped
ffe10d5ca6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit 69c15be333 into main 2026-11-20 16:31:12 +00:00
Sign in to join this conversation.