Repository navigation
Cherry pick #129899 to 26.3: Match filtered source grants only against the location that is actually accessed - #132665
Conversation
A filtered SOURCES grant was matched against `normalizeURIForAccessCheck(uri)`:
Poco resolves `.`/`..`, drops empty segments, percent-decodes the path and
lower-cases a scheme-like prefix. No storage repeats that: `S3::URI` keeps dot
and empty segments in the key and folds a query into it (where `?` is a
wildcard), `url()` sends the raw path and expands `{a,b}` after the check, and
Azure blob names and local paths are used as written. So e.g.
`BACKUP ... TO S3('.../denied/../allowed/x.tar')` passed an `allowed/.*` filter
and AWS S3 stored the literal key, and an Azure backup to `db/other/../backups/x`
or `db%2Fbackups/y` was written outside `WRITE ON AZURE('db/backups/.*')`.
`ITableFunction::checkSourceAccessForURI` is now the single check for table
functions and `BackupFactory` (its copy `normalizeAccessURI` is removed): the
filter is matched only when the normalized string is the accessed location,
otherwise the subject is empty and only the unfiltered grant passes. Azure and
File names are matched as written; an Azure archive destination is authorized
as the post-split key the writer opens, so `blob_path_with_archive` is gone.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t filters
Poco's toString percent-encodes a raw `*`, `?`, `{`, `}`, `|` of the path exactly as it
encodes their escaped spelling, while S3 and `url()` expand both as a glob after the check.
So a filter written against the escaped form (`.../a%2A.tsv`) authorized the glob `a*.tsv`.
The subject now spells these characters as written: `toString` encodes a `%` of the path as
`%25`, so before the query such an escape can only come from a glob character. This replaces
the refusal of escaped S3 wildcards, which closed nothing for the raw spelling; an escaped
wildcard now gets the same subject as the raw one.
A `#fragment` is kept in the subject but never accessed (the S3 key and the HTTP request use
the path and query only), so a URI with `#` now needs the grant on the whole source.
The test gains the escaped-filter and fragment cases and allows under a filter for a glob,
glob alternatives, a local path and an Azure archive destination.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…d escaped
Spelling a glob character as written in the subject (previous commit) let the `.` of an
ordinary exact-object filter match it: `READ ON S3('.../data/report.csv')` authorized
`s3('.../data/report*csv')`, which S3 expands to `report[^/]*csv` and uses to read keys the
filter does not match. Master's subject spelled `*` as `%2A`, which a single `.` cannot
match, so this was wider than master. The same held for an S3 `%3F`, HDFS `*`, a `url()`
top-level `|` failover and the raw Azure and `File` names.
A glob is expanded after the check, so neither spelling is the accessed location. The check
now requires the filter to match the location both as written and with glob characters
percent-encoded, which authorizes nothing that master or the as-written subject alone denied.
The test gains exact-object grants and five cases: the exact read is allowed, while `*`,
`%3F`, `url()` failover and an Azure `*` against the exact filter are refused.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…urce
`url()` expands `{}` alternatives and splits `|` failover across the whole URI, but the
access-check subject escapes glob characters only in the path: Poco appends the authority
and the query as written. A `|` or `{}` in the query therefore stayed a single character
that the `.*` of a prefix filter matches, so `READ ON URL('http://h/allowed/.*')`
authorized `url('http://h/allowed/missing?x|http://other/secret')`, which fails over to the
second URL and reads it. Such a location now gets the empty subject, so only the grant on
the whole source passes.
The test gains a failover and an alternative in the query, and is tagged
`no-replicated-database`: replicated access storage drops grant filters when
`enable_read_write_grants` is off, which makes every filtered grant whole-source.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Azure blob paths and local paths are matched against a source grant filter as written,
but a local path is opened as written and the file system resolves `//` as `/`, while
master's subject dropped empty segments. So under a segment-shaped filter such as
`READ ON FILE('/ufp/db/.*/public/.*')`, `icebergLocal('/ufp/db//public/t')` was
authorized although it opens `/ufp/db/public/t`, which the filter refuses. Such a name
now gets the empty subject, the same rule the URI sources already apply to `//`, so only
the grant on the whole source passes. For an Azure flat-namespace blob this refuses a
literal `//` as well, which keeps one rule for both names.
The test gains a local path and an Azure backup destination with `//`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
… escapes
`url` sends its path as written (`enable_url_encoding` is 0 by default), but the
subject the filter is matched against is Poco's `toString`, which escapes every path
character other than alphanumerics and `-._~/&+;=:@`. So under
`READ ON URL('http://h/data/a%21b')`, `url('http://h/data/a!b')` was authorized and sent
`/data/a!b`, and under `READ ON URL('http://h/allowed/.*')`, `url('http://h/allowed/..\secret')`
was authorized with the subject `.../allowed/..%5Csecret`, which a server that treats `\`
as `/` resolves to `/secret`. A `url` path may now hold only the characters the subject
keeps plus the glob syntax `*{}|,`, which the as-written and escaped witnesses already
handle; anything else gives the empty subject, so only the grant on the whole source
passes. This subsumes the `%` rule for `url`; other non-S3 URI sources keep it.
The test gains a raw `!` against a filter that spells it `%21`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ritten
The `url` rule allows `,` in a raw path (glob syntax inside `{a,b}`), but the escaped
witness renders it `%2C` and `unescapeGlobCharacters` restored only `*?{}|`, so for
`url('http://h/data/a,b')` both witnesses were `.../a%2Cb`, while `url` sends `/data/a,b`
as written. So `READ ON URL('http://h/data/a%2Cb')` authorized the raw `a,b`, and a filter
excluding commas (`.../allowed/[^,]*`) authorized `.../allowed/a,b`. For `url` the
as-written witness now also turns `%2C` back into `,`: a raw `%` is already refused for
`url`, so before the query a `%2C` can only come from a raw `,`, and the witness equals the
raw path. The escaped witness is still required, so nothing master denied is allowed. S3
decodes the key, so its `%2C` subject already is the accessed key and stays as it is.
The test gains a raw `,` against a filter that spells it `%2C`.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Condense four multi-line comments in ITableFunction.{h,cpp} to one line each and drop the comment on escapeGlobCharacters.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ssed-location Match filtered source grants only against the location that is actually accessed
|
This one cannot be resolved as a merge, because both halves of #129899 build on code that 26.3 does not have:
The table function part does apply to 26.3. On the official 26.3.63.123 build, with So 26.3 would need its own port of the table function part (a non-throwing filter check in place of |
26.3 does not check backup destinations against source grants, so the backup part and its test cases are left out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Original pull-request #129899
Do not merge this PR manually
This pull-request is a first step of an automated backporting.
It contains changes similar to calling
git cherry-picklocally.If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.
The check results does not matter at this step - you can safely ignore them.
Before you resolve anything
Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.
Troubleshooting
If the conflicts were resolved in a wrong way
If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:
pr-cherrypicklabel from the PRYou also need to check the Original pull-request for
pr-backports-createdlabel, and delete if it's presented thereThe PR source
The PR is created in the CI job