Skip to content

[Hadoop] Serve the vended GCS token when credential renewal is disabled - #2323

Merged
yili-db merged 4 commits into
unitycatalog:mainfrom
maharanay22:fix-gcs-fixed-credentials
Nov 23, 2026
Merged

yili-db merged 4 commits into
unitycatalog:mainfrom
maharanay22:fix-gcs-fixed-credentials

Conversation

@maharanay22

@maharanay22 maharanay22 commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

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

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.

With renewal disabled, the GCS props set only fs.gs.auth.access.token.credential and
fs.gs.auth.access.token.expiration, which no class in the GCS connector reads, and left
fs.gs.auth.type unset. The connector then fell back to its default Compute Engine
credentials, so table and path access failed off GCE and ran as the VM's service account
on GCE.

The fixed path now also sets fs.gs.auth.type=ACCESS_TOKEN_PROVIDER with the new
GcsFixedTokenProvider, which serves the vended token with its expiration and never renews
it. Once the token expires, its refresh fails with an error that says to load the table or
path again or enable credential renewal.

Signed-off-by: Maha Rana Yadavalli <[email protected]>
@yili-db

yili-db commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

/review

@timothyw553 timothyw553 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.

production code looks good. i left a couple comments on test coverage and docs, plus one small nit on validation.

`spark.hadoop.fs.gs.auth.type=APPLICATION_DEFAULT`). With the default renewing credentials, Unity Catalog sets its own
auth type for each table, so that session-wide setting only applies to locations Unity Catalog does not vend for, such
as the checkpoint.
`spark.hadoop.fs.gs.auth.type=APPLICATION_DEFAULT`). Unity Catalog sets its own auth type for each table it vends a

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.

does this apply to vended paths too, not just tables? also could we name spark.sql.catalog.<name>.renewCredential.enabled=false so readers know which setting disables renewal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, path credentials use the same props builder, so it applies to paths too. Done in c918ee3: the note now says table or path and names spark.sql.catalog..renewCredential.enabled=false.

@yili-db

yili-db commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db 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.

[AI Assisted] Comment. The docs update is accurate. Approve-worthy once the APPLICATION_DEFAULT row is added: the PR states this override and no test exercises it. Hadoop tests pass, and reverting the fixed-path wiring fails the 68 tests the description names.

*/
@ParameterizedTest(name = "renew={0} credScoped={1} expiring={2}")
@CsvSource({
"false, false, false",

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.

[AI Assisted] The PR says the fixed path overrides a session-wide fs.gs.auth.type (the checkpoint docs use APPLICATION_DEFAULT for exactly this case), but no row starts from a configuration that already sets it. Could we add a row that sets fs.gs.auth.type=APPLICATION_DEFAULT before the built props are applied, and assert AccessTokenProviderCredentials with the vended bearer value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added two rows starting from fs.gs.auth.type=APPLICATION_DEFAULT in a442c57. Dropping the fixed auth type makes the renewal-off row fail.

this.accessToken =
new AccessToken(
conf.get(ACCESS_TOKEN_KEY),
Instant.ofEpochMilli(conf.getLong(ACCESS_TOKEN_EXPIRATION_KEY, 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.

[AI Assisted] Nit: Long.MAX_VALUE as the no-expiration value is written by GcsCredPropsBuilder and read back here as the default. A shared constant would keep the two in step.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in a442c57. GcsFixedTokenProvider.NO_EXPIRATION_MILLIS is now shared by the builder and the provider.

try {
Configuration conf = new Configuration(false);
conf.set(UCHadoopConfConstants.UC_TEST_CLOCK_NAME, clockName);
Instant expiration = clock.now().plusSeconds(60).truncatedTo(ChronoUnit.MILLIS);

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.

[AI Assisted] Nit: the 60 second expiry is deliberately inside google-auth's expiration margin, so each request goes through refresh(). A short comment here would stop a later margin change from looking like a provider bug.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a short comment in a442c57 explaining that 60 seconds sits inside google-auth's expiration margin, so every request calls refresh().

@yili-db

yili-db commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

/review

@yili-db yili-db 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.

[AI Assisted] Approve. The earlier points are addressed: the session-wide APPLICATION_DEFAULT rows catch a regression in the fixed auth type, the expiration constant is shared, and the 60 second comment is in place. Hadoop tests pass, and reverting the fixed-path wiring fails the GCS tests.

@yili-db
yili-db merged commit 705c439 into unitycatalog:main Nov 23, 2026
19 checks passed
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