Delete One DNS Record — Guard Healthtech Onboarding Against Identity Drift
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Delete One DNS Record — Guard Healthtech Onboarding Against Identity Drift
在删除单个 DNS 记录之前,请先列出该区域已发布的记录,然后使用从该列表中返回的确切标识符。对于医疗科技(healthtech)的入驻流程,决定性的约束是“漂移”(drift):一个排队等待删除的作业所预期的证明记录,可能已经不再是当前发布的记录。在证据得到核实之前,请保持所有权验证处于挂起状态。简而言之:按区域、类型和名称进行选择;要求恰好匹配一个预期结果;将其内容与批准的前置状态进行比较;使用刚刚读取的标识符进行删除。保留完整的列表条目以备恢复。
A Node.js worker needs the same checks as any other client. The Go example below isolates that decision without inventing provider request fields. How do you delete a single DNS record without guessing? Consider an illustrative clinic onboarding request for clinic.example. Its cleanup intent names a TXT record at _ownership.clinic.example with content onboarding-proof-old. These are example values, not a prescribed verification protocol.
Node.js 工作进程需要与任何其他客户端进行相同的检查。下面的 Go 示例在不虚构提供商请求字段的情况下隔离了该决策。你如何能在不猜测的情况下删除单个 DNS 记录?考虑一个针对 clinic.example 的诊所入驻请求示例。其清理意图指向 _ownership.clinic.example 处的一个 TXT 记录,内容为 onboarding-proof-old。这些是示例值,并非规定的验证协议。
Before the queued cleanup runs, an administrator replaces the intended proof with onboarding-proof-current. A job that reconstructs the target from the original name can now act against the wrong state. The requested work became stale. Stop the deletion. The useful postmortem question is where intent stopped matching evidence. A record name identifies the place being inspected, but it does not prove that the current content belongs to the old onboarding attempt.
在排队的清理任务运行之前,管理员将预期的证明替换为了 onboarding-proof-current。一个通过原始名称重构目标的作业现在可能会作用于错误的状态。所请求的工作已经过时。停止删除。有用的事后分析问题是:意图在何处不再与证据匹配。记录名称标识了正在检查的位置,但它并不能证明当前内容属于旧的入驻尝试。
An old identifier does not establish that the record has remained unchanged either. Listing first provides both the identity needed for deletion and a before-state that an operator can examine later. Capture the zone identifier, record identity, type, name, content, and all returned attributes needed to reconstruct the entry. Associate that evidence with the onboarding attempt in the application audit trail before performing the destructive change. Cleanup must not erase its own explanation.
旧的标识符也不能证明该记录保持未变。先进行列出操作,既能提供删除所需的标识符,也能提供操作员稍后可以检查的前置状态。捕获区域标识符、记录标识符、类型、名称、内容以及重构条目所需的所有返回属性。在执行破坏性更改之前,将该证据与应用程序审计跟踪中的入驻尝试关联起来。清理工作绝不能抹除其自身的解释。
Make the deletion conditional on evidence Use four gates in the worker: establish the intended zone, list its records, select the exact type and name, and compare the selected entry with the approved content. Zero matches means there is no listed target to authorize. Two matches mean the selection is ambiguous. Neither condition permits a destructive guess. Even one match must be rejected if its content differs from the approved before-state.
使删除操作以证据为条件。在工作进程中使用四个门控:确定目标区域、列出其记录、选择确切的类型和名称,并将所选条目与批准的内容进行比较。零匹配意味着没有可授权的列出目标。两个匹配意味着选择存在歧义。这两种情况都不允许进行破坏性的猜测。即使只有一个匹配项,如果其内容与批准的前置状态不同,也必须拒绝删除。
This standalone Go program first retrieves the public discovery inventory for schema inspection, then checks a local review artifact. Its JSON fields belong to this example; they are not a vendor response schema. A provider adapter must produce the artifact from a complete listing and retain the original response separately. The program outputs the inventory on standard error and a candidate identity on standard output. It never issues a destructive request.
这个独立的 Go 程序首先检索公共发现清单以进行模式检查,然后检查本地审查工件。其 JSON 字段属于本示例;它们并非供应商的响应模式。提供商适配器必须从完整列表中生成该工件,并单独保留原始响应。该程序将清单输出到标准错误,将候选标识符输出到标准输出。它从不发出破坏性请求。
package main
import (
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
"time"
)
type Record struct {
ID string `json:"id"`
Type string `json:"type"`
Name string `json:"name"`
Content string `json:"content"`
}
type Review struct {
Zone string `json:"zone"`
ExpectedType string `json:"expected_type"`
ExpectedName string `json:"expected_name"`
ExpectedContent string `json:"expected_content"`
Records []Record `json:"records"`
}
func inspectDiscovery() error {
base := strings.TrimRight(os.Getenv("INFRAI_API_BASE"), "/")
key := os.Getenv("INFRAI_API_KEY")
if base == "" || key == "" {
return fmt.Errorf("set INFRAI_API_BASE and INFRAI_API_KEY")
}
client := &http.Client{Timeout: 15 * time.Second}
for attempt := 0; attempt < 3; attempt++ {
req, err := http.NewRequest(http.MethodGet, base+"/discovery", nil)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+key)
resp, err := client.Do(req)
if err != nil {
return err
}
body, readErr := io.ReadAll(resp.Body)
resp.Body.Close()
if readErr != nil {
return readErr
}
if resp.StatusCode == http.StatusTooManyRequests {
if attempt == 2 {
return fmt.Errorf("discovery rate limited after 3 attempts: %s", body)
}
delay := time.Second * time.Duration(1<<attempt)
retry := resp.Header.Get("Retry-After")
if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 {
requested := time.Duration(seconds) * time.Second
if requested > delay {
delay = requested
}
} else if deadline, err := http.ParseTime(retry); err == nil {
if requested := time.Until(deadline); requested > delay {
delay = requested
}
}
time.Sleep(delay)
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("discovery HTTP %d: %s", resp.StatusCode, body)
}
if !json.Valid(body) {
return fmt.Errorf("discovery returned invalid JSON")
}
_, err = fmt.Fprintln(os.Stderr, string(body))
return err
}
return fmt.Errorf("discovery retry limit reached")
}
func run() error {
if err := inspectDiscovery(); err != nil {
return err
}
var review Review
if err := json.NewDecoder(os.Stdin).Decode(&review); err != nil {
return fmt.Errorf("decode review: %w", err)
}
if review.Zone == "" || review.ExpectedType == "" || review.ExpectedName == "" || review.ExpectedContent == "" {
return fmt.Errorf("missing required approval evidence")
}
var matches []Record
for _, record := range review.Records {
if record.Type == review.ExpectedType && record.Name == review.ExpectedName {
matches = append(matches, record)
}
}
if len(matches) != 1 {
return fmt.Errorf("refuse deletion: expected 1 match, found %d", len(matches))
}
target := matches[0]
if target.ID == "" || target.Content != review.ExpectedContent {
return fmt.Errorf("refuse deletion: missing identity or changed content")
}
return json.NewEncoder(os.Stdout).Encode(struct {
Zone string `json:"zone"`
Before Record `json:"before"`
}{Zone: review.Zone, Before: target})
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Save this as main.go and run it with go run main.go, supplying the review JSON on standard input. Set INFRAI_API_BASE to the provider.
将此代码保存为 main.go 并使用 go run main.go 运行,通过标准输入提供审查 JSON。将 INFRAI_API_BASE 设置为提供商地址。