以 headless 方式管理劳动力(Identity Center)用户(M2M)¶
从后端服务管理你组织的 劳动力(Identity Center)用户,无需交互式登录 — 仅使用服务 access key(AK/SK)和 STS。该模式忠实于 AWS:你的 key assumes a role,而该 role 的临时凭证携带管理 IdC 用户的权限。
AK/SK → assume-role → ASIA temp creds → FGAI-HMAC + X-FGAI-Security-Token
→ /identity/v1/organizations/{orgId}/identity-center/users…
为什么使用角色(而不是直接使用你的密钥)?Workforce-user 管理在每次调用时都针对 identitycenter:User:{verb} 授权。该权限授予一个位于你组织的 management account 中的角色;你 assume 该角色来以其身份操作。这会让你的长期 service key 保持较少权限,并遵循与 AWS IAM + STS 相同的形态。
Prerequisites: a service access key (see Integrate an external app with AK/SK) and the ability to sign requests with FGAI-HMAC-SHA256 (see IAM roles and STS AssumeRole). All calls below are one signed HTTPS request to https://api.flexgalaxy.ai.
角色位于管理账号中¶
WorkforceAdminRole 始终位于你的组织的管理账号({mgmtAccountId})中,因为 Identity Center 目录锚定在那里。因此其 FRN 是 frn:{mgmtAccountId}:iam:role/WorkforceAdminRole,其权限策略授予 identitycenter:User:* 到 frn:{mgmtAccountId}:identitycenter:user/*。你应选择哪条路径取决于你的服务主体位于哪里:
路径 |
你的 service principal 位于… |
你通过…获取该角色 |
|---|---|---|
Primary — platform-seeded(external integrator) |
你的自有 tenant account(不是 management account) |
platform 会在 management account 中为你预置该 role;其 trust 允许你的 principal 的 FRN 跨 accounts 访问,并要求 |
Secondary — 自写入(仅 management-account) |
management account 本身 |
你需要自行编写该 role、它的 managed policy 以及 attachment,然后 assume 它。 |
主路径是外部集成方的常规路径:服务 key 被固定到其自己的账号,因此它不能在管理账号中创建角色 — 平台会播种该角色。self-author 路径仅当你的主体已经位于管理账号中时才可用。
两个关键约束¶
先阅读这些 — 任一错误都会产生静默的 403 IMPLICIT_DENY。它们在两条路径上都成立(平台预置 role 已满足它们)。
权限通过 MANAGED policy 授予,并 attach 到 role。 role 的 inline policy 在此路径中不会生效。grant 是通过
POST …/roles/{roleId}/policiesattach 的 customer-managediam-policy。policy
Resource必须匹配 Identity Center user FRN。 它必须是frn:{mgmtAccountId}:identitycenter:user/*(或*)。更窄或错误的Resource不会匹配,调用会被拒绝。
主路径 — assume 平台预置的 role(外部集成方)¶
你的 service principal 位于你自己的 tenant account 中。在 onboarding 期间,平台会在你组织的 management account 中 seed WorkforceAdminRole,其 trust policy 会跨账号接纳你的 principal FRN,并要求共享密钥 sts:ExternalId。你无需编写任何内容 — 只需 assume 并执行。
onboarding 会给你什么:
role FRN —
frn:{mgmtAccountId}:iam:role/WorkforceAdminRoletrust condition 使用的
externalIdshared secret你的
{orgId}(及其{mgmtAccountId})
1. Assume the role → temporary credentials¶
POST /identity/v1/sts/assume-role — 使用你的静态服务密钥(AKIA)签名,即使该角色位于不同的(管理)账号中也是如此。这是跨账号 assume-role;角色的 trust policy 是门控条件。
{
"roleFrn": "frn:{mgmtAccountId}:iam:role/WorkforceAdminRole",
"roleSessionName": "workforce-batch-42",
"durationSeconds": 3600,
"externalId": "shared-secret-xyz"
}
响应返回 ASIA… 凭证(accessKeyId、secretAccessKey、sessionToken、expiration)。durationSeconds 被限制在 [900, role.maxSessionDuration]。错误或缺失的 externalId 返回 403,且不返回凭证。
2. Manage workforce users with the temporary credentials¶
使用 ASIA 凭证(FGAI-HMAC-SHA256)为每次调用签名,并添加 X-FGAI-Security-Token header,其值设为 sessionToken。
… /identity/v1/organizations/{orgId}/identity-center/users
方法 |
路径 |
目的 |
|---|---|---|
|
|
列出劳动力用户 |
|
|
邀请劳动力用户 |
|
|
读取劳动力用户 |
|
|
更新 workforce user |
|
|
禁用 / 启用 |
|
|
重置登录凭证 |
|
|
移除劳动力用户 |
每个操作都会根据 identitycenter:User:{verb} 检查;使用 seeded role 的 managed policy 时,检查返回 ALLOW。
如何查找你的 mgmtAccountId¶
角色 FRN、策略 Resource 和 {orgId} 路径都指向你的组织的管理账号。从组织解析它:读取你的组织(GET /organizations/v1/{orgId})— 其管理账号 id 是 mgmtAccountId。对于 self-author(管理账号)主体,这就是你自己的账号 id。
长时间运行的作业:会话时长和重新 assume¶
Assumed-role credentials 是短期的 — durationSeconds 会被限制到 [900, role.maxSessionDuration](默认 3600)。长时间运行的 headless batch 必须在当前 expiration 之前重新 assume 该 role,并继续使用新的 ASIA credentials 签名。请在到期前稍早刷新(例如生命周期的 80%),而不是等待 401。
失败¶
签名缺失/无效 →
401。Role 缺失 或 其 trust policy 拒绝你(错误 principal 或错误
externalId)→403(不可区分,因此调用方无法探测另一个账户中的 roles),且 不会 返回 credentials。权限未授予(未附加 managed policy,或
Resource不匹配)→identity-center/users调用返回403。
另请参见¶
Integrate an external app with AK/SK — FGAI-HMAC signing。
IAM roles and STS AssumeRole — roles、trust policies、STS reference。
[FRN format](https://docs.flexgalaxy.ai/dev/dotid/frn-format/)