Repository navigation
fix(domain): 修复域名抢注、复检误降级与 Let's Encrypt 配额耗尽(High) - #5
Merged
Merged
Conversation
ruanbw
force-pushed
the
fix/high-domains
branch
from
October 8, 2026 07:23
29cd1b6 to
9ffc0ad
Compare
This was referenced Oct 8, 2026
Owner
Author
|
已 rebase 到 文本无冲突(internal.go / config.go / .env.example / docker-compose.prod.yml 与 #2、#3 的改动自动合并;迁移 0020/0021(#6)与 0030(本 PR)均保留)。 合并顺序:#1 → #6 → #3 → #2 → #4 → #5(请按此顺序依次合并;每个 PR 合并后,下一个 PR 的 base 会由 GitHub 自动改指向其上一级的目标分支)。 验证:每一步 rebase 后均 |
1. 域名抢注:被他人占位(pending/expired/failed 且从未证明归属)的 FQDN 可由能发布 TXT 的租户认领接管(新增 domain_claims 表,事务内复核并驱逐旧行, 认领方直接激活);worker 每日回收 expired 超过 30 天且无短链/访问的占位行。 保留 fqdn 全局 UNIQUE,读路径不受影响。 2. 归属复检容错:Verify 区分"查询失败"(ErrDNSLookup,跳过不降级)与 "否定答案";连续 3 次复检失败才降级(新增 recheck_failures 列,失败后每小时重查); 降级时写 verify_token_created_at,成熟域名不再被立刻打成 expired。 3. Let's Encrypt 配额:新增可选泛域名证书模式(Caddyfile.prod.wildcard + DNS-01, JANUS_WILDCARD_TLS=true 时授权端点拒绝平台子域 on-demand 签发),默认行为不变; 注册时新增保留 slug 名单(www/mail/api/admin/status 等)。 迁移编号 0030,避开旧版本号与并行分支的 0020 段。
ruanbw
force-pushed
the
fix/high-domains
branch
from
October 8, 2026 07:25
9ffc0ad to
f54b7a5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
基于
fix/critical-review,修复代码审查中域名相关的三个 High 级问题。改动
1. 域名抢注(fqdn 全局 UNIQUE 被 pending 行永久占位)
fqdn全局 UNIQUE。跳转热路径、Caddy 授权端点、错误页、证书探活全部按 fqdn 取"那一行";改成部分唯一索引后同名会出现多行,每条读路径都要补"该用哪一行"的规则,改动面太大,所以没有放宽唯一约束。store.IsDomainClaimable):属于其他租户、origin=self、ownership_verified_at IS NULL、状态为pending/expired/failed。active/stopped 以及证明过归属的行一律不可认领。POST /api/domains撞到可认领行时):domain_claims。token 未过期(JANUS_DNS_MAX_AGE)前不变;_janus-verify.<fqdn>和 A/AAAA;details带claimable: true / verifyRecord / verifyValue / verifyNeeds / serverIp;link_domains关联,然后驱逐旧行、为认领方建行并直接激活,返回 201,同时作废该 fqdn 的全部认领 token。domain-gc循环(节奏同JANUS_VISIT_CLEANUP_INTERVAL):回收进入 expired 超过 30 天、没有短链关联也没有访问记录的自有域名,同时清理过期的认领 token。0030_domain_claims_recheck_failures.sql。编号跳到 0030,避开旧版本号和并行分支在 0020 段新增的迁移。2. 一次 24h 复检失败就让成熟域名下线
DNSChecker.Verify:A/AAAA 查询错误不再丢弃。TXT 查询只有IsNotFound(NXDOMAIN/无记录)才算 need_txt,超时、SERVFAIL 等一律返回包裹domain.ErrDNSLookup的错误。worker 复检、后台重检遇到这个错误时跳过本轮,不计失败也不降级。创建域名时照常落库为 pending(只是不给指引);恢复(PATCH active)返回 503,提示稍后重试。DegradeDomain/ 达到阈值时的降级会同时写verify_token_created_at = now(),租户从降级起有完整的 72h 宽限期,沿用原 TXT 即可自动恢复,不再被立刻判成 expired。domains.recheck_failures列。查到了但不匹配,需要连续 3 次才降级(RecordOwnershipRecheckFailure,一条原子 UPDATE)。复检成功或降级都会清零。第一次失败后改为每小时重查(扫描循环 1h,健康域名仍是 24h 复检一次),整个确认在几小时内完成,易主窗口不会拉长到 72h。手动"重新校验"也走同一套计数。3. 注册量耗尽 Let's Encrypt 配额
Caddyfile.prod.wildcard:example.com和*.example.com走 DNS-01(示例用 Cloudflare 插件),app 与全部租户子域共用泛域名证书(同一站点内按 host 分流),租户自有域名仍走 on-demand;JANUS_WILDCARD_TLS=true时,授权端点拒绝<任意>.<平台域名>(app 除外)的 on-demand 签发,作为兜底;docs/deploy.md第 8 节、.env.example、docker-compose.prod.yml(新增转发变量和 DNS 插件构建说明)以及 ADR-0004 的补充说明。domain.IsReservedSlug(app/www/mail/api/admin/status/ns1/autodiscover 等)。之前只挡了app。验证
gofmt干净(pkg/plugin/plugin_test.go原本就未格式化,未改动),go build ./...和go vet ./...通过。go test ./...,全部通过:TestVerifySurfacesAddrLookupError、TestVerifySurfacesTXTLookupError、TestVerifyNoAddrRecordsIsNeedDNS;TestRecheckOwnershipSkipsOnDNSError(store 置 nil,确认 DNS 出错时完全不碰库)、TestOwnershipRecheckTuning;TestIsReservedSlug、TestIsPlatformSubdomain、TestIsDomainClaimable;TestWildcardTLSFlag、TestAuthorizeWildcardModeDeniesPlatformSubdomains。TestClaimSquattedDomainWithOwnershipProof、TestClaimSquattedDomainNeedsTXT、TestClaimRejectedForActiveDomain;TestOwnershipRecheckFailureThreshold(成熟域名降级后不会被判 overdue)、TestOwnershipRecheckSuccessResetsFailures;TestGCExpiredDomains、TestRegisterReservedSlugs。caddy-dns/cloudflare)跑过caddy adapt。wildcard 版的 TLS 策略确认为:平台两张证书走 DNS-01,其余主机名走 on-demand。部署注意
0030新增domain_claims表、domains.recheck_failures列和 expired 回收索引,均为加法,可在线执行。details现在可能带claimable: true和 TXT 指引,前端可以按需展示"发布 TXT 后重新提交即可接管"。现有前端只显示 message,不受影响;JANUS_CADDY_DNS_API_TOKEN,把 caddy 挂载的配置文件换成Caddyfile.prod.wildcard,再设JANUS_WILDCARD_TLS=true。Caddyfile 和开关要一起切换:只开开关不换 Caddyfile,租户子域握手会失败。