IAM 角色和 STS AssumeRole

DotID 以与 AWS IAM 相同的方式建模角色:角色是账户中可被担任的身份,带有信任策略(谁可以担任它)和附加的权限策略(它可以做什么)。调用方通过 STS AssumeRole 担任角色,并接收短期凭证,该凭证以角色账户中的角色权限运行。这是跨账户访问背后的机制。

认证

角色管理和 STS 由账户管理员自管理。使用账户服务用户访问密钥通过 FGAI-HMAC-SHA256 签名请求(见 [CLI 与服务认证](https://docs.flexgalaxy.ai/dev/dotid/cli-authentication/));也接受 bearer JWT。你的凭证固定到一个账户 — 你只能管理该账户中的角色。

Base URL: https://api.flexgalaxy.ai.

角色

方法

路径

用途

POST

/identity/v1/accounts/{account_id}/roles

创建角色

GET

/identity/v1/accounts/{account_id}/roles

列出角色

GET

/identity/v1/accounts/{account_id}/roles/{role_id}

获取角色

PUT

/identity/v1/accounts/{account_id}/roles/{role_id}

更新信任策略 / 描述 / 最大会话

DELETE

/identity/v1/accounts/{account_id}/roles/{role_id}

删除角色

POST

/identity/v1/accounts/{account_id}/roles/{role_id}/policies

附加权限策略

GET

/identity/v1/accounts/{account_id}/roles/{role_id}/policies

列出已附加策略

DELETE

/identity/v1/accounts/{account_id}/roles/{role_id}/policies/{policy_id}

分离策略

创建角色

The trust_policy is required and answers "who may assume me". name is required; description, path, and max_session_duration (seconds) are optional.

Field names on the wire are snake_case. Every DotID request and response body uses snake_case (trust_policy, role_frn, access_key_id, …). A body spelled in camelCase binds nothing and the API answers 400 with "role_frn: must not be blank" — a message that reads like a missing field when the real cause is the spelling.

{
  "name": "DeviceReader",
  "description": "Read-only device access, assumable by the ops tooling account.",
  "max_session_duration": 3600,
  "trust_policy": {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Principal": { "Account": ["acc-0a1b2c3d4e5f"] },
        "Action": "sts:AssumeRole"
      }
    ]
  }
}

响应是创建的角色,包含其 id:

{
  "id": "8b2f0a3e-1c4d-4e6f-9a01-2b3c4d5e6f70",
  "account_id": "11111111-1111-1111-1111-111111111111",
  "name": "DeviceReader",
  "trust_policy": { "…": "…" },
  "max_session_duration": 3600,
  "version": 1,
  "created_at": "2026-07-07T09:00:00Z"
}

信任策略

当 Effect 为 Allow、Action 包含 sts:AssumeRole、Principal 块匹配调用方,并且每个 Condition 都满足时,每条语句允许一个调用方。评估是故障关闭的:没有匹配的 Allow 时调用方被拒绝,匹配的 Deny 总是胜出。

Principal 接受:

形式

含义

"*"

任何调用方。

{ "Account": ["acc-…"] }

该账户中的任何 principal。

{ "FGAI": ["frn:acc-…:iam:user/name"] }

