lasdf1234 commented on code in PR #14954:
URL: https://github.com/apache/gravitino/pull/14954#discussion_r4561083693


##########
core/src/main/java/org/apache/gravitino/catalog/FilesetOperationDispatcher.java:
##########
@@ -322,7 +323,7 @@ private Fileset alterFilesetWithPreparedSecrets(
     SecretMaterialsHolder writtenSecretMaterials = new SecretMaterialsHolder();
     boolean alterCommitted = false;
     try {
-      Pair<FilesetChange[], List<SecretMaterial>> secretResult =
+      Pair<FilesetChange[], PreparedSecrets> secretResult =

Review Comment:
   **Medium — drop the `0L` entity-id fallback for write-through secrets.**
   
   Write-through URNs embed a real Gravitino entity id 
(`…:<entityType>:<entityId>:<propertyKey>`), and ownership/GC 
(`isWriteThroughForEntity`) depend on it. Using `0L` when there is no 
`StringIdentifier` and no `FilesetEntity` / `SchemaEntity` is not a stored id — 
it is a sentinel. After a later import with a real id, ownership checks fail 
and alters can take the wrong path (e.g. foreign immediate `writeSecret` 
instead of versioned alter).
   
   This matters for **never-imported external** schema/fileset objects (present 
in the underlying catalog only; Gravitino has no entity row / string id yet).
   
   ### Product rule
   
   1. **No resolvable entity id → reject write-through:** `setSecretBinding`, 
and `setProperty` / `removeProperty` that touch an existing 
write-through-shaped URN. Also reject `setSecretReference` when it **replaces** 
an existing write-through URN (release/GC still needs a real id).
   2. **No resolvable entity id → allow** plain `setSecretReference` on a 
non–write-through key, and non-secret property changes. External refs do 
**not** need `entityId`.
   
   ### API: make `entityId` optional on the shared prepare/alter paths (no 
placeholder `0L`)
   
   Today `SecretAlterChanges.prepare{Catalog,Schema,Fileset}Changes(..., long 
entityId, ...)` always takes a `long`, which invites `else { id = 0L }`. Please 
change the methods that can serve **both** write-through and reference so 
`entityId` is optional, e.g. `OptionalLong` or `@Nullable Long`:
   
   - `prepareCatalogChanges` / `prepareSchemaChanges` / `prepareFilesetChanges`
   - `SecretManager.alterSetProperty` (only `orElseThrow` when the current 
value is this entity’s write-through URN)
   
   Write-through-only helpers can keep a required `long` once the id is 
resolved, e.g. `alterSetSecretBinding`, `buildSecretBindingUrns`, 
`prepareSecretVersions` when actually writing/releasing write-through material 
— call them only after `orElseThrow` with a clear message. 
`alterSetSecretReference` already takes no entity id; leave it that way.
   
   Do **not** keep `else { filesetId = 0L; }` / `else { entityIdForSecrets = 
0L; }` even “only for reference”.
   
   ### Please change both call sites
   
   - `FilesetOperationDispatcher.alterFilesetWithPreparedSecrets` (`filesetId = 
0L`)
   - `SchemaOperationDispatcher.alterExternalSchemaUnderLock` 
(`entityIdForSecrets = 0L`)
   
   ### Tests
   
   - No id + `setSecretBinding` → clear `IllegalArgumentException`, nothing 
written to the provider.
   - No id + `setSecretReference` on a fresh key → success.
   - No id + `setSecretReference` / `removeProperty` replacing an existing 
write-through URN → rejected (needs id).
   - With a real string id / entity id → behavior unchanged.
   



##########
core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java:
##########
@@ -539,7 +555,7 @@ private Pair<Schema, SchemaChange[]> 
alterExternalSchemaUnderLock(
     SecretMaterialsHolder writtenSecretMaterials = new SecretMaterialsHolder();
     boolean alterCommitted = false;
     try {
-      Pair<SchemaChange[], List<SecretMaterial>> secretResult =
+      Pair<SchemaChange[], PreparedSecrets> secretResult =

Review Comment:
   **Medium — drop the `0L` entity-id fallback for write-through secrets.**
   
   Write-through URNs embed a real Gravitino entity id 
(`…:<entityType>:<entityId>:<propertyKey>`), and ownership/GC 
(`isWriteThroughForEntity`) depend on it. Using `0L` when there is no 
`StringIdentifier` and no `FilesetEntity` / `SchemaEntity` is not a stored id — 
it is a sentinel. After a later import with a real id, ownership checks fail 
and alters can take the wrong path (e.g. foreign immediate `writeSecret` 
instead of versioned alter).
   
   This matters for **never-imported external** schema/fileset objects (present 
in the underlying catalog only; Gravitino has no entity row / string id yet).
   
   ### Product rule
   
   1. **No resolvable entity id → reject write-through:** `setSecretBinding`, 
and `setProperty` / `removeProperty` that touch an existing 
write-through-shaped URN. Also reject `setSecretReference` when it **replaces** 
an existing write-through URN (release/GC still needs a real id).
   2. **No resolvable entity id → allow** plain `setSecretReference` on a 
non–write-through key, and non-secret property changes. External refs do 
**not** need `entityId`.
   
   ### API: make `entityId` optional on the shared prepare/alter paths (no 
placeholder `0L`)
   
   Today `SecretAlterChanges.prepare{Catalog,Schema,Fileset}Changes(..., long 
entityId, ...)` always takes a `long`, which invites `else { id = 0L }`. Please 
change the methods that can serve **both** write-through and reference so 
`entityId` is optional, e.g. `OptionalLong` or `@Nullable Long`:
   
   - `prepareCatalogChanges` / `prepareSchemaChanges` / `prepareFilesetChanges`
   - `SecretManager.alterSetProperty` (only `orElseThrow` when the current 
value is this entity’s write-through URN)
   
   Write-through-only helpers can keep a required `long` once the id is 
resolved, e.g. `alterSetSecretBinding`, `buildSecretBindingUrns`, 
`prepareSecretVersions` when actually writing/releasing write-through material 
— call them only after `orElseThrow` with a clear message. 
`alterSetSecretReference` already takes no entity id; leave it that way.
   
   Do **not** keep `else { filesetId = 0L; }` / `else { entityIdForSecrets = 
0L; }` even “only for reference”.
   
   ### Please change both call sites
   
   - `FilesetOperationDispatcher.alterFilesetWithPreparedSecrets` (`filesetId = 
0L`)
   - `SchemaOperationDispatcher.alterExternalSchemaUnderLock` 
(`entityIdForSecrets = 0L`)
   
   ### Tests
   
   - No id + `setSecretBinding` → clear `IllegalArgumentException`, nothing 
written to the provider.
   - No id + `setSecretReference` on a fresh key → success.
   - No id + `setSecretReference` / `removeProperty` replacing an existing 
write-through URN → rejected (needs id).
   - With a real string id / entity id → behavior unchanged.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to