コンテンツにスキップ

ポリシー管理

概要

ポリシー管理APIは、アクセス制御ポリシーを定義・管理するためのエンドポイントを提供します。条件ベースのルールを設定し、アクセス制御の挙動をシミュレーションできます。

エンドポイント一覧

メソッドエンドポイント説明
GET/api/admin/policiesポリシー一覧取得
GET/api/admin/policies/:idポリシー詳細取得
POST/api/admin/policiesポリシー作成
PUT/api/admin/policies/:idポリシー更新
DELETE/api/admin/policies/:idポリシー削除
POST/api/admin/policies/simulateポリシーシミュレーション
GET/api/admin/policies/condition-types条件タイプ一覧取得

ポリシー一覧取得

テナント内のポリシー一覧を取得します。

エンドポイント

GET /api/admin/policies

クエリパラメータ

パラメータ必須説明
limitinteger-取得件数(デフォルト: 20、最大: 100)
cursorstring-ページネーションカーソル
statusstring-ステータスでフィルタ(active, inactive
resourcestring-リソースでフィルタ

リクエスト例

Terminal window
curl -X GET "https://{tenant-domain}/api/admin/policies?status=active" \
-H "Authorization: Bearer {token}"

レスポンス例

{
"items": [
{
"id": "policy_abc123",
"name": "admin-only-settings",
"description": "設定変更は管理者のみ",
"status": "active",
"effect": "deny",
"priority": 100,
"resource": "settings:*",
"created_at": 1705881600,
"updated_at": 1705968000
},
{
"id": "policy_def456",
"name": "office-hours-access",
"description": "オフィス時間内のみアクセス可能",
"status": "active",
"effect": "allow",
"priority": 50,
"resource": "documents:*",
"created_at": 1705968000,
"updated_at": 1706054400
}
],
"total": 10,
"cursor": null
}

ポリシー詳細取得

指定されたポリシーの詳細情報を取得します。

エンドポイント

GET /api/admin/policies/:id

パスパラメータ

パラメータ必須説明
idstringポリシーID

リクエスト例

Terminal window
curl -X GET "https://{tenant-domain}/api/admin/policies/policy_def456" \
-H "Authorization: Bearer {token}"

レスポンス例

{
"id": "policy_def456",
"name": "office-hours-access",
"description": "オフィス時間内のみアクセス可能",
"status": "active",
"effect": "allow",
"priority": 50,
"resource": "documents:*",
"actions": ["read", "write"],
"conditions": [
{
"type": "time_range",
"operator": "between",
"value": {
"start": "09:00",
"end": "18:00",
"timezone": "Asia/Tokyo"
}
},
{
"type": "day_of_week",
"operator": "in",
"value": ["monday", "tuesday", "wednesday", "thursday", "friday"]
},
{
"type": "ip_range",
"operator": "in",
"value": ["192.168.1.0/24", "10.0.0.0/8"]
}
],
"subjects": {
"roles": ["employee"],
"exclude_roles": ["contractor"]
},
"created_at": 1705968000,
"updated_at": 1706054400
}

ポリシー作成

新しいポリシーを作成します。

エンドポイント

POST /api/admin/policies

リクエストボディ

フィールド必須説明
namestringポリシー名
descriptionstring-説明
effectstring効果(allow, deny
priorityinteger-優先度(高いほど先に評価、デフォルト: 0)
resourcestring対象リソース(ワイルドカード可)
actionsstring[]-対象アクション
conditionsobject[]-条件のリスト
subjectsobject-対象サブジェクト(ロール、ユーザー等)

リクエスト例

Terminal window
curl -X POST "https://{tenant-domain}/api/admin/policies" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"name": "mfa-required-for-admin",
"description": "管理機能へのアクセスにはMFAが必要",
"effect": "deny",
"priority": 200,
"resource": "admin:*",
"actions": ["*"],
"conditions": [
{
"type": "mfa_verified",
"operator": "equals",
"value": false
}
],
"subjects": {
"roles": ["tenant_admin", "system_admin"]
}
}'

レスポンス例

{
"id": "policy_xyz789",
"name": "mfa-required-for-admin",
"status": "active",
"effect": "deny",
"priority": 200,
"resource": "admin:*",
"created_at": 1706140800
}

ポリシー更新

既存のポリシーを更新します。

エンドポイント

PUT /api/admin/policies/:id

リクエスト例

Terminal window
curl -X PUT "https://{tenant-domain}/api/admin/policies/policy_def456" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"description": "オフィス時間内(9:00-19:00)のみアクセス可能",
"conditions": [
{
"type": "time_range",
"operator": "between",
"value": {
"start": "09:00",
"end": "19:00",
"timezone": "Asia/Tokyo"
}
}
]
}'

