feat(branding): tenant branding store, endpoints and check field (#155, part 1) #156

Merged
sharang merged 2 commits from feat/branding into main 2026-12-01 13:13:23 +00:00
Owner

Customer branding (#155), part 1: the contract surface. Products and the portal can read and set a workspace's CI colour and logo. The derivation from the signup domain is part 2, #157, stacked on this one.

Contract as agreed with Prüfwerk (pruefwerk#1087) and posted on #155: #155 (comment)

What changes

  • Migration 0035 tenant_branding: colour, logo (256×256 PNG) with its sha256 as ETag, manual, provenance (domain, sources, hashes, derived_at), the derivation queue, and the notice acknowledgement. ON DELETE CASCADE, so a purge removes it.
  • Entitlements check: new branding field {color, logo_etag, notice, domain, name}.
    • It's sent only when allowed is true and there is a colour or a logo.
    • domain is sent only while notice is true.
    • A branding read error leaves the field out; the check itself never fails on it.
  • GET /v1/tenants/{id}/branding (tenants.read, via the {id}/{sub} route): returns colour, provenance and state, plus derive_enabled. There are no logo bytes.
  • PUT /v1/tenants/{id}/branding (tenants.write): sets or removes colour and/or logo; a missing field stays.
    • The branding becomes manual: it is never derived over again and shows no notice.
    • The logo is decoded (PNG, JPEG, GIF, ICO with a small own parser) and re-encoded as a 256×256 PNG. SVG is refused.
  • GET /v1/tenants/{id}/branding/logo (new group branding.read): returns image/png, ETag: "<logo_etag>", 304 on If-None-Match, and 404 without a logo.
  • POST /v1/tenants/{id}/branding/ack (new group branding.ack): records "Passt".
    • The registry checks in Keycloak that user_id is an enabled, unblocked IT_ADMIN or OWNER.
    • Otherwise it answers 403 not_admin, including when Keycloak can't be asked (fail closed).
  • Config BRANDING_DERIVE (off by default): only reported as derive_enabled here. Part 2 uses it.
  • CI: runs the new internal/branding tests.
  • Unrelated fix: TestMigrate_productsSeedMatchesDefaults still expected the SKU list from before #152. CI doesn't run ./migrations, so it went unnoticed.

Rollout

  • Needs the orca AUTHZ_RULES change: branding.read,branding.ack for every product client and the portal's. Separate orca PR.
  • Without it, products get 403 on logo and ack, and everything else is unchanged.
  • Nothing is derived by this PR, and no customer site is fetched.

Tests

  • go test -race on the CI package list, against Memory and Postgres (testcontainers): all green, total coverage 81.6 %. The coverage gate measures it differently; the server package alone was 70.5 % across ./internal/....
  • golangci-lint v2.12.2: 0 issues.
  • New tests:
    • TestBranding_manualAndCheck, TestBranding_derivedNoticeAndAck, TestBranding_queue, on both stores;
    • authz cases;
    • TestNormalizeLogo: determinism, aspect, ICO PNG and BMP entries, SVG refused, size caps.

🤖 Generated with Claude Code

Customer branding (#155), part 1: the contract surface. Products and the portal can read and set a workspace's CI colour and logo. The derivation from the signup domain is part 2, #157, stacked on this one. Contract as agreed with Prüfwerk (pruefwerk#1087) and posted on #155: https://git.breakpilot.com/platform/tenant-registry/issues/155#issuecomment-20264 ## What changes - **Migration 0035** `tenant_branding`: colour, logo (256×256 PNG) with its sha256 as ETag, `manual`, provenance (domain, sources, hashes, `derived_at`), the derivation queue, and the notice acknowledgement. `ON DELETE CASCADE`, so a purge removes it. - **Entitlements check**: new `branding` field `{color, logo_etag, notice, domain, name}`. - It's sent only when `allowed` is true and there is a colour or a logo. - `domain` is sent only while `notice` is true. - A branding read error leaves the field out; the check itself never fails on it. - **`GET /v1/tenants/{id}/branding`** (tenants.read, via the `{id}/{sub}` route): returns colour, provenance and state, plus `derive_enabled`. There are no logo bytes. - **`PUT /v1/tenants/{id}/branding`** (tenants.write): sets or removes colour and/or logo; a missing field stays. - The branding becomes manual: it is never derived over again and shows no notice. - The logo is decoded (PNG, JPEG, GIF, ICO with a small own parser) and re-encoded as a 256×256 PNG. SVG is refused. - **`GET /v1/tenants/{id}/branding/logo`** (new group `branding.read`): returns `image/png`, `ETag: "<logo_etag>"`, 304 on `If-None-Match`, and 404 without a logo. - **`POST /v1/tenants/{id}/branding/ack`** (new group `branding.ack`): records "Passt". - The registry checks in Keycloak that `user_id` is an enabled, unblocked IT_ADMIN or OWNER. - Otherwise it answers 403 `not_admin`, including when Keycloak can't be asked (fail closed). - **Config `BRANDING_DERIVE`** (off by default): only reported as `derive_enabled` here. Part 2 uses it. - **CI**: runs the new `internal/branding` tests. - **Unrelated fix:** `TestMigrate_productsSeedMatchesDefaults` still expected the SKU list from before #152. CI doesn't run `./migrations`, so it went unnoticed. ## Rollout - Needs the orca `AUTHZ_RULES` change: `branding.read,branding.ack` for every product client and the portal's. Separate orca PR. - Without it, products get 403 on logo and ack, and everything else is unchanged. - Nothing is derived by this PR, and no customer site is fetched. ## Tests - `go test -race` on the CI package list, against Memory and Postgres (testcontainers): all green, total coverage 81.6 %. The coverage gate measures it differently; the server package alone was 70.5 % across `./internal/...`. - golangci-lint v2.12.2: 0 issues. - New tests: - `TestBranding_manualAndCheck`, `TestBranding_derivedNoticeAndAck`, `TestBranding_queue`, on both stores; - authz cases; - `TestNormalizeLogo`: determinism, aspect, ICO PNG and BMP entries, SVG refused, size caps. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 2 commits 2026-12-01 12:16:08 +00:00
Customer branding (#155), the contract part: products and the portal
can read and set a workspace's CI colour and logo. The derivation from
the signup domain follows in a separate change.

- Migration 0035: tenant_branding (colour, 256×256 PNG logo with its
  sha256 ETag, manual flag, provenance, derivation queue, notice ack).
  ON DELETE CASCADE, so a purge removes it.
- Entitlements check: "branding" {color, logo_etag, notice, domain,
  name}, only when allowed and there is a colour or logo. A read error
  leaves the field out instead of failing the check.
- GET/PUT /v1/tenants/{id}/branding (tenants.read/write): the portal's
  Erscheinungsbild page; a PUT makes the branding manual. Logos are
  decoded (PNG, JPEG, GIF, ICO) and re-encoded; SVG is refused.
- GET /v1/tenants/{id}/branding/logo (branding.read): PNG, ETag, 304.
- POST /v1/tenants/{id}/branding/ack (branding.ack): "Passt" by an IT
  admin or owner, checked in Keycloak; 403 not_admin otherwise.
- BRANDING_DERIVE config switch (off by default), reported to the
  portal as derive_enabled.
- CI runs the new internal/branding tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
test(migrations): expect the Monitor SKU after 0034
ci / shared (pull_request) Successful in 28s
ci / test (pull_request) Successful in 8m33s
ci / image (pull_request) Skipped
d64fc342d1
TestMigrate_productsSeedMatchesDefaults still expected the SKU list
before 0034 (#152). CI does not run the migrations package, so it went
unnoticed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang merged commit 9685ec0475 into main 2026-12-01 13:13:23 +00:00
Sign in to join this conversation.