Repository navigation
Conversation
A row policy created on a `TimeSeries` table applied only to `SELECT` queries on that table. PromQL reads (`prometheusQuery`, `prometheusQueryRange`, the `promql` dialect, the Prometheus HTTP API and remote read) select time series from the inner tags table directly, and the planner attaches a row policy only to the storage it scans, so a tenant restricted to `tags['tenant'] = 'a'` could read every tenant. The inner tags table now inherits the `SELECT` row policies of its `TimeSeries` table. `collectRowPolicyFilters` resolves the owner of an inner tags table with `StorageTimeSeries::tryGetOwnerOfInnerTagsTable` (by UUID for `.inner_id.tags.<uuid>`, by name for `.inner.tags.<name>`) and adds the owner's policies to the filter. The inner tags table stores every tag of every series in its `tags` Map, including `__name__` and the tags promoted with `tags_to_columns`, so the policy expression applies to it as written and the generated SQL does not change. The read of the `TimeSeries` table itself marks its context with `is_time_series_inner_read_by_owner`, so a plain `SELECT` evaluates the policy once on the outer read and not again on the inner scan. A policy over a column the inner tags table lacks, for example `samples`, keeps working for `SELECT` and fails a PromQL read with `UNKNOWN_IDENTIFIER`. The `TimeSeries` engine documentation gains a Row policies section.
…policy The `/api/v1/metadata` endpoint reads the inner metrics table, which has no tags, so a row policy on the `TimeSeries` table could not filter it and every metric family was returned. When the user has an effective `SELECT` row policy on the `TimeSeries` table, `getMetadata` adds a condition which keeps only the metric families with at least one metric name (the family plus the suffixes of its type) among the metric names of the inner tags table. The inner tags table inherits the policy, so that subquery sees only the visible series.
…er tags table The test creates a plain and a promoted `TimeSeries` table, a restricted user, and a `SELECT` row policy on the `TimeSeries` table. It checks that the policy filters `SELECT` from the table, `timeSeriesTags`, the inner tags table itself, `prometheusQuery`, `prometheusQueryRange` and the `promql` dialect, that `timeSeriesSamples` stays unfiltered, that the inherited policy is recorded in `used_row_policies`, that a policy on the inner tags table combines with the inherited one, and that a policy on a column the inner tags table lacks keeps working for `SELECT` but fails the PromQL read with `UNKNOWN_IDENTIFIER`.
…s row policy The stateless server configuration exposes no Prometheus API handlers, so the HTTP paths need an integration test. With a `SELECT` row policy on the `TimeSeries` table, the test checks `/api/v1/query`, `/api/v1/query_range`, `/api/v1/series`, `/api/v1/labels`, `/api/v1/label/<name>/values`, `/api/v1/metadata` and remote read for a restricted user and for the default user, and checks that a policy on the `samples` column fails a PromQL query with a `bad_data` error. The remote read helpers accept an `auth` argument for that.
d03877b to
6b9cbd3
Compare
|
Workflow [PR], commit [1945467] Summary: ❌
AI ReviewSummaryThe PR applies Missing context / blind spots
Findings❌ Blockers
Tests
Final VerdictStatus: ❌ Block. Preserve policy semantics for map subcolumns and make policy rewriting/validation respect expression scopes, with the focused regressions above. |
| /// table apply to it as they are. The TimeSeries table's own read already evaluated them on its context. | ||
| if (!context->isTimeSeriesInnerReadByOwner()) | ||
| if (auto owner = StorageTimeSeries::tryGetOwnerOfInnerTagsTable(storage_id, context)) | ||
| collectRowPolicyFilters(*owner, context, result, visited); |
There was a problem hiding this comment.
❌ Blocker: evaluate the inherited policy against reconstructed tags.
The stored inner tags map does not always have the same contents as the outer column. Existing tables written by older versions omit __name__ and tags promoted with tags_to_columns; makeExpressionForOuterTags deliberately reconstructs them from the dedicated columns. Applying the outer expression directly to the stored map changes its result: for an old row with dedicated tenant = 'b' and no tenant key in tags, tags['tenant'] != 'b' is false on the outer table but true here ('' != 'b'). PromQL and HTTP reads therefore expose a series excluded by the policy.
Reconstruct the outer tag values before evaluating the inherited filter, or translate the filter with equivalent semantics. Add a regression using the older partial-map representation; inserting fresh rows into a promoted table does not exercise it.
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes9 object files changed (+60.34 KiB total), 0 added.
711 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Slowest function optimization changes (ThinLTO)Median per-function time ratio to the master baseline:
Compile time of recompiled translation units11 translation units recompiled, 37 s compile time in total, 11 of them have a recent master baseline. Median compile-time ratio to the baselines is ×1.11 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio. |
…w-policy-propagation # Conflicts: # src/Interpreters/Context.cpp # src/Interpreters/Context.h # src/Storages/StorageTimeSeries.cpp # src/Storages/TimeSeries/PrometheusHTTPProtocolAPI.cpp
Translate the TimeSeries SELECT row policy onto tags-target columns and inject it where the storage builds tags-table queries. Remove the pull-side owner lookup and the Context exemption flag.
Filter /api/v1/metadata by the translated tags predicate, refuse timeSeriesTags when the owner has an effective row policy, and document the push-side behavior.
Expect timeSeriesTags to be denied under a policy, keep direct inner tags reads unfiltered, qualify table-function names for parallel replicas, and cover version-9 external tags plus partial stored maps.
StorageMetadataHandle deletes operator-> on temporaries, so store the handle before reading columns.
Validate rewritten policy identifiers against the tags table before injection so names such as samples raise UNKNOWN_IDENTIFIER instead of becoming correlated outer references. Update the samples-count expectation for the version-11 one-row-per-series layout.
Keep the Prometheus HTTP error text aligned with the analyzer wording the row-policy integration test expects.
|
|
||
| if (const auto * identifier = node->as<ASTIdentifier>()) | ||
| { | ||
| if (!identifier->compound() && !tags_columns.has(identifier->shortName())) |
There was a problem hiding this comment.
A valid tags-only policy such as USING arrayExists(x -> x = 'a', [tags['tenant']]) works for SELECT from the TimeSeries table, but every PromQL read now throws UNKNOWN_IDENTIFIER for x. This traversal visits both the lambda parameter declaration and its uses and requires them to be tags-table columns. It likewise checks identifiers local to a policy's subquery against the wrong table.
Make the validation scope-aware, or validate resolved column references instead of every ASTIdentifier. The rewrite also needs to preserve lambda bindings when a parameter is named tags. Please add a stateless case comparing plain SELECT and prometheusQuery for a lambda policy, while retaining the existing rejection of a free samples reference.
PromQL Compliance ReportBaseline: S3 master
Extended support (upstream engine tests): native-histogram exclusions: 149; excluded assertions: 248; upstream Note: Prometheus compliance score is unchanged vs baseline. |
A row policy on a
TimeSeriestable only filtered plainSELECTqueries. PromQL reads (prometheusQuery,prometheusQueryRange, thepromqldialect, the Prometheus HTTP API, remote read) read the tags target directly, where no policy applied. A tenant limited totags['x_org_id'] = 'org-a'could therefore read every tenant's series.The
TimeSeriestable now translates its ownSELECTrow policy into a predicate over the tags target and adds that predicate to every tags-table read it generates. The reads covered are the PromQL functions, thepromqldialect, the HTTP query, series, labels, and values endpoints, remote read, federate, and the visible-metric-names subquery of/api/v1/metadata. The predicate uses the dedicated tag columns for__name__and fortags_to_columnstags, so a series whose stored map omits those tags is filtered as the outer table filters it.The
timeSeriesTagstable function fails withACCESS_DENIEDwhile a row policy applies to the table. Direct reads of the inner tags table are not filtered by the owner's policy. GrantSELECTon that table only to users who may read every series.A policy that uses a column the tags target lacks, such as
samples, still works for plainSELECT. It fails PromQL reads withUNKNOWN_IDENTIFIERrather than returning unfiltered rows.Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Row policies on a
TimeSeriestable now apply to PromQL queries, the Prometheus HTTP API, and remote read.Workflow [PR]
Sync PR [sync-upstream/pr/127035]