feat: implement license platform business flows and delivery tooling
Add admin and customer interfaces, orders, signed activation and leases, protected package delivery, keyring verification, migrations, security controls, tests and deployment documentation. Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
33
docs/activation-contract-draft.md
Normal file
33
docs/activation-contract-draft.md
Normal file
@@ -0,0 +1,33 @@
|
||||
# v5 实例激活与签名证书契约(DEV 草案)
|
||||
|
||||
## 管理员 API
|
||||
|
||||
- `POST /api/v1/licenses/{license_id}/instances`:需要管理员会话。服务生成 UUIDv4 `instance_id` 与 256-bit bootstrap secret;响应仅此一次返回 `secret`。数据库仅保存 SHA-256(secret),列表/详情永不返回 secret。
|
||||
- `GET /api/v1/licenses/{license_id}/instances`:需要管理员会话;只返回 instance_id、状态、激活时间、证书版本,不返回 secret、secret_hash、证书签名私密材料。
|
||||
- `GET /api/v1/activation/public-key`:返回 ECDSA P-256/SHA-256 公钥 PEM、证书版本和签名编码。
|
||||
|
||||
## 集成客户端 API
|
||||
|
||||
`POST /api/v1/activation/instances/{instance_id}`,无需管理员 Cookie。JSON 必须包含 `license_key` 和一次性提交的 `secret`;`Idempotency-Key` 必须为 1 至 128 个字符。服务端校验授权密钥、实例 secret、客户/产品归属、客户和产品启用状态、有效期和 issued 订单(若有关联)。成功返回 v1 certificate;secret 不在任何成功响应中回显。
|
||||
|
||||
同一实例和幂等键重放相同请求返回首次成功响应;改变 secret/license_key 或使用已激活实例返回 409/403。实例按数据库行锁串行化,一个实例最多成功激活一次。业务写入、幂等记录、审计事件同一事务,审计失败会回滚激活。
|
||||
|
||||
## 签名格式
|
||||
|
||||
Canonical payload 是 UTF-8、无 BOM、无尾随换行的固定顺序 `key=value` 行:
|
||||
|
||||
```text
|
||||
version=license-v1
|
||||
instance_id=00000000-0000-4000-8000-000000000001
|
||||
license_id=1
|
||||
customer_id=2
|
||||
product_id=3
|
||||
starts_at=2026-09-30T00:00:00Z
|
||||
expires_at=2027-09-30T00:00:00Z
|
||||
```
|
||||
|
||||
对完整 UTF-8 canonical bytes 做 SHA-256,再用环境注入的 P-256 ECDSA 私钥签名。signature 为 ASN.1 DER,base64 无填充。响应同时提供 `canonical_sha256`,便于跨语言测试向量定位。公钥只经接口发布;私钥不入数据库、日志或浏览器。
|
||||
|
||||
## 明确未实现
|
||||
|
||||
heartbeat、offline lease、冻结传播、实时撤销推送、租户隔离和离线授权均不属于本 v5 slice。证书签发不构成这些功能的模拟实现。
|
||||
56
docs/admin-modules.md
Normal file
56
docs/admin-modules.md
Normal file
@@ -0,0 +1,56 @@
|
||||
# 审计日志与系统设置
|
||||
|
||||
管理模块均要求有效的 `lp_session` 管理员会话;非管理员返回403,未登录返回401。写请求继续使用全局同源保护。
|
||||
|
||||
## 数据库
|
||||
|
||||
新增 `000009_admin_settings`:单例 `system_settings` 表以及审计时间/ID索引。当前服务要求 clean schema 9。启动服务不自动迁移。已有环境升级前备份并运行标准 migrate up,再启动新代码。down 会删除平台设置,需明确接受数据丢失后执行。
|
||||
|
||||
2026-10-09 本机仅升级独立开发库 `license_platform_local_261009`;原 `license_platform` 未修改。
|
||||
|
||||
## 审计日志
|
||||
|
||||
`GET /api/v1/audit-events` 返回 `{data: [...], meta:{page,page_size,total}}`。
|
||||
|
||||
支持 `page`、`page_size`(默认20,最大100)、`q`(邮箱/动作/资源类型包含查询,最多200字)、`action`、`resource_type`(精确匹配,最多64字节),以及 `from`、`to`(RFC3339时间,包含端点)。返回按时间、ID倒序,count和分页共享只读一致性快照。
|
||||
|
||||
记录字段:`id`、`actor_admin_id`、`actor_email`、`action`、`resource_type`、`resource_id`、`details`、`created_at`。详情仅允许已知业务字段;密码、会话令牌、实例凭据不提供。
|
||||
|
||||
已接入事件来自原有授权、订单、实例、版本发布/下载/门户业务审计,以及新增 `settings.updated`、`admin.password_changed`。这不是覆盖所有HTTP请求的访问日志;旧客户/产品CRUD、登录失败和命令行admin-init没有历史审计事件。实例产生的事件通过 `details.client_actor=instance` 区分;关联管理员字段来自既有业务归属规则。
|
||||
|
||||
审计只读,不提供编辑或删除接口。
|
||||
|
||||
## 系统设置
|
||||
|
||||
`GET /api/v1/settings` 和 `PUT /api/v1/settings` 使用 `{data:{site_name,support_email,announcement,updated_at}}`。PUT提交三个文本字段;平台名称1至100字、联系邮箱可空且最多254字节、公告最多2000字。所有管理员共享;更新时间由服务端生成。设置更新和不包含文本内容的审计记录同事务提交。
|
||||
|
||||
这些是展示配置,不控制TLS、签名密钥、数据库、限流器和授权有效期;运行参数仍由服务进程环境配置。
|
||||
|
||||
`POST /api/v1/settings/password` 提交 `{current_password,new_password}`,成功204。必须验证当前密码,新密码非空、最多72字节,无复杂度要求。更新bcrypt哈希、撤销该管理员其他会话、写入不含密码的审计记录同事务提交;当前会话保留。
|
||||
|
||||
## 日期时间展示
|
||||
|
||||
前端业务时间统一通过 `frontend/src/date-format.ts` 的 `formatDateTime` 展示,格式为 `YYYY-MM-DD HH:mm:ss`,按浏览器所在时区换算,使用24小时制。License 列表及详情、实例、订单详情、客户门户、审计时间和设置更新时间均采用此约定;缺失或无效时间显示 `—`,部分业务保留“未确认”“暂无租约”“尚未更新”等提示。审计详情中的原始 JSON 保留接口时间值,方便排查。
|
||||
|
||||
API 的 RFC3339 时间传输及 UTC 存储语义保持不变;审计本地时间筛选仍转换为 UTC 提交,仪表盘月份统计继续使用 UTC。新增页面展示业务时间时复用统一函数,不直接输出原始 ISO 字符串。
|
||||
|
||||
## 验证
|
||||
|
||||
后端单元测试覆盖设置边界、审计敏感字段过滤、筛选时间范围及未认证请求。独立开发库真实接口验证覆盖迁移、设置写入读取、非法参数、错误当前密码、密码修改、其他会话撤销、当前会话保留、审计筛选。验证后管理员密码恢复为原来的本地开发密码。
|
||||
|
||||
|
||||
## 多管理员与用户名登录(schema 10)
|
||||
|
||||
管理台登录提交 `{username,password}`,不再使用邮箱登录。用户名统一去除首尾空格并转换为小写,允许 3–32 位字母、数字、下划线和短横线。邮箱作为唯一联系信息保留。现有管理员迁移后用户名为 `admin-{id}`,密码保持原值。
|
||||
|
||||
管理员账户页面 `/admins` 支持列表、新增、启用、停用、密码重置。所有管理员拥有同等后台权限。不能停用当前登录账户;停用账户和重置密码均撤销目标账户的所有会话。自身修改密码仍通过设置页面完成,保留当前会话。账号操作与审计写入同一事务,密码与哈希不会返回或写入审计详情。
|
||||
|
||||
接口:`GET /api/v1/admins`、`POST /api/v1/admins`(username/email/password)、`POST /api/v1/admins/:id/active`(active)、`POST /api/v1/admins/:id/reset-password`(password)。用户名或邮箱重复返回 409。
|
||||
|
||||
新部署先迁移到 schema 10,然后初始化:
|
||||
|
||||
```sh
|
||||
go run ./cmd/admin-init -username admin -email admin@example.test -password 'YOUR_PASSWORD'
|
||||
```
|
||||
|
||||
初始化命令按邮箱识别已有账户,用户名冲突将报错,不会重置另一个账户。重新初始化会撤销该账户的旧会话。已有部署只执行迁移即可,不需要重置密码。原始业务数据库没有在本次开发中迁移;本地隔离数据库的既有账号为 `admin-1`,密码保持 `123456`。
|
||||
28
docs/business-contract-draft.md
Normal file
28
docs/business-contract-draft.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# 基础管理台契约草案(待业务确认)
|
||||
|
||||
状态:实现用临时契约,不代表业务签字、正式 OpenAPI 或授权规则冻结。
|
||||
|
||||
## 本阶段开发假设
|
||||
|
||||
- 首个管理界面仅供内部管理员使用;管理员账号由部署操作者通过一次性命令初始化,不开放公网自助注册。
|
||||
- 当前只有 `admin` 角色;服务端对所有主数据接口强制检查有效会话与 admin 角色。未来角色/权限需由业务签字后细分。
|
||||
- 管理员以邮箱标识,bcrypt 哈希密码;服务端仅保存随机会话令牌 SHA-256 摘要。会话固定 8 小时,登出即时撤销。
|
||||
- 客户暂用名称、联系邮箱、active/inactive 状态;产品暂用唯一编码、名称、说明、启用标志。
|
||||
- 客户列表分页参数为 page/page_size,默认 1/20、每页上限 100,可按名称或邮箱搜索。
|
||||
- 删除当前为物理删除,仅适用于无授权关联的基础数据阶段。建立授权关联后必须重新决策为软删除/停用或限制删除。
|
||||
- 默认仅绑定 loopback。任何实际环境必须使用 HTTPS、受控网络和备份;不提供生产部署验收。
|
||||
- v4 DEV 假设:线下订单是一客户、一产品、一笔 CNY 整数分金额;状态为 `pending_payment -> paid -> issued`。录单、收款确认、一次性发放仅允许 admin,服务端锁定并校验 customer/product active 状态。
|
||||
- v4 DEV 状态机:仅 `pending_payment` 可确认收款,实收金额必须等于订单金额;仅 `paid` 可发放一次授权;撤销/退款、作废、审批驳回不在本切片执行。
|
||||
- v4 DEV 幂等:每个订单操作要求 `Idempotency-Key`,同一管理员/操作/键匹配请求重放首次响应,指纹冲突返回 409;订单、授权、操作状态和 audit_events 同一事务提交。
|
||||
- v4 DEV 权限:当前统一 admin 门禁;审批角色、财务确认角色、退款角色和客户/租户范围尚未冻结。
|
||||
- v4 DEV 时间:发放请求显式提供 RFC3339 UTC 开始/结束时间,结束必须晚于开始且在 MySQL TIMESTAMP 范围;续期起始日是否允许早于当前时间仍待确认。
|
||||
|
||||
## 错误响应草案
|
||||
|
||||
业务错误统一为 `{"error":{"code":"...","message":"..."}}`。登录失败统一返回 401,不区分账号不存在和密码错误。未经认证返回 401,权限不足返回 403,字段校验错误 400,重复编码等冲突 409。
|
||||
|
||||
## 尚未确认
|
||||
|
||||
订单正式状态机及订单号规则、套餐/价格快照、支付渠道与对账、收款凭据格式、发放审批角色、renewal start-date 规则、退款后授权撤销/回收关系、跨客户/产品租户范围、财务报表口径均为可替换 DEV 假设,等待 T01/T02 正式确认。
|
||||
|
||||
管理员组织/租户归属、多管理员邀请与恢复流程、完整 RBAC 权限矩阵、客户身份唯一性及字段、产品版本/套餐/生命周期、删除/审计保留规则、锁定与速率限制策略、会话空闲续期、正式 API/OpenAPI/error catalog,均待产品、安全和接入负责人确认。授权激活、心跳、续期、退款、克隆、实例绑定规则不在本阶段实现。
|
||||
15
docs/business-quickstart.md
Normal file
15
docs/business-quickstart.md
Normal file
@@ -0,0 +1,15 @@
|
||||
# 本地基础管理台运行
|
||||
|
||||
开发阶段需本机 Go 1.23+、Node 20+、npm 与 Docker。
|
||||
|
||||
1. 启动专用 MySQL:`docker run -d --name license-platform-mysql-app -e MYSQL_ROOT_PASSWORD=<本地临时密码> -e MYSQL_DATABASE=license_platform -p 13307:3306 mysql:8.0`
|
||||
2. 在 `backend` 设置 `MIGRATION_DSN='mysql://root:<密码>@tcp(127.0.0.1:13307)/license_platform?multiStatements=true'` 和 `MYSQL_DSN='root:<密码>@tcp(127.0.0.1:13307)/license_platform?parseTime=true'`。
|
||||
3. 执行 `go run ./cmd/migrate -dsn "$MIGRATION_DSN" -dir ./migrations up`。
|
||||
4. 交互式输入密码初始化管理员,避免密码落入 shell history(当前命令行参数仍可能被本机进程查看,生产初始化需改为安全输入通道):`read -rsp 'Admin password: ' ADMIN_PASSWORD; echo; go run ./cmd/admin-init -dsn "$MYSQL_DSN" -email admin@example.test -password "$ADMIN_PASSWORD"; unset ADMIN_PASSWORD`。密码只要求非空,允许简单数字密码(例如 `123456`),不要求大小写或特殊字符;最多 72 字节。重复初始化同一邮箱会重置密码并启用账号。不要在共享机器使用本文示例邮箱。
|
||||
5. 启动后端:`HTTP_ADDR=127.0.0.1:18081 MYSQL_DSN="$MYSQL_DSN" go run ./cmd/server`。
|
||||
6. 新终端启动前端:`cd frontend && npm run dev -- --port 15173`,访问 `http://127.0.0.1:15173/`。
|
||||
|
||||
管理员登录后可新增、搜索、删除客户和新增、查看、删除产品;选择 active 客户和产品、填写开始/结束时间后可签发期限授权并分页查看。迁移需要 version 2 clean,见 `license-contract-draft.md`(DEV-LICENSE-v0.1)。客户下拉目前使用当前搜索结果的第一页,超过 20 条需要搜索定位。已有授权引用的主数据不可物理删除。后端目前也提供客户/产品 PUT 接口,编辑表单尚未接入。开发本地 HTTP Cookie 不设 Secure;直接 TLS 请求设 Secure,不信任任意 X-Forwarded-Proto。TLS 终止代理部署的 Secure Cookie 策略尚未配置,不能直接按此启动方式投入生产。生产使用 HTTPS、明确可信代理边界,并遵循组织密钥管理、数据库备份及安全运维流程。本快速启动不构成生产部署指南或 UAT。
|
||||
|
||||
|
||||
管理员登录现使用用户名和密码。schema 10 迁移后既有账户用户名为 `admin-{id}`;新初始化可指定 `-username admin`(默认 admin)。后台“管理员账户”页面支持新增、启停与密码重置,详见 [管理员模块](admin-modules.md)。
|
||||
34
docs/client-integration-center.md
Normal file
34
docs/client-integration-center.md
Normal file
@@ -0,0 +1,34 @@
|
||||
# 客户端接入中心
|
||||
|
||||
管理员登录后进入 `/integration`,选择 Python、Go、Java、.NET 或 Node.js,以及桌面、常驻服务或容器模式。页面提供接口清单、可复制工程提示词、完整协议、安全约束、字段示例和 ZIP/Markdown 下载。首版交付生成资料,不包含五种语言已经实现并完成生产验收的 SDK。
|
||||
|
||||
SDK 与工程提示词默认使用 `https://license.yihuiyong.cn` 作为授权平台根地址;部署可以通过 `LICENSE_API_BASE_URL` 覆盖。该值必须是根地址,不能附加 `/api/v1`。协议、OpenAPI、Markdown 与 ZIP 内的资料都使用相同默认值。
|
||||
|
||||
## 管理员接口
|
||||
|
||||
以下 GET 路由使用现有管理员会话保护,不属于外部客户端运行 API:
|
||||
|
||||
- `/api/v1/integration-kit?language=python&mode=service`:JSON 资料。
|
||||
- `/api/v1/integration-kit/download?language=python&mode=service`:UTF-8 Markdown,包含选定提示词、协议和字段示例。
|
||||
- `/api/v1/integration-kit/archive?language=python&mode=service`:ZIP,包含 README.md、protocol.md、openapi.json、prompt.md、test-vectors.json。
|
||||
|
||||
省略参数默认 python/service。未知语言或模式返回 400,不接受文件路径参数。下载使用 no-store,文件名按受控语言/模式生成。无需新数据库表,不包含任何真实实例 secret、数据库凭据或生产私钥。
|
||||
|
||||
每次 ZIP 下载为测试向量生成独立随机 P-256 密钥,返回公钥及 license-v2/lease-v2 的有效 DER ECDSA 签名、固定规范化内容及 SHA-256。私钥仅在生成时的内存中使用,不输出,不落盘。向量使用固定历史时间,时间相关测试必须使用给定固定 now;生产不得信任测试公钥。
|
||||
|
||||
## 协议维护
|
||||
|
||||
协议源文件在 `backend/internal/httpapi/integration_assets/protocol.md`,OpenAPI 3.0.3 在同目录 `openapi.json`,由 Go embed 嵌入二进制。修改接口实现时必须同时核对这两个文件,重新构建后端后生效。`client/verify.mjs` 提供 v2 验签与运行状态算法参考。
|
||||
|
||||
选择语言会加入对应加密库、HTTP/取消/状态存储/测试要求;运行模式在提示词中明确,完整协议包括桌面/服务/容器的身份和持久化约束。页面请求使用序列号忽略旧请求返回,避免快速切换后显示过期资料。
|
||||
|
||||
部署方须确认 keyring 已配置并通过受控渠道交付公钥;legacy v1 默认部署不满足本资料要求。keyring 发现不是信任引导。14 天离线租约意味着冻结/撤销最多可延迟 14 天生效,不能宣传立即离线撤销或硬件防克隆。Kubernetes 集群代理、移动设备、CI 临时身份、完全离线授权需要额外方案。
|
||||
|
||||
## 验证记录
|
||||
|
||||
- 后端 `go test ./...` 与 `go vet ./...` 通过。新增测试检查三个管理员接口未认证均为 401、非法选择 400、五种语言提示、OpenAPI JSON、ZIP 五文件及两类签名/篡改失败。
|
||||
- 前端类型检查、12 个测试文件共 33 项测试、生产构建通过。新增面板测试检查加载/失败/选择更新及下载参数,路由测试包括 `/integration`。
|
||||
- 使用隔离数据库 `license_platform_local_261009` 的真实管理员会话:JSON 与 ZIP 下载均 200,ZIP 包内容与 no-store 响应头已核对。
|
||||
- 浏览器实际切换 .NET:专属 DER 格式提示与下载 URL 更新。390×844 窄屏无整体横向溢出,控制台 0 error。
|
||||
|
||||
未迁移或修改原业务数据库,未提交或推送代码。现有大包构建提示与旧测试的组件 stub 警告仍存在。全仓 `git diff --check` 的两项旧文档末尾空行不在本次功能范围内。
|
||||
53
docs/deployment-delivery.md
Normal file
53
docs/deployment-delivery.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# Deployment delivery rehearsal
|
||||
|
||||
Status: development scaffolding, not production accepted. Existing API 18081 is not restarted by this work. Do not reuse its in-memory signing key lifecycle for deployment.
|
||||
|
||||
## Files and configuration
|
||||
|
||||
The root compose.yaml builds deploy/Dockerfile.api and deploy/Dockerfile.web. Only the web port is bound to host loopback (18083). MySQL, Redis, API and package storage have no published host ports. The private service network is internal. Redis is optional under the `cache` profile; the API currently does not use Redis for sessions or rate limiting.
|
||||
|
||||
Set these non-secret environment paths externally (not secret values in .env): MYSQL_APP_SECRET_FILE, MYSQL_ROOT_SECRET_FILE, LICENSE_SIGNING_KEY_HOST_FILE, PACKAGE_STORAGE_HOST. All refer to protected, pre-existing absolute host paths outside Git and the build context. App DB password must be a randomly generated URL-safe value using letters, digits, underscores and hyphens. The image reads it at runtime, never logs it; driver DSNs remain process environment secrets. Compose local secrets are bind mounts, not an encrypted secret manager. Secure their host ACLs, process access, backups and crash dumps.
|
||||
|
||||
The package directory must be writable by API UID 10001 and readable by Nginx, on a filesystem supporting hard links. Nginx mounts it read-only, serves it only through an internal location, disables directory listing and symlinks. Do not put it in the frontend/public tree. The API is non-root with read-only rootfs, all capabilities dropped and no-new-privileges; this is not a complete container-hardening assessment.
|
||||
|
||||
Run from the repository root, using an independent Compose project/database and protected persistent key:
|
||||
|
||||
```sh
|
||||
docker compose config --quiet
|
||||
docker compose build
|
||||
docker compose up -d mysql
|
||||
# Optional only: docker compose --profile cache up -d redis
|
||||
docker compose --profile tools run --rm migrate
|
||||
docker compose up -d api web
|
||||
```
|
||||
|
||||
Migrations are explicit; startup never migrates. The migration profile uses the development app account, which also has DDL privileges in this local profile. Production needs separate least-privilege runtime and migration accounts. No administrator account/password is created by Compose. Stop/restart only this rehearsal project, never the existing 18081 process. Do not run down -v against retained data.
|
||||
|
||||
## Operations slice
|
||||
|
||||
See [operations-security.md](operations-security.md) for JSON logging, optional loopback metrics, local per-process entry limits, cookie/origin/body controls and CI evidence. New server main exposes only liveness publicly; readiness and metrics use numeric-loopback METRICS_ADDR (Compose 19090). Redis Lua shared entry limits are now default, with runtime failure returning 503 and no automatic fallback; local-dev must be explicitly selected for controlled development. ENTRY_REDIS_ADDR must be a numeric private/loopback IP; ENTRY_REDIS_PASSWORD_FILE optionally injects a protected absolute password file. Production Redis TLS/ACL/HA/capacity remain gates; the current Compose cache profile is not automatically wired to the API. Two isolated new API subprocess starts passed key-continuity and internal HTTP checks; unchanged 18081 still runs old source. See the release-gate update in operations-security.md for evidence limits.
|
||||
|
||||
## TLS, proxy trust and Redis
|
||||
|
||||
The loopback HTTP listener is for local rehearsal, not internet exposure. `deploy/nginx/tls-proxy.conf.example` is an example requiring managed CA certificates mounted read-only; it is deliberately not enabled by default and contains no development/self-signed key. Production must restrict upstream reachability, set `SESSION_COOKIE_SECURE=true`, and set `HTTP_TRUSTED_PROXY_CIDRS` to exact proxy source CIDRs only. Config rejects malformed CIDRs and `0.0.0.0/0`/`::/0`; Gin trusts no proxies by default. Nginx overwrites forwarded headers rather than forwarding client-supplied values. Direct TLS also sets Secure. Automated unit tests cover forced Secure and reject treating a bare X-Forwarded-Proto header as trusted. TLS deployment wiring, real certificate verification, ingress restrictions, CSRF/origin controls and end-to-end proxy spoof tests remain outstanding.
|
||||
|
||||
Redis is optional and not used by the current API for sessions, rate limits, or authoritative state. It is under Compose profile `cache`; API startup/readiness does not depend on it. Do not claim Redis-backed behavior.
|
||||
|
||||
The API has `/api/v1/health/live` for process liveness and `/api/v1/health/ready` for database connectivity plus exactly one clean migration row at schema version 8. Startup refuses a database that cannot be pinged or is not exactly at clean version 8; startup never migrates. Readiness returns only generic 503 on DB/schema failure, without internal error details. Compose API/web health checks use readiness. Unit tests cover unavailable DB, no migration row, old/future version and dirty schema; full Compose fault injection is pending. Load/capacity testing, pre-auth rate limiting, pinned image digests and vulnerability remediation remain open.
|
||||
|
||||
## Backup and restore
|
||||
|
||||
`scripts/backup-delivery.sh` creates a MySQL logical dump and deterministic tar of private package storage with checksums. Run only during a maintenance window that quiesces uploads and administrative writes: MySQL `--single-transaction` does not make a filesystem snapshot atomic with SQL. Protect/encrypt the destination and record schema version/checkpoint separately. Signing keys are intentionally excluded; recover them separately from protected secret management, never from SQL or these scripts. Redis is optional and holds no authoritative platform data.
|
||||
|
||||
`scripts/restore-delivery.sh` requires `CONFIRM_EMPTY_RESTORE=YES` and independently refuses both nonempty package directories and databases containing tables. YES does not bypass either check. Supply only a trusted backup and an isolated empty DB/private directory with no listener; the script does not validate arbitrary or malicious SQL/tar inputs. After restore, run explicit migration/version checks and compare all `product_releases`/`package_objects` references, file size/SHA-256 and key fingerprint before any traffic. The restore command is not a substitute for application-level reconciliation. Scripts use MySQL CLI and protected `MYSQL_PASSWORD_FILE`; ensure the image/host has mysql client tools. A minimal isolated dump/restore drill has passed; full-platform reconciliation, production recovery objectives, encrypted backup handling and a complete application recovery drill remain pending.
|
||||
|
||||
## Executed evidence (2026-09-30)
|
||||
|
||||
- docker compose config --quiet: passed with placeholder external paths; no real secrets were printed.
|
||||
- Web image build: passed, including npm ci and typecheck/Vite build. npm reported two moderate dependency vulnerabilities; no forced upgrade performed. Existing 1.13 MB bundle warning remains.
|
||||
- API image build: NOT passed. Earlier attempts failed on a base-image layer and DNS. The latest retry resolved proxy.golang.org but TCP/443 was refused during go mod download. No fallback registry or weakened checksum verification was configured.
|
||||
- Full Compose start, migration and admin/login smoke: NOT executed. API image remains blocked by outbound Docker network refusal to proxy.golang.org; no local Go module cache image was available. Protected deployment inputs are not provisioned.
|
||||
- Readiness unit tests passed for clean v8, old/future/dirty/empty/unavailable schema and nil DB; startup schema gate now requires exactly version 8 clean. Compose config with protected placeholder paths passed and uses readiness healthchecks. Redis is now an explicit optional `cache` profile because the current API does not use it.
|
||||
- Isolated backup/restore rehearsal passed in a disposable MySQL 8.0 container: logical dump plus package tar checksums verified, restored schema row was 8 clean, package object size/digest and restored file SHA-256 matched. The signing key was excluded. The final restore used a new empty `license_restore_empty` database and an empty private directory; a second attempt against the nonempty database was rejected. This used a minimal synthetic dataset, not the full business database. Rehearsal containers were stopped; business MySQL and 18081 were untouched.
|
||||
- Independently executed isolated MySQL/Nginx download integration: passed actual bytes/digest, Range 206, internal-path 404 and unauthenticated denial, plus expired/unpublished/missing release denial audits. This is not equivalent to full Compose acceptance.
|
||||
- Go test/vet, npm test (10 cases), npm build: passed. Manual logged-in browser acceptance remains separate and pending.
|
||||
32
docs/download-contract-draft.md
Normal file
32
docs/download-contract-draft.md
Normal file
@@ -0,0 +1,32 @@
|
||||
# Local release/download DEV slice
|
||||
|
||||
Status: in progress, not ready for formal acceptance. U07 resumable chunk upload, crash/orphan reconciliation, formal key rotation and authenticated browser acceptance remain incomplete.
|
||||
|
||||
## API
|
||||
|
||||
- Admin GET `/api/v1/products/:id/releases?page=1`: paginated metadata, no physical storage path/key.
|
||||
- Admin POST `/api/v1/products/:id/releases?version=...`: raw binary, 1 byte through 64 MiB. SHA-256 content address; transactional publication metadata/audit. Apply migrations 007 and 008 before starting this code.
|
||||
- Instance POST `/api/v1/customers/:customer_id/releases/:id/download`: JSON instance ID/secret. Current customer/product entitlement, freeze/revocation and instance ownership checked before transactional audit and X-Accel-Redirect. Secret must not appear in URLs.
|
||||
- Downloads use POST with Range headers; clients must repeat credentials for every resumed request. Not a public download URL.
|
||||
|
||||
## Storage and consistency
|
||||
|
||||
`PACKAGE_STORAGE_ROOT` must be an absolute trusted non-public existing directory writable only by the application/storage owner. Digest keys are 64 lowercase hex characters plus `.bin`. Package symlinks are rejected. Directory modification by an untrusted process is outside the safe operating boundary; Nginx also disables symlinks.
|
||||
|
||||
Migration 008 package_objects rows serialize same-digest writes across products. New files are removed for metadata/audit failure before rollback. A commit acknowledgement failure or process crash can leave an unreachable object; preserve it for reconciliation rather than risking deletion of an actually committed package. No crash recovery/automatic garbage collection claim is made.
|
||||
|
||||
## Executed evidence (2026-09-30)
|
||||
|
||||
Dedicated `license_download_260930` database migrated to 008; no destructive cleanup of normal development data.
|
||||
|
||||
`TestDownloadsMySQLIntegration`: customer/product isolation, bad secret, freeze/revoke/customer inactive/product inactive, unauthenticated publication, audit failure blocking redirect and publication, failure file cleanup, concurrent cross-product same digest, conflicting version, empty file, 67108864-byte success and 67108865-byte denial passed.
|
||||
|
||||
Linux container `TestLocalPackageRejectsTraversalAndSymlink` passed without skip.
|
||||
|
||||
Isolated Nginx stable-alpine on http://127.0.0.1:18181 with temporary API 18082: authenticated exact bytes and SHA256 header matched; Range bytes=0-6 returned 206 with `package`; guessed internal path 404; empty credentials 400. Container and temporary API stopped after automated test. Configuration: deploy/nginx/download-local.conf, storage read-only mounted at /srv/license-packages; no unrelated Nginx modified.
|
||||
|
||||
Frontend release list/upload panel compiled; existing frontend tests/build passed, existing bundle-size warning remains. Authenticated browser upload/list/instance interaction needs user login at http://127.0.0.1:15173.
|
||||
|
||||
## Runtime/key boundary
|
||||
|
||||
Existing development 18081 remains v6, development database remains 007; 008 and new code have not been applied to that runtime. Its ephemeral signing key cannot be recovered through supported APIs. Do not rerun the old launcher, since it silently generates a different key. Upgrade requires protected persistent key injection and an explicit decision concerning old DEV certificates/leases, or coordinator approval for deliberate test-only key rotation. See signing-key-operations.md. No private key saved or logged.
|
||||
53
docs/heartbeat-lease-contract-draft.md
Normal file
53
docs/heartbeat-lease-contract-draft.md
Normal file
@@ -0,0 +1,53 @@
|
||||
# v6 心跳、租约、冻结传播(DEV 草案)
|
||||
|
||||
未经 T01/T02 签字,不代表正式产品策略或 UAT 验收。
|
||||
|
||||
## API 与认证
|
||||
|
||||
客户端 `POST /api/v1/instances/{instance_id}/heartbeat`,JSON `{ "secret": "<bootstrap secret>", "client_time": "<RFC3339>" }`,必须带 `Idempotency-Key`。只用 instance_id + secret 认证,解码 32-byte base64url secret 并比较 SHA-256;不记录、不回显明文。请求体最多 4096 bytes。
|
||||
|
||||
管理员 `POST /api/v1/instances/{instance_id}/freeze`,JSON `{ "frozen": true|false }`,必须带管理员 Cookie 与 Idempotency-Key。冻结状态和操作/audit 同事务。冻结不篡改已发租约时间,也不模拟主动推送。
|
||||
|
||||
每实例成功心跳间隔至少 60 秒,429 提供 Retry-After。新状态传播不受正常限频限制。相同键/相同 client_time 返回首次成功响应且不更新 last_seen;改变载荷 409。若冻结/撤销等状态变化,则旧成功响应重放返回 409 state_changed,客户端必须新键重试。
|
||||
|
||||
## 状态与时间
|
||||
|
||||
成功响应 data.payload:version、instance_id、state、server_time、entitlement_expires_at、lease_expires_at;附 signature、canonical_sha256、algorithm、next_heartbeat_seconds。
|
||||
|
||||
- `active`:lease_expires_at = min(server_time + 14 天, entitlement_expires_at)。权益截止独立于租约;远期/永久式权益绝不产生永久离线权限。现有数据库只支持有期限权益,真正 null 永久权益尚未实现。
|
||||
- `frozen`、`revoked`、`expired`、`pending`、`not_activated`:不给新使用权限,lease_expires_at = server_time。撤销优先于冻结。
|
||||
- DEV 假设:联网收到签名冻结/撤销立即停用并清除允许缓存。离线无法获知新的冻结/撤销,旧租约可用至原截止,且最长 14 天;不得声称即时离线撤销。
|
||||
- 时间以服务端 MySQL UTC_TIMESTAMP(6) 为准;客户端绝对偏差/相对前次时间回拨超过 5 分钟返回 409 clock_skew。服务端较 last_seen 回拨超过 5 分钟暂停签发;容差内高水位单调不降。
|
||||
- 客户端必须验签、核对实例和版本、只接受 active 状态,校验 now < lease_expires_at 且 now < entitlement_expires_at,校验租约跨度 <=14 天,并持久化可信时间高水位/单调时间;本切片没有客户端执行器,不承诺对系统时钟篡改或存储回滚的完整防护。
|
||||
|
||||
last_seen、租约、observed_state、幂等响应和 audit 同事务。审计 actor 暂借实例 provisioner 外键,details 标明 client_actor=instance,正式客户端主体模型待确认。
|
||||
|
||||
## Canonical / 跨语言公开向量
|
||||
|
||||
UTF-8,无 BOM、无尾换行,固定顺序如下。SHA-256 后以 P-256 ECDSA 签名,ASN.1 DER / base64 无填充;公钥是 SPKI PEM。公钥与签名均为公开测试材料,随机生成私钥不持久化。
|
||||
|
||||
```text
|
||||
version=lease-v1
|
||||
instance_id=00000000-0000-4000-8000-000000000001
|
||||
state=active
|
||||
server_time=2026-09-30T12:00:00Z
|
||||
entitlement_expires_at=2036-09-30T12:00:00Z
|
||||
lease_expires_at=2026-10-14T12:00:00Z
|
||||
```
|
||||
|
||||
SHA-256: `777150ed1107b51f17dd1ffaefac303310a32ec415e3d83a4b16cb05b9aac379`
|
||||
|
||||
Signature: `MEQCIFHuseC8F3iv6Jz9W3yywkacJ5qBOcDRJSNFLdFWS2w9AiBRZEmPGOzti3IJ0VOPccUOmmtVfWs6ZxtjcSDKJLH8BQ`
|
||||
|
||||
```pem
|
||||
-----BEGIN PUBLIC KEY-----
|
||||
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEz39VZCPp0fPgbDhKOM0jUHqzJAe3
|
||||
7GSZpcSe1TO9UGqv8BO3PBI8Th3Z9Fy5EdPaVggh8V/pjW/dcsUg9QbzWA==
|
||||
-----END PUBLIC KEY-----
|
||||
```
|
||||
|
||||
任何一个字段被篡改必须验签失败;license-v1 激活证书不能替代 lease-v1 租约。
|
||||
|
||||
## 明确阻塞
|
||||
|
||||
克隆检测、实例迁移、扩容、真正永久权益、客户端可信存储/执行器、密钥轮换 key_id、分布式入口限流、异常激活监测、缓存推送失效、正式策略签字及 UAT 尚未实现。不得以当前 instance secret 认证声称防克隆。
|
||||
37
docs/keyring-client-contract-draft.md
Normal file
37
docs/keyring-client-contract-draft.md
Normal file
@@ -0,0 +1,37 @@
|
||||
# DEV-KEYRING-v2 / client execution draft
|
||||
|
||||
Status: configurable development implementation, not T01/T02-approved production protocol. Existing 18081 unchanged. No commits/releases.
|
||||
|
||||
## Environment and wire format
|
||||
|
||||
LICENSE_KEYRING_FILE is an absolute JSON file (regular file, <=64 KiB). Structure:
|
||||
|
||||
```json
|
||||
{"current_key_id":"release_2026_10","keys":[{"key_id":"release_2026_10","public_key_pem":"PUBLIC PEM ONLY","revoked":false},{"key_id":"previous","public_key_pem":"PUBLIC PEM ONLY","revoked":false}]}
|
||||
```
|
||||
|
||||
The current private key still comes exclusively from existing protected LICENSE_SIGNING_PRIVATE_KEY_FILE or the existing PEM injection mechanism; do not put private keys in the keyring. Each unique key ID uses [a-zA-Z0-9_-]{1,64}. Maximum 32 entries. Current entry must exist, be non-revoked, be P256 and match the private key or startup fails. Retired verification-only entries need no private key.
|
||||
|
||||
With keyring configured, NEW certificates use license-v2 and NEW heartbeat leases use lease-v2. The existing fixed canonical v1 field order is retained, with the new version and a final newline followed by key_id=<ID>. No trailing newline. SHA256, ECDSA P256, ASN.1 DER signature, raw standard base64 (no padding). key_id belongs INSIDE payload and is signed. IDs in Node are positive safe integers; client rejects larger numeric IDs rather than accepting rounded JSON integers. RFC3339 UTC times remain exact signed text, not reformatted by client.
|
||||
|
||||
Without keyring, old v1 signing remains for development compatibility. The new client intentionally refuses all v1 payloads. /api/v1/activation/keyring exposes public metadata, but is discovery ONLY; never trust it automatically. Public keys and revocation policy must be pinned/distributed through a separately authenticated deployment path. Unknown/revoked key fails closed. A revoked signing key cannot be current.
|
||||
|
||||
## Migration and rollback
|
||||
|
||||
No historical SQL migration changed and no new schema migration required: certificate_payload and operation response JSON persist version and key_id; certificate_version stores v2. Existing idempotent activation/heartbeat operations replay original responses without re-signing, including v1. Retry with the SAME idempotency key, never assume replay upgrades a certificate.
|
||||
|
||||
Stage clients and pinned old+new keys BEFORE switching the API current key. Keep old unrevoked PUBLIC key for the full approved historical certificate/lease lifetime, then retire only after explicit lifecycle review. Do not overwrite key IDs with different public keys. Server validates current configuration only; deployment approval must enforce key ID immutability/history. Runtime reload is NOT supported; use approved rolling deployments with persistent protected injection. No current production key was generated or rotated.
|
||||
|
||||
Rollback is configuration/software rollout, not business-data down migration: restore previous API image plus its matching current private key and public keyring while preserving public keys needed for already-issued v2 payloads. Rolling back to a v1-only binary DOES NOT make v2 artifacts verifiable by old clients. Do not delete stored responses/certificates or force schema version. Preserve quiesced backup, issued artifacts and approvals. Formal retention windows, emergency revocation publication, config generation monotonicity and live business rotation drill remain gates.
|
||||
|
||||
## Independent client module
|
||||
|
||||
client/verify.mjs is a Node server-side reference package, NOT the management console and NOT a deployed customer integration. No instance secret/session stored by this module. verifyEnvelope takes caller-pinned keys, rejects unknown/revoked, altered key_id or payload. acceptLease verifies instance binding, signed state, entitlement bound, max14-day lease, 5-minute server skew, monotonic client/server milliseconds. canRunOffline checks previously accepted lease until expiration. Caller must atomically persist returned state BEFORE enabling licensed work, update local high-water before EVERY subsequent execution, protect it from tampering and disable on all errors. This does not resist privileged cloning, disk snapshot rollback or clock manipulation by host owner; monotonic trusted time/storage design still requires T01 approval. Millisecond comparison loses sub-ms precision; server-issued microsecond exact ordering and replay digest persistence are future hardening gates.
|
||||
|
||||
Go test TestKeyringCrossLanguageRotation generates public Go->Node vectors with ephemeral private keys only in memory. Checks old/current certificate verification, revoked/unknown rejection, signed key substitution/payload tamper rejection, lease verification, instance mismatch, local/server high-water rollback, offline expiry. No private test fixture committed. This is cross-language component evidence, not authenticated activation/heartbeat rotation E2E. Node required for backend tests; CI explicitly installs Node24.
|
||||
|
||||
## Integrator API / customer portal boundary
|
||||
|
||||
Provisioning remains administrator-only POST /api/v1/licenses/:id/instances, returning a one-time secret that must reach the authorized integrator via secure channel. Client activation POST /api/v1/activation/instances/:instance_id uses secret + license_key and Idempotency-Key. Heartbeat POST /api/v1/instances/:instance_id/heartbeat uses secret + client_time and Idempotency-Key; follow the current heartbeat draft field contract. Download POST /api/v1/customers/:customer_id/releases/:id/download uses existing credential draft and Nginx internal handoff. No secret belongs in query strings/logs/browser localStorage. Timeouts/429 use bounded backoff; 403/409 must not silently reactivate, bypass checks or reuse mismatched payloads.
|
||||
|
||||
There is NO customer-account authentication domain or customer portal in the current implementation. The Vue UI is administrator management only. T25 remains unstarted, pending tenant identity/account reset/RBAC/renewal contracts. Do not build an unauthenticated customer-data page using administrator cookies or pretend this module is a customer portal. Minimum future portal: customer login/session isolation, only-own licenses/orders/leases/releases, no administrator routes, secure secret delivery/recovery, expiry/renewal requests, logout/reset and tenant-negative tests.
|
||||
10
docs/license-contract-draft.md
Normal file
10
docs/license-contract-draft.md
Normal file
@@ -0,0 +1,10 @@
|
||||
# 授权签发闭环草案
|
||||
|
||||
版本:DEV-LICENSE-v0.1(2026-09-30)。状态:开发假设,未替代正式业务决策或 OpenAPI 签字。
|
||||
|
||||
- 当前授权是后台管理员为 active 客户和 active 产品签发的一条期限记录。
|
||||
- `starts_at` 和 `expires_at` 必须是 RFC3339 时间,服务端转 UTC 保存;结束时间必须晚于开始时间,精度为微秒;当前 TIMESTAMP 存储范围限定为 1970-01-01T00:00:01Z 至 2038-01-19T03:14:07Z(上界不含)。
|
||||
- 授权初始状态为 `active`,拥有不可预测的 128-bit 十六进制 `license_key`。本阶段仅提供后台查看,不把它当作客户端激活凭证。
|
||||
- 请求必须带 `Idempotency-Key`(1 至 128 字符)。同一管理员、同一键、同一请求字段重放返回原授权;字段不一致返回 409。管理员行锁串行化并发签发,客户/产品行锁确保状态校验一致;事务不会产生第二条授权或第二条签发审计。前端网络失败后保留原键重试。
|
||||
- 签发事务同时写 `audit_events`,审计只记录管理员、资源、动作和非敏感期限/主数据 ID,不记录密码、会话令牌或完整 HTTP 内容。
|
||||
- 本阶段不实现实例身份绑定、激活协议、离线租约、设备扩容/克隆、心跳、退款、客户门户或下载权限。新增的撤销/续期仅是后台期限记录开发假设:管理员级权限、Idempotency-Key、锁定授权行的事务操作记录与审计;续期只允许延后结束时间,撤销后不得续期。它们不等同续费、订单发放、激活或正式冻结/解绑。正式状态机、授权码展示/轮换、租户隔离和审计保留策略待确认。
|
||||
50
docs/operations-security.md
Normal file
50
docs/operations-security.md
Normal file
@@ -0,0 +1,50 @@
|
||||
# Operations and security slice
|
||||
|
||||
Status: isolated integration evidence only, not production acceptance or full Compose runtime acceptance.
|
||||
|
||||
## 2026-10-01 release-gate update (supersedes earlier local-only notes)
|
||||
|
||||
- Production server main now defaults to Redis entry limiting. Missing Redis configuration fails startup unless ENTRY_LIMIT_MODE=local-dev is explicitly selected. Lua INCR+PEXPIRE shares a 60-second fixed window across API instances. Redis runtime errors return 503 rate_limit_unavailable before handlers; no automatic fallback. Numeric private/loopback transport only in this profile; ENTRY_REDIS_PASSWORD_FILE is absolute with a size bound. Redis ACL/TLS, namespace policy, eviction/restart durability, key-cardinality attack capacity and production HA remain gates. Redis memory eviction/reset can reset counters; this is not equivalent to a durable security quota.
|
||||
- Real isolated Redis integration passed: two independent HTTP servers/clients shared a 10-request login quota (11th=429); closing one Redis client produced 503 and no handler execution. Only login was exercised across clients in the real Redis test; existing unit tests cover all four route classifications. Infrastructure outage/restart/load/HA acceptance remains pending. CI now provides isolated Redis and requests race tests; no remote CI execution claim.
|
||||
- Server main no longer registers readiness on the public router. METRICS_ADDR loopback operations listener serves readiness and metrics. Public ready and metrics returned 404 in two real API subprocess runs; internal ready/metrics returned 200. API Compose healthcheck uses loopback 19090; Web checks public liveness. If METRICS_ADDR is absent no readiness endpoint is available. This is source and isolated HTTP evidence, not full Compose validation.
|
||||
- TestSigningFileAPIRestart built and launched the new API twice against isolated clean008 database. A test-only persistent P256 file was stored outside repository in an inheritance-disabled user-only Windows ACL directory, never logged or retained. Both public keys matched and previously signed canonical license-v1 and lease-v1 payloads verified after both launches. Test directory/key were removed by test cleanup. This tests key loading/restart continuity, NOT issuance/activation/heartbeat persistence through a complete business workflow. key_id, multi-key verification windows and rotation are NOT implemented and block production rollout.
|
||||
- New API subprocesses loaded operations/security and checked internal HTTP boundaries plus real HTTP unauthorized write=401, foreign Origin=403, oversized login body=413, each with server X-Request-ID. Existing 18081 was NOT restarted. Browser at 15173 showed unauthenticated email/password/login form; no credentials entered; it still points to old API and is not new-backend authenticated acceptance.
|
||||
- Local Linux race attempt found GCC in WSL but no Go; official toolchain download failed/timed out. Windows race previously blocked by CGO disabled. CI race configured, NOT executed here. Do not mark race passed.
|
||||
- Release blockers: unsigned T01/T02 contracts; persistent production secret injection/rotation/key_id; Redis TLS/ACL/HA and outage-load acceptance; managed TLS/proxy spoof and complete CSRF acceptance; Docker API build/full Compose; logged-in browser/end-to-end issuance lifecycle; U07 chunk/resume/quota/crash reconciliation; compatibility/forced/gray releases; T19 notification/dedup/retries; OSS deferred; production backups/binlogs/restore/reconciliation/rollback; alerts/P95/capacity/vulnerability remediation; race evidence; UAT and signatures. No commit/push/release/task closure.
|
||||
|
||||
The following sections preserve earlier slice evidence; their local-only limiter and publicly accessible readiness descriptions are superseded by the update above.
|
||||
|
||||
## Logging and errors
|
||||
|
||||
The HTTP middleware emits JSON through slog with an allowlist: server-generated request_id/trace_id, route template, operation, HTTP status, error code and elapsed seconds. Client IDs are ignored. trace_id currently equals request_id; no W3C tracing or cross-service propagation is implemented. No request bodies, raw URL paths, query strings, cookies, authorization headers, IP addresses, SQL errors or panic values are logged. Panic handling emits a generic internal_error; startup logs a generic startup_error instead of dumping potentially secret connection errors. Error responses retain code/message and add request_id. Server errors have a generic message. Existing domain codes remain unchanged; a complete contract-signed error registry is still pending.
|
||||
|
||||
Audit details were inspected in activation, heartbeat, download, order and license handlers: they use explicit field lists (resource IDs, state, timestamps, package digest/size), not full request objects. Instance credentials, session tokens, passwords and signing PEM must never be added. This inspection is not a complete automated data-loss-prevention audit. Authentication success/failure metrics are not a durable audit trail.
|
||||
|
||||
## Metrics and exposure
|
||||
|
||||
Set METRICS_ADDR to a numeric loopback address such as 127.0.0.1:19090 to opt into a separate metrics listener. Non-loopback addresses are rejected. /metrics is not registered on the public API router or Nginx. In containers, collection must occur inside that network namespace; no host port publication or container-external collector is configured. Metrics are Prometheus text counters for requests and summed duration, with bounded operation/outcome labels (login, activation, heartbeat, download, authorization, other; success/failure). Authorization means license-route HTTP outcomes, not every internal authorization decision. Download success measures the authorization handoff, not completion of Nginx file transmission. Metrics reset on restart; histogram/P95, alerts, durable aggregation and dashboard setup are pending.
|
||||
|
||||
Liveness/readiness remain existing API endpoints for Compose checks, including the local Web proxy. They return generic statuses but are NOT restricted to an internal listener in the current scaffold. Production ingress must restrict /api/v1/health/ before external exposure; strict internal-only health enforcement is still pending.
|
||||
|
||||
## Entry rate limits
|
||||
|
||||
A bounded local fixed-window limiter runs before login, activation, heartbeat and download handlers: login 10 per minute per effective client IP; other three 60 per minute per IP per operation. Buckets are capped at 10,000; capacity exhaustion denies new keys (fail-closed) with 429/Retry-After. Trusted proxies default to none; production must configure exact proxy CIDRs and prevent direct upstream access. Forwarded IP spoof tests passed with default no-trust configuration.
|
||||
|
||||
IMPORTANT: this implementation is single-process only. Separate processes have independent counters; restart clears them, NAT shares quota and fixed-window boundaries permit bursts. Redis distributed limits, Redis authentication/TLS configuration, atomic distributed counters and outage fail-closed policy are NOT implemented or tested. Redis remains optional and unused. Do not deploy multiple replicas assuming a global limit. Thresholds need capacity acceptance and product approval.
|
||||
|
||||
## Browser and body controls
|
||||
|
||||
Session cookies are HttpOnly, SameSite=Strict, and Secure for direct TLS or explicit SESSION_COOKIE_SECURE=true. Write requests with an Origin must match request Host and effective secure scheme; cross-site Fetch Metadata is rejected. CORS does not allow external origins. Requests without Origin/Fetch Metadata are still allowed for non-browser clients; there is no synchronizer CSRF token, signed origin allowlist or complete browser CSRF acceptance yet. This policy requires same-origin browser deployment.
|
||||
|
||||
General request bodies have a 64 KiB MaxBytesReader; known-length overflows return 413. Unknown-length/chunked overflows reach existing JSON validation and return 400. Uploads retain their streaming 64 MiB bound; activation/heartbeat/download retain more restrictive existing guards where applicable. Path and SQL security still rely on existing digest/path validation and parameterized SQL; no new claim of exhaustive SQL injection testing is made.
|
||||
|
||||
## Executed checks
|
||||
|
||||
- go test ./... and go vet ./... passed after this slice.
|
||||
- Logging tests verify secret body/query/path/cookie/panic text and forged request IDs are absent.
|
||||
- All four entry routes tested for pre-handler 429 and forwarded-IP spoof resistance.
|
||||
- Tests cover origin rejection, no external CORS allow header, known/chunked body limits, malformed sessions, cookie attributes, bucket capacity/reset and independent limiter scope.
|
||||
- Frontend 10 tests, typecheck and production build passed; existing >500 kB bundle warning remains.
|
||||
- scripts/check-delivery.sh checks contiguous migration versions, nonempty up/down pairs and shell syntax. Compose placeholder configuration passed. This is not SQL execution or container runtime validation.
|
||||
- Local race execution was blocked because CGO is disabled. Linux CI now requests focused race tests; that remote workflow has not been run here.
|
||||
- Existing API 18081 was not restarted and remains live. Docker API build remains blocked by outbound proxy.golang.org TCP/443 refusal; full Compose, production security, load and failure acceptance remain pending.
|
||||
66
docs/release-gate-matrix.md
Normal file
66
docs/release-gate-matrix.md
Normal file
@@ -0,0 +1,66 @@
|
||||
# Release gates / 2026-10-01
|
||||
|
||||
No release approval. No commit/push/task closure. Existing API18081 not restarted.
|
||||
|
||||
## TLS, trusted proxies and CSRF deployment
|
||||
|
||||
Managed certificate chain/private key are read-only protected mounts, never repository/backup artifacts. Terminate TLS1.2/1.3 at reviewed Nginx config deploy/nginx/tls-proxy.conf.example. Set SESSION_COOKIE_SECURE=true on API; only allow API traffic from the actual proxy network. HTTP_TRUSTED_PROXY_CIDRS must use exact proxy sources, never /0; do not configure generic private subnets solely for convenience. Nginx must overwrite Host/X-Forwarded-For/X-Forwarded-Proto; caller-supplied forwarded values are not authority. Keep metrics/readiness loopback only and deny package internal paths publicly. Managed certificate renewal, redirects/HSTS, listener ACL and actual proxy deployment remain unverified.
|
||||
|
||||
Browser session writes require same Origin scheme+Host and reject Sec-Fetch-Site cross-site; cookie HttpOnly+SameSiteStrict+Secure. Missing Origin/Fetch Metadata remains allowed for non-browser clients; this is NOT a formal synchronizer-token implementation. No CORS allowlist/credentialed external frontend. Formal CSRF threat model (sibling domains, DNS/Host trust, missing headers), token policy and TLS proxy acceptance require T01/T02 decision. Never claim broad CSRF acceptance from a unit test.
|
||||
|
||||
TestTLSOriginCookieBoundary passed on real isolated httptest TLS listener with test certificate: same-origin200, foreign Origin403, HTTP Origin on HTTPS403, Secure/HttpOnly/Strict cookie, forwarded spoof IP ignored with no trusted proxies. This is actual direct-TLS component evidence, not Nginx production TLS validation. Existing tests cover explicit CIDR/default proxy controls. No production certificate installed.
|
||||
|
||||
## Compose run gates
|
||||
|
||||
API image build previously failed reaching proxy.golang.org; no successful new image/runtime claim. Redis remains optional cache profile, while API defaults to mandatory Redis with ENTRY_REDIS_ADDR empty. To rehearse explicitly select either controlled ENTRY_LIMIT_MODE=local-dev (NOT production/multi-instance acceptance) or start cache and configure a numeric private Redis address after inspecting the isolated container network. Current address validation does not accept service name redis; static-IP/service-discovery design must be reviewed before reproducible Compose delivery. Redis dependencies/ACL/password/TLS/HA are not wired for production. Placeholder compose config success does not demonstrate startup. LICENSE_KEYRING_FILE is not mounted by base Compose; opt-in development overlay must mount public ring read-only and inject path. Never inject private key through this public ring.
|
||||
|
||||
## Backup / restore / rollback checklist
|
||||
|
||||
1. Obtain approved maintenance/quiesce window; block writes and drain upload/activation/heartbeat transactions. Record image/config/schema IDs and file manifest counts/hashes without secrets. Fail if consistent snapshot cannot be proven.
|
||||
2. Use existing backup-delivery.sh with trusted SQL/tar only. DB snapshot/binlog position and object files must share a consistency point; existing restore rehearsal is not proof of production binlog consistency. Encrypt production backups/access-control them. Signing private keys are excluded and recovered separately through protected approved secret management.
|
||||
3. Restore only isolated EMPTY database/private target with no listener and CONFIRM_EMPTY_RESTORE=YES. Refuse nonempty targets regardless of confirmation. Verify schema clean008, every object metadata/hash/size, license/order/operation relations, audits and public-key fingerprints. Restore application should remain offline until approval.
|
||||
4. Rehearse previous image/config/keyring rollout with both old and newly-issued public keys retained. Do not down migrated business schema or erase idempotency/certificate JSON. Confirm stored v2 artifacts verify after rollout; retain revocation policy. Failed key/schema/readiness checks block listeners and rollback approval.
|
||||
5. Verify actual isolated activation/heartbeat/download lifecycle, denial, Redis outage, TLS proxy, logs, alerts, lease expiration and recovery reconciliation. Reopen traffic only after evidence review. No production recovery/RTO/RPO/binlog/rollback claim currently.
|
||||
|
||||
## T01-T30 inventory
|
||||
|
||||
Canonical task status remains Chinese task plan; no task accepted/closed by this update.
|
||||
|
||||
| Task | Status | Remaining release gate |
|
||||
| --- | --- | --- |
|
||||
| T01 | blocked | Product/integrator owner, deployment identity and business decisions/signatures |
|
||||
| T02 | blocked | Approved OpenAPI/errors/RBAC/crypto/lifecycle contract |
|
||||
| T03 | needs acceptance | Actual deployment, remote CI/review |
|
||||
| T04 | in progress | Full entitlements/schema/seed/RBAC approval |
|
||||
| T05 | in progress | Customer identity/refresh; Redis shared limiter implemented, TLS/HA acceptance pending |
|
||||
| T06 | in progress | Permission routes/full CRUD/pagination/browser acceptance |
|
||||
| T07 | in progress | Quotas/crash reclamation/storage abstraction acceptance |
|
||||
| T08 | in progress | Build network/Redis wiring/full Compose/managed TLS |
|
||||
| T09 | in progress | Multi-account/RBAC management and audit |
|
||||
| T10 | in progress | Customer identities/subaccounts/tenant isolation |
|
||||
| T11 | in progress | Modules/templates/disable constraints/edit UI |
|
||||
| T12 | in progress | Full entitlement and state contracts |
|
||||
| T13 | in progress | Opt-in signed key_id v2 + keyring + Go->Node vectors implemented; rotation E2E and lifecycle approval pending |
|
||||
| T14 | in progress | Clone/migration/scaling identity approvals |
|
||||
| T15 | in progress | Reference client verifier/high-water implemented; trusted persistence/host integration/monitoring/UAT missing |
|
||||
| T16 | deferred | Not first release |
|
||||
| T17 | in progress | Packages/pricing snapshots/approvals |
|
||||
| T18 | in progress | Renewal/refund/approval rules |
|
||||
| T19 | not started | Notifications/dedup/retry |
|
||||
| T20 | not started | Finance/report/export |
|
||||
| T21 | in progress | Compatibility/forced/gray release |
|
||||
| T22 | in progress | Chunk/resume/quota/orphan reclaim |
|
||||
| T23 | in progress | Version check/real client update |
|
||||
| T24 | deferred | OSS outside first release |
|
||||
| T25 | in progress | Instance-credential read-only portal `/customer` + `/api/v1/portal/snapshot` implemented; customer account login/tenant/RBAC/reset contract still absent, so not accepted as account portal |
|
||||
| T26 | in progress | Audit pagination/filter/retention |
|
||||
| T27 | in progress | Independent Node verifier and vectors exist; actual integrator E2E absent |
|
||||
| T28 | in progress | Race/pressure/capacity/outage/security review/vulnerabilities |
|
||||
| T29 | in progress | Production encrypted recovery/binlog reconciliation/alerts/rollback |
|
||||
| T30 | blocked | No signed UAT, gray observation, production approval, or release authorization |
|
||||
|
||||
## Matrix evidence boundaries
|
||||
|
||||
Passed: Go full tests/vet; frontend Vitest (10 tests); instance-credential portal unit boundary; isolated MySQL v2 activation/heartbeat old/new key rotation, historical replay, router re-registration, Node public-vector verification, portal pagination/audit/no-store and cross-instance rejection; old v1 compatibility tests; Go->Node ephemeral vector verification/tamper/revocation/unknown rejection and lease high-water; isolated direct TLS boundary; prior isolated Redis shared login and fail-closed; prior new API two-process persistent signing continuity/internal ready.
|
||||
|
||||
Not executed in this increment: OS-process restart with new-v2 keyring continuity (required DSN/Redis test inputs were absent), public keyring HTTP matrix, Redis infrastructure restart/load, Nginx managed TLS, full Compose, Linux race, authenticated customer-account portal, hosted integrator workflow, production rollback and UAT. Browser-only `/customer` layout checks passed at 390x844 and 1440x900 with no horizontal overflow, but no credentials were entered and no authenticated download/cross-tenant browser flow was claimed. Compose was blocked before build by missing protected external paths (`MYSQL_APP_SECRET_FILE`, `MYSQL_ROOT_SECRET_FILE`, `LICENSE_SIGNING_KEY_HOST_FILE`, `PACKAGE_STORAGE_HOST`); earlier API build attempts also hit `proxy.golang.org` TCP/443 refusal. The MySQL evidence uses a newly-created dedicated schema and router re-registration; it does not establish production acceptance. Do not reuse prior v1 isolated startup as v2 end-to-end evidence.
|
||||
11
docs/signing-key-operations.md
Normal file
11
docs/signing-key-operations.md
Normal file
@@ -0,0 +1,11 @@
|
||||
# Signing key operations (development boundary)
|
||||
|
||||
The v6 smoke launcher generated a fresh P-256 private key in memory on every process start. This is test-only behavior: every restart changes the public key, so certificates and lease signatures issued before restart must not be treated as verifiable across the restart.
|
||||
|
||||
For persistent development and production, inject `LICENSE_SIGNING_PRIVATE_KEY_PEM` from a secret manager or protected process environment. Do not put private keys in Git, database rows, browser storage, `.env` files, logs, crash dumps, or HTTP responses. Restart acceptance requires the same protected key to be injected and `/api/v1/activation/public-key` to remain stable.
|
||||
|
||||
`LICENSE_SIGNING_PRIVATE_KEY_FILE` now supports an absolute protected PEM file path; configuring both file and PEM sources is rejected. The file must be readable, nonempty and at most 16 KiB. Host ACL enforcement, secret-manager provisioning and startup cryptographic format validation are not provided by this config loader; signing handlers still enforce P-256 format. File content is read once at startup, not hot-reloaded. Compose mounts this file read-only. The existing 18081 process has not been restarted or rotated.
|
||||
|
||||
`key_id`, public-key sets and overlapping verification windows are NOT implemented. The current public-key response contains a single public key, and certificate/lease payloads do not carry a key identifier. No persistent key was created or provisioned during this slice.
|
||||
|
||||
Planned rotation contract: add an immutable `key_id` to activation certificates and lease payloads, publish a public-key set by `key_id`, and retain old public keys for the certificate/lease verification window. Rotation and revocation ownership remain pending T01/T02 approval; no automatic key replacement is implemented by this slice.
|
||||
144
docs/task-execution.md
Normal file
144
docs/task-execution.md
Normal file
@@ -0,0 +1,144 @@
|
||||
# 开发任务执行记录
|
||||
|
||||
## 2026-10-01:DEV keyring / 独立客户端 / 发布矩阵
|
||||
|
||||
- 本轮发布证据收口:未执行 OS 进程级 v2 keyring 重启。现有 `TestSigningFileAPIRestart` 只验证持久文件下 v1 canonical license/lease 的公钥连续性,且 `SIGNING_RESTART_TEST_DSN` 与 `ENTRY_REDIS_TEST_ADDR` 当前未配置;不能把进程内 router 重注册或该 v1 测试扩大为 v2 真实激活/心跳重启验收。
|
||||
- 浏览器仅检查未认证 `/customer` 页面:`http://127.0.0.1:15173/customer` 在移动 390x844 和桌面 1440x900 下 `document/body scrollWidth == viewport clientWidth`,无横向溢出;未输入、记录或截图任何实例凭据,因此跨租户错误和真实下载仍未做浏览器验收。
|
||||
- 隔离 Compose 未启动:`docker compose config --quiet` 和 `docker compose build api` 均在插值阶段拒绝,缺少受保护外部路径 `MYSQL_APP_SECRET_FILE`、`MYSQL_ROOT_SECRET_FILE`、`LICENSE_SIGNING_KEY_HOST_FILE`、`PACKAGE_STORAGE_HOST`;本轮未创建伪密钥、未放宽路径要求、未触碰现有业务服务。此前 API 镜像还曾受 `proxy.golang.org` TCP/443 阻断。
|
||||
|
||||
|
||||
- 显式LICENSE_KEYRING_FILE启用license-v2/lease-v2,签名载荷包含key_id;启动校验当前公私钥匹配、唯一ID、撤销和P256,旧public key保留验证。默认v1不变、历史JSON/幂等重放不改,无新增schema迁移。生命周期尚未批准,不是正式轮换验收。
|
||||
- 新client/verify.mjs为Node接入方参考组件而非管理台/客户门户:预置公钥验签、未知/撤销拒绝、实例绑定、14天/权益边界及时间高水位。可信存储/真实宿主集成、防克隆/快照回滚未完成。
|
||||
- Go生成只含公钥/签名的临时向量,Node旧/新key、未知/撤销/篡改和租约回拨/离线到期测试通过;私钥只在Go内存,未落盘。真实TLS测试监听同源200/外源403/降级Origin403与Secure/HttpOnly/Strict Cookie、forwarded spoof拒绝通过;这不是生产Nginx证书验收。
|
||||
- 完整T01-T30现状、Compose Redis地址/profile缺口、正式TLS/CSRF策略缺口、备份/恢复/回滚步骤见[发布矩阵](release-gate-matrix.md),开发接入文档见[keyring客户端契约](keyring-client-contract-draft.md)。T25客户身份域和门户仍未开始。
|
||||
- 真实v2数据库签发/轮换重启、实际接入方、Nginx TLS/fullCompose/Linux race/生产恢复/UAT未执行。18081不重启、不提交/推送/发布/关闭任务。
|
||||
|
||||
|
||||
## 2026-10-01:发布门禁继续推进
|
||||
|
||||
- 新增Redis Lua分布式入口计数,默认redis模式,缺配置拒绝启动;只允许显式local-dev受控降级,Redis请求故障503且不调用handler。真实隔离Redis两个HTTP实例共享登录额度测试通过,第11次429;关闭客户端503通过。Redis TLS/ACL/HA、eviction/重启计数清零与容量验收未完成。
|
||||
- 新API main移走public ready,只在METRICS_ADDR numeric loopback监听ready/metrics。两次真实API启动public ready/metrics=404,internal=200,Compose健康配置改用内部19090,Web仅live。完整Compose运行未验收。
|
||||
- 仓库外Windows user-only ACL临时持久key,两次真实API启动公钥一致,旧canonical license-v1与lease-v1签名都验签通过;key测试结束清理、不入仓库/日志。这不是完整真实签发-心跳-重启生命周期验收。key_id/轮换/多key窗口未实现,保持发布阻塞。
|
||||
- 浏览器15173未登录表单邮箱/密码/登录快照通过,未输入凭据,仍连旧18081;新API演练为独立子进程加载新源码,演练后停止。
|
||||
- Linux race尝试:WSL有gcc无go,官方Go下载网络失败/超时,未获得race结果;CI新增隔离Redis服务及Redis race用例,远端未执行。发布未实现清单见[门禁更新](operations-security.md)。
|
||||
- T07/T21/T22/T27/T28/T29仍进行中,T19未开始。没有commit/push/release/close,18081与业务库不动。
|
||||
|
||||
## 2026-10-01:质量与运维DEV切片
|
||||
|
||||
- 新增白名单slog JSON请求日志、服务端request_id/trace_id、统一错误关联ID与服务端错误脱敏;panic/startup不输出敏感原始错误。trace_id仅本请求关联,不是分布式trace。
|
||||
- 新增可选METRICS_ADDR独立numeric loopback指标监听,公共API无/metrics;记录login/activation/heartbeat/download/license路由成功失败及耗时sum。health仍可经现有Web访问,生产内部限制未完成。
|
||||
- 新增认证前四类入口单进程IP固定窗口限流,桶容量10000满时拒绝新key;不是Redis分布式限流,多进程独立计数和重启清零。保留Redis可选且未使用的事实。
|
||||
- Cookie增加SameSite=Strict;写请求Origin同源及cross-site Fetch Metadata检查;通用64KiB body上限,上传保留64MiB。无Origin请求仍支持非浏览器客户端,完整CSRF token方案/真实浏览器验收未完成。
|
||||
- 新增测试覆盖脱敏、panic、request_id、四入口限流、X-Forwarded-For伪造、请求体known/chunked、Origin/CORS、无效session、Cookie、限流容量/窗口/独立作用域。go test ./...及go vet ./...通过;前端10测试及build通过。race本地因CGO禁用未运行,加入Linux CI但远端执行尚无证据。
|
||||
- CI保留Go/frontend检查,新增迁移配对序号/非空、shell语法、Compose config检查;脚本与placeholder config本地通过。这不是SQL/Compose运行验收。必要镜像runtime检查仍受Docker网络阻塞。
|
||||
- T07/T27按已实现切片转为进行中,T19未开始,T21/T22/T28/T29保留进行中并更新证据。审计字段仅代码白名单抽查,不代表自动化全量敏感数据验收。详见[运维安全边界](operations-security.md)。
|
||||
- 18081未重启、业务库未动、未commit/push/release/close。
|
||||
|
||||
## 2026-09-30:v6 心跳 / 租约 / 冻结传播 DEV 切片
|
||||
|
||||
- 新增显式 000006_heartbeat_lease up/down:实例 last_seen/client_seen 高水位、独立 lease_expires_at、freeze_state/observed_state,以及心跳/冻结幂等操作表。专用 MySQL 已显式 up 到006;本轮未执行有数据的 down,回滚演练仍待隔离空库验证。
|
||||
- 新增实例凭据心跳与管理员冻结接口;只校验32字节secret的SHA-256,不存储/回显明文。成功心跳、租约、操作记录及audit同事务;60秒限频,重复请求不刷新last_seen,状态变化允许立即传播。
|
||||
- lease-v1 P-256签名,UTC服务端时钟,最大14天且不越过entitlement_expires_at;5分钟回拨容差、高水位单调。冻结/撤销联网停用,离线旧租约到原截止的DEV假设见 heartbeat-lease-contract-draft.md。
|
||||
- 真实 MySQL TestBusinessMySQLIntegration 通过(3.573s):错误secret、audit失败last_seen回滚、并发幂等、签名验签、限频、载荷冲突、时钟偏差、冻结/恢复/撤销传播。完整 go test ./...、go vet ./... 通过。
|
||||
- 前端实例抽屉增加last_seen、租约、冻结、权益与传播状态,不泄露secret;npm test 3文件/9用例及npm run build通过,现有大chunk警告保留。
|
||||
- 发布固定公开租约验签向量且单测验证篡改失败;客户端可信存储/执行器、防克隆、迁移、扩容、key_id轮换、异常监测、正式策略/UAT仍阻塞或未实现。T13/T14/T15/T26保持进行中。
|
||||
- 21:10后补验:独立库 license_v6_rehearsal_260930 执行005→006→005→006,version=6 dirty=false;admins/customers/products/licenses/license_instances/activation_operations/audit_events夹具保留,006操作表与新增状态在down明确丢弃。新增 TestV6Rehearsal 可复现,需全新专用库,未触碰主测试数据。
|
||||
- 已重启18081加载v6源码构建;签名私钥仅启动器内存随机生成/环境注入,不落盘,重启将换DEV公钥且旧租约不适用,生产密钥管理/轮换仍阻塞。真实HTTP:/api/v1/health/live=200 status ok;public-key=200 ECDSA-P256-SHA256;错误secret心跳=403 forbidden;无幂等键=400 invalid_idempotency_key;未登录冻结(含错误参数)=401 unauthorized,认证在参数校验之前。/healthz不存在=404,不是健康路径。
|
||||
- 限频由共享MySQL实例FOR UPDATE锁及last_seen时间实现,不是单进程内存计数;认证前全局/来源IP限流、攻击防护、部署容量未验收。
|
||||
- 后台新增冻结/恢复确认、幂等重试与刷新状态按钮。浏览器390x844快照获得真实登录表单,但无管理员凭据,且截图display surface不可用;桌面/移动已登录实例操作仍待人工验收,不重置/索要/存储密码。最小操作:用户在15173登录,打开授权实例抽屉,核对无secret,冻结/恢复并由实例下一次真实心跳观察传播状态。
|
||||
- 未提交、推送、发布或关闭任务。
|
||||
|
||||
|
||||
任务状态以 [详细开发任务方案](../软件授权与统一管理平台-详细开发任务方案.md) 中的执行状态表为准。每个任务完成后先更新实现/验证依据,再转为待验收;评审、真实环境验收及必要签字全部满足后才标记已验收。阻塞任务不得以建议规则冒充已确认规则。
|
||||
|
||||
## 2026-09-30:T01/T02 核对,T03 基础设施增量
|
||||
|
||||
- 保留本轮开始时两份方案文档的已有未提交修改,没有覆盖或回退。
|
||||
- T01:阻塞。产品/接入负责人、实例身份、权限矩阵、审批及负载规则仍待确认;现有 ADR 和 U01-U11 是草案。
|
||||
- T02:阻塞。正式 OpenAPI、证书、租户与错误码契约依赖 T01。
|
||||
- T03:进行中。新增环境配置加载与校验、HTTP 请求超时、禁用默认可信代理、信号优雅退出;新增配置默认值、覆盖值及非法输入测试。
|
||||
- 新增可测试的 HTTP 生命周期实现:真实 TCP 监听、在途请求排空、优雅退出超时和监听失败测试均已覆盖。
|
||||
- 新增前端 Vitest/jsdom 测试:API 在线/异常检测和首页初次检测/手动重测共 5 个用例通过;CI 已加入 `npm test`。
|
||||
- 新增迁移目录规范。未创建业务 SQL,未选择迁移执行器,未执行 MySQL 空库/回滚验收。
|
||||
- 本地执行 `cd backend && go test ./...`:通过;`go vet ./...`:通过。
|
||||
- 本地执行 `cd frontend && npm test`:2 个测试文件、5 个用例通过;`npm run build`:类型检查及生产构建通过。
|
||||
- Element Plus 全量引入导致 JS 大 chunk 警告仍存在;实际迁移验证、代码评审与远端 CI 验证尚缺,因此 T03 未完成。
|
||||
- 本轮没有提交或推送;已有开发服务可能仍运行旧进程,新服务入口需重启后生效。
|
||||
|
||||
## 2026-09-30:后续执行开始
|
||||
|
||||
- 已核对 git status/diff、两份中文方案及已有实现;未发现根目录 AGENTS.md/CLAUDE.md。保留所有已有增量。
|
||||
- T03 继续进行中:选用 golang-migrate v4.18.3(兼容 Go 1.23),专用 MySQL 8 容器只承载本仓库测试夹具,不连接其他项目数据库。
|
||||
- T01/T02 继续阻塞;T16/T24 保持暂缓。其余任务只开展不固化未签字业务规则的独立工程子项,不越过正式依赖验收。
|
||||
- shell 未提供 apply_patch,使用文件工具精确替换已有内容及创建新文件。
|
||||
|
||||
## 2026-09-30:T03 迁移与验证增量
|
||||
|
||||
- 新增 `backend/internal/migrations` 执行器和 `backend/cmd/migrate` 显式命令,支持 `up`、`down`、`version`、人工指定版本的 `force`;服务启动不自动迁移,避免隐式改库。
|
||||
- 使用专用 `mysql:8.0` 容器(仅本仓库测试库、独立端口)完成空库 `up`、版本/数据核对、`down`;故意非法 DDL 后确认 `dirty=true`、普通 `up` 被阻断,再显式 force 到版本 1 恢复 clean。演练夹具和容器已删除。
|
||||
- `backend/migrations/README.md` 已记录 URL 格式、命令、防误操作边界及演练结果;尚无业务 SQL,T04 仍未开始。
|
||||
- Go `test ./...`、`vet ./...` 通过;前端 `npm test` 通过 2 文件/5 用例;`npm run build` 通过(仍有 Element Plus 大 chunk 警告)。生命周期测试继续覆盖真实监听、排空、超时及监听失败。
|
||||
- T03 更新为“待验收”:实现和本地检查完成,但真实部署、远端 CI、代码评审仍缺,不能标记“已验收”。
|
||||
- 当前下一步:补充客户/产品编辑 UI、API 合同测试和审计/速率限制等安全策略;这些工作需与待确认的正式权限、租户和授权规则保持隔离。
|
||||
|
||||
## 2026-09-30:基础管理台业务切片
|
||||
|
||||
- 按继续实施指令完成第一条可运行业务纵向切片:新增核心 MySQL 迁移(管理员、会话、客户、产品),真实数据库 CRUD API,bcrypt 管理员初始化命令,HttpOnly 会话令牌、服务端 admin 角色控制、统一错误结构和客户分页搜索。
|
||||
- 新增 Vue 管理台登录、会话恢复/退出、客户新增/搜索/删除、产品新增/查看/删除页面;保留健康检查和错误/空状态。
|
||||
- 专用 MySQL 8.0 隔离库已执行 migration version 1 clean;真实集成测试验证未登录 401、bcrypt 登录、会话 cookie、客户/产品写读、登出后会话失效。测试账户仅用于隔离库,容器仍可供本地试用,不代表 UAT。
|
||||
- 初始化方式为 `backend/cmd/admin-init`,密码要求至少 12 位,不写入默认密码。`docs/business-contract-draft.md` 记录了未签字的临时契约假设;授权激活、心跳、续期、退款、克隆、实例绑定等未决业务没有固化。
|
||||
- `docs/business-quickstart.md` 记录数据库、迁移、管理员初始化、后端和前端启动方式。当前切片完成后仍不是完整授权产品;T01/T02及正式OpenAPI/RBAC/安全运维规则仍待确认,任务保持进行中或待验收。
|
||||
|
||||
## 2026-09-30:期限授权切片
|
||||
|
||||
- 新增 migration version 2:licenses 与 audit_events;专用 MySQL 已验证 version 2 clean。迁移仍显式执行,服务启动不自动改库。
|
||||
- 管理员 API 新增期限授权签发与分页查看。签发生成 128-bit 十六进制密钥;同一管理员幂等键要求请求字段一致;管理员/客户/产品事务锁保证并发一致;授权插入和 `license.issued` 审计原子提交。
|
||||
- 新增前端授权表单和列表,active 客户/产品选择、RFC3339 时间、提交中防重复、失败重试复用幂等键、分页、空/错误状态。该切片不是激活凭证、证书、订单、实例绑定或完整权益模型。
|
||||
- 真实 MySQL 集成覆盖未认证 401、首次 201、重放 200、载荷冲突 409、viewer 403、停用产品 400、审计故障回滚、并发一写一重放及一授权一审计;当前 `go test ./...`、`go vet ./...`、前端 `npm test`(6 用例)和 `npm run build` 通过。
|
||||
- 已重启隔离后端 `127.0.0.1:18081`,浏览器实际登录并签发第二条授权;桌面 1200px、移动 390px 检查无横向溢出,截图留存于会话下载目录。浏览器驱动 fill/click 异常,交互验证部分使用原生 DOM 事件,不能替代完整 UAT。
|
||||
- 文档新增 DEV-LICENSE-v0.1 期限/幂等边界;T02 正式契约、T04 完整模型、生产代理 TLS、客户/产品编辑和完整权限/审计仍未验收。
|
||||
|
||||
## 2026-09-30:授权详情、撤销与续期切片
|
||||
|
||||
- 新增 migration version 3 `license_operations`,按管理员、操作类型和幂等键保存请求指纹;迁移已应用到隔离 MySQL,服务启动仍不自动迁移。
|
||||
- 新增 `GET /api/v1/licenses/:id`、`POST /api/v1/licenses/:id/revoke`、`POST /api/v1/licenses/:id/renew`。撤销/续期锁定授权行,在同一事务更新授权、写操作幂等记录和审计;重放返回原结果,变更请求返回 409。
|
||||
- 续期只延后后台记录的结束时间;已撤销授权不可续期。前端表格提供确认撤销和 RFC3339 续期操作;仍不构成激活、订单、续费、退款或离线授权流程。
|
||||
- 真实 MySQL 集成新增详情、续期重放/冲突、撤销重放、撤销后续期拒绝和审计计数;`go test ./...`、`go vet ./...`、真实 MySQL 集成、前端 6 项测试和 `npm run build` 全部通过。构建仍有约 1.1MB JS chunk warning。
|
||||
- DEV-LICENSE-v0.1 已记录这些实现假设;T01/T02 正式状态机、权限/错误契约、实例和权益规则仍待确认,T12/T18 保持进行中。
|
||||
|
||||
## 2026-09-30 v4 线下订单开发切片
|
||||
|
||||
- 已显式应用 000004_orders 迁移;历史 migrations 不改,启动不自动迁移。
|
||||
- 真实接口:GET/POST `/api/v1/orders`、GET `/api/v1/orders/:id`、POST `/:id/confirm-payment`、POST `/:id/issue`。整数分 CNY、active 主数据校验、admin 服务端门禁、待收款->已收款->已发放。
|
||||
- Vue OrdersPanel 已接入真实 API,包含录单、分页列表、详情抽屉、收款对话框、发放对话框;未变请求失败后保留幂等键,成功后清除。
|
||||
- MySQL 集成覆盖未登录/非admin拒绝、无键/金额错误、inactive 客户/产品、顺序限制、同键重放/异请求冲突、并发发放一写一重放、不同键重复发放拒绝、支付及发放审计故障回滚、授权关联范围、操作与审计计数。
|
||||
- `go test ./...`、`go vet ./...`、指定真实 MySQL 集成均通过;前端 9 项 Vitest 和 vue-tsc/Vite build 通过。Element Plus 选择器在单测中使用可控 stub 验证重试逻辑,不等同真实浏览器验证。构建仍有约 1.1MB JS chunk warning。
|
||||
- DEV 合同已补充一订单一产品一授权、续期起始日、退款/撤销和审批角色待签字事项。未实现套餐/价格权益快照、审批、退款、激活、证书或报表;T17/T18/T26 仍进行中,T20 尚未实现。
|
||||
- 本记录仅为本地开发证据,不代表 UAT/生产验收;未 commit/push,也未关闭任务。
|
||||
|
||||
## 下载纵向切片补充(2026-09-30)
|
||||
|
||||
- 007 历史未改;新增 008 package_objects 摘要锁表,支持跨产品相同 digest 并发及发布失败文件清理。提交确认丢失/进程崩溃仍需孤立文件对账,不做原子文件系统与 MySQL 承诺。
|
||||
- 专用 license_download_260930 真实 MySQL 测试通过:客户/产品隔离、secret 错误、冻结/撤销/主数据停用、未登录发布、审计失败、失败上传文件与记录回滚、重复摘要并发、64 MiB 精确边界。
|
||||
- Linux 容器路径与 symlink 测试无 skip 通过。隔离 Nginx 18181 + 临时 API 18082 验证真实字节/SHA256、Range 206、外部 internal 路径拒绝和未鉴权拒绝;测试服务已停止。未改其他项目 Nginx。
|
||||
- Vue 版本分页列表/原始文件上传/加载错误态已接入;4 文件 10 项 Vitest、类型检查/build、Go test/vet 通过。现有 bundle warning 保留;用户登录浏览器验收单列未执行。
|
||||
- 开发 18081 保留原 v6 临时密钥,未擅自重启轮换;主库仍 007。008 与新版运行待保护性持久密钥注入/明确测试密钥轮换批准。key_id/多公钥版本目前仅方案,未声称实现。
|
||||
- T11/T12、U07/U08 仍进行中,不标待验收;分块上传/重试续传、崩溃清理、正式密钥生命周期仍未完成。合同与证据见 docs/download-contract-draft.md 和 docs/signing-key-operations.md。未 commit/push/发布/关闭任务。
|
||||
|
||||
## 2026-09-30:下载拒绝矩阵与部署交付增量
|
||||
|
||||
- 新增 expired、unpublished、missing-release 三项真实 MySQL 拒绝测试,均为403、无X-Accel-Redirect,每次增加一条 release.download_denied 审计;有效实例使用数值主键核对审计。隔离 MySQL/Nginx 整体回归通过(4.08s),含真实字节/SHA256、Range 206、internal路径404;临时服务已停止。
|
||||
- 配置增加 LICENSE_SIGNING_PRIVATE_KEY_FILE 绝对保护文件注入,拒绝双来源/不可读/空或超限文件;PACKAGE_STORAGE_ROOT 必须是绝对现存目录。配置单测通过;key_id、公钥集合、重叠轮换仍未实现,密钥格式仍在签名handler校验。未生成/保存新的持久密钥,18081未重启。
|
||||
- 只读数据库核对:license_platform=007 clean,license_download_260930=008 clean。迁移README补007到008回填前校验、对象并发锁、commit确认不确定保留文件、崩溃孤儿对账与隔离删除语义;自动对账/GC仍未实现。
|
||||
- T08推进为进行中:新增compose.yaml、Go API/迁移镜像、Vue/Nginx镜像、保护secret文件、内部网络/健康依赖及只读包挂载。默认不发布MySQL/Redis/API或目录,web只监听宿主127.0.0.1:18083。Redis尚非API功能依赖。
|
||||
- docker compose config --quiet通过;web镜像构建通过。API镜像第一次下载层EOF,第二次go mod download被Docker DNS到proxy.golang.org超时阻断,未算成功。完整Compose运行未验收,无自动迁移现有主库。
|
||||
- Go test ./...和vet ./...通过;前端4文件10用例、类型检查/Vite构建通过,约1.13MB chunk警告保留;镜像npm ci报告2项moderate依赖漏洞,未强制升级。
|
||||
- 新增 `/api/v1/health/ready`:必须能查数据库且唯一schema_migrations为version 8 dirty=false;启动也拒绝旧/未来/dirty/不可用schema;readiness只返回通用503。单测覆盖以上故障矩阵,Compose API/web healthcheck改用ready。HTTP_TRUSTED_PROXY_CIDRS仅接受显式非零CIDR,拒绝trust-all;SESSION_COOKIE_SECURE可显式强制,X-Forwarded-Proto未经代理信任不会令cookie安全。TLS样例要求真实受管证书,未启用自签证书。Redis置于可选cache profile,当前API不依赖Redis。
|
||||
- 新增scripts/backup-delivery.sh与restore-delivery.sh:MySQL最小权限dump(no-tablespaces)、私有包tar/sha256,恢复要求YES且目标目录为空,清单不含签名key。一次性隔离MySQL恢复演练通过:schema 8 clean、package_objects和文件SHA256一致,容器已清理;未触碰业务库。
|
||||
- docs/deployment-delivery.md已更新TLS/CIDR/Secure cookie、readiness、Redis可选语义及备份证据。Docker API构建仍被proxy.golang.org出站连接拒绝阻断,不能算完整Compose运行。浏览器人工登录、U07、正式合同和UAT仍开放;不提交/推送/发布/关闭任务。
|
||||
|
||||
## 下一步
|
||||
|
||||
1. 由产品和集成负责人确认 T01/T02 正式授权、实例、权益、权限和错误契约,再决定是否演进 DEV-LICENSE-v0.1。
|
||||
2. 补齐完整 RBAC、审计查询/导出、客户/产品编辑及正式 OpenAPI/契约测试,并完成远端 CI、评审、部署验收。
|
||||
3. T16/T24 保持暂缓,其余任务按方案依赖实施并逐项更新,不把当前切片算作完整授权产品。
|
||||
Reference in New Issue
Block a user