简体   繁体   English

从 Java 中的 IAM 用户名获取 Amazon 访问密钥和秘密密钥

[英]Get Amazon Access Key & Secret Key from IAM Username in Java

I came across Get Username from Amazon Access Key in Java when searching for a solution for a problem I have.在为我遇到的问题寻找解决方案时,我遇到了从 Java 中的 Amazon Access Key 获取用户名

But the only difference is I want to achieve the exact opposite: Is it possible to get the access key & secret key to perform Java SDK operations by using the username created in IAM?但唯一的区别是我想要实现完全相反的目标:是否可以通过使用在 IAM 中创建的用户名来获取访问密钥和秘密密钥来执行 Java SDK 操作?

I want to build an application when the user logs in with his IAM credentials he can start and stop instances in the application.我想构建一个应用程序,当用户使用他的 IAM 凭证登录时,他可以启动和停止应用程序中的实例。 But to do that I need the access & secret key of that user.但要做到这一点,我需要该用户的访问和秘密密钥。

I hope someone can help me or knows a workaround for my problem.我希望有人可以帮助我或知道我的问题的解决方法。

Thank you!谢谢!

Assuming your application has respectively sufficient AWS security credentials of its own (eg by running on an EC2 instance with an IAM Role for Amazon EC2 ), you can achieve this by means of the ListAccessKeys API action:假设您的应用程序各自拥有足够的 AWS 安全凭证(例如,通过在具有Amazon EC2IAM 角色的 EC2 实例上运行),您可以通过ListAccessKeys API 操作实现这一点:

Returns information about the access key IDs associated with the specified user.返回有关与指定用户关联的访问密钥 ID 的信息。 If there are none, the action returns an empty list.如果没有,则操作返回一个空列表。

This API action is exposed in the AWS SDK for Java as listAccessKeys() .此 API 操作在适用于 JavaAWS 开发工具包中公开为listAccessKeys()

Quite an old question but I don't believe a correct answer was provided.一个很老的问题,但我认为没有提供正确的答案。 To directly answer your question it's not possible to retrieve the secret key after it's been created.要直接回答您的问题,无法在创建后检索密钥。 The documentation for ListAccessKeys notes - To ensure the security of your AWS account, the secret access key is accessible only during key and user creation. ListAccessKeys的文档说明 - To ensure the security of your AWS account, the secret access key is accessible only during key and user creation.

You'll need to solve your problem via another means.您需要通过其他方式解决您的问题。 Some suggestions would be to use federated login or have the application manage its own set of roles that determines whether the user is authorized to start/stop instances.一些建议是使用联合登录或让应用程序管理自己的一组角色,以确定用户是否有权启动/停止实例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM