item-atlas/deploy/public/README.md

67 lines
6.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 见物公网预览
`api-atlas.tutudog.com` 为 iOS 提供 HTTPS。完整路径为公网 Nginx → 两条 FRP STCP → 工作 Mac 的 SSD VM → Kubernetes Service。`/api/` 到网关,`/auth/realms/item-atlas/` 与 `/auth/resources/` 到 Keycloak。身份服务用 Keycloak 的生产启动模式和固定 issuer。账号由内部后台创建,开放注册关闭。
## 应用和数据
在 `item-atlas-public` 命名空间部署,另有 PostgreSQL 持久卷和私有图片桶。物品、录入和身份服务各用独立数据库。先准备环境私密文件,再应用底座及应用 chart。
```sh
kubectl get namespace item-atlas-public >/dev/null 2>&1 || kubectl create namespace item-atlas-public
python3 deploy/public/prepare-secrets.py "$ATLAS_SECRET_DIR" \
--owner "$ATLAS_INITIAL_ACCOUNT" --ollama-url "$ATLAS_INTERNAL_OLLAMA_URL"
```
把生成的各 `.env` 按文件名创建同名 Kubernetes Secret。用 `item-atlas-realm.json` 创建 `atlas-public-realm`,文件键用 `item-atlas.json`。在 Garage 建立 `jianwu-public-photos`,导入 `atlas-public-media.env` 里的应用密钥,只授予该桶的读取和写入权限。镜像仓库通过 `item-atlas-registry` 提供拉取权限。生成文件、用户口令和服务密钥保存在 SSD 上的受控目录。
这些文件用于初始化。已有环境的 Keycloak realm、账号和数据库密码由运行中的服务维护。备份与恢复时,以当前数据库、图片桶和现用 Secret 为准。
```sh
theme=deploy/public/keycloak/jianwu/login
kubectl -n item-atlas-public create configmap atlas-public-login-theme \
--from-file="$theme/theme.properties" --from-file="$theme/messages/messages_zh_CN.properties" \
--from-file="$theme/messages/messages_en.properties" --from-file="$theme/resources/css/jianwu.css" \
--from-file=brand.png=apps/ios/ItemAtlas/Assets.xcassets/BrandMark.imageset/BrandMark.png \
--dry-run=client -o yaml | kubectl -n item-atlas-public apply --server-side \
--field-manager=item-atlas-login-theme -f -
kubectl -n item-atlas-public apply -f deploy/public/base.yaml
kubectl -n item-atlas-public rollout status deployment/atlas-keycloak --timeout=5m
helm upgrade --install item-atlas deploy/helm/item-atlas -n item-atlas-public \
-f deploy/public/values.yaml --set-string image.tag="$ATLAS_PUBLISHED_SHA" \
--atomic --wait --timeout 12m --history-max 10
```
`ATLAS_PUBLISHED_SHA` 取已成功发布镜像的 Drone 构建标识。公网预览使用同一 Helm chart。初次建立该环境时,运行上述 Helm 命令并验收,再配置公网域名。切换版本前先记录当前修订和三个镜像摘要。
`jianwu` 主题继承 Keycloak 26.8.2 的 `keycloak.v2` 登录表单。首次导入会给 `atlas-ios` 设置 Login theme。已有 realm 在管理端打开 Clients → atlas-ios → Settings → Login theme,选择 `jianwu`。更新主题文件后重启 Keycloak Deployment 以刷新缓存。单副本重启期间登录入口会短暂中断。先检查主题文件和回调,再验收登录。遇到显示问题可把该客户端的 Login theme 恢复为默认。 [Keycloak 主题](https://www.keycloak.org/ui-customization/themes)
### 原生会话配置
启用公网 values 前准备两份 Secret。生成独立的 RSA 密钥对,至少 2048 位,原文件和备份保存到 SSD 的受控目录。
| Secret | 内容 | 注入对象 |
| --- | --- | --- |
| `atlas-native-verification` | `ATLAS_NATIVE_ISSUER=https://api-atlas.tutudog.com/session` 与 `ATLAS_NATIVE_PUBLIC_KEY`(Base64 X.509 DER) | 物品、录入服务,并供只读候选验签 |
| `atlas-native-signing` | `ATLAS_NATIVE_PRIVATE_KEY`(Base64 PKCS#8 DER) | 稳定版物品服务 |
首次使用 Flyway V5 建表。运维核对用户原有的 Keycloak 用户编号后,将规范化用户名、原编号和 BCrypt 哈希插入 `native_account`。可用 `htpasswd -niB -C 12 "$ATLAS_USERNAME"` 从标准输入生成哈希,再只保存冒号后的哈希字段。更新密码时按用户事务更新哈希并清理该用户的 `native_session`,已有访问令牌最长 5 分钟到期。暂停账号时设置 `enabled=false`。
渲染并加载本目录的 Nginx 模板,使 `/api/session/` 使用独立限流。在真机安装新版前先通过 [原生会话冒烟](../../docs/deployment/identity-and-media.md#ios-公网连通性验收)。若回退到早于 V5 的镜像,原生登录入口也随之回退,安排回退前先确认手机端的可用版本与登录路径。
## 转发和验收
在集群里用 FRP 客户端直连 `svc/item-atlas-gateway` 和 `svc/atlas-keycloak`。将 `frpc.toml.template` 渲染为受控文件,其中两条 STCP 各用独立密钥。云端 visitor 使用匹配的名称和密钥,只监听 Nginx 容器可达的私有网桥,由 systemd 管理。
```sh
kubectl -n item-atlas-public create secret generic atlas-public-frpc \
--from-file=frpc.toml="$ATLAS_SECRET_DIR/frpc.toml" --dry-run=client -o yaml |
kubectl -n item-atlas-public apply --server-side -f -
kubectl -n item-atlas-public apply -f deploy/public/frpc.yaml
kubectl -n item-atlas-public rollout status deployment/atlas-public-frpc --timeout=2m
kubectl -n item-atlas-public logs deployment/atlas-public-frpc --tail=20
```
日志应显示两个代理注册成功。渲染 `nginx.conf.template`,将两个 `ATLAS_VISITOR_*` 填为实际私有监听地址和端口。用 `nginx -t` 通过后重载。先用 `curl --resolve` 指定目标 IP,核对 TLS、OIDC discovery 和业务 API,再加入公网 A 记录。通过公网跑原生会话冒烟,带令牌查询 `GET /api/households` 应返回 200。另查未登录的 API 及管理路径,预期分别为 401 和 404。仍有旧版 iOS 使用时再验一次 OIDC 授权码回调。 [iOS 验收步骤](../../docs/deployment/identity-and-media.md#ios-公网连通性验收)
工作 Mac 需要挂载 SSD 并运行 Linux VM,集群会启动 FRP 客户端并重连。通常检查顺序是 DNS、TLS、Nginx、STCP、Service 与应用。检查应用版本用 `helm history item-atlas -n item-atlas-public`,回退前先核对数据库迁移兼容性。需要关闭公网预览时停用该域名的独立 Nginx 站点。数据库和私有桶有独立备份流程。