Skip to content

[Hadoop] Give each fixed credential its own credential-scoped file system - #2305

Merged
yili-db merged 1 commit into
unitycatalog:mainfrom
maharanay22:fix-fixed-credential-delegate-reuse
Nov 19, 2026
Merged

yili-db merged 1 commit into
unitycatalog:mainfrom
maharanay22:fix-fixed-credential-delegate-reuse

Conversation

@maharanay22

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 renewCredential.enabled=false and credential-scoped file systems on (the default), every table or path load vends a new fixed credential, but CredScopedFileSystem caches its delegate under a FileSystemCredId that leaves the credential out. For AWS S3 with vended keys s3Storage is empty, and the Azure and GCS ids never include the token. So every later load is served by the delegate built with the first load's credential. Once that credential expires, about an hour later, every query on the table fails with an expired token until the JVM restarts or the delegate is evicted from the cache. With renewal on, the delegate's token provider renews the credential itself, so only the fixed path is affected.

The props builder now records a SHA-256 hash of the fixed credential keys it sets, never the keys themselves, as fs.unitycatalog.fixed.credential.id when credential-scoped file systems are on, and FileSystemCredId includes it in equals and hashCode but not in toString. A load with a new credential gets its own delegate, and loads that share a credential, such as two loads served from initialCredCache, still share one. The old delegate is closed through the existing eviction and lease logic once nothing uses it. This is the same idea S3-compatible fixed keys already use, since they are hashed into s3Storage. To keep each cloud's builder the only place that knows which keys carry the credential, setInitFixedCredKeys became initFixedCredKeys, which returns the keys for build() to set and hash.

One assertion in S3CredPropsTest.severalCredentialsWithoutKeysLeaveTheEngineKeysInUse expected the next load's fixed keys to get the same id as the first load's. That is the case this PR changes, so it now expects a different id, while two users of one credential still share an id.

docs/ doesn't describe renewCredential.enabled or credential-scoped file systems, so there is nothing to update there.

Tests

CredPropsRoundTripTest.reloadWithoutRenewalUsesFreshlyVendedCredential loads a table twice without renewal, with a different credential each time, and checks for S3, Azure and GCS that the second load's delegate carries the second credential while the first load's configuration still gets its original delegate. It fails on main for all three clouds with the first credential. reloadWithoutRenewalOfTheSameCredentialReusesDelegate checks that two loads of the same credential share one delegate. Leaving the id out of FileSystemCredId, not setting it in the builder, ignoring it in equals, or hashing a constant each make a test fail.

build/sbt "hadoop/test" passes (1520 tests) on Windows with JDK 17, and so do hadoop/javafmtCheckAll and hadoop/Test/javafmtCheckAll.

…stem

With renewCredential.enabled=false, every table or path load vends a
fresh fixed credential, but CredScopedFileSystem cached its delegate by a
key that did not include the credential. Later loads reused the delegate
built with the first load's credential, so once that expired every query
on the table failed until the JVM restarted or the delegate was evicted.

The props builder now records a hash of the fixed credential keys it sets
in fs.unitycatalog.fixed.credential.id when credential-scoped file systems
are on, and FileSystemCredId includes it. A load with a new credential
gets its own delegate, loads that share a credential still share one, and
the old delegate is closed through the existing eviction and lease logic.

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

yili-db commented Nov 19, 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 fixed-credential file system key looks right, and the reload tests fail without it on all three clouds.

@yili-db
yili-db merged commit 1165cc6 into unitycatalog:main Nov 19, 2026
19 checks passed
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.

2 participants