Repository navigation
Match filtered source grants only against the location that is actually accessed - #129899
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]>
Internal second-model review (click to expand)Bounce cap reached - published as-is; residual findings listed below (the rows marked "Not changed" or "Noted").
|
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261107-064600 |
|
cc @pufit @pamarcos, could you review this and add the |
|
Workflow [PR], commit [3953cf5] Summary: ✅
AI ReviewSummaryPR #129899 centralizes filtered source-grant authorization for table functions and backups, rejects ambiguous locations, and checks both spellings of glob characters. Reviewed head Missing context / blind spots
Final Verdict✅ Approve. No new inline findings; CI validation remains outstanding. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes6 object files changed (-7.19 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units97 translation units recompiled, 701 s compile time in total, 97 of them have a recent master baseline. |
5bc97f0
…rgeTreeParts` Since #129899, a filtered `AZURE` grant is matched against a blob name as written, and a subject containing `//` is refused, so the `<storage_account_url>/<container>/` subject of `mergeTreeParts` could never match a filter and `05270_merge_tree_parts_azure_source_grants` failed after merging `master`. A blob name filter cannot describe a disk that reads any blob of its container, so an Azure disk now needs the unfiltered grant, as a local disk needs the unfiltered `READ ON FILE`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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]>
Cherry pick #129899 to 26.3: Match filtered source grants only against the location that is actually accessed
…he location that is actually accessed
Cherry pick #129899 to 26.8: Match filtered source grants only against the location that is actually accessed
…he location that is actually accessed
Cherry pick #129899 to 26.9: Match filtered source grants only against the location that is actually accessed
…he location that is actually accessed
Cherry pick #129899 to 26.10: Match filtered source grants only against the location that is actually accessed
…the location that is actually accessed
Backport #129899 to 26.10: Match filtered source grants only against the location that is actually accessed
Backport #129899 to 26.9: Match filtered source grants only against the location that is actually accessed
Backport #129899 to 26.8: Match filtered source grants only against the location that is actually accessed
Related: #88089
Related: #114405
Related: #129605
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a filtered source grant (e.g.
GRANT WRITE ON S3('https://bucket/allowed/.*')) authorizing a location outside the filter.BACKUP/RESTOREand table functions likes3,urlandazureBlobStoragewith./..or empty path segments, a fragment, escapes that change the name, a query in an S3 URI (where?is a wildcard) orurlalternatives outside the path now need the grant on the whole source. A glob character (*?{}|, and,inurl) must match the filter both as written and percent-encoded.Description
On 26.10.2.103, a user with
WRITE ON AZURE('db/backups/.*')canBACKUP ... TO AzureBlobStorage(..., 'db/other/../backups/x', ...)and Azurite stores that literal blob; withREAD ON S3('.../test/exact'),s3('.../test/exact?')readstest/exactX. An S3 backup to.../denied/../allowed/x.tarpasses anallowed/.*filter and sends the literal key (MinIO answers HTTP 400).Root cause: filtered source checks match the filter against
normalizeURIForAccessCheck(uri)(Poco resolves dot and empty segments, decodes and re-escapes the path, lower-cases a scheme-like prefix, keeps a fragment), but storages do not: S3 keeps dot and empty segments in the key and folds a query into it,urlsends the raw path and expands{}/|across the whole URI, Azure and local names are used as written.Change:
ITableFunction::checkSourceAccessForURI, now used by table functions andBackupFactory, matches the filter only when the normalized string is the accessed location, else only the whole-source grant passes. Azure andFilenames are matched as written, an Azure archive as its written key. A glob character must match both ways, so neither a filter spelled%2Anor the.of.../report.csvauthorizesreport*csv. As on master, a glob is matched as a pattern, not per expanded key.Behaviour change, filtered grants only: a location with a
./..segment (including glob alternatives),//, a#fragment,{}|outside the path, a non-globurlpath character the check would escape (such as%,!,\) or a?in an S3 URI (alsoversionId) needs the unfiltered grant, and a filter spelled%2A/%7B(or%2Cinurl) no longer authorizes the raw character. Workaround: write the location plainly, or grant the whole source.Validation: new test
05564_source_grant_dot_segmentsfails on master and passes with the fix; each rule has a case that fails without it.03636,03595,04774,04776andtest_backup_source_grantspass.Workflow [PR]
Sync PR [sync-upstream/pr/129899]
Version info
26.11.1.1631-master(included in26.11and later)26.10.7.26,26.9.33.13,26.8.41.15