仅根据存储桶策略将 AWS IAM 实例角色策略设置为 GetObject

发布于 2025-01-15 12:31:58 字数 999 浏览 0 评论 0原文

我无法更改我们企业环境中的 IAM 角色策略。所以我希望能够根据存储桶策略更改角色对S3的权限。我想将 AWS IAM 实例角色设置为允许基于此存储桶策略的“s3:GetObject”。

我的存储桶策略中有这样的内容:

{
        "Sid": "tag-based",
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::XY:role/testing"
        },
        "Action": "s3:*",
        "Resource": [
            "arn:aws:s3:::bucket1/path1/*",
            "arn:aws:s3:::bucket1/path1"
        ]
    },

我希望在我的 IAM 角色内联策略中加入类似的内容 ->仅允许 TagKey 等于“SG”的资源:

{
        "Effect": "Allow",
        "Action": [
            "s3:PutObject",
            "s3:GetObject",
            "s3:DeleteObject",
            "s3:PutObjectAcl"
        ],
        "Resource": "<HOW TO SETUP IT ONLY FOR RESORUCES WHICH HAVE TAG KEY 'SG?'>",
        "Condition": {
            "ForAllValues:StringEquals": {
                "aws:TagKeys": [
                    "SG"
                ]
            }
        }
    }


Is this right way to achieve it?

I'm not able to change IAM role policy in our corporate environment. So I want to be able to change role's permissions to S3 based on bucket policy. I want to setup AWS IAM instance role to have Allow on "s3:GetObject" based on this bucket policy.

I have this in my bucket policy:

{
        "Sid": "tag-based",
        "Effect": "Allow",
        "Principal": {
            "AWS": "arn:aws:iam::XY:role/testing"
        },
        "Action": "s3:*",
        "Resource": [
            "arn:aws:s3:::bucket1/path1/*",
            "arn:aws:s3:::bucket1/path1"
        ]
    },

And I want something like this in my IAM role inline policy -> To have allow only for resources which have TagKey equal to 'SG':

{
        "Effect": "Allow",
        "Action": [
            "s3:PutObject",
            "s3:GetObject",
            "s3:DeleteObject",
            "s3:PutObjectAcl"
        ],
        "Resource": "<HOW TO SETUP IT ONLY FOR RESORUCES WHICH HAVE TAG KEY 'SG?'>",
        "Condition": {
            "ForAllValues:StringEquals": {
                "aws:TagKeys": [
                    "SG"
                ]
            }
        }
    }


Is this right way to achieve it?

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

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

发布评论

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

评论(1

極樂鬼 2025-01-22 12:31:58

S3 支持 授权标签是部分的,这意味着并非所有操作都支持基于标签的条件。进一步提到这里也是如此

至于您在策略中提到的调用,描述了它们如何使用标签 此处

GetObjectPutObect 围绕 x-amz-tag-count 标头 展开。这还需要另一个名为 GetObjectTagging 的权限

“<如何仅针对具有标签键“SG”的资源进行设置?>”

没有专门针对资源的此类子句,您可以在上面的链接页面中名为 Amazon S3 定义的资源类型 的部分中找到相同的子句。

总而言之,您想要简单地实现的目标是tag 的授权可能无法完全按照您的预期工作。

S3 support for Authorization based on tags is partial that means not all the operations supports tag based conditions. Which is further mentioned here as well.

As far as the calls you mentioned in your policy how they work with tags are described here

GetObject and PutObect revolves around x-amz-tag-count header. Which further requires another permission named GetObjectTagging

"<HOW TO SETUP IT ONLY FOR RESORUCES WHICH HAVE TAG KEY 'SG?'>"

There is no such clause for resources specifically, you can find the same in the above linked page under the section named Resource types defined by Amazon S3

In summary what you are trying to achieve simply in terms of tag based authorization might not fully work as you expect.

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