ポリシー削除

ポリシーを削除します。

エンドポイント

DELETE /api/admin/policies/:id

リクエスト例

Terminal window
curl -X DELETE "https://{tenant-domain}/api/admin/policies/policy_abc123" \
-H "Authorization: Bearer {token}"

レスポンス

ステータスコード 204 No Content(ボディなし)


ポリシーシミュレーション

特定のコンテキストでポリシーがどのように評価されるかシミュレーションします。

エンドポイント

POST /api/admin/policies/simulate

リクエストボディ

フィールド必須説明
resourcestringリソース
actionstringアクション
subjectobjectサブジェクト(ユーザー情報)
contextobject-追加コンテキスト(時間、IP等)

リクエスト例

Terminal window
curl -X POST "https://{tenant-domain}/api/admin/policies/simulate" \
-H "Authorization: Bearer {token}" \
-H "Content-Type: application/json" \
-d '{
"resource": "documents:report_2024",
"action": "read",
"subject": {
"user_id": "usr_abc123",
"roles": ["employee"],
"attributes": {
"department": "Engineering"
}
},
"context": {
"ip_address": "192.168.1.100",
"time": "2024-01-22T14:30:00+09:00",
"mfa_verified": true
}
}'

レスポンス例

{
"decision": "allow",
"evaluated_policies": [
{
"id": "policy_def456",
"name": "office-hours-access",
"effect": "allow",
"matched": true,
"conditions_met": [
{
"type": "time_range",
"result": true,
"reason": "14:30 is within 09:00-18:00"
},
{
"type": "day_of_week",
"result": true,
"reason": "monday is in allowed days"
},
{
"type": "ip_range",
"result": true,
"reason": "192.168.1.100 is in 192.168.1.0/24"
}
]
}
],
"reason": "Policy 'office-hours-access' allowed access"
}

条件タイプ一覧取得

使用可能な条件タイプとその設定オプションを取得します。UI構築時に使用します。

エンドポイント

GET /api/admin/policies/condition-types

リクエスト例

Terminal window
curl -X GET "https://{tenant-domain}/api/admin/policies/condition-types" \
-H "Authorization: Bearer {token}"

レスポンス例

{
"condition_types": [
{
"type": "time_range",
"display_name": "時間範囲",
"description": "アクセス可能な時間帯を指定",
"operators": ["between", "not_between"],
"value_schema": {
"type": "object",
"properties": {
"start": { "type": "string", "format": "time" },
"end": { "type": "string", "format": "time" },
"timezone": { "type": "string" }
}
}
},
{
"type": "day_of_week",
"display_name": "曜日",
"description": "アクセス可能な曜日を指定",
"operators": ["in", "not_in"],
"value_schema": {
"type": "array",
"items": {
"type": "string",
"enum": ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"]
}
}
},
{
"type": "ip_range",
"display_name": "IPアドレス範囲",
"description": "許可するIPアドレス範囲",
"operators": ["in", "not_in"],
"value_schema": {
"type": "array",
"items": { "type": "string", "format": "cidr" }
}
},
{
"type": "mfa_verified",
"display_name": "MFA検証",
"description": "MFAが検証されているか",
"operators": ["equals"],
"value_schema": { "type": "boolean" }
},
{
"type": "user_attribute",
"display_name": "ユーザー属性",
"description": "ユーザーの属性値をチェック",
"operators": ["equals", "not_equals", "in", "not_in", "greater_than", "less_than"],
"value_schema": {
"type": "object",
"properties": {
"attribute": { "type": "string" },
"value": {}
}
}
},
{
"type": "geo_location",
"display_name": "地理的位置",
"description": "アクセス元の国・地域",
"operators": ["in", "not_in"],
"value_schema": {
"type": "array",
"items": { "type": "string", "description": "ISO 3166-1 alpha-2 country code" }
}
}
]
}

ポリシー評価の優先順位

  1. 優先度(priority): 数値が高いポリシーが先に評価されます
  2. 効果(effect): 同じ優先度の場合、denyallow より優先されます
  3. 特異性: より具体的なリソース指定が優先されます
例:
priority: 200, effect: deny -> 最も優先
priority: 200, effect: allow -> 2番目
priority: 100, effect: deny -> 3番目
priority: 100, effect: allow -> 4番目