時間とリソースの属性に基づく条件によるアクセス制限

時間ベースの条件を設定することで、 アカウント内のリソースへの一時的なアクセスを指定したり、特定の時間帯にリソースへのアクセスを許可したりできます。また、リソース属性ベースの条件を設定することで、アクセスニーズに合わせて複数のアクセスポリシーを作成する必要がなくなります。

特定の日時に一時的なアクセスを許可する時間ベースの条件を作成したり、毎週定期的なアクセスを設定することができます。 例えば、定期的なアクセスを指定することで、ユーザーが勤務時間中だけアカウントリソースにアクセスできるようにしたい場合や、請負業者やサービスの機能をデモする必要があるユーザーがいて、一時的なアクセスしか必要ない場合などです。

時間ベースの条件は、サマータイムを採用しているタイムゾーンのサマータイム(DST)の変更をアカウントいない。 管理者は、夏時間の変更に応じてポリシーを更新し、時間ベースの条件を正確に適用する必要があります。 例えば、東部時間帯は標準時の -5 時間ではなく、夏時間中は UTC-4 時間となる。 標準時は11月に始まり、夏時間が始まる3月に終わる。

Kubernetes Service、時間ベースの条件は守らない。 たとえば、All Identity and Access 対応サービスへのアクセスを許可する時間ベースの 条件を持つポリシーには、 Kubernetes Service リソースへのアクセスが含まれる。 ポリシーの対象者は、指定された時間ベースの条件以外では、 Kubernetes Service リソースの一部にアクセスできる。

アクセス・ポリシーの時間ベースの条件は、アクセス割り当てに最小特権の原則を適用し、セキュリティ侵害が発生した場合の攻撃対象領域を減らすのに役立ちます。

リソース属性に基づいた条件でポリシーを作成すると、アクセスニーズを満たすために複数のアクセスポリシーを作成する必要がなくなります。 代わりに、リテラル値またはワイルドカード値を持つリソース属性に適用される OR/AND 演算子を組み合わせて使用することで、単一のポリシーを作成することができます。 複数の条件を同時に満たすリソースにアクセスを許可することも(AND)、複数の条件のいずれかを満たす場合にアクセスを許可することも(OR)できます。 例えば、リソース属性ベースの条件では、 Service instance: abcまたは attribute-1: xyzまたは (attribute-2: def アンド attribute-3: hij) に基づいてアクセスを許可する単一のポリシーを作成できます。

OR/AND とリソース属性に基づく条件を最低2つ使用する必要があります。 条件を1つだけ追加する必要がある場合は、 コンソールでリソースへのアクセスを割り当てSpecific resourcesを選択した後に条件を追加するを参照してください。

ユーザーのアクセスを確認するには、 コンソールで割り当てられたアクセスを確認するを 参照してください。

コンディション・パターン

時間ベースのコンディション・パターン

以下のパターンは、許容される条件の並べ替えを表している:

時間ベースのコンディションで許可されるコンディションパターン。
パターン
時間ベースの条件:1回 特定日の午前9時から午後5時までの一時アクセス UTC-5。
時間ベースの条件:週単位:終日 月~金 UTC-5 終日定期アクセス。
時間ベースの条件:週:カスタム時間 定期アクセス 月~金 午前9時~午後5時 UTC-5.

IAMは、同じポリシー定義で、1回限りの一時的な条件と毎週繰り返される条件を組み合わせることを防ぎます。

リソース属性に基づく条件パターン

以下のパターンは、許容される条件の並べ替えを表している:

リソース属性に基づく条件で許可される条件パターン。
パターン
attribute-based-condition:resource:literal-and-wildcard リテラル値またはワイルドカード値を持つリソース属性に基づく条件(使用する演算子による)

コンソールを使った一時的な時間ベースの条件の作成

日付と時間の範囲を指定することで、その条件がいつアクセスを許可し、いつアクセスを終了するかを決定する、有限の期間のアクセスを割り当てることができます。 たとえば、あなたのアカウント数時間デモを行う必要があるユーザーや、数日間にわたってサービスへの一時的なアクセスが必要な請負業者がいるかもしれません。 一時的な時間ベースの条件を持つアクセスポリシーを割り当てるには、以下の手順を実行します:

  1. IBM Cloud コンソールで、「 管理 > アクセス(IAM) 」に進みます

  2. アクセスを割り当てるエンティティに応じて、 ユーザー信頼済みプロファイルサービスID、またはアクセスグループを選択します。

  3. リストからエンティティ名をクリックし、「 アクセス 」に進む。

  4. 「アクセス権限の割り当て」 をクリックします。

  5. サービスを選択し、「 次へ 」をクリックします。

    • 任意のサービスをユーザーが作成できるようにする場合は、すべての ID およびアクセス対応サービスを選択します。
    • 特定のサービスに対するアクセス権限をユーザーに割り当てる場合は、リストからサービスを選択します。
  6. ユーザーにアクセス権を割り当てたいリソースを選択するか、[すべてのリソース] を選択します。 次へ をクリックします。

  7. (オプション)リソースグループのアクセスロールを選択します。 次へ をクリックします。

  8. サービスアクセスとプラットフォームアクセスのロールの任意の組み合わせを選択し、[ 次へ]をクリックします。

  9. Add conditionをクリックし、 One-timeを選択する。

  10. 時間帯を選択します。

    例として、ダブリンを拠点とする開発者のために条件付きポリシーを作成するとします。 この場合、 UTC+1 を選択し、次のステップで選択する日時の範囲が、その場所の正しい時刻にアクセスを強制するようにします。

  11. 条件がアクセスを許可および終了するタイミングを決定する日付および時間範囲のフィールドを完成させる。

  12. 「作成」 をクリックします。

  13. **「レビュー」**をクリックします。

  14. 追加をクリックして、ポリシー構成をポリシー・サマリーに追加します。

  15. 割り当て をクリックします。

