spec: account subdomains for self-hosted deployments (draft)
Operator-assigned <app>.<name>.<apps-domain> hosts derived from a namespace claim beside the sqid hosts. Draft, before the builder check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+272
−0
docs/superpowers/specs/2026-11-11-account-subdomains-design.md+272 −0
Intent
Attributed to this commit: 32.6 g CO₂e (3,060,662 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-account-name-hosts, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/docs/superpowers/specs/2026-11-11-account-subdomains-design.md b/docs/superpowers/specs/2026-11-11-account-subdomains-design.md| new file mode 100644 |
| index 000000000..b6c4bfea2 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-11-account-subdomains-design.md |
| @@ -0,0 +1,272 @@ |
| +# Account subdomains: `<app>.<name>.<apps-domain>` beside `<app>.<sqid>.<apps-domain>` |
| + |
| +**Date:** 2026-11-11 |
| +**Status:** draft, branch `design-account-name-hosts`. Not reviewed. |
| + |
| +## 1. Why |
| + |
| +Every app's platform URL is `<app>.<sqid>.<apps-domain>`, where the sqid |
| +is the account's frozen identity label (`internal/domains/sqid.go`). The |
| +sqid is deliberately meaningless, and `sqid.go` says why vanity names were |
| +left out: on a shared platform anyone can sign up, so a name in the |
| +platform domain invites squatting, and custom domains are the vanity |
| +mechanism. |
| + |
| +That reason does not hold on a deployment where one operator runs every |
| +account, such as a self-hosted company platform. There the operator wants |
| +URLs people can read and remember: `shop.harbour.apps.example.com` |
| +instead of `shop.bdq.apps.example.com`. Today the only way is a custom |
| +domain claim per app, by hand, and nothing stops a second account from |
| +claiming `other.harbour.apps.example.com`, because no account owns the |
| +`harbour` label. |
| + |
| +## 2. What it looks like |
| + |
| +An operator gives account `bdq` the subdomain `harbour`: |
| + |
| +``` |
| +carlos accounts subdomain set --account bdq harbour |
| +``` |
| + |
| +From then on, every route host the account has under its sqid answers |
| +under the name too, with no further step: |
| + |
| +| Existing URL | Also answers at | |
| +| --- | --- | |
| +| `shop.bdq.apps.example.com` | `shop.harbour.apps.example.com` | |
| +| `team1.bdq.apps.example.com` (an instance) | `team1.harbour.apps.example.com` | |
| +| an app created next week, `blog.bdq...` | `blog.harbour...` the moment its route exists | |
| + |
| +Nothing about identity changes. The sqid stays in bucket paths, CLI flags, |
| +logs and the sqid URLs, which keep working. |
| + |
| +## 3. Goals, non-goals, anti-goals |
| + |
| +**Goals** |
| + |
| +- An operator can give an account one readable subdomain under the apps |
| + domain, and every one of the account's apps answers there. |
| +- The name belongs to that account the way its sqid label does: no other |
| + account can attach anything under it. |
| +- New apps and instances are covered automatically; nothing per app to |
| + keep in sync. |
| + |
| +**Non-goals** |
| + |
| +- Tenants choosing their own subdomain. Only a platform operator assigns |
| + one, which is what removes the squatting problem. |
| +- Replacing the sqid as identity anywhere (paths, flags, records, |
| + manifests). |
| +- Redirecting the sqid URL to the name URL. Both serve; an app that wants |
| + one canonical host sets it itself. |
| +- More than one subdomain per account. |
| + |
| +**Anti-goals** (failure even if it works) |
| + |
| +- A name that ever resolves to a different account than the one it was |
| + given to, or that collides with a sqid some account holds or will hold. |
| +- A name that takes an address the deployment itself stands on (`edge`, |
| + `dev`, `www`, the tunnel host, console hosts, operator deny entries). |
| +- One certificate per app under the name, published to Certificate |
| + Transparency and spending the ACME budget, where a sqid account gets one |
| + wildcard. |
| + |
| +## 4. Design |
| + |
| +### 4.1 The record: a namespace claim |
| + |
| +A subdomain is a `domains.Claim` at `domains/*.<name>.<apps-domain>.json` |
| +with `Host: "*.<name>.<apps-domain>"`, `Account: <sqid>`, a new field |
| +`AccountNamespace: true` (`json:"account_namespace,omitempty"`) and |
| +nothing else: no App, Route, Wildcard, Catchall, Paths, Instances or |
| +Placements. |
| + |
| +This follows the instance catch-all |
| +(`docs/superpowers/specs/2026-10-05-instance-catchall-design.md`): |
| + |
| +- The bucket key is the uniqueness gate. Claim writes are create-only, so |
| + two accounts racing for one name cannot both win, and a namespace claim |
| + and an instance catch-all on the same parent cannot coexist. |
| +- No attach door accepts a `*` (`NormalizeAliasHost`), so the ordinary |
| + domain doors cannot write, rewrite or detach one. |
| +- The field is additive: a binary that predates it decodes a claim with no |
| + Route, no Instances and no Wildcard, the shape every pass already skips, |
| + and derives nothing. Declare it in `Claim` in the same change that first |
| + writes it (the round-trip rule in `claims.go`). |
| + |
| +### 4.2 Which names are allowed |
| + |
| +A name is one DNS label: the account-name shape in `slugname.go` |
| +(`^[a-z0-9]([a-z0-9-]{0,61}[a-z0-9])?$`), refusing `xn--` style labels |
| +(hyphens in positions 3 and 4). It is refused when any of these holds: |
| + |
| +1. **It is a sqid an account holds**, live or deleted |
| + (`AccountAnyBySqid`). |
| +2. **It could become a sqid soon.** If `domains.ValidSqid(name)` and the |
| + name is shorter than 7 letters, refuse it. A 7-letter sqid needs an |
| + account id past 23⁶ − 529, about 148 million accounts, so a 7+ letter |
| + name cannot meet a minted sqid in practice. Names with i, l, o, a |
| + digit or a hyphen are never sqids and have no length floor. |
| +3. **It is in `domains.ReservedSqids()`** (`dev`, `edge`, `www`). |
| +4. **The deployment stands on it.** `domainHostPolicy` says |
| + `hostReserved` for `<name>.<apps-domain>` or for a probe host under it |
| + (covers the steering host, tunnel host, console hosts and demo hosts). |
| + `CONSOLE_DENY_DOMAINS` entries covering it refuse it too. |
| +5. **Something already lives there.** Any claim held by another account, |
| + or any route in the deployment, at `<name>.<apps-domain>` or under it. |
| + Same-account claims are fine (they become exact names inside the |
| + account's own namespace, §4.4). |
| + |
| +The console suggests the account's name when it fits these rules. The |
| +subdomain is a separate value from the account name, because account names |
| +are non-unique by design, can be renamed, and auto-minted personal |
| +accounts are named after an email address. |
| + |
| +### 4.3 The door |
| + |
| +`POST /api/accounts/<sqid>/subdomain` (set) and `DELETE` (remove), allowed |
| +only to a platform operator (`platformOperator`: an owner of the ops |
| +account or an address on `CARLOS_SYSTEM_OPERATORS`), and only from a |
| +person, never an app token. The CLI is |
| +`carlos accounts subdomain set|remove|show`. |
| + |
| +- **Set** checks §4.2, then writes the claim create-only. An account that |
| + already has a subdomain is refused; changing it is remove then set. |
| +- **Remove** deletes the claim (etag-conditional). The derived names stop |
| + serving on the next alias pass. The name is free again at once. Only an |
| + operator can take it next, so reuse is always a deliberate choice. |
| +- **Account deletion** leaves the claim in place. It stays held by the |
| + tombstoned account, its routes are gone so it derives nothing, and an |
| + operator can remove it afterwards. |
| + |
| +There is no environment switch. The door is operator-only on every |
| +deployment, and nothing changes until an operator sets a subdomain. |
| + |
| +### 4.4 Serving: derived alias rows on each box |
| + |
| +`domains.ReconcileAliases` gains a pass beside `deriveInstanceAliases`. |
| +For each namespace claim (account `A`, name `N`), and for each route on |
| +this box that is provisioned, non-sidecar, belongs to `A`, and whose host |
| +is `<prefix>.<Sqid A>.<apps-domain>`, it derives the alias row |
| +`<prefix>.<N>.<apps-domain>` → that route's host. |
| + |
| +The precedence rules are the instance catch-all's, unchanged: |
| + |
| +- An exact claim on the derived name wins, whoever holds it. That lets |
| + the account attach `blog.harbour...` to a different app if it wants. |
| +- A real route on this box, or one any live box publishes, wins. |
| +- A listing failure keeps the existing derived rows for that pass instead |
| + of dropping them. |
| + |
| +The mapping swaps one label, so it is one-to-one: two routes can never |
| +derive the same name. Rows are ordinary `route_aliases` rows, so the |
| +edge, edges file, readings sweep and issuer treat them like any alias. |
| +Every other path that reads aliases (HA ingress via |
| +`deriveHAIngressAliases`, regional placements, replicas) must treat a |
| +derived row exactly as it treats an alias from an exact claim. The |
| +builder checks each one; the instance catch-all made the same walk. |
| + |
| +The derived rows share a per-box cap with instance aliases |
| +(`maxInstanceAliases`) or get their own of the same size; overflow is |
| +logged, as there. |
| + |
| +### 4.5 Namespace protection in the console |
| + |
| +The console's checks that know `<sqid>.<apps-domain>` means "this |
| +account's namespace" learn the name too. `appsNamespace(host)` resolves |
| +the label under the apps domain to an account sqid when it is a sqid |
| +**or** a held subdomain (one claim read, through the existing claim |
| +cache). With that one change: |
| + |
| +- `otherAccountsNamespace` refuses other accounts anything under |
| + `harbour.<apps-domain>`, operators' platform door included, as it does |
| + for sqids today. A removed subdomain stops protecting at once. |
| +- `domainProofExempt` treats the account's own subdomain as proof-exempt, |
| + like its sqid namespace. |
| +- `firstRouteOutsideNamespace` treats a held name as a namespace. |
| + |
| +### 4.6 Certificates |
| + |
| +`edge.parentsFor` makes `<sqid>.<apps-domain>` a wildcard parent for every |
| +route two labels under the apps domain. It gains the same rule for a held |
| +subdomain, so the account gets one `*.harbour.<apps-domain>` certificate, |
| +issued the same way the deployment issues its sqid wildcards. The edge |
| +learns the held names from its registry (the builder picks how: a column |
| +on the derived rows, or a small table written by the alias pass). On a |
| +deployment that issues per-host certificates for sqid hosts, names fall |
| +back to per-host, the same as sqids. |
| + |
| +### 4.7 DNS |
| + |
| +No new records. The apps domain's wildcard (`*.<apps-domain>`) already |
| +answers `shop.harbour.<apps-domain>`, because a DNS wildcard covers every |
| +name below it that has no node of its own. The builder confirms this on |
| +each deployment type (§4 of the instance catch-all spec lists them), |
| +including any that publish per-account records instead of one wildcard. |
| + |
| +### 4.8 Surfaces |
| + |
| +- `carlos accounts subdomain set|remove|show` (§4.3). |
| +- `carlos apps` and the console app page list the subdomain URL first |
| + when the account has one, the sqid URL second. |
| +- The account settings page shows the subdomain (read-only for members; |
| + set and remove for operators). |
| +- Refusals name the rule that refused (taken, reserved, sqid-shaped and |
| + too short, held by another account). |
| + |
| +All strings go through copy review, and the console changes get the UX |
| +pass (AGENTS.md), before they are written. |
| + |
| +### 4.9 Mixed versions |
| + |
| +Boxes roll before the console that writes namespace claims. An old box |
| +derives nothing from one (§4.1), so the worst a too-early claim does is |
| +serve nothing until the box rolls. The console checks in §4.5 ship in the |
| +same release as the door, so no window exists where a name is held but |
| +unprotected. |
| + |
| +## 5. Security cases |
| + |
| +- **A member tries to take a name:** no door. Only the operator door |
| + writes namespace claims. |
| +- **Another account attaches `x.harbour...`:** refused by §4.5. |
| +- **An app token sets a subdomain:** refused; the door needs a person. |
| +- **A name equal to a future sqid:** refused by §4.2 rules 1-2. |
| +- **A name over infrastructure:** refused by §4.2 rules 3-4. |
| +- **A derived name shadows something:** it cannot; exact claims and real |
| + routes beat it (§4.4). |
| +- **A removed name is reused by another account:** possible, and only |
| + by an operator choosing to. Old links then reach the new account. This |
| + is the accepted cost of operator-only assignment (§8). |
| + |
| +## 6. Slices and witness |
| + |
| +One slice. The first merge is something Paul can see: on dev, set a |
| +subdomain on a test account and open `<app>.<name>.<dev apps-domain>` in a |
| +browser, served with a wildcard certificate for `*.<name>`. |
| + |
| +Witness steps on dev: set; load an existing app and an instance through |
| +the name; create a new app and load it through the name without any other |
| +step; try to attach `x.<name>...` from a second account (refused); remove; |
| +confirm the names stop serving and the certificate parent drops. |
| + |
| +Who is asking: Paul, for a self-hosted deployment. Switch-on: the release |
| +it ships in; there is no switch (§4.3). |
| + |
| +## 7. Left to the builder |
| + |
| +- Where the held-name list reaches the edge (§4.6). |
| +- Whether derived rows share the instance-alias cap (§4.4). |
| +- Exact API paths and response shapes, following the existing account |
| + doors. |
| +- Test layout, following the instance catch-all's derivation tests and |
| + `production-wired` witnesses. |
| + |
| +## 8. Calls made in drafting (check these) |
| + |
| +- The subdomain is its own value, not the account name (§4.2). |
| +- Sqid-shaped names need 7+ letters (§4.2 rule 2). |
| +- Operator-only, no switch, available on every deployment (§4.3). |
| +- Remove frees the name at once; no tombstone (§4.3). |
| +- Both URLs serve; no redirect (§3). |
| +- Every route under the sqid is mirrored, instances included (§4.4). |