由 [FRN](https://docs.flexgalaxy.ai/dev/dotid/frn-format/) 标识的特定 principal。

{ "FGAI": ["frn:acc-…:iam:account/acc-…"] }

整个账户(账户形式 FRN)。

可选地通过 sts:ExternalId 条件要求共享密钥:

{
  "Effect": "Allow",
  "Principal": { "Account": ["acc-0a1b2c3d4e5f"] },
  "Action": "sts:AssumeRole",
  "Condition": { "StringEquals": { "sts:ExternalId": "shared-secret-xyz" } }
}

附加权限策略

按 id 附加你账户中的某个 IAM 策略,以授予角色可执行的操作:

curl -fsS -X POST \
  "https://api.flexgalaxy.ai/identity/v1/accounts/$ACCOUNT_ID/roles/$ROLE_ID/policies" \
  -H "Content-Type: application/json" \
  -d '{ "policy_id": "a1b2c3d4-…" }'
  # + FGAI-HMAC-SHA256 signing headers

STS AssumeRole

将你的凭证交换为作用域限定到某个角色的临时凭证。

方法

路径

用途

POST

/identity/v1/sts/assume-role

担任角色 → 临时凭证

请求

role_frn and role_session_name are required; duration_seconds and external_id are optional. Pass external_id when the target role's trust policy requires one.

{
  "role_frn": "frn:acc-target00acct:iam:role/DeviceReader",
  "role_session_name": "ops-tooling-run-42",
  "duration_seconds": 3600,
  "external_id": "shared-secret-xyz"
}

duration_seconds is clamped to [900, role.max_session_duration].

响应

{
  "assumed_role_frn": "frn:acc-target00acct:iam:role/DeviceReader",
  "account_id": "22222222-2222-2222-2222-222222222222",
  "role_session_name": "ops-tooling-run-42",
  "access_key_id": "ASIA…",
  "secret_access_key": "…",
  "session_token": "…",
  "expiration": "2026-07-07T10:00:00Z"
}

The returned credentials are temporary (ASIA… key id). Use them to sign subsequent requests with FGAI-HMAC-SHA256, adding the session token as the X-FGAI-Security-Token header. Requests signed with these credentials act in the role's account with the role's permissions — so authorization decisions for the session resolve from the role's attached policies (see Policy simulator).

失败

  • 缺失或无效签名返回 401。

  • 如果角色不存在或其信任策略拒绝调用方,调用返回 403 — 这两种情况不可区分,因此调用方无法探测另一个账户中的角色。

Assume a role from a workload identity (CI, machine persona)

A workload identity holds no key at all — it authenticates by presenting its IdP-issued OIDC token to the token exchange and receiving a short-lived DotID-signed bearer. A bearer is not a CLI command credential, so a machine persona that needs to transact takes one more step: it assumes a role and receives the same temporary ASIA… credential a human gets from Identity Center.

The route is a workload twin of the one above, not the same one:

方法

路径

Caller

POST

/identity/v1/sts/assume-role

An access key (FGAI-HMAC) or a console/federated JWT

POST

/identity/v1/workload/sts/assume-role

A workload token from the exchange, as Authorization: Bearer

Sending a workload token to the first route returns 401 invalid_token with unknown_realm: token-exchange — that is "wrong door", not "denied". The request and response bodies are identical on both routes.

One-time setup by the account admin

  1. Grant the workload identity the STS audience. Attach an IAM policy allowing iam:ExchangeToken on the STS service resource, so the workload can mint a token the STS lane accepts:

    {
      "Version": "2024-01-01",
      "Statement": [
        {
          "Sid": "ExchangeForSts",
          "Effect": "Allow",
          "Action": "iam:ExchangeToken",
          "Resource": "frn::iam:service/dotid-sts"
        }
      ]
    }
    

    This grants nothing but the right to ask. The audience puts the workload's token on the STS lane; which roles it may assume is still decided, per role, by the trust policy below.

  2. Name the workload in the role's trust policy. A workload identity's principal FRN uses the workload-identity resource type — it is not a user, and a trust policy written for one can never be satisfied by the other:

    {
      "Effect": "Allow",
      "Principal": {
        "FGAI": ["frn:acc-0a1b2c3d4e5f:iam:workload-identity/<workload-identity-id>"]
      },
      "Action": "sts:AssumeRole"
    }
    
  3. Attach the role's permissions as managed policies through POST /identity/v1/accounts/{account_id}/roles/{role_id}/policies. An assumed session resolves the role's attached policies; an inline role policy is not read.

The call

# 1. exchange the CI OIDC token for a workload token on the STS lane
ACCESS_TOKEN=$(curl -fsS -X POST https://api.flexgalaxy.ai/oauth2/token \
  -H "Content-Type: application/x-www-form-urlencoded" \
  --data-urlencode "grant_type=urn:ietf:params:oauth:grant-type:token-exchange" \
  --data-urlencode "subject_token=$OIDC_TOKEN" \
  --data-urlencode "subject_token_type=urn:ietf:params:oauth:token-type:jwt" \
  --data-urlencode "audience=dotid-sts" | jq -r .access_token)

# 2. assume the role — no signing, the bearer IS the credential here
curl -fsS -X POST https://api.flexgalaxy.ai/identity/v1/workload/sts/assume-role \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{ "role_frn": "frn:acc-0a1b2c3d4e5f:iam:role/Publisher",
        "role_session_name": "ci-run-42" }'

The response is the same ASIA… credential shape as above. From here the workload signs requests with FGAI-HMAC-SHA256 exactly like any other principal — including through the fgai CLI:

FGAI_SECRET_ACCESS_KEY="$SECRET_ACCESS_KEY" \
fgai configure --name ci-publisher \
  --account-id "$ACCOUNT_ID" \
  --access-key-id  "$ACCESS_KEY_ID" \
  --session-token "$SESSION_TOKEN" \
  --expiration "$EXPIRATION"

Record --expiration: fgai auth status then reports why a credential started returning 401 instead of the command failing with no explanation.

Telling the failures apart

Status

含义

401 with unknown_realm: token-exchange

Wrong route — you sent a workload token to /identity/v1/sts/assume-role. Use the /workload/ path.

403 on the /workload/ path with no credential shown

Either the token is not on the STS lane (missing the iam:ExchangeToken grant on frn::iam:service/dotid-sts, so the exchange minted a different audience), or the role's trust policy does not name this workload.

400 role_frn: must not be blank

The body was spelled in camelCase. The wire is snake_case.

Revoke a live session at any time with POST /identity/v1/sts/revoke-session ({"access_key_id": "ASIA…"}); the credential stops working within about half a minute.

→ 管理 workforce users

assumed role 的常见用途是无头 workforce(Identity Center)user management:将授予 identitycenter:User:* 的 managed policy attach 到 role,assume 它,然后使用 temporary credentials 在 Identity Center directory 中管理 users — 无需 interactive login。见 Manage workforce (Identity Center) users headlessly (M2M) 中的完整 recipe。

另见