以编程方式访问 AWS IAM 用户策略和访问权限
Programmatic access to AWS IAM users policy and access
我有一个应用程序使用 AWS SDK iOS 2.9.10 将 AWS IAM 用户登录到 his/hers AWS S3 帐户。我希望能够评估用户是否可以 read/write 访问帐户下的各种 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 策略中的操作字段是否允许 "s3:GetObject" 或 "s3:" 之类的权限和资源字段包含 "arn:aws:s3:::examplebucket/" 或“*”形式的值。如果两者都适用,则 IAM 用户有权访问 S3 "examplebucket"。
但是,我无法确定是否可以使用 AWS SDK iOS(Swift 或 Objective-C)以编程方式进行这种 IAM 访问,因此任何帮助都将非常有用.
我认为 AWS SDK iOS 未提供此功能,因为 GitHub 上存在一个未解决的问题,该问题已关闭且未得到答复。 [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.
很遗憾,iOS SDK 不受 IAM 服务的正式支持。这就是 iOS SDK 中不包含 IAM 服务端点的原因。不过,您可以尝试在 GitHub 上打开另一个功能请求...
如果您决定手动实施 HTTP 客户端和适当的请求签名,您可以使用上面提到的 IAM 命令(在 AWS 术语中称为 "Actions"),例如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
我有一个应用程序使用 AWS SDK iOS 2.9.10 将 AWS IAM 用户登录到 his/hers AWS S3 帐户。我希望能够评估用户是否可以 read/write 访问帐户下的各种 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 策略中的操作字段是否允许 "s3:GetObject" 或 "s3:" 之类的权限和资源字段包含 "arn:aws:s3:::examplebucket/" 或“*”形式的值。如果两者都适用,则 IAM 用户有权访问 S3 "examplebucket"。
但是,我无法确定是否可以使用 AWS SDK iOS(Swift 或 Objective-C)以编程方式进行这种 IAM 访问,因此任何帮助都将非常有用.
我认为 AWS SDK iOS 未提供此功能,因为 GitHub 上存在一个未解决的问题,该问题已关闭且未得到答复。 [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.
很遗憾,iOS SDK 不受 IAM 服务的正式支持。这就是 iOS SDK 中不包含 IAM 服务端点的原因。不过,您可以尝试在 GitHub 上打开另一个功能请求...
如果您决定手动实施 HTTP 客户端和适当的请求签名,您可以使用上面提到的 IAM 命令(在 AWS 术语中称为 "Actions"),例如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