DynamoDB 对地图项的细粒度访问

DynamoDB Fine Grained Access to Map Items

我知道有一个功能允许用户在策略中仅更新 DynamoDb 中记录的某些字段,但是有没有办法限制对包含地图的字段中的字段的访问?比如我有一个类似下面的table:

用户 ID [字符串] |名称 [字符串] |属性 [地图] |

在 "attributes" 地图中,我想限制用户只能更新地图的特定列,比方说 "value"(如果它只是 "hash" 和 "value" 自命名列)。如果是 link 权限,则类似于以下内容:

阿恩:.../tables/TestTable/Attributes/Value

这可能吗?

根据我对文档的了解,不,您不能定位地图中的特定键。因此,要么将它们拆分成它们自己的 "fields",要么允许用户修改整个地图。

值得注意的是,在 DynamoDB 术语中,TablesItems 的集合。项目是 属性 的集合。因此,命名一个属性 "Attributes" 可能会 导致混淆。

任何人......我会推荐一个类似于以下特征的模型;)是单独的项目属性:

UserID [string]
Name [string]
Height [string]
Weight [Float]
Race [String]

(我在猜测用户的特征)

这是一项政策,允许他们仅更新身高和体重,并且仅更新他们自己基于 UserID 的记录。当然"users"在这方面就需要federated in some way. For our purposes here I'm assuming you might use Web Identity Federation.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "AllowAccessToOnlyItemsMatchingUserID",
            "Effect": "Allow",
            "Action": [
                "dynamodb:GetItem",
                "dynamodb:BatchGetItem",
                "dynamodb:Query",
                "dynamodb:PutItem",
                "dynamodb:UpdateItem",
                "dynamodb:DeleteItem",
                "dynamodb:BatchWriteItem"
            ],
            "Resource": [
                "arn:aws:dynamodb:us-west-2:123456789012:table/Users"
            ],
            "Condition": {
                "ForAllValues:StringEquals": {
                    "dynamodb:LeadingKeys": [
                        "${www.amazon.com:user_id}"
                    ],
                    "dynamodb:Attributes": [
                        "UserID",
                        "Height",
                        "Weight",
                        ...
                        <list other allowed to edit attributes here>
                    ]
                },
                "StringEqualsIfExists": {
                    "dynamodb:Select": "SPECIFIC_ATTRIBUTES"
                }
            }
        }
    ]
}

是的,${www.amazon.com:user_id} 中的 user_id 是正确的。它是 替代变量

的一部分

From the documentation:

  • dynamodb:LeadingKeys – 此条件键允许用户仅访问分区键值与其用户 ID 匹配的项目。这个 ID ${www.amazon.com:user_id} 是一个替换变量。有关替换变量的详细信息,请参阅使用 Web 身份联合。
  • dynamodb:Attributes – 此条件键限制对指定属性的访问,以便只有权限策略中列出的操作才能 return 这些属性的值。此外,StringEqualsIfExists 子句确保应用程序必须始终提供要执行的特定属性列表,并且应用程序无法请求所有属性。