Skip to content

Support storage-scoped GCP credentials - #5951

Draft
sririshindra wants to merge 10 commits into
apache:mainfrom
sririshindra:named-storage-gcp-credentials
Draft

sririshindra wants to merge 10 commits into
apache:mainfrom
sririshindra:named-storage-gcp-credentials

Conversation

@sririshindra

@sririshindra sririshindra commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

A deployment can already select AWS and Azure credentials per storage through storageName (#3409, which fixed #2970, and #5952), but every GCS catalog has to use the single server default. Teams whose buckets belong to different GCP identities can't share one Polaris server without giving one identity access to everything.

With RESOLVE_CREDENTIALS_BY_STORAGE_NAME enabled, a GCS storage configuration's storageName now selects the credentials set by polaris.storage.gcp.<storage>.credentials-file, or by polaris.storage.gcp.<storage>.credentials with the content of the file itself, which is easier to pass from an environment variable or a Kubernetes secret:

polaris.features."RESOLVE_CREDENTIALS_BY_STORAGE_NAME"=true
polaris.storage.gcp.team-a.credentials-file=/var/run/secrets/team-a/credentials.json

The credentials have the format GOOGLE_APPLICATION_CREDENTIALS points to. Service account key files and Workload Identity Federation configuration files are accepted; anything else is refused. A name sets one of the two properties, not both.

The same two properties also exist without a name, as polaris.storage.gcp.credentials-file and polaris.storage.gcp.credentials, like the unnamed Azure properties from #5952. The server credentials of a storage are then, in order:

  1. with the flag on and a storageName: that name's credentials, with no fallback;
  2. the unnamed credentials-file or credentials;
  3. polaris.storage.gcp.token;
  4. the application default credentials.

The selection lives in GcpCredentialsFactory, an application-scoped bean shaped like AzureCredentialsFactory, and StorageConfiguration only holds the properties. The provider's factory, which vending, refresh and cleanup tasks all go through, asks it for the credentials. Two names never share a cached credential, because the cache key's identity includes the storage configuration and therefore its storageName. Nothing changes for a deployment that sets none of the new properties and doesn't set storageName or leaves the flag off.

Behavior to review:

  • A GCS catalog that already has a storageName, on a deployment with the flag enabled, now fails instead of ignoring the name. The changelog fragment has an upgrade note.
  • A storageName is refused while GCS_PRINCIPAL_ATTRIBUTION_ENABLED is true, with a 500 like the other attribution misconfigurations. When the storage has a gcsServiceAccount and the request has a principal, attribution uses a federated identity instead of the server credentials, and otherwise it falls back to them. A name would apply to some requests only, so the combination is refused.
  • The unnamed credentials and polaris.storage.gcp.token can't be combined: one of them would be ignored, so this fails with a 500 naming the properties. Nobody has both today, since the unnamed properties are new.
  • Credentials from a file or a property are loaded the first time they are used and kept until restart, because loading reads a file. A failed load fails only the storages that use it and is retried on the next use. Unlike Azure's credentials, building a new one per call would save no token request, since every vend already refreshes a newly scoped copy, but it would read the file on every table access.
  • Errors name the property, never its value or the file's content. A failed file read keeps its cause for the server log; a parse failure doesn't, because parser messages can repeat the content. The default credentials (polaris.storage.gcp.token or the application default credentials) are still built once per server, as before.
  • As on AWS and Azure, names apply to the whole deployment, not to one realm. The docs say so.
  • Names such as token, lifespan or expiry are ordinary names: SmallRye keeps polaris.storage.gcp.token apart from polaris.storage.gcp.token.credentials-file, and a test covers it.
  • polaris.storage.gcp.token isn't deprecated here. Its replacement is the unnamed credentials added by this PR, and the Helm chart has no other GCP option yet, so that can follow separately, together with Helm keys for the new properties.

This relates to #5943, which relies on storageName selecting credentials for any storage type, but it works with a catalog's own storage configuration and doesn't depend on that PR.

Testing: unit tests cover named, unnamed and default credentials, files and content, no fallback, unknown and case-different names, the flag on and off and read per realm, cleanup tasks, attribution, the token combination, names like token, environment variables, content pasted into a properties file, loading once and retrying a failed load, separate cache entries per name, and keeping file paths, content and keys out of errors and toString. :polaris-core:check and :polaris-runtime-service:check pass on the head.

Earlier, before the factory and the new properties, I tested this on real GCP with Spark 4.1 and Iceberg 1.12 going through the REST catalog with vended credentials. The setup had two buckets and service accounts that can each reach only one of them, and server default credentials that could reach neither:

  • Each name reads and writes only its own bucket. A name pointed at the other bucket gets a 403 from GCS that names that name's service account, and the name still works on its own bucket afterwards.
  • An unknown name returns 400 and doesn't fall back. A storage without a name uses the default credentials, and with the flag off the name is ignored.
  • A name with GCS_PRINCIPAL_ATTRIBUTION_ENABLED returns 500 with the documented message.
  • With a missing or malformed file, the server starts and only that name fails, and the file's content doesn't appear in responses or logs.
  • With gcsServiceAccount set, the named credentials impersonate that service account.
  • No private key, key ID or access token appears in the server or Spark logs.

I haven't repeated that run for the latest changes yet.

Checklist

  • 🙋 I am the human author: I understand this change and can explain it
  • 🛡️ Don't disclose security issues! (contact [email protected])
  • 🔗 Clearly explained why the changes are needed, or linked related issues: Related to Support Per-Catalog AWS Credentials in MinIO Deployments #2970
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Added a changelog entry in changelog.d/ (if needed, see changelog.d/README.md)
  • 📚 Updated documentation in site/content/in-dev/unreleased (if needed)
  • 🤖 Disclosed significant AI usage (recommended if AI was used, see CONTRIBUTING.md)

A deployment can select AWS credentials per storage through storageName
(apache#3409, fixing apache#2970), but every GCS catalog has to use the single server
default. Teams whose buckets belong to different GCP identities cannot share
one Polaris server without granting one identity access to everything.

With RESOLVE_CREDENTIALS_BY_STORAGE_NAME enabled, a GCS storage configuration's
storageName now selects the credentials file set by
polaris.storage.gcp.<storage>.credentials-file. The file has the format that
GOOGLE_APPLICATION_CREDENTIALS points to; service account key files and Workload
Identity Federation configuration files are accepted. Like the default
credentials, each file is loaded on first use and then shared.

A storage without a storageName keeps using the default credentials, and an
unknown name fails with no fallback, as on AWS. The credentials are selected in
the provider's factory, which vending, refresh and cleanup tasks all go through.
The token and lifespan names stay reserved for the default credentials.

A storageName is refused while GCS_PRINCIPAL_ATTRIBUTION_ENABLED is true, because
attribution uses a federated identity instead of these credentials.

A GCS catalog that already has a storageName, on a deployment with the flag
enabled, now fails instead of ignoring the name; CHANGELOG.md notes this.
Earlier tests load a key file and select credentials by name, but stop short of using
the key. Sign in with two generated key files against a local token endpoint, and check
that each downscoping request carries the token of the service account from that file.
The upgrade note now mentions that a GCS storageName also fails while
GCS_PRINCIPAL_ATTRIBUTION_ENABLED is true, and the server credentials
section says the single credential is the default.

The provider tests no longer run each case for both CATALOG and TASK
entities: the storage configuration lookup ignores the entity type, so
the second run exercised the same code.
…dentials

# Conflicts:
#	runtime/service/src/main/java/org/apache/polaris/service/storage/StorageConfiguration.java
#	runtime/service/src/test/java/org/apache/polaris/service/storage/StorageConfigurationTest.java
#	site/content/in-dev/unreleased/configuration/config-sections/smallrye-polaris_storage.md
A storage name of token, lifespan or expiry was silently skipped, so a
catalog using it later failed with a misleading "not configured" error.
These names are properties of the default GCP credentials, and expiry was
added by apache#5806. Configuring one of them now stops the server from starting.
The storage integration provider is created at startup for this, as
S3CredentialVendingMechanisms already is.

A storage name used while GCS_PRINCIPAL_ATTRIBUTION_ENABLED is true now
fails with an IllegalStateException (500), like the other attribution
misconfigurations, since server settings cause it.

The tests now cover Polaris's own behavior only, in line with the AWS and
Azure named credentials: the token endpoint test, the retry test and the
cache key toString and impersonation tests are removed.
Attribution replaces the source credentials only when the storage has a
gcpServiceAccount and the request has a principal. The comment and the
docs now say so, instead of implying it always does.
@sririshindra
sririshindra marked this pull request as ready for review November 7, 2026 17:42
@dimas-b

dimas-b commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

I'll wait for #5952 then review this PR 😅

@orca-review-bot orca-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice, tight change. It reuses the AWS named-storage pattern and needs no extra cache-key work, because storageName already rides in the key's storage config. Unknown names fail closed, and secrets stay out of errors. A few small things inline.

Outside the diff:

  • Can you confirm :polaris-core:check and :polaris-runtime-service:check pass on the head commit? The description says only three test classes ran after the main merge.
  • Can the CHANGELOG feature entry say names are deployment-wide, not per realm? The GCS guide already says so.
  • Low priority: the 4-arg test constructor (used by TestServices / PolarisAuthzTestBase) always uses the default GCP credential. That's fine, but tests built through it can't exercise names.

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

* credentials supplier, Google HTTP transport factory, request-scope realm config).
*/
@ApplicationScoped
// Created at startup, so that invalid named GCP credentials stop the server instead of failing the

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This says invalid named credentials stop the server. But the files are loaded lazily through Suppliers.memoize, so a missing or bad file still fails on the first request. Only reserved names fail at startup. Can we reword it to "reserved GCP storage names stop the server"?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

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.

exactly

return ExternalAccountCredentials.fromStream(stream);
}
} catch (IOException | RuntimeException e) {
// Only the failure type is reported: parser and library messages can repeat file content.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Dropping the cause makes sense for secrets. But with several names configured, NoSuchFileException alone doesn't say which path is wrong. The path comes from server config, not the file content. Can we include credentialsFile in this message?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

private static GoogleCredentials loadGcpCredentials(String storageName, Path credentialsFile) {
try {
byte[] content = Files.readAllBytes(credentialsFile);
String type = new ObjectMapper().readTree(content).path("type").asText();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: can we use a shared static ObjectMapper instead of creating one per load?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

* credentials supplier, Google HTTP transport factory, request-scope realm config).
*/
@ApplicationScoped
// Created at startup, so that invalid named GCP credentials stop the server instead of failing the

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.

exactly

* {@code expiry} are reserved: configuring one of them stops the server from starting.
*/
@WithName("credentials-file")
Path credentialsFile();

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.

Supporting files is fine, but files alone maybe inconvenient for docker-based execution.

Could we allow the content of the credentials to be specified as a plain text config property too (it will be easily mappable to a k8s secret 🤔 )?

@dimas-b

dimas-b commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

* provider chain will be used.
*/
@WithName("gcp.token")
Optional<String> gcpAccessToken();

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.

Two questions:

  1. Why not have an "unnamed" credentialsFile() method, so that we provide the same resolution mechanism for named and unnamed configs?
  2. Should we now deprecate gcpAccessToken() and the other methods below? After Refresh statically configured GCP access token instead of caching it once #5806 we saw that this token cannot be refreshed, so it seem unsuited for production usage.

* GCP credentials: {@code polaris.storage.gcp.token}, {@code polaris.storage.gcp.lifespan} and
* {@code polaris.storage.gcp.expiry}.
*/
Set<String> RESERVED_GCP_STORAGE_NAMES = Set.of("token", "lifespan", "expiry");

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.

IMHO you don't need this. I'm fairly sure that a name like token works technically, and SmallRye config distinguishes a leaf polaris.storage.gcp.token property from the nested property polaris.storage.gcp.token.credentials-file. You could even have both at the same type.

I'd suggest to leave this to the administrator's due diligence, given that a storage named token or expiry is unlikely to happen anyways.

|| !realmConfig.getConfig(FeatureConfiguration.RESOLVE_CREDENTIALS_BY_STORAGE_NAME)) {
return defaultCredentials.get();
}
// Attribution may replace the source credentials with a per-principal federated identity: it

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.

Refusing to combine both flags is reasonable as a starting point. But I'm wondering if there is a technical limitation that prevents both flags to work properly together? One option is to make the named credentials the identity that signs or exchanges the federation request; IOW, to have attribution wrap the named credentials. Could be a good follow-up.

@adutra

adutra commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Heads-up: #5967 has been merged, so CHANGELOG.md is no longer edited directly. Changelog entries now go in a fragment file under changelog.d/, which avoids merge conflicts on CHANGELOG.md. See changelog.d/README.md for the format.

Could you rebase onto main, revert your changes to CHANGELOG.md, and add a fragment file instead if your change needs a changelog entry? A fragment is only needed for things worth calling out in release notes, such as breaking changes, metastore schema changes, or changes that require manual steps during an upgrade. Thanks!

…dentials

Changelog entries now go in changelog.d fragments (apache#5967), so this PR's
entries move from CHANGELOG.md to changelog.d/gcp-storage-name-credentials.md.
The GCP credential selection moves out of StorageConfiguration and the
storage integration provider into GcpCredentialsFactory, an
application-scoped bean shaped like AzureCredentialsFactory. It owns the
fallback: with RESOLVE_CREDENTIALS_BY_STORAGE_NAME, a storage name selects
its named credentials and never falls back. Otherwise the new unnamed
polaris.storage.gcp.credentials-file or polaris.storage.gcp.credentials
are used, else polaris.storage.gcp.token or the application default
credentials. The unnamed credentials and the token cannot be combined.

A name, or the unnamed credentials, can give the content of a credentials
file with credentials instead of credentials-file, for deployments that
pass secrets as environment variables.

Credentials from a file or a property are loaded on first use and kept,
since loading reads a file; a failed load is retried on the next use. A
failed file read keeps its cause for the server log. A parse failure still
does not, since parser messages can repeat the content.

The names token, lifespan and expiry are no longer reserved: SmallRye
keeps polaris.storage.gcp.token apart from
polaris.storage.gcp.token.credentials-file. The provider is no longer
created at startup, which only that check needed.
The GCS page lists where the server credentials come from, in order, and
shows passing the content of a credentials file from a Kubernetes secret.
It uses the Azure page's wording for environment variables and realms, and
says that names are case-sensitive. The changelog fragment adds the
unnamed properties and says that names apply to the whole deployment.
@sririshindra
sririshindra marked this pull request as draft November 28, 2026 01:59

This branch has not been deployed

No deployments
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.

Support Per-Catalog AWS Credentials in MinIO Deployments

4 participants