Repository navigation
Support storage-scoped GCP credentials - #5951
sririshindra wants to merge 10 commits into
Conversation
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.
|
I'll wait for #5952 then review this PR 😅 |
orca-review-bot
left a comment
There was a problem hiding this comment.
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:checkand:polaris-runtime-service:checkpass 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 |
There was a problem hiding this comment.
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.
| return ExternalAccountCredentials.fromStream(stream); | ||
| } | ||
| } catch (IOException | RuntimeException e) { | ||
| // Only the failure type is reported: parser and library messages can repeat file content. |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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 |
| * {@code expiry} are reserved: configuring one of them stops the server from starting. | ||
| */ | ||
| @WithName("credentials-file") | ||
| Path credentialsFile(); |
There was a problem hiding this comment.
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 🤔 )?
|
dev discussion for community awareness: https://lists.apache.org/thread/42hgrj6oz0xhvhqvjo8jjgp2m08d0kts |
| * provider chain will be used. | ||
| */ | ||
| @WithName("gcp.token") | ||
| Optional<String> gcpAccessToken(); |
There was a problem hiding this comment.
Two questions:
- Why not have an "unnamed"
credentialsFile()method, so that we provide the same resolution mechanism for named and unnamed configs? - 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"); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
|
Heads-up: #5967 has been merged, so Could you rebase onto |
…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.
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_NAMEenabled, a GCS storage configuration'sstorageNamenow selects the credentials set bypolaris.storage.gcp.<storage>.credentials-file, or bypolaris.storage.gcp.<storage>.credentialswith the content of the file itself, which is easier to pass from an environment variable or a Kubernetes secret:The credentials have the format
GOOGLE_APPLICATION_CREDENTIALSpoints 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-fileandpolaris.storage.gcp.credentials, like the unnamed Azure properties from #5952. The server credentials of a storage are then, in order:storageName: that name's credentials, with no fallback;credentials-fileorcredentials;polaris.storage.gcp.token;The selection lives in
GcpCredentialsFactory, an application-scoped bean shaped likeAzureCredentialsFactory, andStorageConfigurationonly 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 itsstorageName. Nothing changes for a deployment that sets none of the new properties and doesn't setstorageNameor leaves the flag off.Behavior to review:
storageName, on a deployment with the flag enabled, now fails instead of ignoring the name. The changelog fragment has an upgrade note.storageNameis refused whileGCS_PRINCIPAL_ATTRIBUTION_ENABLEDis true, with a 500 like the other attribution misconfigurations. When the storage has agcsServiceAccountand 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.polaris.storage.gcp.tokencan'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.polaris.storage.gcp.tokenor the application default credentials) are still built once per server, as before.token,lifespanorexpiryare ordinary names: SmallRye keepspolaris.storage.gcp.tokenapart frompolaris.storage.gcp.token.credentials-file, and a test covers it.polaris.storage.gcp.tokenisn'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
storageNameselecting 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 andtoString.:polaris-core:checkand:polaris-runtime-service:checkpass 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:
GCS_PRINCIPAL_ATTRIBUTION_ENABLEDreturns 500 with the documented message.gcsServiceAccountset, the named credentials impersonate that service account.I haven't repeated that run for the latest changes yet.
Checklist
changelog.d/(if needed, seechangelog.d/README.md)site/content/in-dev/unreleased(if needed)CONTRIBUTING.md)