gpt4 book ai didi

objective-c - 以编程方式访问 AWS IAM 用户策略和访问权限

转载 作者:行者123 更新时间:2023-11-28 13:34:11 25 4
gpt4 key购买 nike

我有一个应用程序使用 AWS SDK iOS 2.9.10 将 AWS IAM 用户登录到他/她的 AWS S3 账户。我希望能够评估用户是否对帐户下的各种 S3 存储桶具有读/写访问权限。基本上,我想以编程方式执行此操作:

aws iam list-user-policies --user-name IAM_User_Name

aws iam get-user-policy --user-name IAM_User_Name --policy-name IAM_Policy_Name

使用这些输出了解 IAM 用户有权访问哪个 S3 存储桶,然后我可以检查 IAM 策略中的 Action 字段是否允许“s3:GetObject”或“s3:”之类的权限和资源字段包含作为“arn:aws:s3:::examplebucket/”或“*”的值。如果两者都适用,则 IAM 用户有权访问 S3“examplebucket”。

但是,我无法确定是否可以使用 AWS SDK iOS(Swift 或 Objective-C)以编程方式进行这种 IAM 访问,因此任何帮助都将非常有用。

最佳答案

我认为 AWS SDK iOS 不提供此功能,因为 GitHub 上有一个 Unresolved 问题已关闭且未得到答复。 [1]

相反,您可以使用服务的所谓 IAM 查询 API [2] 直接查询服务。
AWS 声明:

AWS provides SDKs that consist of libraries and sample code for various programming languages and platforms (Java, Ruby, .NET, iOS, Android, etc.). The SDKs provide a convenient way to create programmatic access to IAM and AWS. For example, the SDKs take care of tasks such as cryptographically signing requests (see below), managing errors, and retrying requests automatically. For information about the AWS SDKs, including how to download and install them, see the Tools for Amazon Web Services page.

遗憾的是,IAM 服务并未正式支持 iOS SDK。这就是 IAM 服务端点未包含在 iOS SDK 中的原因。不过,您可以尝试在 GitHub 上打开另一个功能请求...

如果您决定手动实现 HTTP 客户端和适当的请求签名,您可以使用上面提到的 IAM 命令(在 AWS 术语中称为“操作”),例如ListUserPolicies 操作 [3]。

改进建议

I could then check the Action field in the IAM policy if it allows permission like "s3:GetObject" or "s3:" and resource field contains the value as "arn:aws:s3:::examplebucket/" or "*". If both applicable then IAM user has permission to the S3 "examplebucket".

如果您想要一种更强大的方法,我建议使用 IAM 策略模拟器 API。 [4]

引用资料

[1] https://github.com/aws-amplify/aws-sdk-ios/issues/496
[2] https://docs.aws.amazon.com/IAM/latest/APIReference/Welcome.html
[3] https://docs.aws.amazon.com/IAM/latest/APIReference/API_ListUserPolicies.html
[4] https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_testing-policies.html#policies-simulator-using-api

关于objective-c - 以编程方式访问 AWS IAM 用户策略和访问权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56892788/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com