一時的なポリシーは自動的に削除されない。 アカウントポリシー上限に達するのを避けるために、管理者は有効期限が切れた後にポリシーを手動で削除することができます。

アクセスポリシーの時間ベースの条件の詳細については、 アクセスポリシーの条件を 参照してください。

開始前に

アクセス・ポリシーで条件を使用できるように、 IBM Cloud CLIの最新バージョンを確認してください。

使用している IBM Cloud CLI バージョンを判別するには、以下のコマンドを実行します。

ibmcloud -v

最新バージョンの CLI を使用する必要があります。 最新バージョンを使用していない場合、以下のコマンドを実行して CLI を更新します。

ibmcloud update

現行リリースを実行している場合には、以下の出力が表示されます。

Checking for updates...
No update required. Your CLI is already up-to-date.

詳細については、 スタンドアロン IBM Cloud CLIのインストールを 参照してください。

CLIを使用した一時的な時間ベースの条件の作成

日付と時間の範囲を指定することで、その条件がいつアクセスを許可し、いつアクセスを終了するかを決定する、有限の期間のアクセスを割り当てることができます。 たとえば、あなたのアカウント数時間デモを行う必要があるユーザーや、数日間にわたってサービスへの一時的なアクセスが必要な請負業者がいるかもしれません。 次の例では、すべてのアカウント管理サービスの Operator としてユーザーに一時的なアクセス権を付与することで、 アカウント 1 回限りの時間ベースの条件を作成する方法を示します。

  1. IBM Cloud® CLI にログインします。 複数のアカウントを持っている場合、使用するアカウントを選択するように求めるプロンプトが出されます。 -r フラグを使用してリージョンを指定していない場合、リージョンも選択しなければなりません。

    ibmcloud login
    

    資格情報が拒否された場合、統合 ID を使用している可能性があります。 フェデレーテッド ID を使用してログインするには、--sso フラグを使用します。 詳しくは、フェデレーテッド ID を使用したログインを参照してください。

    IBM Cloud CLIを使うのが初めての方は、 チュートリアルを ご覧ください。

  2. アクセス・ポリシーを作成し、それをユーザーまたはサービスIDに割り当てるには、次のコマンドを使用します。 ibmcloud iam user-policy-create.

  3. Operator ロールで アカウント マネジメント・サービス にアクセス権を割り当てる:

    ibmcloud iam service-policy-create [your service ID here] --roles Operator --account-management --api-version v2
    
  4. 以下の一時的な時間ベースのポリシーJSONスキーマの例を使用して、独自の条件を作成してください:

    {
      "type": "access",
      "description": "time-based conditions policy example restricting access to the full day of 2022-12-23 UTC",
      "control": {
        "grant": {
          "roles": [
            {
              "role_id": "crn:v1:bluemix:public:iam::::role:Operator"
            }
          ]
        }
      },
      "resource": {
        "attributes": [
          {
            "operator": "stringEquals",
            "value": "d4b763ad0cbd4dca8dd1edb427d7a77e",
            "key": "accountId"
          },
          {
            "value": "platform_service",
            "operator": "stringEquals",
            "key": "serviceType"
          }
        ]
      },
      "pattern": "time-based-conditions:once",
      "rule": {
        "operator": "and",
        "conditions": [
          {
            "key": "{{environment.attributes.current_date_time}}",
            "operator": "dateTimeGreaterThanOrEquals",
            "value": "2022-12-23T00:00:00+00:00"
          },
          {
            "key": "{{environment.attributes.current_date_time}}",
            "operator": "dateTimeLessThanOrEquals",
            "value": "2022-12-23T23:59:59+00:00"
          }
        ]
      },
      "subject": {
        "attributes": [
          {
            "key": "iam_id",
            "operator": "stringEquals",
            "value": "IBMid-550000HFVV"
          }
        ]
      }
    }
    

パターン time-based-conditions:once を使用する一時的なポリシーは、自動的に削除されません。 アカウントポリシー上限に達するのを避けるために、管理者は有効期限が切れた後にポリシーを手動で削除することができます。

アクセスポリシーの時間ベースの条件の詳細については、 アクセスポリシーの条件を 参照してください。

