Skip to content

feat(prisma): Prisma.DomainOwnership, proved automatically for Website domains - #2701

Closed
sam-goodwin wants to merge 15 commits into
fix/prisma-domain-ownershipfrom
feat/prisma-domain-verification
Closed

sam-goodwin wants to merge 15 commits into
fix/prisma-domain-ownershipfrom
feat/prisma-domain-verification

Conversation

@sam-goodwin

@sam-goodwin sam-goodwin commented Oct 27, 2026 •

Copy link
Copy Markdown
Member

Prisma requires a workspace to prove it owns a hostname before it attaches a custom domain. A Prisma website with domain: { name, dns } now proves ownership itself, in the same deploy:

yield* Prisma.Website.StaticSite("Site", {
  domain: { name: "app.example.com", dns: Cloudflare.DNS.Adapter() },
});
// publishes TXT _prisma-verification.app.example.com and the CNAME,
// proves ownership, then attaches the domain

Prisma.DomainOwnership proves a domain directly, e.g. a wildcard once for many apps:

const ownership = yield* Prisma.DomainOwnership("example.com", {
  project,
  domain: "*.example.com",
  dns: Cloudflare.DNS.Adapter(),
});
yield* Prisma.CustomDomain("api", { app: api, hostname: "api.example.com", ownership });
yield* Prisma.CustomDomain("admin", { app: admin, hostname: "admin.example.com", ownership });

Destroying it deletes the ownership and its TXT record. An ownership this resource didn't create (another stack, or proved by hand) is Unowned and needs --adopt, so destroying one stack never strips another's proof.

Built on Prisma's new domain-ownership API (alchemy-run/distilled#1007):

  • The record comes from GET /v1/workspaces/{id}/domain-ownerships/verification, so the .invalid probe is gone.
  • Prisma.CustomDomain moves from the hand-written client to distilled's /v1/services routes (/v1/apps is deprecated) and handles the typed DomainOwnershipRequired / DomainDnsNotConfigured errors.
  • Before Prisma looks up a just-published record, the deploy waits until every authoritative nameserver answers it, then waits a 10s margin. That margin is skipped when the record was already visible, so attaching the domain after the proof takes ~1s.

🤖 Generated with Claude Code

@sam-goodwin
sam-goodwin added this pull request to stack #2702 October 27, 2026 20:13
@sam-goodwin sam-goodwin changed the title feat/prisma domain verification feat(prisma): publish the domain ownership TXT record through the DNS adapter Oct 27, 2026
@alchemy-version-bot

alchemy-version-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

pnpm install https://pkg.alchemy.run/alchemy/pr:2701:cd4484d
@alchemy.run (28)
pnpm install https://pkg.alchemy.run/@alchemy.run/better-auth/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/git/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/drizzle/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/acme/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/axiom/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/doppler/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/infisical/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/turso/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/planetscale/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/neon/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/prisma/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/hetzner/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/railway/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/fly/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/github/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/stripe/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/cloudflare/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/gcp/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/aws/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/domain/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/kubernetes/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/docker/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/redis/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/sql/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/cloudflare-runtime/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/frontend-frameworks/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/node-utils/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@alchemy.run/pkg/pr:2701:cd4484d
Transitive Dependencies (19)
pnpm install https://pkg.alchemy.run/@distilled.cloud/aws/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/acme/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/axiom/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/core/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/doppler/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/infisical/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/turso/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/planetscale/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/neon/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/prisma/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/hetzner/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/railway/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/fly-io/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/github/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/stripe/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/aws4signer/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/cloudflare/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/iceberg/pr:2701:cd4484d
pnpm install https://pkg.alchemy.run/@distilled.cloud/gcp/pr:2701:cd4484d

Published Oct 29, 2026, 6:29 PM UTC. Expires Nov 5, 2026, 6:29 PM UTC, extended while this pull request is open.

@sam-goodwin

Copy link
Copy Markdown
Member Author

@wmadden, a Management API question for you, since you know the Prisma side.

Prisma now refuses a new custom domain until the workspace proves it owns the hostname:

POST /v1/apps/{appId}/domains  →  422
{"error":{"code":"domain-ownership-required",
  "message":"Verify ownership of app.example.com before connecting it to this workspace.",
  "hint":"Add a TXT record named _prisma-verification.app.example.com with value prisma-verification=<token>. Keep this record to reconnect domains in this workspace, then retry the same command."}}

Alchemy publishes a site's DNS records before it registers the domain (domain: { name, dns: Cloudflare.DNS.Adapter() }), so it could publish this TXT record as well. The problem is that it can't get the token beforehand:

  • No endpoint in the OpenAPI spec (GET /v1/doc) returns the token. It only appears in the hint text of this 422.
  • The only way to get that 422 is to try to create a domain. When ownership is already proven, the same call creates the domain.

This PR works around that by requesting a domain on alchemy-ownership-probe.invalid. That works only because the ownership check runs before the DNS check and the token is the same across the workspace. Both are undocumented, so we don't want to ship it.

Request: a read-only endpoint that returns the verification record for a hostname. Something like:

GET /v1/workspaces/{workspaceId}/domain-verification?hostname=app.example.com
→ { "data": { "type": "TXT", "name": "_prisma-verification.app.example.com", "value": "prisma-verification=<token>", "verified": false } }

It would also help to put the record in the 422 body as structured fields (verification: { name, value }), not only in the hint text, and to document domain-ownership-required in the spec.

