workforce (Identity Center) users を headless に管理する (M2M)

backend service から interactive login なしで organization の workforce (Identity Center) users を管理します — service access key (AK/SK) と STS のみを使用します。このパターンは AWS に忠実です。key が role を assume し、その role の temporary credentials が IdC users を管理する permission を持ちます。

AK/SK  →  assume-role  →  ASIA temp creds  →  FGAI-HMAC + X-FGAI-Security-Token
       →  /identity/v1/organizations/{orgId}/identity-center/users…

なぜ role (key を直接使わないのか) なのか。Workforce-user management は、すべての call で identitycenter:User:{verb} に対して authorization されます。その permission は、organization の management account に存在する role に付与されます。あなたはその role を assume して操作します。これにより、長期有効な service key の permission を軽く保ち、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.

role は management account に存在する

WorkforceAdminRole は常に organization の management account({mgmtAccountId})に存在する。Identity Center directory がそこに anchoring されているためである。したがってその FRN は frn:{mgmtAccountId}:iam:role/WorkforceAdminRole であり、permission policy は frn:{mgmtAccountId}:identitycenter:user/* に対する identitycenter:User:* を grant する。どの path に従うかは、あなたの service principal がどこに存在するかによって決まる:

Path

service principal の場所…

role の取得方法…

Primary — platform-seeded(external integrator)

あなた自身の tenant account (management account ではありません)

platform が management account 内の role をあなたのためにseedします。その trust は、あなたの principal の FRN を account 間で許可し、sts:ExternalId を要求します。あなたはそれを cross-account で assume します。

Secondary — self-authored(management-account のみ)

management account 自体

あなたは role、その managed policy、および attachment を自分で作成し、その後それを assume します。

primary path は外部 integrator にとって標準である。service key は自分の account に固定されるため、management account 内で role を author できない。その role は platform が seed する。self-author path は、principal がすでに management account 内に存在する場合 のみ 利用可能である。

2 つの重要な制約

まずこれらを読んでください — どちらかを誤ると silent 403 IMPLICIT_DENY になります。これらは両方の paths で成り立ちます (platform-seeded role はすでに満たしています)。

  1. permission は role に attached された MANAGED policy で付与されます。 role の inline policy はこの path では尊重されません。grant は POST …/roles/{roleId}/policies で attached される customer-managed iam-policy です。

  2. policy Resource は Identity Center user FRN と一致しなければなりません。 frn:{mgmtAccountId}:identitycenter:user/*(または *)である必要があります。より狭い、または誤った Resource は一致せず、call は denied されます。

Primary path — platform-seeded role を assume する (external integrator)

service principal はあなた自身の tenant account に存在します。onboarding 中に platform は organization の management account に WorkforceAdminRole を seed します。この role には、account 間であなたの principal FRN を許可し、shared-secret sts:ExternalId を要求する trust policy があります。何かを作成する必要はありません。assume して操作します。

onboarding で得られるもの:

  • role FRN — frn:{mgmtAccountId}:iam:role/WorkforceAdminRole

  • trust condition 用の externalId shared secret

  • あなたの {orgId} (およびその {mgmtAccountId})

1. Assume the role → temporary credentials

POST /identity/v1/sts/assume-role — ロールが 別の (管理) アカウントにある場合でも、ユーザーの 静的 サービスキー (AKIA) で署名します。これはクロスアカウントの assume-role です。ロールの信頼ポリシーがゲートになります。

{
  "roleFrn": "frn:{mgmtAccountId}:iam:role/WorkforceAdminRole",
  "roleSessionName": "workforce-batch-42",
  "durationSeconds": 3600,
  "externalId": "shared-secret-xyz"
}

response は ASIA… credentials(accessKeyId, secretAccessKey, sessionToken, expiration)を返す。durationSeconds は [900, role.maxSessionDuration] に clamp される。誤った、または欠落した externalId は credentials なし で 403 を返す。

2. Manage workforce users with the temporary credentials

各呼び出しを ASIA credentials(FGAI-HMAC-SHA256)で署名し、sessionToken を設定した X-FGAI-Security-Token header を追加する。

… /identity/v1/organizations/{orgId}/identity-center/users

Method

Path

Purpose

GET

…/identity-center/users

workforce users を一覧表示する

POST

…/identity-center/users

workforce user を招待する

GET

…/identity-center/users/{userId}

workforce user を読み取る

PUT

…/identity-center/users/{userId}

workforce user を更新する

POST

…/identity-center/users/{userId}/disable | /enable

無効化 / 有効化

POST

…/identity-center/users/{userId}/reset-password

login credential を reset する

DELETE

…/identity-center/users/{userId}

workforce user を削除する

各 operation は identitycenter:User:{verb} に対してチェックされます。seeded role の managed policy では、このチェックは ALLOW を返します。

Secondary path — role を self-author する(management-account principal のみ)

これを使用するのは、service principal がすでに management account に存在する場合のみです。その場合、以下の paths の {accountId} は {mgmtAccountId} です。したがって、static key を使って public routes 上で chain 全体を作成し、上記 step 1 とまったく同じように role を assume できます。

1. Create the managed permission policy

POST /identity/v1/accounts/{mgmtAccountId}/policies

{
  "name": "WorkforceAdmin",
  "policyDocument": {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Action": "identitycenter:User:*",
        "Resource": "frn:{mgmtAccountId}:identitycenter:user/*"
      }
    ]
  }
}

必要であれば、Action を必要な正確な verbs に絞り込んでください: identitycenter:User:List, :Read, :Create, :Update, :Delete, :Disable, :Enable, :ResetPassword。response は policy id を返します。

2. Create the role with a trust policy that admits your service principal

POST /identity/v1/accounts/{mgmtAccountId}/roles

trust policy は "who may assume me" に答える。自分の service principal を FRN で admit し、sts:AssumeRole を require する。Recommended: sts:ExternalId condition(confused-deputy hardening)を追加し、assume-role 時に同じ値を渡す。

{
  "name": "WorkforceAdminRole",
  "maxSessionDuration": 3600,
  "trustPolicy": {
    "Version": "2012-10-17",
    "Statement": [
      {
        "Effect": "Allow",
        "Principal": { "FGAI": ["frn:{mgmtAccountId}:iam:user/{yourPrincipalId}"] },
        "Action": "sts:AssumeRole",
        "Condition": { "StringEquals": { "sts:ExternalId": "shared-secret-xyz" } }
      }
    ]
  }
}

response は role id を返す。role FRN は frn:{mgmtAccountId}:iam:role/WorkforceAdminRole である。

3. Attach the managed policy to the role

POST /identity/v1/accounts/{mgmtAccountId}/roles/{role_id}/policies

{ "policyId": "a1b2c3d4-…" }

これは role が IdC user を管理できるようにする手順です。(role に policy を inline でアタッチしても機能しません。constraint 1 を参照してください。)

4. Assume the role and manage users

role を assume し、primary path(上記 steps 1–2)とまったく同じように users を管理します。roleFrn = frn:{mgmtAccountId}:iam:role/WorkforceAdminRole を使用します。

mgmtAccountId の見つけ方

role FRN、policy Resource、{orgId} path はすべて organization の management account を指す。organization からそれを解決する: organization を読む(GET /organizations/v1/{orgId})— その management account id が mgmtAccountId である。self-author(management-account)principal の場合、これは単に自分自身の account id である。

長時間実行ジョブ: session duration と re-assume

Assumed-role credentials は short-lived です — durationSeconds は [900, role.maxSessionDuration] に clamped されます(default 3600)。長時間の headless batch は、現在の expiration の前に role を re-assume し、新しい ASIA credentials で signing を継続する必要があります。401 を待つのではなく、expiry より少し前(例: lifetime の 80%)に refresh してください。

Failures

  • signature がない、または無効 → 401。

  • Role が存在しない or その trust policy が拒否している(principal が誤っている、または externalId が誤っている)→ 403(区別不能なため、呼び出し元は別アカウントの role を探索できない)。credentials は返されない。

  • Permission が付与されていない (managed policy が attach されていない、または Resource が一致しない) → identity-center/users call で 403。

関連項目