Repository navigation
feat(storage): inline polaris.storage.name overrides for namespace/table - #4023
sririshindra wants to merge 13 commits into
Conversation
|
This should definitely go behind a feature flag since there's currently no way to limit what a user can put in I hate to be adding to the feature flag proliferation in polaris, but maybe there should be a way to configure at what level override is allowed to happen. I can see an admin wanting to allow override on namespace level, but not on table level since |
Thanks for the review, @tokoko! I'll go ahead and put this behind a feature flag. I intentionally kept authorization out of scope for this phase, but we can definitely address integrating |
8cdf152 to
7e84dce
Compare
| } | ||
|
|
||
| @Test | ||
| void serializationRoundTrip() { |
There was a problem hiding this comment.
what is this test trying to test? That an overriden PolarisStorageConfigurationInfo can be serialized/deserialized? Is there any custom logic that puts this into doubt?
There was a problem hiding this comment.
You're right. The intent was to verify that a config produced by withStorageName() survives serialize() → deserialize() since these objects use Jackson's @JsonTypeInfo/@JsonSubTypes for polymorphic deserialization. But in practice, builder().from() produces the same concrete type, so Jackson will always serialize/deserialize it correctly. Looks like awsFieldsPreserved test already covers field preservation. Happy to remove the round-trip test if you think it's redundant.
There was a problem hiding this comment.
Yes, I think we should remove the test IMO. I'm all for adding tests but this one looks like we're basically just testing the Jackson library.
There was a problem hiding this comment.
Thanks, agreed. I removed the serializationRoundTrip test.
| * @param value the input value | ||
| * @return {@code null} if the input is null, empty, or blank; otherwise the trimmed value | ||
| */ | ||
| public static @Nullable String normalizeBlankToNull(@Nullable String value) { |
There was a problem hiding this comment.
Is there a reason this shouldn't be called from within validate?
There was a problem hiding this comment.
They serve different purposes: validate() is a pure check, while normalizeBlankToNull() is a transformation. Combining them would make validate() impure — callers wouldn't expect a validation method to also mutate/transform the input. That said, I could rename normalizeBlankToNull to something clearer like toNullIfBlank or inline it at the call sites if you'd prefer. Open to suggestions.
There was a problem hiding this comment.
I understand your point but given that this function is always only called right before validate, maybe there's a way to combine both the functions to reduce the total amount of functions and reduce caller code as well.
There was a problem hiding this comment.
I combined normalization and validation into a single helper, normalizeAndValidate, and updated all call sites to use it.
dimas-b
left a comment
There was a problem hiding this comment.
Hi @sririshindra , thanks for the PR, but I'm a bit confused by the new code... specific comments below. Sorry, if I missed something obvious 😅
| new NamespaceEntity( | ||
| new PolarisEntity.Builder(nsBuilder.build()) | ||
| .addInternalProperty( | ||
| PolarisEntityConstants.getStorageConfigInfoPropertyName(), | ||
| namespaceStorageConfig.serialize()) |
There was a problem hiding this comment.
Why embed a copy of the config into the entity here?
Based on previous dev discussion (link below) my impression is that we'd want to keep (named) storage configs at the catalog level for ease of management.
I'd expect entities to only reference storage config by name, and the config resolution to happen when requested 🤔
There was a problem hiding this comment.
Agreed — this is fixed in the latest revision. Entities now store only a lightweight storage_name_override string reference, not a full config copy. The full config resolution happens on-demand at access time.
| StorageNameValidator.validate(storageName); | ||
| } | ||
|
|
||
| PolarisStorageConfigurationInfo baseConfig = deserializeStorageConfigFromEntityPath(parentPath); |
There was a problem hiding this comment.
This config is loaded regardless on the "name", so I'm not sure what the purpose of adding POLARIS_STORAGE_NAME_PROPERTY to the entity properties might be 🤔
There was a problem hiding this comment.
In the updated implementation, polaris.storage.name is the user-facing API property that gets translated into an internal storage_name_override reference. At resolution time, StorageConfigResolver finds the nearest override in the hierarchy and applies it to the catalog's base config via withStorageName(). The purpose is to allow different namespaces/tables to use different named storage configurations while the actual configs remain managed centrally at the catalog level. The property is no longer redundant — it's the mechanism by which users select which storage configuration to use.
ba4748e to
095e0ac
Compare
| long currentParentId = entity.getParentId(); | ||
| while (currentParentId != PolarisEntityConstants.getNullId() && currentParentId != catalogId) { | ||
| EntityResult parentResult = | ||
| loadEntity(callCtx, catalogId, currentParentId, PolarisEntityType.NAMESPACE); |
There was a problem hiding this comment.
I'm not sure about this loop, TBH... So far the usual workflow for requests was to use the Resolver to find all relevant entities based on API parameters upfront, then proceed with request execution.
So, normally, all the parents up to the catalog should already be loaded by the time StorageAccessConfig is required. Could we reuse existing data from the resolution manifest.
There was a problem hiding this comment.
I think this PR would no longer have to solve this dual resolution issue after #3699 since everything happens in StorageAccessConfigProvider there. honestly this feels like we're putting bandaids on bandaids 😄 ideally we should have a single place (StorageAccessConfigProvider most likely) that would resolve storageInfo, resolve storage name, get additional properties from config per storage name and return effective storage configuration. I don't think that's possible to do now w/o first getting rid of all these unnecessary layers.
There was a problem hiding this comment.
From my POV, I'd prefer to merge #3699 first, then rebase this PR.
@sririshindra : WDYT?
flyingImer
left a comment
There was a problem hiding this comment.
Thanks, the newer override-resolution tests are useful.
I still think there is one high-priority correctness issue worth fixing before this moves forward.
IIUC doCommit() still resolves commit-time storage access from the pre-override hierarchy, and only later materializes polaris.storage.name into the table state. If so, the post-commit state may look correct while the first metadata write already used the previous credentials.
That feels like the key invariant here: the effective storage for the write path should be resolved before the commit-time metadata write happens, not only after the override has been persisted.
I’d be much more comfortable if we either move that resolution earlier in the flow, or add explicit coverage proving the first create/update write already uses the overridden credentials.
@flyrain WDYT?
adnanhemani
left a comment
There was a problem hiding this comment.
@flyingImer's pointing out of the "cold start" issue is a known issue with approaching this feature unfortunately (we discussed it at the last Polaris Community Sprint).
I think we are ok with saying that the credential can only be used once the table is pre-created. But @sririshindra - can you explicitly list (within this PR) the set of operations in which users can do this to avail this feature?
| } | ||
|
|
||
| @Test | ||
| void serializationRoundTrip() { |
There was a problem hiding this comment.
Yes, I think we should remove the test IMO. I'm all for adding tests but this one looks like we're basically just testing the Jackson library.
| * @param value the input value | ||
| * @return {@code null} if the input is null, empty, or blank; otherwise the trimmed value | ||
| */ | ||
| public static @Nullable String normalizeBlankToNull(@Nullable String value) { |
There was a problem hiding this comment.
I understand your point but given that this function is always only called right before validate, maybe there's a way to combine both the functions to reduce the total amount of functions and reduce caller code as well.
095e0ac to
c015b8c
Compare
|
This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
c015b8c to
eae0266
Compare
Trim, blank-to-null normalization, length cap (128), and a [a-zA-Z0-9_-]+ character allowlist for the user-facing polaris.storage.name property. Pure utility; no callers wired yet.
Static helper on PolarisStorageConfigurationInfo that returns a copy of the given config with only its storageName replaced. Dispatches across all four subtypes (Aws/Azure/Gcp/File) via their Immutables builders so the override flows transparently into the per-backend cache key (AwsStorageCredentialCacheKey etc. include storageConfig in equality).
Internal-properties key for the persisted name reference set by entity writes that include polaris.storage.name. Resolution happens at access time leaf-to-root, so namespaces and tables hold only this string, not a copy of the full storage config.
Gates write-path acceptance of polaris.storage.name on namespaces and tables. Default false. The flag does not gate read-path resolution: any override already persisted is honored regardless, so disabling the flag later does not silently change vended credentials. End-to-end named- credential routing still requires RESOLVE_CREDENTIALS_BY_STORAGE_NAME.
The polaris. prefix is reserved, so polaris.storage.name would otherwise be filtered out of namespace and table property updates before IcebergCatalog gets a chance to validate, gate, and persist it as the storage_name_override internal property.
Pure data resolver that walks an entity hierarchy leaf-to-root, captures the nearest storage_name_override, finds the catalog's base storage_configuration_info, and applies withStorageName when an override is present. Returns empty if no base config exists, regardless of any overrides higher in the chain. Used by the credential-vending and FileIO paths to share one resolution algorithm.
Replace the findStorageInfoFromHierarchy + extractStorageConfiguration chain in getStorageIntegration() with StorageConfigOverrideResolver, which performs the same base-config lookup and additionally applies any nearest storage_name_override via withStorageName before the integration is constructed. The bound storageConfig on the resulting CachingStorageIntegration carries the effective storageName, so the existing AWS factory's RESOLVE_CREDENTIALS_BY_STORAGE_NAME-gated lookup and the per-backend cache keys (which include storageConfig in equality) both pick it up automatically.
…okup FileIOUtil.findStorageInfoFromHierarchy now returns a synthetic copy of the catalog entity whose storage_configuration_info reflects any nearest storage_name_override on the path, so callers (e.g., dropTable purge tasks) that read internal_properties off the returned entity see the effective config — matching the override semantics that flow through StorageAccessConfigProvider/PolarisStorageIntegrationProvider for live credential vending.
…ergCatalog Validate, gate via ALLOW_STORAGE_NAME_OVERRIDE, and translate the user- facing polaris.storage.name property into the internal storage_name_override key on entity internalProperties. Wired at four sites: * createNamespace * setProperties (namespace) * removeProperties (namespace) * doCommit + overwriteRegisteredTable (table commit / cold start) The flag is enforced only when the requested value would change the persisted override; idempotent re-sets pass through with the flag off so operators can safely disable the flag after entities already have overrides set. A blank or whitespace value clears the override. For cold-start createTable, the FileIO that writes the FIRST metadata file is built from the parent namespace/catalog (the table entity does not exist yet), so a table-level override only takes effect from the second commit forward. A namespace-level override on the parent works for the cold-start write because resolvedStorageEntity is the namespace.
Prove that two override paths with different polaris.storage.name values through PolarisStorageIntegrationProvider produce non-equal bound storage configs, which (via AwsStorageCredentialCacheKey's storageConfig value field) guarantees distinct cache entries.
…Namespace The previous createNamespaceInternal hunk built a fresh internalProperties map with only the storage-name override and passed it to setInternalProperties, which wholesale-replaced the map and wiped the parent-namespace key that NamespaceEntity.Builder(Namespace) sets in its constructor. This broke loadNamespaceMetadata for any namespace at depth >= 2 (35 test failures across IcebergCatalogHandlerAuthzTest, IcebergCatalogHandlerNoSqlAuthzTest, RestCatalogFileIntegrationTest). Use addInternalProperty per entry instead, so the override key is added incrementally and the parent-namespace internal key is preserved. Tables were unaffected because IcebergTableLikeEntity.Builder.setInternalProperties defensively carries forward the parent-namespace, metadata-location, and last-admitted-notification-timestamp keys; NamespaceEntity.Builder has no such guard.
eae0266 to
e908263
Compare
dimas-b
left a comment
There was a problem hiding this comment.
Thanks for resuming this PR, @sririshindra !
| PolarisConfiguration.<Boolean>builder() | ||
| .key("ALLOW_STORAGE_NAME_OVERRIDE") | ||
| .description( | ||
| "If set to true, allows namespaces and tables to set the polaris.storage.name " |
There was a problem hiding this comment.
What is the value of this flag? If a user points to a non-existent storage name, the adverse effect is localized to that user's change.
Adding storage names is a Catalog Management action and should probably be covered by AuthZ checks.
I'd think setting/changing polaris.storage.name probably needs an new AuthZ operation rather than a global feature flag.
WDYT?
| if (!userProperties.containsKey(POLARIS_STORAGE_NAME_PROPERTY)) { | ||
| return; | ||
| } | ||
| String rawValue = userProperties.remove(POLARIS_STORAGE_NAME_PROPERTY); |
There was a problem hiding this comment.
Modifying parameters is not intuitive... Can we avoid this?
| try { | ||
| requested = StorageNameValidator.normalizeAndValidate(rawValue); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new BadRequestException( |
There was a problem hiding this comment.
IllegalArgumentException should automatically result in a 400 response at the REST API layer... Why do we need BadRequestException here?
| void processStorageNameOverrideOnWrite( | ||
| Map<String, String> userProperties, | ||
| Map<String, String> internalProperties, | ||
| @Nullable String priorOverride) { |
There was a problem hiding this comment.
Is priorOverride actually an "override"? What does it override? 🤔
| if (requested == null) { | ||
| internalProperties.remove(storageOverrideKey); | ||
| } else { | ||
| internalProperties.put(storageOverrideKey, requested); |
There was a problem hiding this comment.
This logic effectively make the table metadata control the storage name value on the server side. I'm not sure it is ideal.
Ultimately, the catalog owns storage configuration. Why should table metadata have precedence over catalog-side settings?
I'd imagine Polaris CLI being the tool for setting storage name 🤔
Perhaps we need to dive deeper into this on the dev ML 🤔
| @NonNull List<? extends PolarisEntity> entityPath) { | ||
| String override = null; | ||
| for (int i = entityPath.size() - 1; i >= 0; i--) { | ||
| Map<String, String> internalProps = entityPath.get(i).getInternalPropertiesAsMap(); |
There was a problem hiding this comment.
nit: we assume indexed access is efficient here... WDYT about List.reversed()?
| PolarisStorageConfigurationInfo base = | ||
| PolarisStorageConfigurationInfo.deserialize(serializedBase); | ||
| if (override != null) { | ||
| return Optional.of(PolarisStorageConfigurationInfo.withStorageName(base, override)); |
There was a problem hiding this comment.
I'm not sure I understand the purpose of reusing the same config with a different name in different sub-trees 🤔 How do you envision this to be used?
My impression from the ML discussion is that the idea was to define multiple distinct Storage Configurations at the Catalog level and let entities choose one of them by name 🤔
There was a problem hiding this comment.
I think you might be misreading this (or maybe I am). storage names are set effectively from server configuration similar to how they are handled after #3409. changing storage name of a config from table/namespace metadata simply changes the pointer to the predefined storages that are part of server config.
P.S. I also agree the entire approach isn't exactly ideal, but my understanding of the devlist consensus was also how it's implemented in the PR.
There was a problem hiding this comment.
I'd expect different storage names to be associated with different PolarisStorageConfigurationInfo objects (semantically). The storage name would act as a user-level identifier for a specific PolarisStorageConfigurationInfo piece of data.
Simply updating the name in a PolarisStorageConfigurationInfo in runtime looks odd to me 🤔
There was a problem hiding this comment.
I remember that introducing a separate crud resource for storages was rejected, but iiuc what you're talking about is allowing multiple PolarisStorageConfigurationInfo to be defined on catalog level and then tables/namespaces would be able to choose between them, is that right? I suppose that's a reasonably clean approach.
One thing to note... storagaName field from #3409 is more of a pointer atm rather than a unique name designation for a specific PolarisStorageConfigurationInfo. I suppose it can be both, but it might be a little awkward: for example what if two catalogs define a storage config with same names, but want to resolve different credentials from the server config. I guess it shouldn't be a problem as long as it's well-documented.
There was a problem hiding this comment.
I guess the whole idea for multiple storage configs/names is applicable only to self-managed deployments. So the admin should be able to sort out name overlaps there.
I'm not sure how this idea can fit in SaaS deployments, TBH 🤔
There was a problem hiding this comment.
Exactly, I don't think it's a good idea to let users define the storage profile name on a namespace or table in a managed environment.
I remember that introducing a separate crud resource for storages was rejected
You mean for storage profile names or for PolarisStorageConfigurationInfo? I think we need to settle on this topic; I am leaning more towards the idea of leveraging the management API. That's the direction suggested in this design doc by @sririshindra.
There was a problem hiding this comment.
Heads up: this PR is on the agenda for the Community Sync call today 😉
| import org.apache.polaris.core.storage.gcp.GcpStorageConfigurationInfo; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class WithStorageNameTest { |
There was a problem hiding this comment.
This test class name is a bit confusing IMHO 🤔 Why not add the new test cases to PolarisStorageConfigurationInfoTest?
| .containsKey(PolarisEntityConstants.getStorageConfigInfoPropertyName())) | ||
| .findFirst(); | ||
| return storageInfoEntity; | ||
| if (baseEntity.isEmpty()) { |
There was a problem hiding this comment.
Why repeat the search already performed by StorageConfigOverrideResolver.resolveEffectiveConfig()? Can we be sure the outcome is / will be the same?
Why not have StorageConfigOverrideResolver return a tuple of all the data we need here?
There was a problem hiding this comment.
+1, there is some overlap between this class and StorageConfigOverrideResolver.
| * @return an {@link Optional} containing the (possibly synthetic) entity with the effective | ||
| * storage config, or empty if no entity in the chain has a base storage config |
There was a problem hiding this comment.
Callers of this method only need to know the presence of this entity and if present, its properties... Why bother with synthetic entities? I'd propose to refactor this code to return an Optional<some properties class>... WDYT?
adutra
left a comment
There was a problem hiding this comment.
Thanks @sririshindra for this PR.
I must say, I have some reservations regarding the mechanism this PR introduces for passing properties back and forth between user and internal spaces. I am concerned that this approach might set a problematic precedent for future implementations.
Was this topic already discussed? My apologies if it was; I am currently catching up on a significant backlog of PR reviews. 😓
While the PR description suggests this method is better than creating new management API endpoints, I am questioning if dedicated endpoints wouldn't actually be a superior solution for configuring items like storage profile names.
As I mentioned in a separate comment, allowing users to specify which storage profile to use leads to a "split-brain" scenario where Polaris admins define the profiles, but the profile selection responsibility falls to the users.
Furthermore, although this PR addresses storage profile selection, I am unclear on how we intend to handle the application of a full PolarisStorageConfigurationInfo at the table or namespace level. Relying on additional user properties for such use cases does not seem like a scalable strategy.
Apologies if I'm off track here.
| * | ||
| * @throws IllegalArgumentException if {@code base} is not one of the four supported subtypes | ||
| */ | ||
| public static PolarisStorageConfigurationInfo withStorageName( |
There was a problem hiding this comment.
Conceptually, this should be an abstract instance method:
public abstract PolarisStorageConfigurationInfo withStorageName(@Nullable String storageName);Each subclass would implement accordingly.
Then callers would do:
PolarisStorageConfigurationInfo base = ...
return base.withStorageName("some-storage");| * Trim, validate, and normalize a candidate storage name. | ||
| * | ||
| * @param value raw user input | ||
| * @return the trimmed name if valid, or {@code null} if the input is blank |
There was a problem hiding this comment.
What do we mean by "normalize"? I think it could be counter-intuitive if Polaris changed a user-supplied identifier without notifying the user about the change, even if it's just trimming spaces.
| * storage profile to use for credential vending. Validated and translated into the internal | ||
| * property {@link PolarisEntityConstants#getStorageNameOverridePropertyName()}. | ||
| */ | ||
| static final String POLARIS_STORAGE_NAME_PROPERTY = "polaris.storage.name"; |
There was a problem hiding this comment.
Just thinking out loud: if I get this correctly, we would be tying a namespace or table property to a storage profile that must be declared in the server configuration. IOW, the namespace or table in question becomes unusable if the catalog configuration changes and does not contain the profile anymore. Probably OK, but this requires some coordination between two personas: the user that created the table, and the admin that manages the server configuration.
| .containsKey(PolarisEntityConstants.getStorageConfigInfoPropertyName())) | ||
| .findFirst(); | ||
| return storageInfoEntity; | ||
| if (baseEntity.isEmpty()) { |
There was a problem hiding this comment.
+1, there is some overlap between this class and StorageConfigOverrideResolver.
flyingImer
left a comment
There was a problem hiding this comment.
Hi @sririshindra, catching up on this one: IIUC the direction after the dev-list discussion was to keep #4023 on hold until the catalog-level multiple-storage-config work lands, then rebase this on top of that.
Is that still the plan for this PR, or are you planning to continue moving the current approach forward independently?
If the former, I'm happy to hold off on further review here and take another pass once it's rebased.
HI @flyingImer , Sorry I didn't see your message earlier. |
Summary
This PR adds inline storage-name overrides for namespaces and tables using the polaris.storage.name property, so credential vending can select named credentials per entity without introducing new management APIs.
It also refactors hierarchy lookup logic to remove duplication and adds focused test coverage for override behavior and credential vending.
Why this change is needed
Today, catalog-level storage credentials are often too coarse for multi-tenant or team-isolated workloads. This change enables namespace/table-scoped credential selection by storing an inline override and resolving it through the existing hierarchy at runtime.
What changed
Behavioral notes
Testing
Reviewer notes
Checklist