-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-18154. S3A Authentication to support WebIdentity #4070
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package org.apache.hadoop.fs.s3a; | ||
|
|
||
| import org.apache.commons.lang3.StringUtils; | ||
|
||
| import com.amazonaws.auth.AWSCredentials; | ||
| import com.amazonaws.auth.AWSCredentialsProvider; | ||
| import com.amazonaws.auth.WebIdentityTokenCredentialsProvider; | ||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.security.ProviderUtils; | ||
| import org.slf4j.Logger; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * WebIdentityTokenCredentialsProvider supports static configuration | ||
| * of OIDC token path, role ARN and role session name. | ||
| * | ||
| */ | ||
| //@InterfaceAudience.Public | ||
| //@InterfaceStability.Stable | ||
| public class OIDCTokenCredentialsProvider implements AWSCredentialsProvider { | ||
| public static final String NAME | ||
| = "org.apache.hadoop.fs.s3a.OIDCTokenCredentialsProvider"; | ||
|
|
||
| //these are the parameters to document and to pass along with the class | ||
| //usually from import static org.apache.hadoop.fs.s3a.Constants.*; | ||
| public static final String JWT_PATH = "fs.s3a.jwt.path"; | ||
jclarysse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static final String ROLE_ARN = "fs.s3a.role.arn"; | ||
jclarysse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static final String SESSION_NAME = "fs.s3a.session.name"; | ||
|
|
||
| /** Reuse the S3AFileSystem log. */ | ||
| private static final Logger LOG = S3AFileSystem.LOG; | ||
|
|
||
| private String jwtPath; | ||
| private String roleARN; | ||
| private String sessionName; | ||
| private IOException lookupIOE; | ||
|
|
||
| public OIDCTokenCredentialsProvider(Configuration conf) { | ||
|
||
| try { | ||
| Configuration c = ProviderUtils.excludeIncompatibleCredentialProviders( | ||
| conf, S3AFileSystem.class); | ||
| this.jwtPath = S3AUtils.lookupPassword(c, JWT_PATH, null); | ||
| this.roleARN = S3AUtils.lookupPassword(c, ROLE_ARN, null); | ||
| this.sessionName = S3AUtils.lookupPassword(c, SESSION_NAME, null); | ||
| } catch (IOException e) { | ||
| lookupIOE = e; | ||
| } | ||
| } | ||
|
|
||
| public AWSCredentials getCredentials() { | ||
| if (lookupIOE != null) { | ||
| // propagate any initialization problem | ||
| throw new CredentialInitializationException(lookupIOE.toString(), | ||
| lookupIOE); | ||
| } | ||
|
|
||
| LOG.debug("jwtPath {} roleARN {}", jwtPath, roleARN); | ||
|
|
||
| if (!StringUtils.isEmpty(jwtPath) && !StringUtils.isEmpty(roleARN)) { | ||
| final AWSCredentialsProvider credentialsProvider = | ||
| WebIdentityTokenCredentialsProvider.builder() | ||
| .webIdentityTokenFile(jwtPath) | ||
|
||
| .roleArn(roleARN) | ||
| .roleSessionName(sessionName) | ||
| .build(); | ||
| return credentialsProvider.getCredentials(); | ||
| } | ||
|
||
| else throw new CredentialInitializationException( | ||
| "OIDC token path or role ARN is null"); | ||
| } | ||
|
|
||
| public void refresh() {} | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return getClass().getSimpleName(); | ||
jclarysse marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move to org.apache.hadoop.fs.s3a.auth