在Java中扮演Web Indidentity请求的角色
Kubernetes中的微服务需要访问私有AWS API网关中的API。身份验证和授权是AWS_IAM。
Kubernetes具有适当的环境变量 aws_web_identity_token_file AWS_ROLE_ARN
KUBERNETES中的Pods使用服务帐户运行。对于AWS_IAM,我们需要生成会话令牌。
WebIdentityTokenFileCredentialSprovider.Create()有助于仅生成访问密钥和访问秘密。这不会生成会话令牌。
基本上,我们需要将STS CLI命令转换为Java
在 - -olole-arn $ aws_role_arn \ - 角色 - 会议名称Mysession \ -web-nidentity-token file:// $ aws_web_identity_token_file \ - 持续时间1000> /tmp/irp-cred.txt我在Java代码中传递了正确的内容
ausherolewithwebidentityrequindityrequest asherolewithwebidentityRequindityRequest = ausheroleleolewithwebidentityrequest.builder() 。 。 .Rolesessessname(“用户”) 。建造(); log.info(“ asherolewithwebidentityRequest:{}”,asherolewithwebidentityRequest.toString()); stsclient stsclient = stsclient.builder() .Build(); asherolewithwebidentityResponse asherolewithwebidentityResponse = stsclient.assumerolewithwebidentity(asherolewithwebidentityRequest); log.info(“ asherolewithwebidentityResponse:{}”,asherolewithwebidentityResponse.toString()); 凭证凭证= asherolewithwebidentityResponse.credentials(); log.info(“凭据,accessKey:{},accessSecret:{},accessToken:{}”,recretentials.accesskeyid(),recretentials.secretaccesskey(),recretentials.sessiontoken();
我正在使用以下依赖关系
< depentency> < groupId> software.amazon.awssdk</groupid> < artifactid> acm</artifactid> <版本> 2.17.102</version> </depentency>
,但这不起作用。
有人可以帮忙吗?
The microservice in Kubernetes needs to access the API's hosted in a private AWS API gateway. The authentication and authorization is AWS_IAM.
The Kubernetes has the proper environment variables
AWS_WEB_IDENTITY_TOKEN_FILE
AWS_ROLE_ARN
The pods in Kubernetes are running with service account. For AWS_IAM, we need the session token to be generated.
WebIdentityTokenFileCredentialsProvider.create() helps to generate only access key and access secret. This does not generate the session token.
So basically, we need to convert the sts cli command to Java
aws sts assume-role-with-web-identity \ --role-arn $AWS_ROLE_ARN \ --role-session-name mysession \ --web-identity-token file://$AWS_WEB_IDENTITY_TOKEN_FILE \ --duration-seconds 1000 > /tmp/irp-cred.txt
I am passing the correct things in the Java code
AssumeRoleWithWebIdentityRequest assumeRoleWithWebIdentityRequest = AssumeRoleWithWebIdentityRequest.builder() .webIdentityToken("file:///var/run/secrets/eks.amazonaws.com/serviceaccount/token") .roleArn("arn:aws:iam::*:role/eks/test") .roleSessionName("user") .build(); log.info("AssumeRoleWithWebIdentityRequest:{}",assumeRoleWithWebIdentityRequest.toString()); StsClient stsClient = StsClient.builder() .region(region).build(); AssumeRoleWithWebIdentityResponse assumeRoleWithWebIdentityResponse = stsClient.assumeRoleWithWebIdentity(assumeRoleWithWebIdentityRequest); log.info("AssumeRoleWithWebIdentityResponse:{}",assumeRoleWithWebIdentityResponse.toString()); Credentials credentials = assumeRoleWithWebIdentityResponse.credentials(); log.info("credentials, AccessKey:{},AccessSecret:{},AccessToken:{}",credentials.accessKeyId(),credentials.secretAccessKey(),credentials.sessionToken();
I am using below dependency
<dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>acm</artifactId> <version>2.17.102</version> </dependency>
But this is not working.
Can someone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论