Repository navigation
Conversation
db5a301 to
2fd720e
Compare
|
Workflow [PR], commit [c583cc9] Summary: ❌
AI ReviewSummaryAdds Findings❌ Blockers
Missing context / blind spots
Tests
Final Verdict❌ Block. Close the executable-setting privilege bypass and enforce source row policies (or reject unsupported policy-bearing paths); align access checks with the promised column grants, and reconcile legacy |
| AccessType::SELECT, | ||
| config.time_series_storage_id, | ||
| Strings{TimeSeriesColumnNames::MetricName, TimeSeriesColumnNames::Tags, TimeSeriesColumnNames::getOuterSamples(time_series_storage->getVersion())}); | ||
| auto target_tables_context = time_series_storage->getSQLSecurityOverriddenContext(context); |
There was a problem hiding this comment.
[P1] Enforce the source table's row policy before reading as its definer
checkAccess checks grants, but does not apply row policies. Here the generated queries read the tags and samples targets under the definer, and no query reads config.time_series_storage_id as the caller. The outer planner sees a StorageTimeSeriesSelector with a table-function storage ID, so it cannot apply the policy attached to the real TimeSeries table either.
Create a nonempty ts with SQL SECURITY DEFINER, grant reader only SELECT on ts, and attach CREATE ROW POLICY deny ON ts USING 0 TO reader. A direct read returns no rows, but timeSeriesSelector(ts, 'http_requests', ...) returns samples. prometheusQuery, prometheusQueryRange, PromQL HTTP queries and remote-read inherit this bypass. The new HTTP series/labels/metadata paths similarly check only grants before querying targets as the definer.
Apply the caller's policy on the source table to these reads, or reject these entrypoints when a nontrivial source policy is active until it can be honored. Add a caller-only deny-policy regression covering the selector and HTTP paths.
There was a problem hiding this comment.
That's a preexisting problem and it's difficult to fix it at this point.
It will be fixed in a separate PR.
ddd7a4d to
6f140b8
Compare
|
|
||
| /// Only the definition of the TimeSeries table is read here, so the `SHOW COLUMNS` privilege is checked before the table | ||
| /// is found. The data is read by `timeSeriesSelector` in the generated SQL, which checks the `SELECT` privilege on the read columns. | ||
| context->checkAccess(AccessType::SHOW_COLUMNS, time_series_storage_id); |
There was a problem hiding this comment.
[P1] Keep prometheusQuery{Range} compatible with column-level grants
This table function now rejects users before the generated SQL runs unless they have table-wide SHOW COLUMNS on the TimeSeries table. That is stronger than the contract in the PR body/docs: a user with SELECT(metric_name, tags, samples) on db.ts can satisfy the actual read, but context->checkAccess(AccessType::SHOW_COLUMNS, time_series_storage_id) fails here first. timeSeriesSelector already avoids that regression by checking the known read columns before lookup and the version-dependent samples column after lookup.
Please mirror that pattern here instead of requiring whole-table SHOW COLUMNS, and add a regression where prometheusQuery / prometheusQueryRange are executed under column grants without table-wide SHOW COLUMNS.
| StoragePtr checkAccessAndGetTable() | ||
| { | ||
| auto table_id = getTimeSeriesTableID(); | ||
| context->checkAccess(AccessType::SHOW_COLUMNS, table_id); |
There was a problem hiding this comment.
[P1] The shared HTTP lookup now over-constrains every Prometheus endpoint
This helper runs before the endpoint-specific access checks, so /api/v1/query, remote-read, remote-write, series/labels, and metadata all require table-wide SHOW COLUMNS just to resolve the TimeSeries storage. That blocks legitimate users who only have the advertised column-level rights (for example SELECT(metric_name, tags, samples) for query/read or column-level INSERT for remote-write), even though the later code already performs the concrete SELECT / INSERT checks each path needs.
Please move this precheck out of the shared helper and mirror the timeSeriesSelector approach per endpoint: fail early on the concrete columns that are known up front, then check any version-dependent column after loading the table. A regression with column grants but no table-wide SHOW COLUMNS would catch this.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1377 translation units recompiled, 8956 s compile time in total, 1376 of them have a recent master baseline. Translation units without a recent master baseline:
|
…table functions A `TimeSeries` table runs the queries over its target tables with the permissions given by its `DEFINER` / `SQL SECURITY` clauses, so reading or writing it requires privileges on the table only. `timeSeriesSelector`, `prometheusQuery` and the Prometheus HTTP API follow the same rule and require `SELECT` on the columns they read. `timeSeriesSamples`, `timeSeriesTags` and `timeSeriesMetricFamilies` return a target table itself, so they require `SHOW COLUMNS` on the `TimeSeries` table and the privilege on the target table.
6f140b8 to
c583cc9
Compare
| return std::make_shared<TimeSeriesSink>(*this, metadata_snapshot->getSampleBlock(), insert_columns, local_context, async_insert); | ||
| /// The inserts into the target tables run with the permissions given by the SQL security of this table. | ||
| return std::make_shared<TimeSeriesSink>( | ||
| *this, metadata_snapshot->getSampleBlock(), insert_columns, getSQLSecurityOverriddenContext(local_context), async_insert); |
There was a problem hiding this comment.
[P1] Authorize changes to id_generator before running it as the definer
Passing the overridden context to the whole TimeSeriesSink also makes initTagsAndSamplesPipelines evaluate the stored id_generator with the definer's privileges (TimeSeriesSink.cpp:508-512, 563-578). However, checkSettingCanBeAltered still permits changing that expression, and InterpreterAlterQuery::getRequiredAccessForCommand requires only ALTER SETTINGS for it. There is no corresponding SET DEFINER / ALLOW SQL SECURITY NONE check.
For example, on an administrator-defined table with the default tuple ID, a user granted only ALTER SETTINGS, INSERT and SELECT on ts can replace the generator with:
tuple(sipHash64(metric_name), dictGetUUID('db.private_dictionary', 'secret', toUInt64(1)))The next insert reads the private dictionary as the administrator and stores its UUID in the series ID, which the user can retrieve through timeSeriesSelector, despite lacking dictGet on that dictionary or SET DEFINER. Before this change, the same expression ran as the inserting user and failed its dictionary access check.
Require authorization to replace expressions executed as another definer (and under SQL SECURITY NONE) when modifying/resetting id_generator, analogous to the existing protection for ALTER ... MODIFY QUERY. Add a stateless regression with an unrelated definer and a user having only table-level grants.
`timeSeriesSamples`, `timeSeriesTags`, `timeSeriesTimeRanges` and
`timeSeriesMetricFamilies` (and the aliases `timeSeriesData`,
`timeSeriesMetrics`) look up the TimeSeries table and its target in
`parseArguments` and then return the target's columns, but nothing in the
class checks a privilege on the TimeSeries table. A user with only
`SHOW TABLES` on `db.ts` (or no grant on it at all) therefore got the
target's columns from `DESCRIBE TABLE timeSeriesSamples('db', 'ts')` and
`DESCRIBE (SELECT ...)`, and could `SELECT` from the target, also through a
`remote()` local shard or parallel replicas, while `DESCRIBE TABLE db.ts`
is denied.
Check `SHOW COLUMNS` on the resolved TimeSeries table id before the lookup,
the privilege `DESCRIBE TABLE db.ts` checks at the same point, through the
existing `ITableFunction::checkSourceTableAccess` helper. `parseArguments`
runs before every use of the function, so one check covers every spelling
and all four functions. A table-level `SELECT` or `INSERT` on the TimeSeries
table implies `SHOW COLUMNS`, so ordinary readers and writers are unaffected;
a missing table now gives `ACCESS_DENIED` to a user without the grant, as a
direct `DESCRIBE` does. The Prometheus `/api/v1/metadata` endpoint reads
through `timeSeriesMetricFamilies` as the request's user and inherits the
check.
`timeSeriesSelector`, `prometheusQuery` and `prometheusQueryRange` are not
changed: they are the PromQL engine's read path, can be persisted with
`CREATE TABLE ... AS`, and their access design is the owner's open work
(ClickHouse#120267).
Closes ClickHouse#133495 (the `dictionary(...)` half was fixed by ClickHouse#122678).
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Support SQL SECURITY for TimeSeries tables and check access in their table functions
A
TimeSeriestable runs the queries over its target tables with the permissions given by itsDEFINER/SQL SECURITYclauses, so reading or writing it requires privileges on the table only.timeSeriesSelector,prometheusQueryand the Prometheus HTTP API follow the same rule and requireSELECTon the columns they read.timeSeriesSamples,timeSeriesTagsandtimeSeriesMetricFamiliesreturn a target table itself, so they require
SHOW COLUMNSon theTimeSeriestable and the privilegeon the target table.
Workflow [PR]
Sync PR [sync-upstream/pr/120267]