

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# Directory Service Data 條件索引鍵
<a name="iam_dsdata-condition-keys"></a>

使用 [Directory Service Data](https://docs.aws.amazon.com/directoryservicedata/latest/DirectoryServiceDataAPIReference/welcome.html) 條件索引鍵，將特定陳述式新增至使用者和群組層級存取。這可讓使用者決定哪些主體可以對哪些資源以及在哪些條件下執行動作。

*Condition 元素*或 *Condition 區塊*可讓您指定陳述式生效的條件。Condition 元素是可選用的。您可以建立使用條件運算子的條件式表達式，例如等於 (=) 或小於 (＜)，以比對政策中的條件與請求中的值。

如果您在陳述式中指定多個條件元素，或在單一條件元素中指定多個索引鍵， 會使用邏輯 AND 操作 AWS 來評估它們。如果您為單一條件索引鍵指定多個值， 會使用邏輯 OR 操作 AWS 來評估條件。必須符合所有條件，才會授與陳述式的許可。您也可以在指定條件時使用預留位置變數。例如，您可以授予 IAM 使用者存取資源的許可，前提是該資源已加上使用者名稱的標籤。如需詳細資訊，請參閱《*IAM 使用者指南*》中的[具有多個索引鍵或值的條件](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_multi-value-conditions.html)。

如需支援這些條件金鑰的動作清單，請參閱《服務*授權參考*》中的 [AWS Directory Service Data 定義的動作](https://docs.aws.amazon.com/service-authorization/latest/reference/list_directoryservice-data.html)。

**注意**  
如需標籤型資源層級許可的詳細資訊，請參閱 [搭配 IAM 政策使用標籤](IAM_Auth_Access_IdentityBased.md#using_tags_with_iam_policies)。

## ds-data：SAMAccountName
<a name="dsdata_condition-SAMAccountName"></a>

適用於[字串運算子](https://docs.aws.amazon.com//IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)。

使用此金鑰可明確允許或拒絕 IAM 角色在特定使用者和群組上執行動作。

**重要**  
使用 `SAMAccountName`或 時`MemberName`，建議您指定 `ds-data:Identifier`為 `SAMAccountName`。這可防止 AWS Directory Service Data 支援的未來識別符，例如 `SID`破壞現有的許可。

下列政策拒絕 IAM 主體描述使用者`joe`或描述群組 `joegroup`。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "DenyDescribe",
      "Effect": "Deny",
      "Action": "ds-data:Describe*",
      "Resource": "*",
      "Condition": {
        "StringEqualsIgnoreCase": {
          "ds-data:SAMAccountName": [
            "{{joe}}",
            "{{joegroup}}"
          ],
          "ds-data:identifier": [
            "SAMAccountName"
          ]
        }
      }
    }
  ]
}
```

------

**注意**  
此條件索引鍵不區分大小寫。無論字母大小寫為何，您都必須使用 `[StringEqualsIgnoreCase](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)`或 `[StringNotEqualsIgnoreCase](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)`條件運算子來比較字串值。

## ds-data：Identifier
<a name="dsdata_condition-identifier"></a>

適用於[字串運算子](https://docs.aws.amazon.com//IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)。

使用此金鑰來定義要在 IAM 政策許可中使用的識別符。目前僅支援 `SAMAccountName`。

下列政策允許 IAM 主體更新使用者 `joe`。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "UpdateJoe",
      "Effect": "Allow",
      "Action": "ds-data:UpdateUser",
      "Resource": "arn:aws:ds:{{us-east-1}}:{{111122223333}}:directory/{{d-012345678}}",
      "Condition": {
        "StringEqualsIgnoreCase": {
          "ds-data:SAMAccountName": [
            "{{joe}}"
          ],
          "ds-data:identifier": [
            "SAMAccountName"
          ]
        }
      }
    }
  ]
}
```

------

## ds-data：MemberName
<a name="dsdata_condition-MemberName"></a>

適用於[字串運算子](https://docs.aws.amazon.com//IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)。

使用此金鑰來定義可以對其執行操作的成員。

**重要**  
使用 `MemberName`或 時`SAMAccountName`，建議您指定 `ds-data:Identifier`為 `SAMAccountName`。這可防止 Directory Service Data 支援的未來識別符，例如 `SID`中斷現有的許可。

下列政策允許 IAM 主體`AddGroupMember`對任何群組`joe`中的成員執行 。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
        "Sid": "AddJoe",
        "Effect": "Allow",
        "Action": "ds-data:AddGroupMember",
        "Resource": "arn:aws:ds:{{us-east-1}}:{{111122223333}}:directory/{{d-012345678}}",
        "Condition": {
            "StringEqualsIgnoreCase": {
                "ds-data:MemberName": "{{joe}}"
            }
        }
    }
  ]
}
```

------

**注意**  
此條件索引鍵不區分大小寫。無論字母大小寫為何，您都必須使用 `[StringEqualsIgnoreCase](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)`或 `[StringNotEqualsIgnoreCase](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)`條件運算子來比較字串值。

## ds-data：MemberRealm
<a name="dsdata_condition-MemberRealm"></a>

適用於[字串運算子](https://docs.aws.amazon.com//IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)。

使用此金鑰來檢查政策中的`ds-data:MemberRealm`值是否符合請求中的成員領域。

**注意**  
此條件索引鍵不區分大小寫。無論字母大小寫為何，您都必須使用 `[StringEqualsIgnoreCase](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)`或 `[StringNotEqualsIgnoreCase](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)`條件運算子來比較字串值。

下列政策允許 IAM 主體`AddGroupMember`為領域 `bob`中的成員呼叫 `ONE.TRU1.AMAZON.COM`。

**注意**  
下列範例僅使用 `ds-data:MemberName` 內容金鑰。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "addbob",
      "Effect": "Allow",
      "Action": "ds-data:AddGroupMember",
      "Resource": "arn:aws:ds:{{us-east-1}}:{{111122223333}}:directory/{{d-012345678}}",
      "Condition": {
        "StringEqualsIgnoreCase": {
          "ds-data:MemberName": "{{bob}}",
          "ds-data:MemberRealm": "{{one.tru1.amazon.com}}"
        }
      }
    }
  ]
}
```

------

## ds-data：Realm
<a name="dsdata_condition-Realm"></a>

適用於[字串運算子](https://docs.aws.amazon.com//IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)。

使用此金鑰來檢查政策中的`ds-data:Realm`值是否符合 IAM 主體可用來向 Directory Service Data APIs提出請求的領域。

**注意**  
此條件索引鍵不區分大小寫。無論字母大小寫為何，您都必須使用 `[StringEqualsIgnoreCase](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)`或 `[StringNotEqualsIgnoreCase](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html#Conditions_String)`條件運算子來比較字串值。

下列政策會拒絕 IAM 主體在領域 `ListUsers`上呼叫 `one.tru1.amazon.com`。

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Sid": "DenyTrustedList",
      "Effect": "Deny",
      "Action": "ds-data:ListUsers",
      "Resource": "*",
      "Condition": {
        "StringEqualsIgnoreCase": {
          "ds-data:Realm": [
            "{{one.tru1.amazon.com}}"
          ]
        }
      }
    }
  ]
}
```

------