Skip to content

Revert "Revert "Check access rights in the TimeSeries table functions"" - #119282

Closed
alexey-milovidov wants to merge 1 commit into
masterfrom
revert-119281-revert-116629-groeneai/timeseries-table-function-access-check
Closed

alexey-milovidov wants to merge 1 commit into
masterfrom
revert-119281-revert-116629-groeneai/timeseries-table-function-access-check

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

Reverts #119281


Workflow [PR]
Sync PR [sync-upstream/pr/119282]

@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fcc113f]

Summary: ❌

job_name test_name status info comment
Integration tests (amd_asan_ubsan, db disk, old analyzer, 3/6) FAIL
test_storage_iceberg_with_spark/test_partition_pruning_with_functions.py::test_partition_pruning_with_functions_before_epoch[s3] FAIL cidb
test_storage_iceberg_with_spark/test_partition_pruning_with_functions.py::test_partition_pruning_with_functions_before_epoch[local] FAIL cidb
Fast test (arm_darwin) DROPPED
Build (amd_darwin) DROPPED
Build (arm_darwin) DROPPED
Build (arm_v80compat) DROPPED
Build (amd_freebsd) DROPPED
Build (ppc64le) DROPPED
Build (amd_compat) DROPPED
Build (amd_musl) DROPPED
Build (riscv64) DROPPED

AI Review

Summary

This revert restores privilege checks for the timeSeries* table functions and for timeSeriesSelector() / prometheusQuery(), and it adds focused regression coverage. The access-control contract is still incomplete, though: there are still lookup paths where a caller who lacks privileges on a target table can learn whether that target exists, so I would not merge it yet.

Findings
  • ❌ Blocker: [src/Storages/StorageTimeSeries.cpp:358] tryGetConfiguredExternalTargetTableID() deliberately returns empty for inner targets, but inner targets do have a grantable identity (.inner_id.*, and the new 05137 test grants one). Because callers then fall back to getTargetTable() first, timeSeriesSamples() / timeSeriesTags() / timeSeriesMetrics() and timeSeriesSelector() still return UNKNOWN_TABLE for a dropped inner target before checking access on that target, disclosing its existence to a user who only has privileges on the outer TimeSeries table. Suggested fix: derive the real inner target StorageID up front (including the legacy .inner.data.* samples fallback in Ordinary databases) and run checkAccessToTimeSeriesTargetTableID() before any lookup, the same way external targets are handled now.
  • ❌ Blocker: [src/Storages/StorageTimeSeriesSelector.cpp:842] readImpl() now checks SELECT on the outer TimeSeries table, but it still calls getTargetTableID() / getTargetTable() for samples and tags before any SELECT check on those targets. If one of those targets is dropped, SELECT through timeSeriesSelector() still surfaces UNKNOWN_TABLE instead of ACCESS_DENIED to a user who is not allowed to read the target. prometheusQuery() and prometheusQueryRange() inherit the same leak because they generate timeSeriesSelector() reads. Suggested fix: perform pre-lookup SELECT checks on the target identities here too, using the exact target columns that the generated queries require so the column-scoped grants from 05137 keep working.
Tests
  • ⚠️ Please add a negative SELECT case for timeSeriesSelector() / prometheusQuery() against a TimeSeries table whose external target has been dropped, under a user who still has SELECT on the outer table but not on the target. That is the path the current tests miss and the code above still leaks.
  • ⚠️ Please add the same negative case for an inner target that was dropped manually (.inner_id.* / legacy .inner.*), because the new helper currently skips prechecking inner targets entirely.
Final Verdict

Not ready to merge. The new checks close the DESCRIBE and direct timeSeriesSamples() cases, but target existence is still exposed on the remaining lookup paths above.

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label Sep 10, 2026
{
const auto * target = tryGetTarget(target_kind);

/// An inner target carries a UUID or nothing at all, and the name of a non-Atomic one is derived from

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

05137 already grants on the real inner table name (.inner_id.tags.<uuid>), so returning empty here is not just a comment mismatch: it forces every caller down the "look the inner table up first, authorize later" path. If an inner target has been dropped, timeSeriesSamples() / timeSeriesTags() / timeSeriesMetrics() and timeSeriesSelector() now return UNKNOWN_TABLE to a user who only has privileges on the outer TimeSeries table, which still leaks target existence.

We need a pre-lookup identity for inner targets as well (derived .inner_id.*, plus the legacy .inner.data.* samples fallback in Ordinary databases), otherwise the new access check remains incomplete for inner tables.

/// Authorized here rather than where this storage is created, so that a persistent table built over this
/// table function is authorized on every read, with the reader's own grants. Before the table is
/// resolved, so that an unauthorized reader learns nothing about it.
checkAccessToTimeSeriesTable(config.time_series_storage_id, context, AccessType::SELECT);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still only authorizes the outer TimeSeries table. A few lines later readImpl() calls getTargetTableID() / getTargetTable() for the samples and tags targets before any SELECT check on those targets, so SELECT ... FROM timeSeriesSelector(...) still leaks UNKNOWN_TABLE when one of the hidden targets has been dropped.

The new tests only cover the DESCRIBE path (ts_tags_gone). The read path for timeSeriesSelector() and, transitively, prometheusQuery() / prometheusQueryRange() remains open. We need the same pre-lookup target authorization here that getConfiguration() now does for SHOW COLUMNS, but with the exact columns the generated queries require so the column-scoped grants from 05137 keep working.

@clickhouse-gh clickhouse-gh Bot added the comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... label Sep 10, 2026
@clickhouse-gh

clickhouse-gh Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing fcc113fe9 with master c7a9fe7c9 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

6 translation units recompiled, 4 s compile time in total, 6 of them have a recent master baseline.

Job report

@vitlibar

Copy link
Copy Markdown
Member

Checking access rights for TimeSeries needs to be fixed manually, I'll do that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-promql PromQL / time-series subsystem: TimeSeries storage engine, PromQL parser, PromQL-to-SQL converter... pr-not-for-changelog This PR should not be mentioned in the changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants