Repository navigation
Add GCS token renewal support for UC-Spark connector - #1137
Conversation
Signed-off-by: TimothyW553 <[email protected]>
3270b8d to
316124b
Compare
Signed-off-by: TimothyW553 <[email protected]>
316124b to
6a9b9d6
Compare
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
| implements AccessTokenProvider { | ||
|
|
||
| public static final String ACCESS_TOKEN_KEY = "fs.gs.auth.access.token.credential"; | ||
| public static final String ACCESS_TOKEN_EXPIRATION_KEY = "fs.gs.auth.access.token.expiration"; |
There was a problem hiding this comment.
What's the difference between this key and the fs.gs.init.oauth.token.expired.time ? Seems it's easily to confuse people. Maybe we can just remove this key, right ?
There was a problem hiding this comment.
Yeah, we can just use the one in UCHadoopConf
There was a problem hiding this comment.
Then I think this one can be removed now, as we discussed in the above thread.
There was a problem hiding this comment.
So actually because of existing test, it may be better to keep it.
81d8282 to
26099d1
Compare
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
There was a problem hiding this comment.
Deleted and moved to spark/auth/GcsVendedTokenProvider.java
| GcpOauthToken gcpToken = tempCreds.getGcpOauthToken(); | ||
| GcsPropsBuilder builder = new GcsPropsBuilder() | ||
| .set("fs.gs.auth.type", "ACCESS_TOKEN_PROVIDER") | ||
| .set("fs.gs.auth.access.token.provider", GcsVendedTokenProvider.class.getName()) |
There was a problem hiding this comment.
We only set fs.gs.auth.access.token.provider for the renewal flow, where the access token provider refreshes creds, unlike the fixed credential path.
There was a problem hiding this comment.
So for the fixed credential path, I think we just set the key fs.gs.auth.access.token.credential and it will automatically choose the default credential provider, rather than the customized GcsVendedTokenProvider, right ?
i think it should be correct.
There was a problem hiding this comment.
Yeah that's right.
openinx
left a comment
There was a problem hiding this comment.
Thanks @timothyw553 for the contribution. There are several minor comments, please take a look. I can give my approval for this now. Please address the comments for the next update.
Also please help remove the draft flag, thanks.
| return new GcsPropsBuilder() | ||
| .set(GcsVendedTokenProvider.ACCESS_TOKEN_KEY, gcpOauthToken.getOauthToken()) | ||
| .set(GcsVendedTokenProvider.ACCESS_TOKEN_EXPIRATION_KEY, | ||
| String.valueOf(tempCreds.getExpirationTime())) |
There was a problem hiding this comment.
What's the reason that we finally keep this expiration time for the fixedCredProps, seems like can be removed now ?
There was a problem hiding this comment.
And it's possible that the TemporaryCredentials have nullable expiration time, for example the StaticCredentialsGenerator won't have any expiration time https://github.com/unitycatalog/unitycatalog/blob/main/server/src/main/java/io/unitycatalog/server/service/credential/aws/CredentialsGenerator.java#L41 . It's a credential that generated from the OSS UC server.
There was a problem hiding this comment.
The reason I kept this is because the following test /spark/GCSCredentialTestFileSystem.java requires the expiration key.
When expiration is null should we just use Long.MAX_VALUE?
There was a problem hiding this comment.
Okay, then could you please open a separate issue to remove this key ? I think we can temporarily keep this config key. And I think we also need to change the oss uc server logic, because currently it just use the static expiration time.
There was a problem hiding this comment.
Please link this comment to the newly created issue, thanks.
| GcpOauthToken gcpToken = tempCreds.getGcpOauthToken(); | ||
| GcsPropsBuilder builder = new GcsPropsBuilder() | ||
| .set("fs.gs.auth.type", "ACCESS_TOKEN_PROVIDER") | ||
| .set("fs.gs.auth.access.token.provider", GcsVendedTokenProvider.class.getName()) |
There was a problem hiding this comment.
So for the fixed credential path, I think we just set the key fs.gs.auth.access.token.credential and it will automatically choose the default credential provider, rather than the customized GcsVendedTokenProvider, right ?
i think it should be correct.
| implements AccessTokenProvider { | ||
|
|
||
| public static final String ACCESS_TOKEN_KEY = "fs.gs.auth.access.token.credential"; | ||
| public static final String ACCESS_TOKEN_EXPIRATION_KEY = "fs.gs.auth.access.token.expiration"; |
There was a problem hiding this comment.
Then I think this one can be removed now, as we discussed in the above thread.
| Class<?> providerClazz = conf.getClassByName(conf.get("fs.gs.auth.access.token.provider.impl")); | ||
| AccessTokenProvider provider = | ||
| (AccessTokenProvider) ReflectionUtils.newInstance(providerClazz, conf); |
There was a problem hiding this comment.
Is it possible to use the google filesystem's default loader ( rather than the ReflectionUtils ) to test the class loading process ? we designed this test before, because we want to make sure that the S3AFileSystem/GCSFileSystem can successfully load/reflect the class. That's why we need the buildin loader from the GCSFileSystem to test it.
There was a problem hiding this comment.
Yes, updated the test to instantiate FileSystem for gs://..., which forces GoogleHadoopFileSystem to run its own loader; we then assert it hands back our GcsVendedTokenProvider. No more direct ReflectionUtils.
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
tdas
left a comment
There was a problem hiding this comment.
Thanks for this. this was great addition following the s3 template.
**PR Checklist** - [ ] A description of the changes is added to the description of this PR. - [ ] If there is a related issue, make sure it is linked to this PR. - [ ] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** <!-- Please state what you've changed and how it might affect the users. --> --------- Signed-off-by: TimothyW553 <[email protected]>
Original Author is: Timothy Wang <[email protected]> --------- Signed-off-by: Zheng Hu <[email protected]>
**PR Checklist** - [ ] A description of the changes is added to the description of this PR. - [ ] If there is a related issue, make sure it is linked to this PR. - [ ] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** Backport the [PR change](#1137) to branch-0.3 The whole backport progress is here: #1163 Notice, the original PR author is @timothyw553 , and I'm helping to backport to branch-0.3. I also keep the original author in the commit message. Please see: ```bash Author: Zheng Hu <[email protected]> Date: Wed Nov 5 14:16:34 2025 -0800 Add GCS token renewal support for UC-Spark connector (#1137) Original Author is: Timothy Wang <[email protected]> --------- Signed-off-by: Zheng Hu <[email protected]> ``` Signed-off-by: Zheng Hu <[email protected]>
…ed (#2323) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [x] If you've fixed a bug or added code that should be tested, add tests! - [x] If you've added or modified a feature, documentation in `docs` is updated **Description of changes** With credential renewal disabled (`renewCredential.enabled=false` in Spark, or `enableCredentialRenewal(false)` in `UCCredentialHadoopConfs`), GCS tables and paths don't use the token Unity Catalog vends. The props builder writes the token to `fs.gs.auth.access.token.credential` and `fs.gs.auth.access.token.expiration`, but no class in the GCS connector reads those keys, and `fs.gs.auth.type` is never set. The connector then falls back to its default Compute Engine credentials. For example, reading a GCS table from a laptop with renewal off fails because the metadata server can't be found, and on a GCE VM the same read silently runs as the VM's service account instead of the table-scoped token. S3 doesn't have this problem because S3A's default providers read the fixed keys, and Unity Catalog records when an engine provider overrides them. GCS has no provider chain, so the table's auth type has to be set. This regressed in #1137, which replaced the provider that read those keys with the renewable one and kept the auth keys only on the renewal path. The fixed path now also sets `fs.gs.auth.type=ACCESS_TOKEN_PROVIDER` with a new `GcsFixedTokenProvider`. It serves the vended token with its expiration and never renews it. Like the renewal path, this overrides a session-wide `fs.gs.auth.type` for that table only. The provider #1137 removed always threw from `refresh()`, while the new one only throws once the token has expired, which keeps the token in use during the few minutes before expiry when the connector refreshes early. After that the refresh fails with an error that says to load the table or path again or to enable credential renewal. The provider reads its clock the same way `GenericCredentialProvider` does. The two auth keys are constant, so the fixed credential id from #2305 still changes only with the token and its expiry, and a new token still gets its own credential-scoped file system. Users who ran with renewal off and relied on the VM or application default identity for Unity Catalog tables will now use the vended token instead. The streaming checkpoint note in `docs/integrations/unity-catalog-spark.md` said Unity Catalog sets its own GCS auth type only with renewal. It now says it does so for each table or path it vends a token for, apart from one that gets several tokens while renewal is off, and it names `spark.sql.catalog.<name>.renewCredential.enabled=false`. In that case no credential keys are set for any cloud, which predates this change and is left for a follow-up. **Tests** `GcsCredPropsTest.gcsConnectorAuthenticatesWithTheVendedToken` runs the built props through the connector's own `HadoopCredentialsConfiguration.getCredentials` with renewal on and off, with and without an expiration, with credential-scoped file systems on, and from a configuration that already sets `fs.gs.auth.type=APPLICATION_DEFAULT`. It checks that the connector sends the vended token and reports its expiration. On `main` every renewal-off row fails and resolves to Compute Engine credentials. `fixedTokenIsUsedUntilItExpires` uses a manual clock to check that a fixed token is still sent one millisecond before its expiration and that the refresh fails at exactly the expiration. Making the refresh never fail, always fail, fail only after the expiration, or ignore the expiration or the clock each makes a test fail, Dropping the two auth keys failed 68 tests before the `APPLICATION_DEFAULT` rows were added, and dropping only `fs.gs.auth.type` from the fixed path makes the renewal-off `APPLICATION_DEFAULT` row fail because the connector looks for Application Default Credentials. The tests run against the unshaded `HadoopCredentialsConfiguration` from util-hadoop 3.0.2, while production uses the shaded copy of the same version in the GCS connector. The expiry failure was not checked end to end against a real `GoogleHadoopFileSystem` or a GCS bucket. On Windows with JDK 17, `GcsCredPropsTest`, `S3CredPropsTest`, `AzureCredPropsTest`, `CredPropsRoundTripTest` and the `id` tests pass, and at the current head the full `hadoop/test` (1528 tests) and the hadoop format checks pass. The Spark integration tests run in CI. --------- Signed-off-by: Maha Rana Yadavalli <[email protected]> Co-authored-by: Maha Rana Yadavalli <[email protected]>
PR Checklist
docsis updatedDescription of changes