Sandbox 测试操作员 — 用于 CI 的无头登录 token

当你为面向操作员的流程(mobile operator app、warehouse terminal、任何由 PDP-gated 的资源访问)编写自动化验收测试时,CI 需要一个真实的 end-user token,且携带 account_id claim — 其形状与人工操作员登录后获得的 token 相同。你无法脚本化人工登录(它有意受 email OTP + CAPTCHA 保护),而裸的 admin-created user 不携带 account_id。

sandbox test-operator API 解决了这个问题:一次 AK/SK 认证调用会在你自己的账号中预配一个 workforce operator,并返回一个真实的、由 Keycloak 签发的 operator token,你的 CI 可以立即使用。

TL;DR. POST https://api.flexgalaxy.ai/developer/v1/test-users, signed with your account's access key (FGAI-HMAC). Pass the service_id of the product your CI is about to call. You get back { user_id, email, access_token, expires_in }. The access_token is a real operator token (carries account_id + user_type=workforce), valid for 5 minutes. It is addressed to the product you named, plus the DotID base audience — the product's own API accepts it, and the PDP accepts it everywhere. Delete the operator with DELETE /developer/v1/test-users/{user_id} when the suite finishes.

前提条件 — 一次性账户设置

将此转发给你的 Account root 或已授权的 account admin:

  1. 组织内的一个 sandbox account。 测试操作员会作为Identity Center instance 中的 workforce user 创建,因此你预置到的账户必须属于某个组织(不能是独立账户)。

  2. 该账户中某个 principal 的 access key(Profile → Credentials → Access keys,或 developer credential API)。

  3. 向该 principal 授予 iam:CreateTestUser capability — 一个限定到账户的 IAM policy statement:

    {
      "Effect": "Allow",
      "Action": "iam:CreateTestUser",
      "Resource": "frn:<accountId>:iam:account/<accountId>"
    }
    

    该 capability 正是让一个账号成为 "sandbox" 的原因:只有 admin 明确授予它的账号才能 mint test operators,并且调用方只能预配到自己的账号(账号来自 AK/SK token,绝不来自请求 body)。

创建 operator

像为其他 /developer/v1/* 或 /identity/v1/* 调用签名一样,使用 FGAI-HMAC-SHA256 为请求签名(参见 Integrate with access keys)。

POST /developer/v1/test-users
Authorization: FGAI-HMAC-SHA256 Credential=AKIA.../.../identity/fgai4_request, ...
Content-Type: application/json

{ "user_type": "workforce", "service_id": "bazaar" }

service_id names the registered product your CI will call; the minted token is addressed to that product's API audience so the product's API accepts it. Omit it and the token carries only the DotID base audience — usable against DotID's own APIs, but a product API will reject it. An unregistered id is refused with 400 {"error":"unknown_service_id"}. user_type is optional (only workforce is supported today) and email is optional (a @sandbox.flexgalaxy.test address is generated when omitted).

201 响应:

{
  "user_id": "b3a0de58-318f-41f9-bba5-dfe8fdbaa17d",
  "email": "op-2124a427b3@sandbox.flexgalaxy.test",
  "access_token": "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUI...",
  "expires_in": 300
}

access_token 会解码为真实的 operator token:

{
  "iss": "https://auth.flexgalaxy.ai/auth/realms/flexgalaxy",
  "aud": ["<the product's audience>", "flexgalaxy-api"],
  "sub": "b3a0de58-318f-41f9-bba5-dfe8fdbaa17d",
  "account_id": "<your sandbox account UUID>",
  "user_type": "workforce",
  "exp": "<iat + 300>"
}

(aud with the service_id above; without it, aud is just "flexgalaxy-api".)

Present it to any FlexGalaxy.AI API as Authorization: Bearer <access_token>. It validates against the realm JWKS like a real login, resolves the correct account_id, and is denied on cross-account access — exactly what your acceptance test asserts. (The policy simulator is a different credential class: it is called with FGAI-HMAC-signed service-user keys, never this token.)

短 TTL,无刷新。 token 有效期为 5 分钟。对于更长的 suite,再次调用 POST /developer/v1/test-users 获取新 token(或复用同一个 operator user_id — 它会一直存在,直到你删除它)。

列出和删除

GET    /developer/v1/test-users            → [{ "user_id", "email" }, ...]
DELETE /developer/v1/test-users/{user_id}  → 204

DELETE 会删除 operator 及其账户分配。请在测试运行结束时清理,避免 sandbox operators 持续累积。

范围和安全性

  • operator 是真实的 workforce user,通过真实的 Identity Center assignment 获权访问你的 sandbox 账号 — 平台会强制该门禁,因此 token 只能携带你实际拥有的 account_id。

  • 它仅限于你自己的账户;不能触碰其他租户。

  • 每次创建和删除都会被审计(DeveloperTestUserCreated / DeveloperTestUserDeleted)。

  • 这是一个 sandbox/testing 设施。不要将 test operators 用作生产身份。