With that endpoint, Prisma.DomainVerification reads the record and the DNS adapter publishes it, so users get their domain in one deploy. Until then, #2698 fails with a typed PrismaDomainOwnershipRequired error that names the record for the user to add. Would Prisma be open to adding this?

@sam-goodwin
sam-goodwin marked this pull request as draft October 27, 2026 21:51
@wmadden

wmadden commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Hi Sam,

The verification record is now returned as data. This is live in production.

When you POST /v1/apps/{appId}/domains for a hostname the workspace hasn't verified yet, the 422 looks like this:

{
  "error": {
    "code": "domain-ownership-required",
    "message": "Verify ownership of staging.example.com before connecting it to this workspace.",
    "hint": "Add a TXT record named _prisma-verification.staging.example.com with value prisma-verification=... Keep this record to reconnect domains in this workspace, then retry the same command.",
    "verification": {
      "type": "TXT",
      "name": "_prisma-verification.staging.example.com",
      "value": "prisma-verification=...",
      "ttl": 300
    }
  }
}

message and hint are unchanged. error.verification is new and optional on the shared error shape, so existing clients are unaffected.

Two things worth knowing for the DNS adapter:

  • The value is derived from the workspace, so it is the same for every hostname in that workspace. One record per hostname, same value each time.
  • Ownership is checked before DNS routing. You can call the create route on a hostname whose CNAME doesn't exist yet, read the record from the 422, publish it, and retry. The CNAME check only runs after ownership passes.

This is documented in the OpenAPI spec at https://api.prisma.io/v1/doc on the 422 response of that route.

Let me know if the shape doesn't fit what Alchemy needs.

@sam-goodwin
sam-goodwin marked this pull request as ready for review October 29, 2026 17:18
@sam-goodwin

Copy link
Copy Markdown
Member Author

Thanks @wmadden, that's exactly what we needed, and thanks for documenting the ownership-before-DNS ordering in the spec.

Both PRs now read error.verification instead of parsing the hint:

@sam-goodwin sam-goodwin changed the title feat(prisma): publish the domain ownership TXT record through the DNS adapter feat(prisma): Prisma.DomainOwnership, proved automatically for Website domains Oct 29, 2026
@sam-goodwin
sam-goodwin marked this pull request as draft October 29, 2026 18:12
@sam-goodwin
sam-goodwin marked this pull request as ready for review October 29, 2026 18:31
wmadden-electric added a commit to wmadden-electric/alchemy that referenced this pull request Nov 19, 2026
Carries the Prisma parts of alchemy-run#2698 and alchemy-run#2701 onto main: Prisma.DomainOwnership, the internal DomainVerification and AuthoritativeDns helpers, Prisma.CustomDomain on distilled with an optional ownership, and the Website domain proving its hostname.

Prisma now saves a domain ownership as unverified and returns it, so a successful create no longer proves anything. Proving creates the domain ownership, waits for the TXT record at the authoritative nameservers, then calls the verify route until Prisma reports verified. If it never does, the deploy fails with PrismaDomainOwnershipRequired and a domain ownership the deploy created is removed. Attributes add status and expiresAt; verifiedAt is null unless verified.

The distilled pin is temporary: 51020e295 on the bot fork wmadden-electric/distilled (branch feat/prisma-routing-urls-on-alchemy-pin), which is Distilled's feature commits on top of 63ab82684, the commit Alchemy pins upstream. They expose httpStatus on createServiceDomain and createWorkspaceDomainOwnership and drop DomainOwnershipRequired from createWorkspaceDomainOwnership. Replace the pin with a Distilled main commit before the pull request opens.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
wmadden-electric added a commit to wmadden-electric/alchemy that referenced this pull request Nov 20, 2026
Carries the Prisma parts of alchemy-run#2698 and alchemy-run#2701 onto main: Prisma.DomainOwnership, the internal DomainVerification and AuthoritativeDns helpers, Prisma.CustomDomain on distilled with an optional ownership, and the Website domain proving its hostname.

Prisma now saves a domain ownership as unverified and returns it, so a successful create no longer proves anything. Proving creates the domain ownership, waits for the TXT record at the authoritative nameservers, then calls the verify route until Prisma reports verified. If it never does, the deploy fails with PrismaDomainOwnershipRequired and a domain ownership the deploy created is removed. Attributes add status and expiresAt; verifiedAt is null unless verified.

The distilled pin is temporary: 51020e295 on the bot fork wmadden-electric/distilled (branch feat/prisma-routing-urls-on-alchemy-pin), which is Distilled's feature commits on top of 63ab82684, the commit Alchemy pins upstream. They expose httpStatus on createServiceDomain and createWorkspaceDomainOwnership and drop DomainOwnershipRequired from createWorkspaceDomainOwnership. Replace the pin with a Distilled main commit before the pull request opens.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@wmadden

wmadden commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Hi Sam. #3529 includes what this pull request does, updated for two changes in Prisma's API. Could you close this one if you agree?

Same as here:

  • A website with domain: { name, dns } publishes _prisma-verification.<hostname> and the CNAME in the same deploy.
  • Prisma.DomainOwnership takes project, domain and dns. Destroying it deletes the domain ownership and its TXT record. One it did not create needs --adopt.

Different, because Prisma's API changed:

#3529 needs alchemy-run/distilled#1348 merged first.

@sam-goodwin

Copy link
Copy Markdown
Member Author

Superseded by #3529 (Prisma.RoutingUrl), which replaces the custom-domain routes. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants