Repository navigation
Conversation
|
/review |
|
/review |
|
/review |
timothyw553
left a comment
There was a problem hiding this comment.
core fix looks good. i left a few comments around keeping bucket validation consistent across callers, validating before getStorageBase(), test isolation, and calling out the compatibility change.
| * @return the bucket name | ||
| * @throws BaseException {@code INVALID_ARGUMENT} if the authority is not a valid bucket name | ||
| */ | ||
| public String getS3Bucket() { |
There was a problem hiding this comment.
to my understanding, isS3Path() and StorageCredentialVendorImpl (path.toUri().getAuthority()) still use different bucket rules than getS3Bucket(), and getS3Bucket() itself doesn't check for an s3:// scheme (gs://b/p returns "b"). should we share one scheme-aware check between isS3Path() and getS3Bucket(), and switch the S3-compatible lookup in StorageCredentialVendorImpl to path.getS3Bucket()?
- s3BucketRegions.getS3CompatibleRegion(endpoint, path.toUri().getAuthority())
+ s3BucketRegions.getS3CompatibleRegion(endpoint, path.getS3Bucket())| */ | ||
| private String discoverRegion(NormalizedURL storageBase) { | ||
| String bucket = storageBase.toUri().getHost(); | ||
| String bucket = storageBase.getS3Bucket(); |
There was a problem hiding this comment.
path.getStorageBase() rebuilds the URL using uri.getAuthority(), which decodes escapes (s3://%62ucket/t becomes s3://bucket) and turns an empty authority (s3:///p) into s3://null before discoverRegion calls getS3Bucket(). should we validate path.getS3Bucket() before getRegion(path.getStorageBase()) (and add a test checking no HeadBucket call is made)?
} else {
+ path.getS3Bucket();
config.put(AwsClientProperties.CLIENT_REGION, getRegion(path.getStorageBase()));
}| URI::getHost, | ||
| uri -> new LinkedList<>(List.of(uri.getPath())), | ||
| // Only bucket-name characters, so a "*" never widens the policy's ARNs. | ||
| NormalizedURL::getS3Bucket, |
There was a problem hiding this comment.
previously URI::getHost extracted "bucket" from s3://user@bucket/p and s3://bucket:80/p, and AWS IAM role location creation doesn't run isS3Path(), so existing locations in those forms will now fail with INVALID_ARGUMENT when vending credentials. assuming rejecting those is intentional, could we call out this compatibility change and how to update existing locations in the PR description?
| assertThatThrownBy( | ||
| () -> | ||
| AwsPolicyGenerator.generatePolicy( | ||
| Set.of(SELECT), List.of(NormalizedURL.from(location)))) |
There was a problem hiding this comment.
nit: calling NormalizedURL.from(location) inside assertThatThrownBy means this test would still pass if URL construction threw instead of generatePolicy. could we construct the URLs outside the lambda (maybe also mixing a valid and invalid location and asserting the message), plus add direct getS3Bucket() cases in NormalizedURLTest for missing authorities, invalid leading characters, and non-s3:// schemes?
+ NormalizedURL invalid = NormalizedURL.from(location);
+ NormalizedURL valid = NormalizedURL.from("s3://valid/p");
assertThatThrownBy(
()
-> AwsPolicyGenerator.generatePolicy(
- Set.of(SELECT), List.of(NormalizedURL.from(location))))
+ Set.of(SELECT), List.of(valid, invalid)))f36f609 to
b7f556e
Compare
|
/review |
6fe072c to
5e04f65
Compare
…atible storage (#2267) **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] 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 **Description of changes** The server looked up S3 bucket regions in two places with two sets of rules: `FileOperationsImpl` for AWS buckets (the Iceberg `client.region`) and `S3BucketRegions` for S3-compatible storage (the vended signing region). Both send an anonymous HeadBucket, but only `S3BucketRegions` bounds its cache, rechecks regions, backs off after failures and runs one lookup per bucket. This shares that lookup, keeping the two fallback rules explicit. - `S3BucketRegions.getAwsRegion(bucket)` serves AWS buckets with the same lookup as `getS3CompatibleRegion`: - a reported region is cached per bucket, at most 10,000 buckets, and asked again after an hour (the AWS map was unbounded and never rechecked) - a failed recheck keeps the reported region, and the bucket is asked again only after the 30-second backoff - one lookup runs per bucket at a time - an AWS bucket in backoff whose reported region was evicted is asked again, never given the S3-compatible default (the two caches evict apart) - a failure to build the lookup client is handled as a failed request: as before on S3-compatible storage; for an AWS bucket it is now a retriable `INTERNAL` error instead of an unhandled exception - each request is capped at 10 seconds - AWS lookups address the bucket virtual-hosted, the SDK default as before; S3-compatible lookups keep the location's addressing style (`path_style_access`) - a 404 drops the reported region on S3-compatible storage, where the bucket may be created again with another region; an AWS bucket keeps it, as for any failed recheck (noted in the class javadoc) - Fallbacks stay explicit and unchanged: - S3-compatible storage without a known region uses `us-east-1` and asks again later - an AWS bucket without a known region fails with `FAILED_PRECONDITION` (no region, such as no such bucket) or `INTERNAL` (transient), with the same messages as before, and is asked again on the next request - `FileOperationsImpl` keeps only the regions configured with `s3.bucketPath.N`/`s3.region.N` and asks `S3BucketRegions` for the rest - Tests: - `S3BucketRegionsTest.testAwsBucketKeepsItsReportedRegionOnAFailedRecheck`, parameterized over a recheck that fails with 503, 404, 403 without a region, 200 without a region, or a malformed region: the region is kept, the 30-second backoff holds, and an eviction during it fails the lookup (through a test-only `evictReportedRegion`) - `testAwsBucketWithoutAKnownRegionHasNoDefault`: no default for an AWS bucket - `testConcurrentRequestsShareOneLookup`, for a success and for a failing AWS lookup that a second caller waits on - `testReportedRegionIsUsedAndCachedPerStorageAndBucket`: two AWS buckets on one instance each get their own region, apart from the same name on S3-compatible storage, and the lookup client has the 10-second timeout - `FileOperationsTest` discovers the region of `my_bucket`, which is not a host name; the other region cases pass unchanged (their mock builder now also stubs `overrideConfiguration`, for the timeout) Follow-up from the review of #2172. #2264 fixes how both places read a bucket name that is not a valid host name (`URI::getAuthority`); this PR already reads it that way, so whichever merges second needs a small rebase. A configured region for S3-compatible storage, to avoid the lookup entirely, is left for a separate proposal. Tests: `build/sbt "server/testOnly *S3BucketRegionsTest *FileOperationsTest"`, and the server suite on H2 (`dev/run-tests.py server/test`). Compatibility: no API or configuration change. An AWS bucket's region is now asked again after an hour instead of cached for the server's lifetime, and a recheck that fails keeps the earlier region. A malformed `x-amz-bucket-region` header from AWS is now refused like a missing one (`FAILED_PRECONDITION`, unless a region was reported before), as it already was for S3-compatible storage. This pull request and its description were written by Isaac. Signed-off-by: Yi Li <[email protected]> Co-authored-by: Isaac <[email protected]>
…e not host names - `AwsPolicyGenerator` grouped locations by `URI::getHost`, which is null for valid bucket names such as `data.2024` or `my_bucket`, so policies named `arn:aws:s3:::null/...` - Group by `URI::getAuthority` instead - `testPolicyLeavesOrdinaryPathUnchanged` checks the exact resources for such buckets Signed-off-by: Yi Li <[email protected]> Co-authored-by: Isaac <[email protected]>
- `FileOperationsImpl.discoverRegion` read the bucket with `URI::getHost`, which is null for `data.2024` or `my_bucket`, so it asked HeadBucket about no bucket - Read it with `URI::getAuthority` - `testGetFileIOConfigS3DiscoversRegionWhenNotConfigured` covers such buckets Signed-off-by: Yi Li <[email protected]> Co-authored-by: Isaac <[email protected]>
- `URI::getAuthority` passed any authority text into the policy ARNs unescaped, so `s3://*/p` named every bucket (`arn:aws:s3:::*`), and `%62ucket` decoded to another name - `NormalizedURL.getS3Bucket` reads the raw authority and takes only letters, digits, '.', '_' and '-'; anything else is `INVALID_ARGUMENT` - `AwsPolicyGenerator` and `FileOperationsImpl.discoverRegion` both use it - `testPolicyLeavesOrdinaryPathUnchanged` refuses a wildcard, a partial wildcard, escapes, user info and a port Signed-off-by: Yi Li <[email protected]> Co-authored-by: Isaac <[email protected]>
- `NormalizedURL.getS3Bucket` requires an `s3://` URL, and `isS3Path` shares its rule - `FileOperationsImpl` checks the bucket on the URL as written, before `getStorageBase()` decodes escapes - `StorageCredentialVendorImpl` passes `getS3Bucket` to the S3-compatible region lookup - Tests: - `NormalizedURLTest`: valid and refused bucket forms - `FileOperationsTest`: an invalid bucket sends no HeadBucket - `AwsPolicyGeneratorTest`: URLs built outside the assertion, next to a valid location Signed-off-by: Yi Li <[email protected]> Co-authored-by: Isaac <[email protected]>
- `ExternalLocationRepository.validateS3CompatibleSettings` reads the bucket with `NormalizedURL.getS3Bucket`, as the policy and region paths do - `BaseExternalLocationCRUDTest`: `s3://-bucket` is not an `s3://` path with a bucket, so it moves from the virtual-hosted cases to the path cases Signed-off-by: Yi Li <[email protected]> Co-authored-by: Isaac <[email protected]>
5e04f65 to
d982039
Compare
PR Checklist
docsis updatedDescription of changes
Session policies on vended S3 credentials, and the region discovery of AWS S3 buckets, used the wrong bucket for valid bucket names that are not valid URI host names.
AwsPolicyGeneratorgrouped a credential's locations byURI::getHost. Java's URI parser returns null for a host such asdata.2024(its last label starts with a digit) ormy_bucket(an underscore), although both are valid S3 bucket names. The policy then scoped access toarn:aws:s3:::null/..., so the vended credential could not reach the table.NormalizedURL.getS3Bucketreads the bucket from the raw authority of ans3://URL and takes only bucket-name characters (letters, digits, '.', '_' and '-', starting with a letter or digit); anything else, such as*,prod-*, a%escape, user info, a port, no bucket or another scheme, isINVALID_ARGUMENT, so it never reaches a session policy, wherearn:aws:s3:::*would name every bucketNormalizedURL.isS3Path, which checks the URLs ofs3_compatiblecredentials' locations, uses the same rule, so a location is refused at creation for what vending would refuse laterAwsPolicyGenerator.getBucketToPathsMapgroups byNormalizedURL::getS3BucketFileOperationsImplreads the bucket withgetS3Buckettoo, on the URL as written, before the configured-region lookup and the sharedS3BucketRegionslookup (getStorageBase()decodes escapes, sos3://%62ucket/tbecames3://bucket)StorageCredentialVendorImplpassesgetS3Bucketto the S3-compatible region lookup, instead ofURI::getAuthorityExternalLocationRepositoryreads the bucket withgetS3Bucketfor the virtual-hosted bucket-name check of S3-compatible locationsFileOperationsTest.testGetFileIOConfigS3DiscoversRegionWhenNotConfiguredcovers the same three bucket names; it fails without the changeFileOperationsTest.testGetFileIOConfigS3RefusesAnInvalidBucketWithoutDiscovery:s3://%62ucket/t,s3://*/tands3://user@bucket/tfail withINVALID_ARGUMENTand send no HeadBucketNormalizedURLTest:getS3BucketandisS3Pathfor valid names, and for no bucket, a bad first character, a wildcard, an escape, user info, a port and other schemesAwsPolicyGeneratorTest.testPolicyLeavesOrdinaryPathUnchangedchecks the exact object and bucket resources ands3:prefixformy-bucket,data.2024andmy_bucket, and thats3://*/p,s3://prod-*/p,s3://%2A/p,s3://%62ucket/p,s3://user@bucket/pands3://bucket:80/pare refused, each next to a valid location, with the URL in the message; it fails without the changeFollow-up from the review of #2172. It applies to AWS S3 and S3-compatible storage alike.
Tests:
build/sbt "server/testOnly *AwsPolicyGeneratorTest *FileOperationsTest *NormalizedURLTest", and the server suite on H2 (dev/run-tests.py server/test).Compatibility: no API or configuration change; session policies for bucket names that are valid host names are unchanged. One behavior change: an external location whose URL has user info or a port (
s3://user@bucket/p,s3://bucket:80/p), or whose bucket is not a valid bucket name, now fails credential vending and Iceberg region lookup withINVALID_ARGUMENT, naming the URL. Before,URI::getHostdropped the user info and port, so such locations worked for AWS. Neither form is a valid S3 location. To fix one, update the external location's URL tos3://<bucket>/<path>. Locations of ans3_compatible_access_keycredential with such URLs are now refused when they are created or updated.This pull request and its description were written by Isaac.