简体   繁体   English

从实例配置文件中检索IAM角色以与v4签名者一起使用

[英]Retrieve IAM Role from Instance Profile for Use With v4 Signer

I'm trying to achieve the same result as the Ruby example code I have using the AWS .NET SDK and am running into trouble querying the instance profile credentials. 我试图获得与使用AWS .NET SDK的Ruby示例代码相同的结果,并且在查询实例配置文件凭证时遇到麻烦。 It seems the .NET SDK hides the credential provider when querying the instance profile. 在查询实例配置文件时,.NET SDK似乎隐藏了凭据提供程序。 However, I need to get to that so I can use it to sign an STS request and pass that to an API that uses that information for authentication purposes. 但是,我需要这样做,以便可以使用它来签名STS请求并将其传递给使用该信息进行身份验证的API。 So far I haven't found a way to query the instance profile and assume the IAM EC2 Role. 到目前为止,我还没有找到查询实例配置文件并承担IAM EC2角色的方法。

Does anyone have a good idea of how this would be done? 有谁知道如何做到这一点?

Ruby: 红宝石:

request = Aws::Sigv4::Signer.new(
  service: 'sts',
  region: 'us-east-1',
  credentials_provider: Aws::InstanceProfileCredentials.new
).sign_request(
  http_method: 'GET',
  url: 'https://sts.amazonaws.com/?Action=GetCallerIdentity&Version=2011-06-15'
).headers

What I am trying to avoid is storing any credentials on the instance. 我试图避免的是在实例上存储任何凭据。 However, the signature for the v4 signer method is: 但是,v4签名者方法的签名为:

var signer = new Amazon.Runtime.Internal.Auth.AWS4Signer();
signer.SignRequest(IRequest request, IClientConfig clientConfig, RequestMetrics metrics, string awsAccessKeyId, string awsSecretAccessKey);

This code will be running on EC2 instances. 该代码将在EC2实例上运行。

Any help would be appreciated! 任何帮助,将不胜感激!

我能够使用Amazon.Runtime.InstanceProfileAWSCredentials.GetCredentials()调用来获取临时凭证,我可以使用这些凭证来查询IAM角色等其他内容。

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

相关问题 IAM 角色未分配实例配置文件 - IAM role is not assigned an instance profile 在具有IAM角色的EC2实例上运行时获取AWS V4签名的凭证 - Getting credentials for AWS V4 Signing when running on a EC2 instance with IAM role 将 IAM 角色附加到实例配置文件时出错 - Error Attaching IAM Role to an Instance Profile AWS实例配置文件与IAM用户角色 - AWS instance profile vs IAM user role AWS 实例配置文件与 IAM 角色? 为什么不直接分配角色? - AWS instance profile vs IAM role? Why not directly assign a role? 如何使用与EC2实例关联的IAM角色从Amazon检索临时AWS凭证(在Java中)? - How to retrieve temporary AWS credentials from Amazon using IAM role associated with the EC2 instance(in java)? AWS associate-iam-instance-profile function,实例需要什么 IAM 角色? - AWS associate-iam-instance-profile function, what IAM role is required for the instance? IAM角色和实例配置文件 - IAM Roles and instance profile 使用 IAM 角色而不是凭证从使用 terraform 的 EC2 实例创建 aws 资源 - Use IAM role instead of credentials to create aws resource from an EC2 instance using terraform CDK cloud9 - 如何将预先构建的实例配置文件附加到 cdk 中的 Cloud9 实例 iam 角色? - CDK cloud9 - How to attach preconstructed instance profile to Cloud9 instance iam role in cdk?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM