# 管理后台本机预览 在 kind 中创建独立的 `item-atlas-admin-preview` 命名空间。管理员和普通账号由独立的 Keycloak realm 管理。网关复用后端候选发布的镜像,物品服务和后台用同一份源码构建预览镜像。PostgreSQL 在一个独立的持久卷上,为登录和物品服务分别创建数据库和用户。 ```mermaid flowchart LR browser[本机浏览器] -->|127.0.0.1:18482| web[Nginx 与管理后台] web -->|OIDC 授权码与 PKCE| identity[Keycloak] web -->|管理 API| gateway[Spring Cloud Gateway] gateway --> inventory[物品服务] inventory -->|内网 JWKS| identity identity --> iddb[(身份数据库)] inventory --> pg[(物品数据库)] ``` 浏览器通过同源 `/auth` 登录,物品服务从集群内获取签名公钥。令牌的 issuer 仍须匹配浏览器地址。管理接口验证签名、有效期、audience、`atlas-admin` 客户端和 `atlas-space-admin` 角色。此配置使用回环 HTTP,公网部署请使用 [HTTPS 身份配置](../../docs/deployment/identity-and-media.md)。 ## 启动 在能访问 kind 的终端执行,确认当前上下文、节点镜像架构和存储类位置。新节点需按 [候选交付流程](../../docs/deployment/backend-release.md) 拉取清单中的网关镜像。Docker 和 kubectl 如果同在虚拟机里,镜像构建与部署命令也在虚拟机中执行。 ```sh kind_cluster=atlas-dev context="kind-$kind_cluster" namespace=item-atlas-admin-preview secret_dir=/path/on/ssd/item-atlas-admin-preview admin_password_file=/path/on/ssd/managed-preview-admin-password mvn -B -ntp -f backend/pom.xml -pl inventory-service -am package docker build -t item-atlas-inventory-service:admin-preview-0.1.3 backend/inventory-service docker build --build-arg VITE_OIDC_URL=/auth \ --build-arg VITE_OIDC_REALM=item-atlas-admin-preview \ -t item-atlas-admin:admin-preview-0.1.4 apps/admin kind load docker-image --name "$kind_cluster" \ item-atlas-inventory-service:admin-preview-0.1.3 item-atlas-admin:admin-preview-0.1.4 python3 deploy/admin-preview/prepare-secrets.py "$secret_dir" --admin-password-file "$admin_password_file" kubectl --context "$context" create namespace "$namespace" for component in postgres keycloak inventory; do kubectl --context "$context" -n "$namespace" create secret generic "atlas-admin-$component" \ --from-env-file="$secret_dir/$component.env" done kubectl --context "$context" -n "$namespace" create secret generic atlas-admin-realm \ --from-file="$secret_dir/item-atlas-admin-preview-realm.json" kubectl --context "$context" apply --dry-run=server -k deploy/admin-preview kubectl --context "$context" apply -k deploy/admin-preview kubectl --context "$context" -n "$namespace" get pods,pvc kubectl --context "$context" -n "$namespace" port-forward --address 127.0.0.1 svc/item-atlas-admin 18482:8080 ``` 首次部署使用 `dongjf` 作为后台管理员,密码由受控文件提供。生成的 `preview-viewer` 供权限验收,凭据位于私有目录的 `credentials.json`。后台和 Keycloak 登录统一使用简体中文。首次导入后,已有 realm 的语言、账号和角色应通过 Keycloak 管理接口更新并复验。重新生成启动文件用于新环境初始化。 [Keycloak 语言配置](https://www.keycloak.org/docs/latest/server_admin/#_user-locale-selection) · [Keycloak 管理接口](https://www.keycloak.org/docs-api/latest/rest-api/) ## 验收和排错 打开 [管理后台](http://127.0.0.1:18482/)。管理员可以分页查空间、按名称或完整 ID 定位、查看物品和照片数量。普通账号登录后会看到权限提示。删除请使用专用测试空间,提交后打开「删除记录」,按空间 ID 核对操作人和时间。对应数据保存在 `space_admin_action`。照片记录被删除时,数据库触发器会在同一个事务登记 `media_cleanup`。本预览用于核对队列写入,真实对象清理由 [对象存储冒烟脚本](../../backend/tests/media_smoke.py) 在带存储的环境验收。 打开「图片清理」检查队列统计。本机预览会标明没有配置图片存储。真实存储环境持续出现待执行或重试时,先核对最早待执行时间,再从物品服务日志查清理重试及对象存储请求耗时。更新此模块时,先交付支持该接口的物品服务,再更新 Web 镜像。 页面打不开先查 `/healthz` 和端口转发。浏览器返回登录页时看 Keycloak 回调地址和 Nginx `/auth` 路由。管理 API 返回 `401` 时核对 issuer、JWKS 和有效期,返回 `403` 时核对客户端和管理员角色。物品服务启动时 Flyway 会等待数据库,持续失败时查看 PVC、PostgreSQL 日志及 Flyway 日志。后台 Nginx 的访问日志保留路径、状态码与响应耗时,省略包含授权码的查询参数。 更新后台 Pod 后端口转发会断开,重新运行 `kubectl port-forward` 即可。停止转发后入口关闭,预览数据库保留在 PVC 中。 [端口转发](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_port-forward/) · [Keycloak hostname](https://www.keycloak.org/server/hostname) · [Spring Boot Flyway 配置](https://docs.spring.io/spring-boot/4.0/appendix/application-properties/#application-properties.data-migration)