Skip to content

Add GCS token renewal support for UC-Spark connector - #1137

Merged
tdas merged 21 commits into
unitycatalog:mainfrom
timothyw553:GCS-token-renewal
Nov 5, 2025
Merged

tdas merged 21 commits into
unitycatalog:mainfrom
timothyw553:GCS-token-renewal

Conversation

@timothyw553

Copy link
Copy Markdown
Collaborator

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

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";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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 ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, we can just use the one in UCHadoopConf

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Then I think this one can be removed now, as we discussed in the above thread.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

So actually because of existing test, it may be better to keep it.

@timothyw553 timothyw553 closed this Nov 4, 2025
@timothyw553 timothyw553 reopened this Nov 4, 2025

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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())

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah that's right.

@openinx openinx left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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()))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What's the reason that we finally keep this expiration time for the fixedCredProps, seems like can be removed now ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

.setExpirationTime(Date.from(Instant.ofEpochMilli(253370790000000L)))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please link this comment to the newly created issue, thanks.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. Issue here: #1159

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())

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Then I think this one can be removed now, as we discussed in the above thread.

Comment on lines +104 to +106
Class<?> providerClazz = conf.getClassByName(conf.get("fs.gs.auth.access.token.provider.impl"));
AccessTokenProvider provider =
(AccessTokenProvider) ReflectionUtils.newInstance(providerClazz, conf);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

@timothyw553
timothyw553 marked this pull request as ready for review November 5, 2025 17:58
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
Signed-off-by: TimothyW553 <[email protected]>
@timothyw553 timothyw553 closed this Nov 5, 2025
@timothyw553 timothyw553 reopened this Nov 5, 2025
Signed-off-by: TimothyW553 <[email protected]>

@tdas tdas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this. this was great addition following the s3 template.

@tdas
tdas merged commit d1b1ea4 into unitycatalog:main Nov 5, 2025
openinx pushed a commit to openinx/unitycatalog that referenced this pull request Nov 13, 2025
**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]>
openinx added a commit to openinx/unitycatalog that referenced this pull request Nov 13, 2025
Original Author is: Timothy Wang <[email protected]>
---------

Signed-off-by: Zheng Hu <[email protected]>
tdas pushed a commit that referenced this pull request Nov 14, 2025
**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]>
yili-db pushed a commit that referenced this pull request Nov 23, 2026
…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]>
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.

3 participants