Skip to content
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

[#4992] support credential vending framework #4995

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

FANNG1
Copy link
Contributor

@FANNG1 FANNG1 commented Sep 23, 2024

What changes were proposed in this pull request?

support credential vending framework

Why are the changes needed?

Fix: #4992

Does this PR introduce any user-facing change?

no

How was this patch tested?

  1. add UT
  2. propose a draft PR in [SIP] support S3 credential vending for IcebergRESTServer #4966 , and could run pass S3 token with Gravitino IcebergRESTServer

import java.util.Map;

/** Interface representing a credential with type, expiration time, and additional information. */
public interface Credential {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of put it to common package?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It maybe used in the client side.

ServiceLoader<CredentialProvider> serviceLoader =
ServiceLoader.load(CredentialProvider.class, classLoader);
List<Class<? extends CredentialProvider>> providers =
Streams.stream(serviceLoader.iterator())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the consideration of using service loader?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Different catalogs may use different credential providers so that users could place the s3 provider in catalogA, place gcs provider in catalogB, so we using service loader to load corresponding jar in catalog classpaths.

*
* <p>A credential provider is responsible for managing and retrieving credentials.
*/
public interface CredentialProvider {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can change to like public interface Credential extends Closeable to avoid defining void stop() here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

*
* @return a map of credential information.
*/
Map<String, String> getCredentialInfo();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest change the style of getXXX to xxx, like credentialType().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to define an interface for Token like Hadoop?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest that you can refer to Hadoop's Credentials, Token and TokenIdentifer to see how to define our credential system.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Credential is like Token in hadoop, the difference is Token in hadoop focus on the security of the identifer, while we focus on how to represent diverse tokens like S3-token, AKSK, delegation token with different properties.

Copy link
Contributor Author

@FANNG1 FANNG1 Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concrete Credential has the clear definition , take S3TokenCredential for example

public class S3TokenCredential implements Credential {
  private String accessKeyId;
  private String secretAccessKey;
  private String sessionToken;
  private long expireMs;

  public S3TokenCredential(
      String accessKeyId, String secretAccessKey, String sessionToken, long expireMs) {
    this.accessKeyId = accessKeyId;
    this.secretAccessKey = secretAccessKey;
    this.sessionToken = sessionToken;
    this.expireMs = expireMs;
  }

  @Override
  public String getCredentialType() {
    return CredentialConstants.S3_TOKEN_CREDENTIAL_TYPE;
  }

  @Override
  public long getExpireTime() {
    return expireMs;
  }

  @Override
  public Map<String, String> getCredentialInfo() {
    return (new ImmutableMap.Builder<String, String>())
        .put(S3Properties.GRAVITINO_S3_ACCESS_KEY_ID, accessKeyId)
        .put(S3Properties.GRAVITINO_S3_SECRET_ACCESS_KEY, secretAccessKey)
        .put(S3Properties.GRAVITINO_S3_TOKEN, sessionToken)
        .build();
  }
}

@@ -28,6 +28,7 @@ plugins {

dependencies {
implementation(project(":api"))
implementation(project(":catalogs:catalog-common"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dependency here looks strange if you only want to define two properties in catalog-common, it is easy to introduce the cyclic dependency.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

catalog-common is mainly used to define some properties used by catalog, client, connectors, I think it's ok to add the dependence here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Subtask] support credential vending framework
2 participants