Repository navigation
[Server] Widen storage path columns - #2234
Conversation
A catalog or schema storage root, a volume storage location or a model version source longer than 255 characters failed with a 500, while table locations allow 2048. Widen uc_catalogs.storage_root and storage_location, uc_schemas.storage_root and storage_location, uc_volumes.storage_location and uc_model_versions.source to varchar(2048) with one step per column for H2, MySQL and PostgreSQL. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
Added the storage root checks for the catalog and schema in e524606. Values over 2048 characters and widening uc_external_locations.url are left for follow-ups, as the description explains. |
…columns Signed-off-by: Maha Rana Yadavalli <[email protected]> # Conflicts: # server/src/main/resources/schema-effects/h2/V3.txt # server/src/main/resources/schema-effects/mysql/V3.txt # server/src/main/resources/schema-effects/postgresql/V3.txt
… steps don't break it Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
|
[AI Assisted] This PR needs a rebase onto main. Main's latest step is now V4 ( #2187 uses the same V4 to V9 numbers. Whichever of the two merges second must renumber above the first, because |
Main added step V4 (credentials stored as text), so this branch's steps move from V4..V9 to V5..V10 on H2, MySQL and PostgreSQL, with their effect files. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
**PR Checklist** - [x] 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. - [x] 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 (not needed, bug fix only) **Description of changes** Creating a function with a long parameter type fails with a 500: ``` POST /api/2.1/unity-catalog/functions (a parameter with a 352 character STRUCT type_text) 500 INTERNAL ... Value too long for column "TYPE_TEXT CHARACTER VARYING(255)" ``` The same happens for a long `full_data_type`, a parameter comment over 255 characters, or a long parameter default. The unitycatalog-ai client sends each docstring argument description as the parameter comment, so a function with a detailed docstring can't be registered. Table columns don't have this problem because `uc_columns` stores `type_text` as a large text column and `comment` in 65535 characters. #2013 fixed the same thing for `uc_function_params.type_json`. This PR widens the remaining columns the same way, with one single-statement step per column for H2, MySQL and PostgreSQL, each with its own effect file: - V5 `uc_function_params.type_text` and V6 `uc_functions.full_data_type` use the width of `uc_columns.type_text` (16777215, so CLOB, mediumtext or text) - V7 `uc_function_params.comment`, V8 `parameter_default` and V9 `uc_schemas.comment` use 65536, `mediumtext` on MySQL. A long schema comment failed with the same 500 while a table comment of the same length worked - V10 `uc_volumes.comment` uses 65536, the volume comment's `maxLength` in `api/all.yaml`, so every comment the API accepts fits. On MySQL that is `mediumtext`, which also holds 65536 multi-byte characters, since MySQL counts `text` in bytes MySQL counts `text` in bytes, so 65535 there holds fewer characters when they are multi-byte, while H2 and PostgreSQL count characters. All four widened comment and default columns are therefore 65536 on H2 and PostgreSQL and `mediumtext` on MySQL, which holds 65536 multi-byte characters. Hibernate maps a length above 65535 to `mediumtext` on MySQL, so the entities use 65536 and `BaselineMatchesEntitiesTest` agrees on all three databases. The existing table, column and model comments are still `text` on MySQL, which is a separate change. Each step only changes a column type. On H2 the steps use the plain `ALTER COLUMN c <type>` form, which keeps the NOT NULL on `type_text` (the effect file shows `nullable=NO` before and after), so no step says NOT NULL on H2 or PostgreSQL. The `comment` columns are quoted because JSqlParser, which the step rules in #2113 use, reads COMMENT as a keyword and can't parse the unquoted statement. Catalog, credential and external location comments are still 255 and can follow in a separate PR. **Testing** `SdkFunctionCRUDTest.testFunctionWithLongTypesAndComments` creates a function with a long STRUCT parameter type, a long return parameter type, a long return type, and distinct long parameter comment and default values, and reads them back. `BaseSchemaCRUDTest` and `BaseVolumeCRUDTest` now update the comment to a 300 character one and read it back. `BaseVolumeCRUDTest` and `BaseSchemaCRUDTest` then update the comment to 65536 `é` characters, over 65535 bytes in UTF-8, and read it back, and `SdkFunctionCRUDTest` now uses 65536 `é` characters for the parameter comment and 65536 `ü` characters for the default. With the volume or schema column left at 65535 the update fails with a 500 on H2. The MySQL and PostgreSQL runs in CI cover the multi-byte case there. These fail with the 500 before the fix and pass after it on H2. `MigrationStepRulesTest`, `BaselineMatchesEntitiesTest` and `SchemaMigratorTest` pass on H2. I also ran the `MigrationStepRulesTest` from #2113 against these steps with `UC_TEST_MIGRATION_CHECKS=true`, and all 11 tests pass on H2, including `eachStepIsOneAllowedStatement` and `typeChangesWiden`. I wrote the MySQL and PostgreSQL effect files by hand from the existing ones because I couldn't run Docker locally, so the upgrade tests in CI check those. Main is merged in. It added steps V3 and V4, so these steps are now V5 to V10. #2234 also adds V5 to V10, so whichever of the two merges second gets renumbered above the other. --------- Signed-off-by: Maha Rana Yadavalli <[email protected]> Co-authored-by: Maha Rana Yadavalli <[email protected]>
Main added steps V5..V10 (unitycatalog#2187), so this branch's steps move from V5..V10 to V11..V16 on H2, MySQL and PostgreSQL, with their effect files. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
…rflow A catalog or schema storage root can now be up to 2048 characters, but managed volume, table and staging table locations append the managed storage prefix and two ids to it. A 1970-character catalog root was stored, and then creating a managed volume or staging table under it failed at the database with a 2076 or 2075-character value. Catalog and schema creation now reject a root whose longest managed child location, a volume, would exceed 2048 characters, so the limit is 1942 characters for a catalog root and 1943 for a schema root. The column length is shared through Constants.MAX_STORAGE_LOCATION_LENGTH. Signed-off-by: Maha Rana Yadavalli <[email protected]>
…icitly Catalog and schema creation now call ExternalLocationUtils.validateManagedLocationsFit next to the managed prefix check, instead of the location builders validating as a side effect. The longest managed location is counted in UTF-8 bytes, so a root with multi-byte characters also keeps the indexed staging table location within PostgreSQL's index entry limit. ASCII roots keep the same 1942 and 1943 character limits. Model version source uses the shared column length constant too. Signed-off-by: Maha Rana Yadavalli <[email protected]>
…entials GcpCredentialVendor limits the access boundary condition to 2048 characters, and the condition repeats the object path four times. With the wider columns a gs:// root of a few hundred characters was accepted while credentials for managed tables and volumes under it could never be vended. The root check now builds the same condition for those managed locations and rejects the root if it is too long. Signed-off-by: Maha Rana Yadavalli <[email protected]>
…limits The root check only covered the columns and the GCS condition of managed tables and volumes. A new StorageLocationValidator now checks every location the server accepts or derives: catalog and schema roots with all managed locations under them (tables, volumes, registered models and model versions), external volumes, external tables, external location URLs, managed staging tables, volumes, models and versions, including those under the server's storage-root fallback, and model version sources. Each location must fit its column in UTF-8 bytes, and the cloud limits that apply when it is used, computed the same way the credential vendors build credentials, without calling the cloud: - AWS S3 (an aws_iam_role credential, or a per-bucket config without an STS endpoint or custom generator): the 1,024 byte object key limit, and the 2,048 character STS session policy limit for a vend that assumes a role. - GCS: the 2,048 character access boundary condition. - Azure: the 1,024 character blob name limit and 63 path segments. S3-compatible storage is not checked, since its limits differ between stores. A vend whose AWS session policy is too long now fails with INVALID_ARGUMENT before calling STS, instead of a 500 from STS. Signed-off-by: Maha Rana Yadavalli <[email protected]>
Pin that S3-compatible STS vends a policy over AWS's limit, that S3 buckets with a custom generator or no configuration and GCS locations with a storage credential aren't checked, and that a failing lookup leaves Azure's limits checked. Drop the cloud storage root skip, since a root can't exceed a limit. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
@shba24 thanks for the detailed review. I've replied to every thread and resolved them. The fixes are in 99fa801 and d482020 for the root limits, 772e17c and a15b382 for the cloud limits and model versions, 74dc554 for units and GCS and Azure details, 00a755d for database-aware counting and call-site tests, 1512d1f for read-only policies and credential changes, and 074944f for tests on every skip. I also merged main, so CI is running again on 7f24d33. |
| import java.util.UUID; | ||
| import java.util.function.Supplier; | ||
| import java.util.stream.Stream; | ||
| import org.hibernate.Session; |
There was a problem hiding this comment.
Nit (not a blocker): Validator in the credential package depends on the Hibernate Session
StorageLocationValidator lives in service.credential, but its public methods take an org.hibernate.Session, for example validateLocation(Session, NormalizedURL, int). Only persist repositories call it, from inside their transactions. It is the only class in the package that imports org.hibernate, so the vending package now depends on the persistence layer's transaction type. Nothing is broken today; this is only about where the class lives.
For example: TableRepository.createTable passes its transaction session into validateLocation. Moving the validation next to the persistence code, or passing a resolved credential in, would remove the import.
Optionally move the class to persist/ or persist/utils, or pass in the resolved credential instead of the Session. Since this is a refactor with no behavior change, it fits a separate PR.
Would you prefer to keep it here for now and move it in a follow-up?
There was a problem hiding this comment.
Moved it in this PR rather than a follow-up, since it was a small change. In 4445cf0 the validator and its test are in persist.utils next to the repositories that call it, and service.credential no longer imports Hibernate. The vendors' limitViolation and StorageLimits stay in service.credential.
| public static Optional<String> objectNameViolation( | ||
| List<NormalizedURL> locations, String kind, Unit unit) { | ||
| return locations.stream() | ||
| .mapToInt(location -> unit.length(objectName(location)) + 2) |
There was a problem hiding this comment.
Blocker: Two-character child allowance rejects an external location that names a single object
The length check adds 2 to the UTF-8 key length of every location, so it always leaves room for a child object. For an external table or volume that points at one file, no child is ever written, so the allowance can reject a key that S3 accepts. The check also runs for static session-token credentials, where the exemption only skips the STS role or policy check and not the object-key check. Both reviewers agree the mechanism is real. They disagree on severity because only keys of 1023 or 1024 bytes are affected. Nobody has run a test for it, so this stays unsettled.
For example: Register an external CSV table at s3://bucket/<1020 ASCII 'a' characters>.csv with static S3 session credentials configured. The key is 1024 bytes and valid, but the check counts 1026 and the request fails with INVALID_ARGUMENT.
Write the failing test first: an external CSV table at that path with a static session-token per-bucket config, through SdkManagedLocationTest or StorageLocationValidatorTest. If it fails, have the check tell a location that names a single object apart from a prefix that must hold children, and apply the +2 allowance only to the prefix case. Managed locations the server builds and writes under should keep the allowance.
Could we add that test first to confirm whether a 1020-character .csv key is really rejected?
There was a problem hiding this comment.
Confirmed and fixed in 4445cf0. A location given in a request may now name a single object, so it only has to be a valid object name itself. Managed locations keep the allowance, since the server writes under them. testRequestLocationMayNameASingleS3Object uses your example on a static session-token bucket. The 1,024 byte .csv key is accepted, 1,025 bytes is rejected, and the same location as a managed one is still rejected. testRequestLocationMayNameASingleAzureBlob does the same for 1,024 characters and 254 segments. Giving request locations the allowance again, or taking it away from managed ones, fails these tests.
…alidator to persist A location given in a request, such as an external table that is one file, only has to be a valid object name itself, so a 1,024 byte S3 key is no longer rejected. Managed locations, which the server writes under, keep the allowance for an object under them. The validator takes a Hibernate Session, so it moves to persist.utils next to its callers. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
| * The most path segments a blob name can have. A hierarchical namespace account allows fewer, 63 | ||
| * counting the account and container, but whether an account has one isn't known from its URL. | ||
| */ | ||
| public static final int MAX_AZURE_PATH_SEGMENTS = 254; |
There was a problem hiding this comment.
Blocker: Azure locations are checked against the flat-namespace segment limit, so a hierarchical-namespace account accepts locations that cannot be used
The comment at lines 25-29 says hierarchical-namespace accounts allow 63 segments, counting the account and container. azurePathSegmentViolation then always compares against 254, because the URL does not show whether an account has a hierarchical namespace. This PR widens the columns to 2,048, so roots of this length can now be stored. Before it, the 255-character storage_root column rejected them. The same gap applies to every caller of the Azure check: catalog and schema roots, managed volume, staging table, registered model and model version, external table and volume, and external location create and update. It applies to both abfs:// and abfss://.
For example: On an ADLS Gen2 account with a hierarchical namespace, create a catalog with storage_root abfss://[email protected]/ followed by 60 'abcd' segments. It passes at 246 allowed root segments (testAzurePathSegmentsAreLimited). The generated catalog location adds 3 segments, which goes over 63, so its managed storage cannot be used. This rests on Azure's documented limit as restated in the code comment. It could not be tested without a real account.
The server has no input that says whether an account has a hierarchical namespace, so a full fix needs one, for example a credential property or a config setting, or an account lookup. Applying 63 to every abfss location would wrongly reject valid paths on flat-namespace accounts. At the least, state the limitation in the PR description and the docs.
Would you prefer to add a namespace setting on the Azure credential, or to document the limit for now?
There was a problem hiding this comment.
I'd like to document it for now. A namespace setting on server.properties would not cover storage credentials, so it needs its own design. In 834ea7d a new Storage location limits section in docs/server/configuration.md explains the 63 segment limit and that the server can't check it. It also says how many segments managed locations add, 5 for a managed table and 7 for a model version under a catalog or schema root. The PR description and the constant's comment say the same. I'm happy to open an issue for the setting if you'd like it tracked.
| ExternalLocationUtils.validateNotOverlapWithManagedStorage(session, storageLocation); | ||
| repositories | ||
| .getStorageLocationValidator() | ||
| .validateLocation(session, storageLocation, Constants.MAX_STORAGE_LOCATION_LENGTH); |
There was a problem hiding this comment.
Blocker: External volume location is checked as if it could be a single object, so a location with no room for children is accepted
The external volume path calls validateLocation, which uses Use.REQUESTED and Extent.OBJECT_OR_PREFIX. That extent exists because an external table can be a single file (StorageLimits.java:63). A volume is always a directory, so every file under it needs at least '/x' more. The same mismatch appears in the other callers that use this extent: external location create and update in ExternalLocationRepository (lines 121, 296, 300, 313), and external table create in TableRepository (lines 875-877) when the format is DELTA or ICEBERG, which are always directories. It affects Azure (1,024 characters and 254 segments), S3 and GCS (1,024 bytes).
For example: Create an external volume at abfss://[email protected]/ followed by 1,024 'b' characters. StorageLocationValidatorTest.testRequestLocationMayNameASingleAzureBlob (line 561) pins this as accepted. Any child name is at least 1,026 characters, so no file can be stored in the volume.
Check external volume locations with a prefix extent so that a child name has to fit, as the managed branch already does. Do the same for external locations, and for external tables whose format is DELTA or ICEBERG (the managed branch at TableRepository.java:882-883 already tells them apart). Keep OBJECT_OR_PREFIX only for formats that can be a single file. Add boundary rows for each caller to the existing StorageLocationValidatorTest, plus one through the volume repository.
How about passing the extent from each caller, so only single-file table formats keep OBJECT_OR_PREFIX?
There was a problem hiding this comment.
Fixed in 834ea7d, as you suggested. Each caller now passes the extent. External volumes, external locations, and external tables whose format is DELTA or ICEBERG are checked as directories, so a file has to fit under them. Only formats that may be a single file, such as CSV, keep OBJECT_OR_PREFIX. The validator test you pointed at is now testOnlyASingleFileRequestLocationMayNameAnAzureBlob. It rejects the 1,024 character location as a directory and accepts 1,022 characters and 253 segments. The S3 test does the same. testExternalLocationNeedsRoomForAFileUnderIt covers external location URLs, and testOnlyDeltaAndIcebergTablesAreAlwaysDirectories checks every table format. Through the repositories, testDirectoryLocationsLeaveRoomForAFile accepts an external volume and a Delta table at 1,022 characters and rejects them at 1,023. It also accepts a CSV table at 1,024 and rejects it at 1,025. External location URLs are capped at 255 characters, so the API can't reach these limits there today. They still use PREFIX in case that column is widened.
…paths as directories A location that holds files has to leave room for one under it. Each caller now passes the extent, so only a table in a format that may be a single file, such as CSV, keeps the single-object check. Document the storage location limits, including the Azure hierarchical namespace limit the server can't check. Signed-off-by: Maha Rana Yadavalli <[email protected]>
timothyw553
left a comment
There was a problem hiding this comment.
overall looks good, nice improvement. i left a few comments on a couple edge cases, test coverage for the production lookup, and the documented limits.
| * fails, such as when the covering external location's credential was force-deleted. | ||
| */ | ||
| private VendCredential credentialFor(Session session, NormalizedURL location) { | ||
| if (!CREDENTIAL_SCHEMES.contains(location.toUri().getScheme())) { |
There was a problem hiding this comment.
what happens if someone passes s3:/// or gs:/// as a storage root? to my understanding location.toUri() throws IllegalArgumentException here and turns catalog or schema creation into an HTTP 500 instead of 400. could we catch that and throw INVALID_ARGUMENT, plus add tests for those malformed roots and a valid bucket root?
- if (!CREDENTIAL_SCHEMES.contains(location.toUri().getScheme())) {
+ String scheme;
+ try {
+ scheme = location.toUri().getScheme();
+ } catch (IllegalArgumentException e) {
+ throw new BaseException(
+ ErrorCode.INVALID_ARGUMENT,
+ "Invalid storage location: " + location,
+ e);
+ }
+ if (!CREDENTIAL_SCHEMES.contains(scheme)) {There was a problem hiding this comment.
[AI Assisted] Pushing back on this one. URI.create("s3:///") does not throw on JDK 17 (it parses with scheme s3 and no authority), so the s3:/// example does not produce an IllegalArgumentException here. A malformed root that does throw, such as one with a space, already reaches BaseExceptionHandler, which maps IllegalArgumentException to INVALID_ARGUMENT (HTTP 400), not 500. The malformed-root test cases are still worth adding for the empty-bucket path, but the catch block is not needed for the status code.
There was a problem hiding this comment.
I checked, and s3:/// and gs:/// fail in NormalizedURL.from before the validator runs, so no catch is needed. testMalformedCloudStorageRootsAreRejected in cbe567e covers s3:///, gs:///, s3:// and gs:// roots, plus valid bucket roots.
There was a problem hiding this comment.
[AI Assisted] Withdrawing this pushback. s3:/// and gs:/// fail in NormalizedURL.from before the validator runs, and the new testMalformedCloudStorageRootsAreRejected covers the 400. Thanks for checking.
| // Checked whether or not the URL changes, against the credential's committed type. | ||
| validateUrlForCredential(existingLocation.getUrl(), current); | ||
| if (updateExternalLocation.getUrl() != null) { | ||
| validateUrlLimits(existingLocation.getUrl(), Optional.ofNullable(current)); |
There was a problem hiding this comment.
if the assigned credential was force-deleted, current is null here. passing Optional.empty() tells the validator to fall back to bucket config, even though real vending fails on the missing credential and never uses that bucket role (e.g. an 82 * URL hits a policy-length error while 82 as passes). should we preserve the Unresolvable distinction so we still check column length without running bucket-role policy checks, and test URL updates with and without a force-deleted credential?
There was a problem hiding this comment.
[AI Assisted] Agree. Optional.ofNullable(current) turns a force-deleted credential into Resolved(empty), so the cloud checks run against bucket config instead of the Unresolvable path that vending would hit. Ask: keep the distinction for URL updates with and without a force-deleted credential, and cover both in tests.
There was a problem hiding this comment.
Fixed in cbe567e. A URL change with a force-deleted credential is now checked only against the column for S3 and GCS, not the bucket config. A validator unit test and a server test cover it.
|
|
||
| The server rejects a location with `INVALID_ARGUMENT` when its database column or its cloud storage can't hold it: | ||
|
|
||
| - Catalog and schema storage roots, table and volume locations, and model version sources can be up to 2,048 |
There was a problem hiding this comment.
catalog and schema roots have to leave room for generated child paths, so the effective limit is 1,942 and 1,943 UTF-8 bytes rather than 2,048 characters. also on line 170, GCS and Azure object-name checks run regardless of bucket credential config while S3 and GCS access-boundary checks depend on it. could we separate column widths from effective root limits and clarify what applies per cloud?
There was a problem hiding this comment.
[AI Assisted] Agree. The docs say roots can be up to 2,048 characters, but children need room under the root and built locations are checked in UTF-8 bytes, so the effective limit is lower. Ask: state the byte versus character rule and the per-cloud checks separately from the column widths.
There was a problem hiding this comment.
Rewritten in cbe567e. It now separates the column widths, the 1,942 and 1,943 byte root limits, the object name limits per cloud, and the vended credential limits.
|
|
||
| private StorageLocationValidator validatorFor(Optional<CredentialDAO> credential) { | ||
| return new StorageLocationValidator( | ||
| cloudCredentialVendor, (session, location) -> credential, () -> Unit.UTF16_CODE_UNITS); |
There was a problem hiding this comment.
these unit tests pass the credential in directly, so they'd still pass if the production lookup stopped supplying the covering IAM-role credential. could we extend a server test to create a credential and external location and verify a volume under it (short path passes, policy-expanding path fails, plus the force-deleted case)?
There was a problem hiding this comment.
[AI Assisted] Agree. These tests pass the credential in directly, so they would still pass if the production lookup stopped supplying the covering credential. Ask: add a server test that creates a credential and an external location, then checks a volume under it: a short path passes, a policy-expanding path fails, and the force-deleted case is covered.
There was a problem hiding this comment.
Added testLocationsAreCheckedWithTheCredentialOfTheirExternalLocation in cbe567e. A short volume under an aws_iam_role location passes, a policy-expanding one fails, and the force-deleted case is covered.
| } | ||
| } | ||
|
|
||
| // Only the S3 and GCS vendors build credentials from a location's storage credential. |
There was a problem hiding this comment.
nit: GcpCredentialVendor rejects a supplied storage credential with UNIMPLEMENTED right now, so this comment about GCS building credentials from a storage credential is a bit misleading.
There was a problem hiding this comment.
Reworded in cbe567e. The comment now says S3 builds its policy from the credential, and GCS builds an access boundary only without one.
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Comment at f4be8f5. Replies in the inline threads cover the items that overlap timothyw553's comments: the force-deleted credential in the update path, the test that bypasses the production lookup, and the docs limits. The s3:/// point is a pushback in its thread.
Normal items:
- Force-deleted credential in the update path (ExternalLocationRepository.java:313): covered in the thread reply.
- Tests bypass the production credential lookup (StorageLocationValidatorTest.java:123): covered in the thread reply.
- Docs describe the limits inaccurately (docs/server/configuration.md:167): covered in the thread reply.
- Scope: this PR now also adds StorageLocationValidator, StorageLimits and the cloud limit checks, about 2,000 lines. The widening and the validator are separable, so splitting the validator into its own PR would make both easier to review.
Followup:
- The "Going back to the baseline release" section in docs/server/upgrades.md still names step 2 only. The widened columns from this PR narrow the same way on a downgrade, so the paragraph should list them.
Nit:
- SchemaMigratorTest has no case that writes a long value after the steps run on an existing database. A case that migrates to step 3, inserts 255 characters, runs the upgrade, then writes 2048 characters and reads both back would cover it.
…tial was force-deleted, cover the credential lookup and malformed roots in server tests, and separate column widths from root and cloud limits in the docs Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
Thanks both for the review. Everything is addressed in cbe567e, and the description is updated. The new server tests can't start on Windows, so CI is their first run. |
| /* isS3Compatible= */ false)))); | ||
| } | ||
|
|
||
| private boolean isOnAwsS3(CredentialContext context) { |
There was a problem hiding this comment.
Nit (not a blocker): Create-time limit check re-derives which generator the vend would use
isOnAwsS3 and awsStsRole work out for themselves whether a vend would reach the AWS STS path, which role and region it would use, and whether a session token skips STS. vendAwsCredentials and createPerBucketCredentialGenerator make the same choice separately. The same pattern appears in GcpCredentialVendor.buildsAccessBoundary (GcpCredentialVendor.java:192), which repeats the branching of vendGcpCredential and createGenerator, including the empty custom-generator class name rule.
Cost of keeping it: If someone adds a credential type that vendAwsCredentials sends to the master-role STS generator, isOnAwsS3 still returns false for it, so the object key and session policy checks are skipped at create time. The vend then rejects that location later with INVALID_ARGUMENT at AwsCredentialGenerator.java:167. The oversized policy is still caught at vend time, so the cost is a late error and not a bad credential. Today the two copies agree, and the tests only pin today's branches.
Move the choice into one pure method that both the vend and the check call. For AWS it could return S3_COMPATIBLE, MASTER_ROLE_STS(role), CUSTOM, STATIC or PER_BUCKET_STS(role, region). The vend builds a generator from that result, and limitViolation runs the policy check only for the STS cases. The shared part should be a description of the choice and not the generator instances, because the per-bucket STS generators are built lazily and the check must not create STS clients. Do the same on the GCP side with one method that says whether the vend would build an access boundary.
Evidence
The vend's selection, AwsCredentialVendor.java:199-215: `if (config.getCredentialGenerator() != null) { ... return (AwsCredentialGenerator) Class.forName(...)` / `if (config.getSessionToken() != null && !config.getSessionToken().isEmpty()) { return new AwsCredentialGenerator.StaticAwsCredentialGenerator(config); }` / `return createStsCredentialGenerator(config);`. And in vendAwsCredentials: `if (credentialDAO.getCredentialType() == CredentialDAO.CredentialType.S3_COMPATIBLE) { return vendS3Compatible(credentialDAO, context); } generator = getAwsS3MasterRoleStsGenerator();`. The copy in the limit check, AwsCredentialVendor.java:398-427: `return context.getCredentialDAO().get().getCredentialType() == CredentialDAO.CredentialType.AWS_IAM_ROLE; ... return config != null && config.getCredentialGenerator() == null;` and `if (config.getSessionToken() != null && !config.getSessionToken().isEmpty()) { return Optional.empty(); } return Optional.of(new AwsStsRole(config.getAwsRoleArn(), configuredRegion(config)));`. Its javadoc (lines 412-414) admits the copies differ: 'Only for an ARN without one does the vend use a region looked up from the environment when none is configured, where this uses commercial AWS.' The generator already checks the same limit at vend time, AwsCredentialGenerator.java:167: `AwsPolicyGenerator.sessionPolicyViolation(awsPolicy)`. GCP, GcpCredentialVendor.java:192-196: `return context.getCredentialDAO().isEmpty() && config != null && (config.getCredentialGenerator() == null || ...)`. This mirrors vendGcpCredential's `getCredentialDAO().ifPresent(... UNIMPLEMENTED ...)` and `if (storageConfig == null) { throw ... FAILED_PRECONDITION`. Taken together, the same branching exists twice, and nothing links the two copies.
How it was checked
Checked by 1 independent check: CONFIRMED
Would a shared pure description of the generator choice work for both paths?
There was a problem hiding this comment.
Agreed that the two copies can drift. I left this out of #2378 to keep it reviewable. If they ever disagree, the vend still rejects a policy that's too long. I can share one description of the generator choice in a follow-up.
| // The S3 and GCS limit checks depend on the location's storage credential. S3 builds its policy | ||
| // from it. GCS builds an access boundary only for a location without one, since it can't vend | ||
| // with a storage credential yet. | ||
| private static final Set<String> CREDENTIAL_SCHEMES = |
There was a problem hiding this comment.
Nit (not a blocker): Which schemes need the storage credential is copied into the persistence layer
CREDENTIAL_SCHEMES records which vendors' limitViolation reads the credential. Both credentialFor (about line 285) and validateExternalLocationUrl (about line 128) use it. Nothing makes a vendor change update the set, and the comment about GCS is already flagged as misleading in an open thread.
Cost of keeping it: Suppose Azure starts vending with a storage credential and its limitViolation reads ctx.getCredentialDAO(). An abfss:// external volume under an Azure external location is then checked with an empty credential, because abfss is not in the set. A force-deleted Azure credential would also be treated as Resolved(empty) and not Unresolvable. The set matches the vendors today, so this is a coupling cost and not a current mismatch.
Add a method like the one above to CloudCredentialVendor, next to limitViolation, so each provider answers it. Have credentialFor and validateExternalLocationUrl call it, and delete CREDENTIAL_SCHEMES with its comment. Today's behavior stays the same: S3 and GS true, Azure false.
boolean limitsDependOnCredential(UriScheme scheme);
Evidence
StorageLocationValidator.java:60-64: `// The S3 and GCS limit checks depend on the location's storage credential. S3 builds its policy from it. GCS builds an access boundary only for a location without one, since it can't vend with a storage credential yet. private static final Set<String> CREDENTIAL_SCHEMES = Set.of(UriScheme.S3.toString(), UriScheme.GS.toString());`. It is used at line 285, `if (!CREDENTIAL_SCHEMES.contains(location.toUri().getScheme())) { return new Resolved(Optional.empty()); }`, and at line 128, `credential.isPresent() || !CREDENTIAL_SCHEMES.contains(url.toUri().getScheme()) ? new Resolved(credential) : new Unresolvable()`. Whether a check uses the credential is decided in the vendors (GcpCredentialVendor.buildsAccessBoundary reads `context.getCredentialDAO().isEmpty()`, and AwsCredentialVendor.isOnAwsS3 reads `context.getCredentialDAO()`), so this set is a second copy of a per-vendor fact.
How it was checked
Checked by 1 independent check: CONFIRMED
How about letting each vendor answer this next to limitViolation?
|
|
||
| // S3-compatible STS publishes no session policy limit, so a policy longer than AWS STS | ||
| // allows is still sent. | ||
| vendCredential( |
There was a problem hiding this comment.
Nit (not a blocker): Test only checks the second STS request, so the first one is never inspected
The second vend added at this line captures a second AssumeRoleRequest. The role, policy, signing key and signer assertions that follow all read requestCaptor.getValue(), which returns the last capture. The first (SELECT-only, short path) request is therefore not checked.
For example: If the first request were built with a policy that lacked the compat-bucket/data resource, or that granted write actions, the test would still pass. The second request still contains arn:aws:s3:::compat-bucket/data and uses the same role and signer. A role or signer bug would likely show on both requests, so the real gap is the first request's policy resource and privileges.
List<AssumeRoleRequest> requests = requestCaptor.getAllValues();
// requests.get(0): short SELECT request - assert roleArn, policy resource, signingKeyId, signer
// requests.get(1): long SELECT+UPDATE request - assert policy length > 2048 and the same fields
Evidence
CloudCredentialVendorTest.java:521-522, 536-542: `vendCredential(COMPAT_PATH, Set.of(CredentialContext.Privilege.SELECT));` is followed by `vendCredential(COMPAT_PATH + "/" + "r".repeat(600), Set.of(CredentialContext.Privilege.SELECT, CredentialContext.Privilege.UPDATE));` and then `assertThat(requestCaptor.getValue().policy()).contains("arn:aws:s3:::compat-bucket/data");`. The assertion checks the second captured request, leaving the first request's policy unchecked.
How it was checked
Checked by 2 independent checks: CONFIRMED
How about asserting on both captured requests so each vend is checked?
| } | ||
| try { | ||
| return new Resolved(credentialLookup.find(session, location)); | ||
| } catch (BaseException e) { |
There was a problem hiding this comment.
Nit (not a blocker): Overlapping external locations skip the cloud limit checks with only a warning
credentialFor catches every BaseException from the credential lookup and returns Unresolvable. That also covers the INTERNAL error that ExternalLocationUtils.java:336-339 throws when two external locations cover one path. The catch is meant for the force-deleted credential case, but it hides this one too.
For example: If a database somehow held two overlapping external locations, a create under that path would pass validation with a logged warning and no cloud limit check. The later vend would then fail on the same lookup. No API caller can create that state, because overlapping locations are rejected, so this only matters on an already-corrupted database.
Have the lookup return a distinct result for a covering location whose credential is gone, such as an empty Optional or a small result type. Then credentialFor maps only that result to Unresolvable and lets other exceptions propagate. Narrowing by ErrorCode will not work, because the overlap error (ExternalLocationUtils.java:339) and the missing-credential error (:347) are both INTERNAL, and matching on the message would be brittle.
Evidence
StorageLocationValidator.java:288-293:
try {
return new Resolved(credentialLookup.find(session, location));
} catch (BaseException e) {
LOGGER.warn("Skipping cloud limit checks for {}: credential lookup failed", location, e);
return new Unresolvable();
}
The lookup (ExternalLocationUtils.java:338-340) throws a BaseException with ErrorCode.INTERNAL, "More than one external location with URL '...' exist.", for an invalid state where two external locations cover the path. The catch handles that the same way as the missing-credential error at ExternalLocationUtils.java:345-351, because it catches every BaseException. The caller then gets a normal accepted create, with only a server log line. I looked in credentialFor and in its callers for a rethrow or a check on the error code and found none.
How it was checked
Checked by 2 independent checks, which split: CONFIRMED, NITPICK
Would you want the lookup to report the missing credential explicitly so other errors can surface?
There was a problem hiding this comment.
[AI Assisted] Agree with the nit, and I would rate it normal. A limit check that fails open on an invalid catalog state (several covering external locations) silently skips the S3 and GCS checks. Ask: let only the force-deleted case return Unresolvable, let other BaseExceptions propagate, and replace the test that expects a bypass with one that expects the error.
There was a problem hiding this comment.
…g with 500 Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Verdict: comment. Thanks for addressing the three thread points (force-deleted credential, docs limits, and the production-lookup test); they look right.
The scope split is still open and has had no reply: the PR now also adds the storage limits and the cloud checks, which are separable from the widening. Splitting the validator into its own PR would make both easier to review.
Inline notes below cover the Delta metadata budget, the read-only check on external locations, and a redundancy. The catch-all in credentialFor is in the thread from shba24.
| * Objects are stored under the location. The shortest name of such an object is the location's | ||
| * name, a slash and one character, one path segment more. | ||
| */ | ||
| PREFIX(2, 1), |
There was a problem hiding this comment.
[AI Assisted] Normal. Table locations are checked with PREFIX(2, 1), which reserves only a slash and one character under the location. A Delta table writes a _delta_log commit file, and a managed Delta table also writes a staged-commit file, so a location near the limit can pass validation and still have no room for its first commit. Ask: reserve a format-specific suffix (Delta at least) for table locations, and add boundary tests with the real suffix lengths.
There was a problem hiding this comment.
Fixed in #2378 (dd15bb6). A Delta table location, managed or external, now leaves room for a staged commit, _delta_log/_staged_commits/<20 digit version>..json, which is 90 characters and three path segments. testDeltaTablesLeaveRoomForAStagedCommit checks the exact 1,024 byte and 254 segment limits, and testDirectoryLocationsLeaveRoomForAFile does the same over the API.
| ? new Resolved(credential) | ||
| : new Unresolvable(); | ||
| validateLocation( | ||
| url, maxLength, columnUnit.get(), Use.REQUESTED, Extent.PREFIX, vendCredential); |
There was a problem hiding this comment.
[AI Assisted] Normal. External tables, external volumes and external location URLs are checked only against the read policy (Use.REQUESTED, which is SELECT only). A writable table or volume can pass here and then fail every write vend, because the longer SELECT and UPDATE policy is what gets sent. Ask: validate these with SELECT and UPDATE, as managed locations are, or document that a long S3 location is readable but not writable.
There was a problem hiding this comment.
| public void validateExternalLocationUrl( | ||
| NormalizedURL url, int maxLength, Optional<CredentialDAO> credential) { | ||
| VendCredential vendCredential = | ||
| credential.isPresent() || !limitsDependOnCredential(url) |
There was a problem hiding this comment.
[AI Assisted] Nit. validateExternalLocationUrl and credentialFor both decide the credential branch through limitsDependOnCredential. Folding the choice into one place would keep them from drifting.
…column widening here The validator, the cloud limit checks and their tests move to the validate-storage-locations branch, which builds on this one. Signed-off-by: Maha Rana Yadavalli <[email protected]>
|
/review |
yili-db
left a comment
There was a problem hiding this comment.
[AI Assisted] Approving at 4c3bb6c. The column widening is good, and the location validator now lives in #2378.
Non-blocking follow-ups:
- The "Going back to the baseline release" section of
docs/server/upgrades.mdshould list the widened columns, since a downgrade narrows them the same way. - The constant name and Javadoc for
MAX_STORAGE_LOCATION_LENGTHshould name the columns it covers. - No test ties the DAO
lengthvalues to the migrated columns. A check against the migrated schema would catch a drift. - Whichever of #2234, #2260 and #1781 merges second renumbers its V11 step.
| private String storageRoot; | ||
|
|
||
| @Column(name = "storage_location") | ||
| @Column(name = "storage_location", length = 2048) |
There was a problem hiding this comment.
Nit (not a blocker): API callers cannot determine which long paths fit
The create-request descriptions identify the path fields but omit the new storage widths. For catalogs and schemas, the generated location must also fit after the server appends its suffix.
For example: A normalized catalog root of 2048 characters fills storage_root. Appending __unitystorage/catalogs/{catalog_id} makes the value written to storage_location longer than its column allows.
Describe the persisted-length limits in api/all.yaml and regenerate the reference pages. For catalog and schema roots, describe the generated-location constraint so readers can account for the suffix.
How it was checked
Checked by 1 independent check: NITPICK
Could we document the persisted limits and the suffix that catalog and schema roots need to accommodate?
There was a problem hiding this comment.
Good point. I'll document the persisted length limits and the managed-location suffix in api/all.yaml in #2378, then regenerate the reference pages.
| assertManagedVolumeUnder(SCHEMA_NAME, schemaInfo.getStorageLocation()); | ||
| assertManagedVolumeUnder(SCHEMA_NAME2, catalogInfo.getStorageLocation()); | ||
|
|
||
| String externalVolumeLocation = "s3://volume-bucket/" + "v".repeat(2029); |
There was a problem hiding this comment.
Nit (not a blocker): A 2,049-character volume location or model version source still gets a 500
The new test stores values of exactly 2,048 characters, so the widened columns are covered from the inside.
One character more, the database raises SQLSTATE 22001. DatabaseErrors maps only PostgreSQL's 54000, so the caller gets INTERNAL on H2, MySQL and PostgreSQL. This is one bug class: A storage path longer than its column reaches the INSERT with no length check, and the database's string-too-long error falls through DatabaseErrors to INTERNAL. The same issue appears in server/src/main/java/io/unitycatalog/server/persist/VolumeRepository.java:78 (An external volume storage_location is checked only for a non-empty prefix and managed-storage overlap, then persisted into a 2048 column. A 2,049-character val); server/src/main/java/io/unitycatalog/server/persist/ModelRepository.java:582 (A model version's source is copied verbatim into uc_model_versions.source (2048) with no length check. createModelVersion uses its own Session/Transaction rathe); server/src/main/java/io/unitycatalog/server/persist/CatalogRepository.java:67 (A catalog storage_root over 2048 (and likewise a schema root, SchemaRepository.java:87) is persisted without a length check and returns 500 rather than 400.); server/src/main/java/io/unitycatalog/server/persist/TableRepository.java:865 (An external table storage_location goes into uc_tables.url (2048, unchanged by this PR) without a length check. A 2,049-character URL returns 500.); server/src/main/java/io/unitycatalog/server/persist/dao/ExternalLocationDAO.java:35 (uc_external_locations.url has no length, so it is still the default varchar(255). This PR widens the paths an external location must cover but leaves this colum); server/src/main/java/io/unitycatalog/server/persist/utils/DatabaseErrors.java:28 (The only mapped entry is PostgreSQL 54000. SQLSTATE 22001, raised by H2, MySQL and PostgreSQL for a value longer than a varchar, is unmapped, so TransactionMana); server/src/test/java/io/unitycatalog/server/sdk/managedlocation/SdkManagedLocationTest.java:145 (The new test asserts only values at or under the limit (1,000/1,200-char roots, 2,048-char volume and model source). It has no row past 2048, and no root whose ).
For example: This is worth knowing because it is the same 500 the PR fixes, now at 2048 instead of 255.
It also covers a catalog root of about 1,988 to 2,048 characters. The root fits storage_root, but the derived storage_location (root plus /__unitystorage/catalogs/<uuid>) does not.
When the validation in #2378 lands, add rows here for a 2,049-character external volume location and model version source, and for a catalog root whose managed location overflows. Assert ErrorCode.INVALID_ARGUMENT on each.
How it was checked
Reproduced: UC_TEST_DATABASE=<H2 default|POSTGRES_18|MYSQL_8> dev/run-tests.py -p 1 --jvm-heap 2g 'server/testOnly io.unitycatalog.server.sdk.managedlocation.SdkManagedLocationTest -- --tests=.*Over2048.*'
head:
SdkManagedLocationTest#testStoragePathsOver2048CharactersAreRejected(): org.opentest4j.AssertionFailedError: expected: 400 but was: 500 (at TestUtils.assertUcErrorEnvelope(TestUtils.java:135)); 1 suites, 16 tests, 1 failed (same on H2, POSTGRES_18, MYSQL_8)
Checked by 1 independent check: CONFIRMED
Would you link #2378 from the description so this boundary has a visible owner until then?
There was a problem hiding this comment.
Thanks. #2378 adds this validation and adds tests just past each limit, including the overflowing catalog root, all expecting INVALID_ARGUMENT.
PR Checklist
docsis updated (not needed, the docs don't describe column widths)Description of changes
Creating a catalog whose storage root is longer than 255 characters fails with a 500:
The same happens for a schema storage root, a managed volume whose catalog or schema location is long enough that
<location>/volumes/<uuid>passes 255 characters, an external volume over 255 characters, and a model versionsourceover 255 characters. Table locations don't have this problem becauseuc_tables.urlisvarchar(2048), and staging table locations are 2048 as well.This PR widens these columns to 2048, the width of
uc_tables.url, with one single-statement step per column for H2, MySQL and PostgreSQL, each with its own effect file, the same way #2187 widens the function columns:uc_catalogs.storage_rootand V12uc_catalogs.storage_locationuc_schemas.storage_rootand V14uc_schemas.storage_locationuc_volumes.storage_locationuc_model_versions.sourceThe matching DAO fields use one constant,
Constants.MAX_STORAGE_LOCATION_LENGTH(2048), which the table url and staging table location columns now use too. Their width doesn't change. Each step only changes a column type fromvarchar(255)tovarchar(2048), and all six columns are nullable and have no default, so the MySQLMODIFYrestatesNULLand drops nothing. None of the six columns is in an index, so no index entry grows.A new database gets the wider columns from the steps. An existing database gets them when
bin/start-uc-server --upgrade-schemaruns the new steps.The steps are V11 to V16, the next numbers after the V10 step #2187 added, because
SchemaMigratorTestexpects the step versions to have no gaps. #2260 and #1781 also add a V11, so whichever of these merges second needs to renumber its steps.uc_external_locations.urlis alsovarchar(255), but it is not widened here. It has theidx_urlindex on all three databases, and at 2048 characters that index would go over MySQL's 3,072 byte key limit and PostgreSQL's 2,704 byte index entry limit, whichMigrationStepRulesTestrefuses. Widening it needs a step that drops or replaces the index, which the step rules don't allow yet, so it can follow separately.Follow-up
Location validation against the columns and the cloud limits moved to its own PR, #2378, which builds on this one. A root that fits its column can still be too long for the managed locations under it, and that PR rejects such roots before they are stored.
Testing
SdkManagedLocationTest.testStoragePathsLongerThan255Characterscreates a 1,020 character catalog root and a 1,219 character schema root and reads them back. It also creates managed volumes under each, then an external volume and a model version source of exactly 2,048 characters, which are read back. On main, each of these fails with a 500.SchemaMigratorTestandMigrationStepRulesTestcheck the new steps on H2, MySQL and PostgreSQL.javafmtCheck,checkstyleandTest/compilepass forserver. The Sdk tests can't start on Windows, so they run on CI.