-
Notifications
You must be signed in to change notification settings - Fork 319
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
[#4994][#4369] feat(core): support S3 credential vending #4966
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
55e8df3
s3 credential
FANNG1 a69edb1
fix
FANNG1 ebe23c7
fix
FANNG1 cc4ec18
fix
FANNG1 3042b4d
make it final
FANNG1 36f5c9f
fix comment
FANNG1 0eb0fa6
fix comment
FANNG1 d5536c3
fix comment
FANNG1 4088c32
use static and session name
FANNG1 809b7f6
use static and session name
FANNG1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
api/src/main/java/org/apache/gravitino/credential/S3SecretKeyCredential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.gravitino.credential; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Map; | ||
|
||
/** S3 secret key credential. */ | ||
public class S3SecretKeyCredential implements Credential { | ||
|
||
/** S3 secret key credential type. */ | ||
public static final String S3_SECRET_KEY_CREDENTIAL_TYPE = "s3-secret-key"; | ||
/** The static access key ID used to access S3 data. */ | ||
public static final String GRAVITINO_S3_STATIC_ACCESS_KEY_ID = "s3-access-key-id"; | ||
/** The static secret access key used to access S3 data. */ | ||
public static final String GRAVITINO_S3_STATIC_SECRET_ACCESS_KEY = "s3-secret-access-key"; | ||
|
||
private final String accessKeyId; | ||
private final String secretAccessKey; | ||
|
||
/** | ||
* Constructs an instance of {@link S3SecretKeyCredential} with the static S3 access key ID and | ||
* secret access key. | ||
* | ||
* @param accessKeyId The S3 static access key ID. | ||
* @param secretAccessKey The S3 static secret access key. | ||
*/ | ||
public S3SecretKeyCredential(String accessKeyId, String secretAccessKey) { | ||
Preconditions.checkNotNull(accessKeyId, "S3 access key Id should not null"); | ||
Preconditions.checkNotNull(secretAccessKey, "S3 secret access key should not null"); | ||
|
||
this.accessKeyId = accessKeyId; | ||
this.secretAccessKey = secretAccessKey; | ||
} | ||
|
||
@Override | ||
public String credentialType() { | ||
return S3_SECRET_KEY_CREDENTIAL_TYPE; | ||
} | ||
|
||
@Override | ||
public long expireTimeInMs() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public Map<String, String> credentialInfo() { | ||
return (new ImmutableMap.Builder<String, String>()) | ||
.put(GRAVITINO_S3_STATIC_ACCESS_KEY_ID, accessKeyId) | ||
.put(GRAVITINO_S3_STATIC_SECRET_ACCESS_KEY, secretAccessKey) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Get S3 static access key ID. | ||
* | ||
* @return The S3 access key ID. | ||
*/ | ||
public String accessKeyId() { | ||
return accessKeyId; | ||
} | ||
|
||
/** | ||
* Get S3 static secret access key. | ||
* | ||
* @return The S3 secret access key. | ||
*/ | ||
public String secretAccessKey() { | ||
return secretAccessKey; | ||
} | ||
} |
112 changes: 112 additions & 0 deletions
112
api/src/main/java/org/apache/gravitino/credential/S3TokenCredential.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.gravitino.credential; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.util.Map; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
/** S3 token credential. */ | ||
public class S3TokenCredential implements Credential { | ||
|
||
/** S3 token credential type. */ | ||
public static final String S3_TOKEN_CREDENTIAL_TYPE = "s3-token"; | ||
/** S3 session access key ID used to access S3 data. */ | ||
public static final String GRAVITINO_S3_SESSION_ACCESS_KEY_ID = "s3-access-key-id"; | ||
/** S3 session secret access key used to access S3 data. */ | ||
public static final String GRAVITINO_S3_SESSION_SECRET_ACCESS_KEY = "s3-secret-access-key"; | ||
/** S3 session token. */ | ||
public static final String GRAVITINO_S3_TOKEN = "s3-session-token"; | ||
|
||
private final String accessKeyId; | ||
private final String secretAccessKey; | ||
private final String sessionToken; | ||
private final long expireTimeInMS; | ||
|
||
/** | ||
* Constructs an instance of {@link S3SecretKeyCredential} with session secret key and token. | ||
* | ||
* @param accessKeyId The S3 session access key ID. | ||
* @param secretAccessKey The S3 session secret access key. | ||
* @param sessionToken The S3 session token. | ||
* @param expireTimeInMS The S3 session token expire time in ms. | ||
*/ | ||
public S3TokenCredential( | ||
String accessKeyId, String secretAccessKey, String sessionToken, long expireTimeInMS) { | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(accessKeyId), "S3 access key Id should not be empty"); | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(secretAccessKey), "S3 secret access key should not be empty"); | ||
Preconditions.checkArgument( | ||
StringUtils.isNotBlank(sessionToken), "S3 session token should not be empty"); | ||
|
||
this.accessKeyId = accessKeyId; | ||
this.secretAccessKey = secretAccessKey; | ||
this.sessionToken = sessionToken; | ||
this.expireTimeInMS = expireTimeInMS; | ||
} | ||
|
||
@Override | ||
public String credentialType() { | ||
return S3_TOKEN_CREDENTIAL_TYPE; | ||
} | ||
|
||
@Override | ||
public long expireTimeInMs() { | ||
return expireTimeInMS; | ||
} | ||
|
||
@Override | ||
public Map<String, String> credentialInfo() { | ||
return (new ImmutableMap.Builder<String, String>()) | ||
.put(GRAVITINO_S3_SESSION_ACCESS_KEY_ID, accessKeyId) | ||
.put(GRAVITINO_S3_SESSION_SECRET_ACCESS_KEY, secretAccessKey) | ||
.put(GRAVITINO_S3_TOKEN, sessionToken) | ||
.build(); | ||
} | ||
|
||
/** | ||
* Get S3 session access key ID. | ||
* | ||
* @return The S3 access key ID. | ||
*/ | ||
public String accessKeyId() { | ||
return accessKeyId; | ||
} | ||
|
||
/** | ||
* Get S3 session secret access key. | ||
* | ||
* @return The S3 secret access key. | ||
*/ | ||
public String secretAccessKey() { | ||
return secretAccessKey; | ||
} | ||
|
||
/** | ||
* Get S3 session token. | ||
* | ||
* @return The S3 session token. | ||
*/ | ||
public String sessionToken() { | ||
return sessionToken; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
bundles/aws-bundle/src/main/java/org/apache/gravitino/s3/credential/S3SecretKeyProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.gravitino.s3.credential; | ||
|
||
import java.util.Map; | ||
import org.apache.gravitino.credential.Credential; | ||
import org.apache.gravitino.credential.CredentialContext; | ||
import org.apache.gravitino.credential.CredentialProvider; | ||
import org.apache.gravitino.credential.S3SecretKeyCredential; | ||
import org.apache.gravitino.credential.config.S3CredentialConfig; | ||
|
||
/** Generate S3 access key and secret key to access S3 data. */ | ||
public class S3SecretKeyProvider implements CredentialProvider { | ||
|
||
private String accessKey; | ||
private String secretKey; | ||
|
||
@Override | ||
public void initialize(Map<String, String> properties) { | ||
S3CredentialConfig s3CredentialConfig = new S3CredentialConfig(properties); | ||
this.accessKey = s3CredentialConfig.accessKeyID(); | ||
this.secretKey = s3CredentialConfig.secretAccessKey(); | ||
} | ||
|
||
@Override | ||
public void close() {} | ||
|
||
@Override | ||
public String credentialType() { | ||
return S3SecretKeyCredential.S3_SECRET_KEY_CREDENTIAL_TYPE; | ||
} | ||
|
||
@Override | ||
public Credential getCredential(CredentialContext context) { | ||
return new S3SecretKeyCredential(accessKey, secretKey); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
what do you mean about
token
andsession-token
?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.
I misunderstand this. I got it now.