Repository navigation
Add GCS credential renewal integration test (local) #1209
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
baf538c
Add local Abfs credential renewal integration test
openinx 1a2d322
Refactor
openinx 26a72d5
Introduce the AzureCredentialGenerator.
openinx 6ce1457
Align the adls config with aws config.
openinx 65b3c85
Minor
openinx 9f3d12d
Make the credentials generato to be constant.
openinx 2bc9836
Fix the CI.
openinx f33cb49
initial commit: refatored from initial PR to use abstracted IT tests
timothyw553 508f5d7
Merge branch 'main' into gcs-cred-renewal-rebase
timothyw553 aec2efc
add test generator
timothyw553 b4bdb45
remove unnecessary const
timothyw553 f08c3e9
Merge branch 'main' into gcs-cred-renewal-rebase
timothyw553 04faba8
fix tests
timothyw553 f81b922
fmt
timothyw553 0580a92
revert cred props utils
timothyw553 a4f9ba1
address comments
timothyw553 ada79d1
add test coverage
timothyw553 ee30197
revert
timothyw553 8d631b6
Merge branch 'main' into gcs-cred-renewal-rebase
timothyw553 6de5da4
docs
timothyw553 b612dcd
Merge branch 'main' into gcs-cred-renewal-rebase
timothyw553 0ac3d49
Merge branch 'main' into gcs-cred-renewal-rebase
timothyw553 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 hidden or 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
This file contains hidden or 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
77 changes: 77 additions & 0 deletions
77
connectors/spark/src/test/java/io/unitycatalog/spark/auth/GcsCredRenewITTest.java
This file contains hidden or 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,77 @@ | ||
| package io.unitycatalog.spark.auth; | ||
|
|
||
| import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
|
|
||
| import com.google.auth.oauth2.AccessToken; | ||
| import com.google.cloud.hadoop.util.AccessTokenProvider; | ||
| import io.unitycatalog.server.service.credential.gcp.GcpCredentialsGenerator; | ||
| import java.time.Instant; | ||
| import java.util.Date; | ||
| import java.util.Map; | ||
|
|
||
| public class GcsCredRenewITTest extends BaseCredRenewITTest { | ||
| private static final String SCHEME = "gs"; | ||
| private static final String CREDENTIALS_GENERATOR_CLASS = GcsCredGenerator.class.getName(); | ||
|
|
||
| @Override | ||
| protected void setUpProperties() { | ||
| super.setUpProperties(); | ||
| serverProperties.put("gcs.bucketPath.0", "gs://" + BUCKET_NAME); | ||
| serverProperties.put("gcs.credentialsGenerator.0", CREDENTIALS_GENERATOR_CLASS); | ||
| // Note: gcs.jsonKeyFilePath.0 is intentionally omitted because we're using a custom | ||
| // credentialsGenerator for testing. The generator is loaded first and jsonKeyFilePath | ||
| // is only used as a fallback for ServiceAccountCredentialsGenerator. | ||
| } | ||
|
|
||
| @Override | ||
| protected String scheme() { | ||
| return SCHEME; | ||
| } | ||
|
|
||
| @Override | ||
| protected Map<String, String> catalogExtraProps() { | ||
| // Override fs.gs.impl to use our testing filesystem that tracks credential renewals | ||
| // Note: fs.gs.impl.disable.cache is already set by CredPropsUtil.GcsPropsBuilder | ||
| return Map.of("fs.gs.impl", GcsCredFileSystem.class.getName()); | ||
| } | ||
|
|
||
| public static class GcsCredGenerator extends TimeBasedCredGenerator<AccessToken> | ||
| implements GcpCredentialsGenerator { | ||
| @Override | ||
| protected AccessToken newTimeBasedCred(long ts) { | ||
| Instant expiration = Instant.ofEpochMilli(ts + DEFAULT_INTERVAL_MILLIS); | ||
| return AccessToken.newBuilder() | ||
| .setTokenValue(String.format("testing-renew://gs://%s#%d", BUCKET_NAME, ts)) | ||
| .setExpirationTime(Date.from(expiration)) | ||
| .build(); | ||
| } | ||
| } | ||
|
|
||
| public static class GcsCredFileSystem extends CredRenewFileSystem<AccessTokenProvider> { | ||
| @Override | ||
| protected String scheme() { | ||
| return String.format("%s:", SCHEME); | ||
| } | ||
|
|
||
| @Override | ||
| protected AccessTokenProvider createProvider() { | ||
| String clazz = getConf().get("fs.gs.auth.access.token.provider"); | ||
| assertThat(clazz).isEqualTo(GcsVendedTokenProvider.class.getName()); | ||
|
|
||
| // The setConf() call will validate the Hadoop configuration, failing fast if | ||
| // any required properties (UC URI, token, credentials UID) are missing. | ||
| AccessTokenProvider provider = new GcsVendedTokenProvider(); | ||
| provider.setConf(getConf()); | ||
| return provider; | ||
| } | ||
|
|
||
| @Override | ||
| protected void assertCredentials(AccessTokenProvider provider, long ts) { | ||
| AccessTokenProvider.AccessToken token = provider.getAccessToken(); | ||
| assertThat(token).isNotNull(); | ||
| assertThat(token.getToken()) | ||
| .as("OAuth token should contain timestamp %d", ts) | ||
| .isEqualTo(String.format("testing-renew://gs://%s#%d", BUCKET_NAME, ts)); | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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
12 changes: 12 additions & 0 deletions
12
.../src/main/java/io/unitycatalog/server/service/credential/gcp/GcpCredentialsGenerator.java
This file contains hidden or 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,12 @@ | ||
| package io.unitycatalog.server.service.credential.gcp; | ||
|
|
||
| import com.google.auth.oauth2.AccessToken; | ||
| import io.unitycatalog.server.service.credential.CredentialContext; | ||
|
|
||
| /** | ||
| * Pluggable contract for generating GCS OAuth tokens. Allows production code to load custom | ||
| * implementations for integration tests without coupling to {@link GcpCredentialVendor}. | ||
| */ | ||
| public interface GcpCredentialsGenerator { | ||
| AccessToken generate(CredentialContext context); | ||
| } |
14 changes: 14 additions & 0 deletions
14
server/src/main/java/io/unitycatalog/server/service/credential/gcp/GcsStorageConfig.java
This file contains hidden or 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,14 @@ | ||
| package io.unitycatalog.server.service.credential.gcp; | ||
|
|
||
| import lombok.Builder; | ||
| import lombok.Getter; | ||
| import lombok.ToString; | ||
|
|
||
| @Getter | ||
| @Builder | ||
| @ToString | ||
| public class GcsStorageConfig { | ||
| private final String bucketPath; | ||
| private final String jsonKeyFilePath; | ||
| private final String credentialsGenerator; | ||
| } |
34 changes: 34 additions & 0 deletions
34
.../main/java/io/unitycatalog/server/service/credential/gcp/TestingCredentialsGenerator.java
This file contains hidden or 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,34 @@ | ||
| package io.unitycatalog.server.service.credential.gcp; | ||
|
|
||
| import com.google.auth.oauth2.AccessToken; | ||
| import io.unitycatalog.server.service.credential.CredentialContext; | ||
| import java.time.Instant; | ||
| import java.util.Date; | ||
|
|
||
| /** | ||
| * Simple generator that returns a static token for GCS. Intended for testing and local development | ||
| * scenarios where a real GCP service account is not available. | ||
| */ | ||
| public class TestingCredentialsGenerator implements GcpCredentialsGenerator { | ||
| private static final long TOKEN_EXPIRATION_MILLIS = 253370790000000L; | ||
|
|
||
| private final AccessToken staticToken; | ||
|
|
||
| public TestingCredentialsGenerator(GcsStorageConfig storageConfig) { | ||
| String tokenValue = storageConfig.getJsonKeyFilePath(); | ||
| if (tokenValue == null || tokenValue.isEmpty()) { | ||
| tokenValue = String.format("testing://%s", storageConfig.getBucketPath()); | ||
| } | ||
| Instant expirationInstant = Instant.ofEpochMilli(TOKEN_EXPIRATION_MILLIS); | ||
| this.staticToken = | ||
| AccessToken.newBuilder() | ||
| .setTokenValue(tokenValue) | ||
| .setExpirationTime(Date.from(expirationInstant)) | ||
| .build(); | ||
| } | ||
|
|
||
| @Override | ||
| public AccessToken generate(CredentialContext context) { | ||
| return staticToken; | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
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.
this file was caught when i ran javafmtAll