feat(branding): derive colour and logo from the signup domain (#155, part 2) #157

Closed
sharang wants to merge 5 commits from feat/branding-derive into main
pull from: feat/branding-derive
Owner

Customer branding (#155), part 2: the registry derives colour and logo from the home page of the workspace's company domain. #156 is merged (9685ec04); main is merged into this branch, so the diff shows only the derivation.

Behaviour

  • Domain: the admin address's registrable domain (eTLD+1).

    • When that's empty or free mail, it's the most frequent company domain among the Keycloak members; a tie goes to the alphabetically first.
    • Free mail is a fixed list, including outlook., yahoo. and gmx.*.
    • No domain: derive_state failed, no_domain, and no branding.
  • Fetch (internal/branding), per #155 step 2:

    • Own http.Transport: no proxy, not the traced default (so no trace headers go to customer sites), no cookie jar.
    • https on port 443 only.
    • Public IPs only, checked in Dialer.Control, so after DNS and on every hop. Private, CGNAT, loopback, link-local, documentation and NAT64 ranges are refused.
    • At most 5 redirects, within the same registrable domain (public suffix list).
    • Limits: 10 s per request, HTML ≤ 2 MB, manifest and images ≤ 1 MB.
    • User-Agent: BreakpilotBranding/1.0, nothing about the customer.
    • Tries https://<domain>/, then https://www.<domain>/.
  • Colour, the first that is usable:

    1. the first theme-color without media;
    2. the manifest's theme_color;
    3. the logo's dominant colour (64×64, the filters, 5-bit buckets, tie to the lowest packed value, rounded mean).

    White, black and grey are skipped. Hex and rgb() are read; named colours are not.

  • Logo, the first candidate that downloads and decodes:

    1. the manifest's largest PNG ≥ 128 px;
    2. apple-touch-icon;
    3. the largest PNG/ICO/JPEG rel=icon;
    4. /favicon.ico.

    It's stored as a 256×256 PNG; SVG-only sites get none.

  • Determinism: the same fetched bytes give the same result. The HTML and logo sha256 are stored as provenance.

  • POST /v1/tenants/{id}/branding/derive ("Neu ermitteln", tenants.write):

    • It is synchronous, bounded to about 25 s (under the 30 s write timeout).
    • It replaces a manual choice and counts as acknowledged, so no notice. A failure keeps what was shown and reports derive_state: failed with the reason.
    • It answers 503 derive_disabled while switched off, and 409 for demo workspaces.
  • Background:

    • Tenant creation and trial requests queue customer workspaces (only while switched on). Signup never waits.
    • RunBranding derives up to 5 per minute.
    • Network failures are retried twice, 6 h apart. A background derivation never overwrites a manual choice: the store checks manual in the same statement.
  • Audit: branding.derived (domain, colour source, logo yes/no, forced) and branding.failed (domain, reason). Logs carry the tenant id only, not the domain.

Switches (both off by default)

  • BRANDING_DERIVE=on: the endpoint, the queueing and the worker.
    • Proposal: on for stage; on prod only once the privacy notice names the fetch (still open on #155).
  • BRANDING_BACKFILL=on: queues every customer workspace without branding once at start.
    • This is the one-off backfill. On prod it's Sharang's call: their admins will see the notice.

Tests

  • internal/branding, against a TLS test server:
    • theme-color plus apple-touch-icon;
    • grey theme-color, then the manifest's colour and icon, with the www fallback;
    • colour from favicon.ico;
    • SVG only;
    • off-domain redirect;
    • redirect loop;
    • private address never dialled (the server sees 0 hits);
    • PublicIP table, PickDomain, colour parsing and the tie rule.
  • TestBrandingDerive on Memory and Postgres:
    • nothing happens while switched off;
    • queued at creation and derived in the background, with a notice;
    • forced over a manual choice;
    • a failed run keeps the branding;
    • background retry;
    • member-domain fallback and no_domain.
  • golangci-lint: 0 issues.

🤖 Generated with Claude Code

Customer branding (#155), part 2: the registry derives colour and logo from the home page of the workspace's company domain. #156 is merged (9685ec04); main is merged into this branch, so the diff shows only the derivation. ## Behaviour - **Domain**: the admin address's registrable domain (eTLD+1). - When that's empty or free mail, it's the most frequent company domain among the Keycloak members; a tie goes to the alphabetically first. - Free mail is a fixed list, including outlook.*, yahoo.* and gmx.*. - No domain: `derive_state` failed, `no_domain`, and no branding. - **Fetch** (`internal/branding`), per #155 step 2: - Own `http.Transport`: no proxy, not the traced default (so no trace headers go to customer sites), no cookie jar. - https on port 443 only. - Public IPs only, checked in `Dialer.Control`, so after DNS and on every hop. Private, CGNAT, loopback, link-local, documentation and NAT64 ranges are refused. - At most 5 redirects, within the same registrable domain (public suffix list). - Limits: 10 s per request, HTML ≤ 2 MB, manifest and images ≤ 1 MB. - `User-Agent: BreakpilotBranding/1.0`, nothing about the customer. - Tries `https://<domain>/`, then `https://www.<domain>/`. - **Colour**, the first that is usable: 1. the first `theme-color` without `media`; 2. the manifest's `theme_color`; 3. the logo's dominant colour (64×64, the filters, 5-bit buckets, tie to the lowest packed value, rounded mean). White, black and grey are skipped. Hex and `rgb()` are read; named colours are not. - **Logo**, the first candidate that downloads and decodes: 1. the manifest's largest PNG ≥ 128 px; 2. `apple-touch-icon`; 3. the largest PNG/ICO/JPEG `rel=icon`; 4. `/favicon.ico`. It's stored as a 256×256 PNG; SVG-only sites get none. - **Determinism**: the same fetched bytes give the same result. The HTML and logo sha256 are stored as provenance. - **`POST /v1/tenants/{id}/branding/derive`** ("Neu ermitteln", tenants.write): - It is synchronous, bounded to about 25 s (under the 30 s write timeout). - It replaces a manual choice and counts as acknowledged, so no notice. A failure keeps what was shown and reports `derive_state: failed` with the reason. - It answers 503 `derive_disabled` while switched off, and 409 for demo workspaces. - **Background**: - Tenant creation and trial requests queue customer workspaces (only while switched on). Signup never waits. - `RunBranding` derives up to 5 per minute. - Network failures are retried twice, 6 h apart. A background derivation never overwrites a manual choice: the store checks `manual` in the same statement. - **Audit**: `branding.derived` (domain, colour source, logo yes/no, forced) and `branding.failed` (domain, reason). Logs carry the tenant id only, not the domain. ## Switches (both off by default) - `BRANDING_DERIVE=on`: the endpoint, the queueing and the worker. - Proposal: on for stage; on prod only once the privacy notice names the fetch (still open on #155). - `BRANDING_BACKFILL=on`: queues every customer workspace without branding once at start. - This is the one-off backfill. On prod it's Sharang's call: their admins will see the notice. ## Tests - `internal/branding`, against a TLS test server: - theme-color plus apple-touch-icon; - grey theme-color, then the manifest's colour and icon, with the www fallback; - colour from favicon.ico; - SVG only; - off-domain redirect; - redirect loop; - **private address never dialled** (the server sees 0 hits); - `PublicIP` table, `PickDomain`, colour parsing and the tie rule. - `TestBrandingDerive` on Memory and Postgres: - nothing happens while switched off; - queued at creation and derived in the background, with a notice; - forced over a manual choice; - a failed run keeps the branding; - background retry; - member-domain fallback and `no_domain`. - golangci-lint: 0 issues. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
sharang added 3 commits 2026-12-01 12:16:10 +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>
feat(branding): derive colour and logo from the signup domain
ci / shared (pull_request) Successful in 30s
ci / test (pull_request) Successful in 8m49s
ci / image (pull_request) Skipped
fb86a78324
Customer branding (#155), steps 1–6: the registry reads the home page
of the workspace's company domain and stores its CI colour and logo.

- Domain: the admin's address, else the most frequent member domain
  (tie: alphabetical); free mail never counts; no domain, no branding.
- Fetch (internal/branding): own transport (no proxy, no trace
  headers, no cookies), https on 443 only, public IPs only, checked on
  every dial after DNS, ≤ 5 redirects within the registrable domain,
  10 s per request, HTML ≤ 2 MB, images ≤ 1 MB, User-Agent
  BreakpilotBranding/1.0.
- Colour: theme-color without media, the manifest's theme_color, else
  the logo's dominant colour; white, black and grey are skipped.
- Logo: manifest PNG ≥ 128 px, apple-touch-icon, PNG/ICO/JPEG icon,
  /favicon.ico; stored as a 256×256 PNG, never SVG.
- POST /v1/tenants/{id}/branding/derive ("Neu ermitteln"): synchronous,
  replaces a manual choice and counts as acknowledged.
- Background: tenant creation and trial requests queue the workspace;
  RunBranding derives queued ones every minute, retries network
  failures twice, 6 h apart. Audit branding.derived / branding.failed.
- Switches: BRANDING_DERIVE=on (off by default), BRANDING_BACKFILL=on
  queues every customer workspace without branding once at start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sharang added 1 commit 2026-12-01 12:29:50 +00:00
fix(branding): stop background retries once the budget ran out
ci / shared (pull_request) Successful in 12s
ci / test (pull_request) Successful in 7m41s
ci / image (pull_request) Skipped
3191617502
When the 25 s budget was what failed, the attempt count was read with
the expired context; Postgres refused, and a retry was scheduled every
6 h without end. The failure is now recorded with a context that has
not ended. README: BRANDING_DERIVE, BRANDING_BACKFILL and the branding
route groups.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
CODEOWNERS rules requested review from Benjamin_Boenisch 2026-12-01 12:29:50 +00:00
sharang added 1 commit 2026-12-01 13:13:56 +00:00
Merge remote-tracking branch 'origin/main' into feat/branding-derive
ci / shared (pull_request) Failing after 4s
ci / test (pull_request) Successful in 8m17s
ci / image (pull_request) Skipped
78e0cb5f82
# Conflicts:
#	internal/config/config.go
#	internal/server/openapi_test.go
#	internal/server/server.go
#	openapi.yaml
Author
Owner

Replaced by #159: same code on a fresh branch from main. This branch carried a merge commit whose subject failed commitlint, and a force-push wasn't an option.

Replaced by #159: same code on a fresh branch from main. This branch carried a merge commit whose subject failed commitlint, and a force-push wasn't an option.
sharang closed this pull request 2026-12-01 13:24:18 +00:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.