googleapis / googleapis/google-cloud-java

[google-auth-library-java] [Question] Support for AWS IRSA?

未关闭
#12,570 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
priority: p3 type: feature request type: question
主要语言
Java
星标
2.1k
派生
1.2k
平均合并
1 天 23 小时
30 天内合并 PR
157

描述

I wonder if there is built-in support for IRSA in this library?
I would like to use credentials for the IRSA role to obtain GCS token.
Currently, I have to implement my own `AwsSecurityCredentialsSupplier` and use AWS library to retrieve IRSA credentials.
```java
import com.google.auth.Credentials;
import com.google.auth.oauth2.AwsCredentials;
import com.google.auth.oauth2.AwsSecurityCredentials;
import com.google.auth.oauth2.AwsSecurityCredentialsSupplier;
import com.google.auth.oauth2.ExternalAccountSupplierContext;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageOptions;
import java.io.IOException;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider;
import software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain;

try {
var awsCredentialsProvider = DefaultCredentialsProvider.builder().build();
var googleCredentials = GoogleCredentials.getApplicationDefault();

if (googleCredentials instanceof AwsCredentials awsCredentials) {
var credentialsWithIrsaRole =
AwsCredentials.newBuilder(awsCredentials)
.setCredentialSource(null) // cannot have credential source and credential supplier
.setAwsSecurityCredentialsSupplier(
new IrsaAwsSecurityCredentialsSupplier(
awsCredentialsProvider))
.build();
scopedCredentials = credentialsWithIrsaRole.createScoped(List.of("https://www.googleapis.com/auth/devstorage.full_control"));
} else {
throw new IllegalStateException(
"Workload Identity Federation requires AWS credentials. Google credentials class: "
+ googleCredentials.getClass().getSimpleName());
}

log.debug("Successfully obtained credentials with Workload Identity Federation");
} catch (IOException exception) {
log.error("Failed to initialize Workload Identity Federation credentials", exception);
throw new IllegalStateException("Unable to initialize WIF credentials", exception);
}

//...
private record IrsaAwsSecurityCredentialsSupplier(AwsCredentialsProvider awsCredentialsProvider)
implements AwsSecurityCredentialsSupplier {

@Override
public AwsSecurityCredentials getCredentials(ExternalAccountSupplierContext context) {
var awsCredentials = awsCredentialsProvider.resolveCredentials();
if (awsCredentials instanceof AwsSessionCredentials sessionCredentials) {
return new AwsSecurityCredentials(
sessionCredentials.accessKeyId(),
sessionCredentials.secretAccessKey(),
sessionCredentials.sessionToken());
}
throw new IllegalStateException(
"Requires aws session credentials with token for irsa. AWS credentials class: "
+ awsCredentials.getClass().getSimpleName());
}

@Override
public String getRegion(ExternalAccountSupplierContext context) {
return DefaultAwsRegionProviderChain.builder().build().getRegion().id();
}
}
```

I wonder if there is a simpler way to achieve this?

贡献指南

打开贡献指南

调研方向

Start with the AwsCredentials, AwsSecurityCredentialsSupplier, and ExternalAccountSupplierContext entry points shown in the issue, along with the AWS SDK credential provider used for IRSA. Determine whether the library already supports this flow and define done as a clear built-in or documented simpler path for obtaining GCS credentials from AWS IRSA.

由索引模型根据 Issue 内容生成。

评估

技术栈
aws, java
领域
authentication, cloud
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。