開始前に

アクセスポリシーで条件を使用できるように、 v2/policies URI( https://iam.coud.ibm.com/v2/policies )を呼び出すことを確認してください。 詳細については、 IAM Policy Management APIと 変更ログを 参照してください。

APIを使用した一時的な時間ベースの条件の作成

日付と時間の範囲を指定することで、その条件がいつアクセスを許可し、いつアクセスを終了するかを決定する、有限の期間のアクセスを割り当てることができます。 たとえば、あなたのアカウント数時間デモを行う必要があるユーザーや、数日間にわたってサービスへの一時的なアクセスが必要な請負業者がいるかもしれません。 以下の例では、すべてのアカウント管理サービスの Operator としてユーザーに一時的なアクセス権を付与することで、 アカウント 1 回限りの時間ベースの条件を作成する方法を示します。

	subjectAttribute := &iampolicymanagementv1.V2PolicyAttribute{
				Key:  core.StringPtr("iam_id"),
				Operator: core.StringPtr("stringEquals"),
				Value: &exampleUserID,
			}
			policySubject := &iampolicymanagementv1.V2PolicyBaseSubject{
				Attributes: []iampolicymanagementv1.V2PolicyAttribute{*subjectAttribute},
			}
			policyRole := &iampolicymanagementv1.PolicyRole{
				RoleID: core.StringPtr("crn:v1:bluemix:public:iam::::role:Operator"),
			}
			v2PolicyGrant := &iampolicymanagementv1.V2PolicyBaseControlGrant{
				Roles: []iampolicymanagementv1.PolicyRole{*policyRole},
			}
			v2PolicyControl := &iampolicymanagementv1.V2PolicyBaseControl{
				Grant: v2PolicyGrant,
			}
			accountIDResourceAttribute := &iampolicymanagementv1.V2PolicyAttribute{
				Key:     core.StringPtr("accountId"),
				Operator: core.StringPtr("stringEquals"),
				Value:    core.StringPtr(exampleAccountID),
			}
			serviceNameResourceAttribute := &iampolicymanagementv1.V2PolicyAttribute{
				Key:     core.StringPtr("serviceType"),
				Operator: core.StringPtr("stringEquals"),
				Value:    core.StringPtr("service"),
			}
			policyResource := &iampolicymanagementv1.V2PolicyBaseResource{
				Attributes: []iampolicymanagementv1.V2PolicyAttribute{
					*accountIDResourceAttribute, *serviceNameResourceAttribute},
			}
			startConditionAttribute :=  &iampolicymanagementv1.V2PolicyAttribute{
				Key:     core.StringPtr("{{environment.attributes.current_time}}"),
				Operator: core.StringPtr("dateTimeGreaterThanOrEquals"),
				Value:    core.StringPtr("2022-12-23T00:00:00+00:00"),
			}
			endConditionAttribute :=  &iampolicymanagementv1.V2PolicyAttribute{
				Key:     core.StringPtr("{{environment.attributes.current_time}}"),
				Operator: core.StringPtr("dateTimeLessThanOrEquals"),
				Value:    core.StringPtr("2022-12-23T23:59:59+00:00"),
			}
			policyRule := &iampolicymanagementv1.V2PolicyBaseRule{
				Operator: core.StringPtr("and"),
				Conditions: []iampolicymanagementv1.V2PolicyAttribute{
					*startConditionAttribute, *endConditionAttribute},
			}
			options := iamPolicyManagementService.NewV2CreatePolicyOptions(
				"access",
				v2PolicyControl,
			)
			options.SetSubject(policySubject)
			options.SetResource(policyResource)
			options.SetRule(policyRule)
			options.SetPattern(*core.StringPtr("time-based-conditions:once"))
			policy, response, err := iamPolicyManagementService.V2CreatePolicy(options)
			if err != nil {
				panic(err)
			}
			b, _ := json.MarshalIndent(policy, "", "  ")
			fmt.Println(string(b))
V2PolicyAttribute subjectAttribute = new V2PolicyAttribute.Builder()
              .key("iam_id")
              .value(EXAMPLE_USER_ID)
              .operator("stringEquals")
              .build();
      V2PolicyBaseSubject policySubject = new V2PolicyBaseSubject.Builder()
              .addAttributes(subjectAttribute)
              .build();
      V2PolicyAttribute accountIdResourceAttribute = new V2PolicyAttribute.Builder()
              .key("accountId")
              .value(exampleAccountId)
              .operator("stringEquals")
              .build();
      V2PolicyAttribute serviceNameResourceAttribute = new V2PolicyAttribute.Builder()
              .key("serviceName")
              .value("iam-groups")
              .operator("stringEquals")
              .build();
      V2PolicyBaseResource policyResource = new V2PolicyBaseResource.Builder()
              .addAttributes(accountIdResourceAttribute)
              .addAttributes(serviceNameResourceAttribute)
              .build();
      PolicyRole policyRoles = new PolicyRole.Builder()
              .roleId("crn:v1:bluemix:public:iam::::role:Operator")
              .build();
      V2PolicyBaseControlGrant policyGrant = new V2PolicyBaseControlGrant.Builder()
              .roles(Arrays.asList(policyRoles))
              .build();
      V2PolicyBaseControl policyControl = new V2PolicyBaseControl.Builder()
              .grant(policyGrant)
              .build();
      V2PolicyAttribute startConditionAttribute = new V2PolicyAttribute.Builder()
              .key("{{environment.attributes.current_time}}")
              .value("2022-12-23T00:00:00+00:00")
              .operator("dateTimeGreaterThanOrEquals")
              .build();
      V2PolicyAttribute endConditionAttribute = new V2PolicyAttribute.Builder()
              .key("{{environment.attributes.current_time}}")
              .value("2022-12-23T23:59:59+00:00")
              .operator("dateTimeLessThanOrEquals")
              .build();
      V2PolicyBaseRuleV2RuleWithConditions policyRule = new V2PolicyBaseRuleV2RuleWithConditions.Builder()
              .operator("and")
              .conditions(new ArrayList<V2PolicyAttribute>(Arrays.asList(startConditionAttribute, endConditionAttribute)))
              .build();
      V2CreatePolicyOptions options = new V2CreatePolicyOptions.Builder()
              .type("access")
              .subject(policySubject)
              .control(policyControl)
              .resource(policyResource)
              .rule(policyRule)
              .pattern("time-based-conditions:once")
              .build();
      Response<V2Policy> response = service.v2CreatePolicy(options).execute();
      V2Policy policy = response.getResult();
const policySubject = {
      attributes: [
        {
          key: 'iam_id',
          operator: 'stringEquals',
          value: exampleUserId,
        },
      ],
    };
    const policyResourceAccountAttribute = {
      key: 'accountId',
      value: exampleAccountId,
      operator: 'stringEquals',
    };
    const policyResourceServiceAttribute = {
      key: 'serviceName',
      operator: 'stringEquals',
      value: 'iam-groups',
    };
    const policyResource = {
      attributes: [policyResourceAccountAttribute, policyResourceServiceAttribute]
    };
    const policyControl = {
      grant: {
        roles: [{
          role_id: 'crn:v1:bluemix:public:iam::::role:Operator',
        }],
      }
    };
    const policyRule = {
      operator: 'and',
      conditions: [
          {
              key: '{{environment.attributes.current_time}}',
              operator: 'dateTimeGreaterThanOrEquals',
              value: '2022-12-23T00:00:00+00:00',
          },
          {
              key: '{{environment.attributes.current_time}}',
              operator: 'dateTimeLessThanOrEquals',
              value: '2022-12-23T23:59:59+00:00',
          },
      ],
    }
    const policyPattern = 'time-based-conditions:once'
    const params = {
      type: 'access',
      subject: policySubject,
      control: policyControl,
      resource: policyResource,
      rule: policyRule,
      pattern: policyPattern,
    };
    try {
      const res = await iamPolicyManagementService.v2CreatePolicy(params);
      examplePolicyId = res.result.id;
      console.log(JSON.stringify(res.result, null, 2));
    } catch (err) {
      console.warn(err)
    }
policy_subject = V2PolicyBaseSubject(
                attributes=[V2PolicyAttribute(key='iam_id', value=example_user_id, operator='stringEquals')]
            )
            policy_role = PolicyRole(role_id='crn:v1:bluemix:public:iam::::role:Operator')
            account_id_resource_attribute = V2PolicyAttribute(
                key='accountId', value=example_account_id, operator='stringEquals'
            )
            service_name_resource_attribute = V2PolicyAttribute(
                key='serviceType', value='service', operator='stringEquals'
            )
            policy_resource = PolicyResource(
                attributes=[account_id_resource_attribute, service_name_resource_attribute],
            )
            policy_control = V2PolicyBaseControl(grant=V2PolicyBaseControlGrant(roles=[policy_role]))
            policy_rule = V2PolicyBaseRuleV2RuleWithConditions(
                operator='and',
                conditions=[
                    V2PolicyAttribute(
                        key='{{environment.attributes.current_time}}',
                        operator='dateTimeGreaterThanOrEquals',
                        value='2022-12-23T00:00:00+00:00',
                    ),
                    V2PolicyAttribute(
                        key='{{environment.attributes.current_time}}',
                        operator='dateTimeLessThanOrEquals',
                        value='2022-12-23T23:59:59+00:00',
                    ),
                ],
            )
            policy_pattern = 'time-based-conditions:once'
            policy = iam_policy_management_service.v2_create_policy(
                type='access',
                subject=policy_subject,
                control=policy_control,
                resource=policy_resource,
                rule=policy_rule,
                pattern=policy_pattern,
            ).get_result()
            print(json.dumps(policy, indent=2))

パターン time-based-conditions:once を使用する一時的なポリシーは、自動的に削除されません。 アカウントポリシー上限に達するのを避けるために、管理者は有効期限が切れた後にポリシーを手動で削除することができます。

アクセスポリシーの時間ベースの条件の詳細については、 アクセスポリシーの条件を 参照してください。

コンソールを使用した定期的な時間ベースの条件の作成

定期的なアクセスを週単位で割り当てることができます。 ユーザーが就業時間中だけアカウント リソースにアクセスできるようにしたい場合もあるでしょう。 以下の手順を実行して、定期的な時間ベースの条件を持つアクセス ポリシーを割り当てます:

  1. IBM Cloud コンソールで、「 管理 > アクセス(IAM) 」に進みます

  2. アクセスを割り当てるエンティティに応じて、 ユーザー信頼済みプロファイルサービスID、またはアクセスグループを選択します。

  3. リストから ID の名前をクリックし、「 アクセス 」に進みます。

  4. 「アクセス権限の割り当て」 をクリックします。

  5. サービスを選択し、「 次へ 」をクリックします。

    • 任意のサービスをユーザーが作成できるようにする場合は、すべての ID およびアクセス対応サービスを選択します。
    • 特定のサービスに対するアクセス権限をユーザーに割り当てる場合は、リストからサービスを選択します。
  6. ユーザーにアクセス権を割り当てたいリソースを選択するか、[すべてのリソース] を選択します。 次へ をクリックします。

  7. (オプション)リソースグループのアクセスロールを選択します。 次へ をクリックします。

  8. サービスアクセスとプラットフォームアクセスのロールの任意の組み合わせを選択し、[ 次へ]をクリックします。

  9. Add conditionをクリックし、 Weeklyを選択する。

  10. 条件付きポリシーのタイムゾーンを選択します。

    例として、ダブリンを拠点とする開発者のために条件付きポリシーを作成するとします。 この場合、 UTC+1 を選択し、次に選択する日時の範囲がその場所の正しい時刻に施行されるようにする。

  11. アクセスを許可する曜日を選択します。

    • (オプション)選択した日の時間枠を指定するには、[ 全日] トグルを [いいえ]に設定します。
  12. 「作成」 をクリックします。

  13. **「レビュー」**をクリックします。

  14. 追加をクリックして、ポリシー構成をポリシー・サマリーに追加します。

  15. 割り当て をクリックします。

アクセスポリシーの時間ベースの条件の詳細については、 アクセスポリシーの条件を 参照してください。

CLIを使用して定期的な時間ベースの条件を作成する

定期的なアクセスを週単位で割り当てることができます。 ユーザーが就業時間中だけアカウント リソースにアクセスできるようにしたい場合もあるでしょう。 次の例では、ユーザーに対して定期的な時間ベースの条件を作成する方法を示します。 このポリシーでは、すべてのアカウント管理サービスのエディターとして、月曜日から金曜日の就業時間中のアクセスを割り当てています。

  1. IBM Cloud® CLI にログインします。 複数のアカウントを持っている場合、使用するアカウントを選択するように求めるプロンプトが出されます。 -r フラグを使用してリージョンを指定していない場合、リージョンも選択しなければなりません。

    ibmcloud login
    

    資格情報が拒否された場合、統合 ID を使用している可能性があります。 フェデレーテッド ID を使用してログインするには、--sso フラグを使用します。 詳しくは、フェデレーテッド ID を使用したログインを参照してください。

    IBM Cloud CLI を初めて使用する場合は、入門チュートリアルを参照してください。

  2. アクセス・ポリシーを作成し、それをユーザーまたはサービスIDに割り当てるには、次のコマンドを使用します。 ibmcloud iam user-policy-create.

  3. Editor ロールで アカウント マネジメント・サービス にアクセス権を割り当てる:

    ibmcloud iam service-policy-create [your service ID here] --roles Editor --account-management --api-version v2
    
  4. 以下の定期的な時間ベースのポリシー JSON スキーマの例を使用して、独自の条件を作成します:

    ibmcloud iam service-policy-create [your service ID here] --file [your JSON file name]
    
    {
      "type": "access",
      "description": "time-based conditions policy example restricting access to the full day of 2022-12-23 UTC",
      "control": {
        "grant": {
          "roles": [
            {
              "role_id": "crn:v1:bluemix:public:iam::::role:Editor"
            }
          ]
        }
      },
      "resource": {
        "attributes": [
          {
            "operator": "stringEquals",
            "value": "d4b763ad0cbd4dca8dd1edb427d7a77e",
            "key": "accountId"
          },
          {
            "value": "platform_service",
            "operator": "stringEquals",
            "key": "serviceType"
          }
        ]
      },
      "pattern": "time-based-conditions:weekly",
      "rule": {
        "operator": "and",
        "conditions": [
          {
            "key": "{{environment.attributes.day_of_week}}",
            "operator": "dayOfWeekAnyOf",
            "value": [
              1,
              2,
              3,
              4,
              5
            ]
          },
          {
            "key": "{{environment.attributes.current_time}}",
            "operator": "timeGreaterThanOrEquals",
            "value": "00:00:00+00:00"
          },
          {
            "key": "{{environment.attributes.current_time}}",
            "operator": "timeLessThanOrEquals",
            "value": "23:59:59+00:00"
          }
        ]
      },
      "subject": {
        "attributes": [
          {
            "key": "iam_id",
            "operator": "stringEquals",
            "value": "IBMid-550000HFVV"
          }
        ]
      }
    }
    

アクセスポリシーの時間ベースの条件の詳細については、 アクセスポリシーの条件を 参照してください。

APIを使用した定期的な時間ベースの条件の作成

定期的なアクセスを週単位で割り当てることができます。 ユーザーが就業時間中だけアカウント リソースにアクセスできるようにしたい場合もあるでしょう。 以下の例では、ユーザーに対する反復的な時間ベースの条件を作成する方法を示します。 このポリシーでは、すべてのアカウント管理サービスのエディターとして、月曜日から金曜日の就業時間中のアクセスを割り当てています。

subjectAttribute := &iampolicymanagementv1.V2PolicyAttribute{
				Key:  core.StringPtr("iam_id"),
				Operator: core.StringPtr("stringEquals"),
				Value: &exampleUserID,
			}
			policySubject := &iampolicymanagementv1.V2PolicyBaseSubject{
				Attributes: []iampolicymanagementv1.V2PolicyAttribute{*subjectAttribute},
			}
			policyRole := &iampolicymanagementv1.PolicyRole{
				RoleID: core.StringPtr("crn:v1:bluemix:public:iam::::role:Editor"),
			}
			v2PolicyGrant := &iampolicymanagementv1.V2PolicyBaseControlGrant{
				Roles: []iampolicymanagementv1.PolicyRole{*policyRole},
			}
			v2PolicyControl := &iampolicymanagementv1.V2PolicyBaseControl{
				Grant: v2PolicyGrant,
			}
			accountIDResourceAttribute := &iampolicymanagementv1.V2PolicyAttribute{
				Key:     core.StringPtr("accountId"),
				Operator: core.StringPtr("stringEquals"),
				Value:    core.StringPtr(exampleAccountID),
			}
			serviceNameResourceAttribute := &iampolicymanagementv1.V2PolicyAttribute{
				Key:     core.StringPtr("serviceType"),
				Operator: core.StringPtr("stringEquals"),
				Value:    core.StringPtr("service"),
			}
			policyResource := &iampolicymanagementv1.V2PolicyBaseResource{
				Attributes: []iampolicymanagementv1.V2PolicyAttribute{
					*accountIDResourceAttribute, *serviceNameResourceAttribute},
			}
			weeklyConditionAttribute :=  &iampolicymanagementv1.V2PolicyAttribute{
				Key:     core.StringPtr("{{environment.attributes.day_of_week}}"),
				Operator: core.StringPtr("dayOfWeekAnyOf"),
				Value:    []int{1,2,3,4,5},
			}
			startConditionAttribute :=  &iampolicymanagementv1.V2PolicyAttribute{
				Key:     core.StringPtr("{{environment.attributes.current_time}}"),
				Operator: core.StringPtr("timeGreaterThanOrEquals"),
				Value:    core.StringPtr("09:00:00+00:00"),
			}
			endConditionAttribute :=  &iampolicymanagementv1.V2PolicyAttribute{
				Key:     core.StringPtr("{{environment.attributes.current_time}}"),
				Operator: core.StringPtr("timeLessThanOrEquals"),
				Value:    core.StringPtr("17:00:00+00:00"),
			}
			policyRule := &iampolicymanagementv1.V2PolicyBaseRule{
				Operator: core.StringPtr("and"),
				Conditions: []iampolicymanagementv1.V2PolicyAttribute{
					*weeklyConditionAttribute, *startConditionAttribute, *endConditionAttribute},
			}
			options := iamPolicyManagementService.NewV2CreatePolicyOptions(
				"access",
				v2PolicyControl,
			)
			options.SetSubject(policySubject)
			options.SetResource(policyResource)
			options.SetRule(policyRule)
			options.SetPattern(*core.StringPtr("time-based-conditions:weekly"))
			policy, response, err := iamPolicyManagementService.V2CreatePolicy(options)
			if err != nil {
				panic(err)
			}
			b, _ := json.MarshalIndent(policy, "", "  ")
			fmt.Println(string(b))
V2PolicyAttribute subjectAttribute = new V2PolicyAttribute.Builder()
              .key("iam_id")
              .value(EXAMPLE_USER_ID)
              .operator("stringEquals")
              .build();
      V2PolicyBaseSubject policySubject = new V2PolicyBaseSubject.Builder()
              .addAttributes(subjectAttribute)
              .build();
      V2PolicyAttribute accountIdResourceAttribute = new V2PolicyAttribute.Builder()
              .key("accountId")
              .value(exampleAccountId)
              .operator("stringEquals")
              .build();
      V2PolicyAttribute serviceNameResourceAttribute = new V2PolicyAttribute.Builder()
              .key("serviceName")
              .value("iam-groups")
              .operator("stringEquals")
              .build();
      V2PolicyBaseResource policyResource = new V2PolicyBaseResource.Builder()
              .addAttributes(accountIdResourceAttribute)
              .addAttributes(serviceNameResourceAttribute)
              .build();
      PolicyRole policyRoles = new PolicyRole.Builder()
              .roleId("crn:v1:bluemix:public:iam::::role:Editor")
              .build();
      V2PolicyBaseControlGrant policyGrant = new V2PolicyBaseControlGrant.Builder()
              .roles(Arrays.asList(policyRoles))
              .build();
      V2PolicyBaseControl policyControl = new V2PolicyBaseControl.Builder()
              .grant(policyGrant)
              .build();
      V2PolicyAttribute weeklyConditionAttribute = new V2PolicyAttribute.Builder()
              .key("{{environment.attributes.day_of_week}}")
              .value(new ArrayList<Integer>(Arrays.asList(1, 2, 3, 4, 5)))
              .operator("dayOfWeekAnyOf")
              .build();
      V2PolicyAttribute startConditionAttribute = new V2PolicyAttribute.Builder()
              .key("{{environment.attributes.current_time}}")
              .value("09:00:00+00:00")
              .operator("timeGreaterThanOrEquals")
              .build();
      V2PolicyAttribute endConditionAttribute = new V2PolicyAttribute.Builder()
              .key("{{environment.attributes.current_time}}")
              .value("17:00:00+00:00")
              .operator("timeLessThanOrEquals")
              .build();
      V2PolicyBaseRuleV2RuleWithConditions policyRule = new V2PolicyBaseRuleV2RuleWithConditions.Builder()
              .operator("and")
              .conditions(new ArrayList<V2PolicyAttribute>(Arrays.asList(weeklyConditionAttribute, startConditionAttribute, endConditionAttribute)))
              .build();
      V2CreatePolicyOptions options = new V2CreatePolicyOptions.Builder()
              .type("access")
              .subject(policySubject)
              .control(policyControl)
              .resource(policyResource)
              .rule(policyRule)
              .pattern("time-based-conditions:weekly")
              .build();
      Response<V2Policy> response = service.v2CreatePolicy(options).execute();
      V2Policy policy = response.getResult();
      System.out.println(policy);
const policySubject = {
      attributes: [
        {
          key: 'iam_id',
          operator: 'stringEquals',
          value: exampleUserId,
        },
      ],
    };
    const policyResourceAccountAttribute = {
      key: 'accountId',
      value: exampleAccountId,
      operator: 'stringEquals',
    };
    const policyResourceServiceAttribute = {
      key: 'serviceName',
      operator: 'stringEquals',
      value: 'iam-groups',
    };
    const policyResource = {
      attributes: [policyResourceAccountAttribute, policyResourceServiceAttribute]
    };
    const policyControl = {
      grant: {
        roles: [{
          role_id: 'crn:v1:bluemix:public:iam::::role:Editor',
        }],
      }
    };
    const policyRule = {
      operator: 'and',
      conditions: [
          {
              key: '{{environment.attributes.day_of_week}}',
              operator: 'dayOfWeekAnyOf',
              value: [1, 2, 3, 4, 5],
          },
          {
              key: '{{environment.attributes.current_time}}',
              operator: 'timeGreaterThanOrEquals',
              value: '09:00:00+00:00',
          },
          {
              key: '{{environment.attributes.current_time}}',
              operator: 'timeLessThanOrEquals',
              value: '17:00:00+00:00',
          },
      ],
    }
    const policyPattern = 'time-based-conditions:weekly'
    const params = {
      type: 'access',
      subject: policySubject,
      control: policyControl,
      resource: policyResource,
      rule: policyRule,
      pattern: policyPattern,
    };
    try {
      const res = await iamPolicyManagementService.v2CreatePolicy(params);
      examplePolicyId = res.result.id;
      console.log(JSON.stringify(res.result, null, 2));
    } catch (err) {
      console.warn(err)
    }
policy_subject = V2PolicyBaseSubject(
                attributes=[V2PolicyAttribute(key='iam_id', value=example_user_id, operator='stringEquals')]
            )
            policy_role = PolicyRole(role_id='crn:v1:bluemix:public:iam::::role:Editor')
            account_id_resource_attribute = V2PolicyAttribute(
                key='accountId', value=example_account_id, operator='stringEquals'
            )
            service_name_resource_attribute = V2PolicyAttribute(
                key='serviceName', value='iam-groups', operator='stringEquals'
            )
            policy_resource = PolicyResource(
                attributes=[account_id_resource_attribute, service_name_resource_attribute],
            )
            policy_control = V2PolicyBaseControl(grant=V2PolicyBaseControlGrant(roles=[policy_role]))
            policy_rule = V2PolicyBaseRuleV2RuleWithConditions(
                operator='and',
                conditions=[
                    V2PolicyAttribute(
                        key='{{environment.attributes.day_of_week}}', operator='dayOfWeekAnyOf', value=[1, 2, 3, 4, 5]
                    ),
                    V2PolicyAttribute(
                        key='{{environment.attributes.current_time}}',
                        operator='timeGreaterThanOrEquals',
                        value='09:00:00+00:00',
                    ),
                    V2PolicyAttribute(
                        key='{{environment.attributes.current_time}}',
                        operator='timeLessThanOrEquals',
                        value='17:00:00+00:00',
                    ),
                ],
            )
            policy_pattern = 'time-based-conditions:weekly'
            policy = iam_policy_management_service.v2_create_policy(
                type='access',
                subject=policy_subject,
                control=policy_control,
                resource=policy_resource,
                rule=policy_rule,
                pattern=policy_pattern,
            ).get_result()
            print(json.dumps(policy, indent=2))

アクセスポリシーの時間ベースの条件の詳細については、 アクセスポリシーの条件を 参照してください。

コンソールを使ったリソース属性ベースの条件作成

条件によってアクセスを許可するリソースを決定するリソース属性を指定することで、アクセスを割り当てることができます。 例えば、あなたのアカウント特定のリソースを使用してデモンストレーションを行う必要があるユーザーがいるとします。 利用可能な演算子についての詳細と例については、 リソース属性ベースの条件を 参照してください。

OR を使用することで、最大10個の条件と2レベルまでのネスティングが可能です。

属性リソースベースの条件を持つアクセスポリシーを割り当てるには、以下の手順を実行します:

  1. IBM Cloud コンソールで、「 管理 > アクセス(IAM) 」に進みます

  2. アクセスを割り当てるエンティティに応じて、 ユーザー信頼済みプロファイルサービスID、またはアクセスグループを選択します。

  3. リストからエンティティ名をクリックし、「 アクセス 」に進む。

  4. 「アクセス権限の割り当て」 をクリックします。

  5. サービスを選択し、「 次へ 」をクリックします。

    すべてのサービスがリソース属性ベースの条件をサポートしているわけではない。 続行するには、リソース属性ベースの条件をサポートするサービスを選択します。 例えば、Cloud Object Storage です。

  6. ユーザーにアクセス権を割り当てたいリソースを選択するか、[ すべてのリソース ] を選択します。 **「次へ」**をクリックします。

  7. (オプション)リソースグループのアクセスロールを選択します。 次へ をクリックします。

  8. サービスアクセスとプラットフォームアクセスのロールの任意の組み合わせを選択し、[ 次へ]をクリックします。

  9. Add conditionをクリックし、 Advanced condition builder > Nextを選択する。

  10. リソース条件を追加し、 Createをクリックする。

例として、 dev/David/dev/Secret/ フォルダの下のすべて、または devOps/cicd/ で始まるパスにアクセスする必要がある開発者のために、条件付きポリシーを作成するとします。 この場合、 Prefixstring matches any of を選択し、 dev/David/*dev/Secret/* を追加する。 次に、OR 条件を追加し、 Path, string matches any of を選択し、 devOps/*cicd/* を追加する。

  1. 作成」>「 確認」 >「 追加 」の順にクリックして、アクセス設定をアクセス概要に追加します。
  2. 割り当て をクリックします。

サービス固有の文書

Cloud Object Storage、リソース属性に基づいた条件を使用する方法については、 バケット内の個々のオブジェクトへのアクセスを制御するを 参照してください。

開始前に

アクセスポリシーで条件を使用できるように、 v2/policies URI( https://iam.coud.ibm.com/v2/policies )を呼び出すことを確認してください。 詳細については、 IAM Policy Management APIと 変更ログを 参照してください。

APIを使用したリソース属性ベースの条件作成

条件によってアクセスを許可するリソースを決定するリソース属性を指定することで、アクセスを割り当てることができます。 例として、 dev/David/*devA/* フォルダの下にあるすべて、または dev/David/*devA/* で始まるパスにアクセスする必要がある開発者のために、条件付きポリシーを作成するとします。 次の例では、 dev/David/ フォルダの下にあるすべて、および devA または特に devA/ フォルダで始まるすべてのパスへのアクセスをユーザーに与える、リソース属性ベースの条件を作成する方法を示します。

OR を使用することで、最大10個の条件と2レベルまでのネスティングが可能です。

利用可能な演算子についての詳細と例については、 リソース属性ベースの条件を 参照してください。

"pattern": "attribute-based-condition:resource:literal-and-wildcard",
"rule": {
    "operator": "or",
    "conditions": [
      {
        "key": "{{resource.attributes.prefix}}",
        "operator": "stringMatchAnyOf",
        "value": [
          "dev/David/*",
          "devA*"
        ]
      },
      {
        "key": "{{resource.attributes.path}}",
        "operator": "stringMatchAnyOf",
        "value": [
          "dev/David/*",
          "devA/*"
        ]
      },
      {
        "operator": "and",
        "conditions": [
          {
            "key": "{{resource.attributes.prefix}}",
            "operator": "stringMatchAnyOf",
            "value": [
              "dev/David/*",
              "devA/*"
            ]
          },
          {
            "key": "{{resource.attributes.delimiter}}",
            "operator": "stringEquals",
            "value": "/"
          }
        ]
      }
    ]
  }