AWS DynamoDB IAM策略 - 拒绝查询特定属性

发布于 2025-02-13 09:37:19 字数 825 浏览 1 评论 0原文

我很难做到这一点。我设置了首先允许查询的策略,以便lambda可以访问我的表格,但是我需要它以防止查询一些特定属性。我可以使用带有StringNotequal的允许的允许,但是我希望拒绝拒绝,因此,如果有人在策略后以后添加其他条件,他们不会意外地授予对受限属性的访问。这是我的两个政策声明:

const psAllow = new PolicyStatement({
  resources: [tableArn],
  actions: ['dynamodb:GetItem','dynamodb:BatchGetItem','dynamodb:Query','dynamodb:Scan'],
  effect: Effect.ALLOW
});

const psDeny = new PolicyStatement({
  resources: [tableArn],
  actions: ['dynamodb:GetItem','dynamodb:BatchGetItem','dynamodb:Query', 'dynamodb:Scan'],
  effect: Effect.DENY
});
psDeny.addCondition('StringEquals', {'dynamodb:Select':'SPECIFIC_ATTRIBUTES'});
psDeny.addCondition('ForAllValues:StringEquals', {'dynamodb:Attributes':['restricted_field1','restricted_field2']});

如果我省略了条件,则拒绝将覆盖允许并正确防止DynamoDB查询。一旦我添加条件,否认就被完全忽略了。我必须格式化条件错误,或者只是在这里缺少一些东西。有什么想法吗?

I'm having trouble getting this to work. I setup a policy to first allow a query so the lambda can access my table, but I need it to prevent query on a few specific attributes. I can make it work using an allow with StringNotEquals but I would prefer a DENY so if someone were to add another condition to the policy later they dont accidentally grant access to the restricted attributes. Here's my two Policy Statements:

const psAllow = new PolicyStatement({
  resources: [tableArn],
  actions: ['dynamodb:GetItem','dynamodb:BatchGetItem','dynamodb:Query','dynamodb:Scan'],
  effect: Effect.ALLOW
});

const psDeny = new PolicyStatement({
  resources: [tableArn],
  actions: ['dynamodb:GetItem','dynamodb:BatchGetItem','dynamodb:Query', 'dynamodb:Scan'],
  effect: Effect.DENY
});
psDeny.addCondition('StringEquals', {'dynamodb:Select':'SPECIFIC_ATTRIBUTES'});
psDeny.addCondition('ForAllValues:StringEquals', {'dynamodb:Attributes':['restricted_field1','restricted_field2']});

If I omit the conditions the DENY will override the ALLOW and correctly prevent the dynamodb query. As soon as I add a condition the DENY is totally ignored. I must be formatting the condition wrong or just missing something here. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挖个坑埋了你 2025-02-20 09:37:19

我认为您应该在拒绝语句中使用foranyValues(而不是forallValues)。

I think you should use ForAnyValues (instead of ForAllValues) in the deny statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文