JingsongLi commented on code in PR #758:
URL: https://github.com/apache/paimon-rust/pull/758#discussion_r3893614229
##########
crates/paimon/src/table/mod.rs:
##########
@@ -315,6 +321,97 @@ impl Table {
}
}
+ /// Whether the server says this table is `query-auth.enabled` right now:
the
+ /// handle's schema is a snapshot, and a cached `false` would skip the
check.
+ pub(crate) async fn server_query_auth_enabled(&self) -> Result<bool> {
Review Comment:
[P1] Apply the live server check to direct search APIs too
This helper closes the stale-handle gap for `TableScan`, but the direct
scored/search entry points still call only
`CoreOptions::ensure_read_authorized()` on the schema cached when the handle
was loaded. In particular, `BatchVectorSearchBuilder::execute` reads the
snapshot/index manifest directly, and `VectorSearchBuilder::execute_scored`,
`FullTextSearchBuilder::execute_scored`, and
`HybridSearchBuilder::execute_scored` reach those direct paths without an
authorized `TableScan`.
Therefore: load a REST table while query auth is false, enable restricted
query auth on the server, then reuse the handle for one of these searches. The
cached guard passes and row IDs/scores derived from protected data are returned
without the auth exchange. Please route every out-of-band search entry through
this async server-state check and reject when query auth is enabled (these
paths cannot apply masking/filtering), with stale-handle regressions analogous
to the new scan test.
##########
crates/paimon/src/table/query_auth.rs:
##########
@@ -0,0 +1,320 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+//! What the REST server authorized a user to read from one table.
+
+use crate::api::AuthTableQueryResponse;
+
+/// The server's answer for one user on one table, kept unparsed.
+///
+/// `session` pins it to the handle that asked: `to_arrow` is public and the
+/// response names neither table nor principal. Java binds nothing. Routing
+/// options are unbound on purpose — sound only while unrestricted grants
+/// authorize.
+#[derive(Debug, PartialEq)]
+pub(crate) struct QueryAuthGrant {
+ response: AuthTableQueryResponse,
+ session: u64,
+}
+
+impl QueryAuthGrant {
+ pub(crate) fn new(response: AuthTableQueryResponse, session: u64) -> Self {
+ Self { response, session }
+ }
+
+ /// The only case this client can serve.
+ pub(crate) fn is_unrestricted(&self) -> bool {
+ self.response.is_unrestricted()
+ }
+
+ /// Travelled and branch views read a schema the server did not rule on.
+ /// Everything else follows from the session, which only the catalog mints.
+ pub(crate) fn matches_table(&self, table: &super::Table) -> bool {
+ !table.is_time_traveled()
+ && !table.is_branch_reference()
+ && table.query_auth_session() == Some(self.session)
+ }
+}
+
+/// `value_stats` and `write_cols` are public on every split, and an older file
+/// can name a since-dropped column the server never ruled on. Refused rather
+/// than scrubbed: rewriting encoded stats is how bounds get mismatched.
+pub(crate) async fn reject_unauthorized_stats(
+ plan: &super::Plan,
+ current: &crate::spec::TableSchema,
+ schemas: &super::schema_manager::SchemaManager,
+) -> crate::Result<()> {
+ let refuse = |column: &str| {
+ Err(unsupported(&format!(
+ "a data file still carries statistics for '{column}', which the
current schema — the \
+ one the server authorized — does not have"
+ )))
+ };
+ let named = |name: &String| current.fields().iter().any(|f| f.name() ==
name);
+ let mut checked = std::collections::HashSet::new();
+ for split in plan.splits() {
+ for file in split.data_files() {
+ for column in file
+ .value_stats_cols
+ .iter()
+ .chain(file.write_cols.iter())
+ .flatten()
+ {
+ if !named(column) {
+ return refuse(column);
+ }
+ }
+ // The file's own schema is the authority: a name can be dropped
and
+ // re-added under a new id, and the lists may be absent entirely.
+ if file.schema_id == current.id() ||
!checked.insert(file.schema_id) {
+ continue;
+ }
+ let older = schemas.schema(file.schema_id).await?;
+ if let Some(gone) = older.fields().iter().find(|f| {
+ !current
+ .fields()
+ .iter()
+ .any(|c| c.id() == f.id() && c.name() == f.name())
+ }) {
+ return refuse(gone.name());
+ }
+ }
+ }
+ Ok(())
+}
+
+/// A refusal naming the option, so callers never match on prose.
+pub(crate) fn unsupported(reason: &str) -> crate::Error {
+ crate::Error::Unsupported {
+ message: format!(
+ "reading a table with 'query-auth.enabled' = true is not
supported: {reason}"
+ ),
+ }
+}
+
+/// Column permissions cover real schema fields, so the server can neither
grant
+/// nor refuse `_ROW_ID` and friends.
+pub(crate) fn reject_system_columns<'a>(
+ names: impl IntoIterator<Item = &'a str>,
+) -> crate::Result<()> {
+ for name in names {
+ if crate::spec::is_reserved_system_field_name(name) {
+ return Err(unsupported(&format!(
+ "the system column '{name}' is not one the server can
authorize: column \
+ permissions are granted over table columns"
+ )));
+ }
+ }
+ Ok(())
+}
+
+/// The read resolves older files by field id, so a non-canonical `(id, name)`
+/// pair reads as something no grant covered. System fields have no entry.
+pub(crate) fn reject_noncanonical_fields(
+ read_type: &[crate::spec::DataField],
+ schema_fields: &[crate::spec::DataField],
+) -> crate::Result<()> {
+ for field in read_type {
+ if crate::spec::is_reserved_system_field_name(field.name()) {
+ continue;
+ }
+ let canonical = schema_fields
+ .iter()
+ .any(|f| f.id() == field.id() && f.name() == field.name());
Review Comment:
[P1] Validate the full nested field shape, not only the top-level pair
Both this guard and the old-file check above compare only the top-level
`(id, name)`. That leaves a concrete disclosure path after nested schema
evolution: suppose the authorized current schema contains `profile
ROW<public>`, while a live older file has the same top-level field id/name but
`profile ROW<public, secret>`. A caller can use the public
`ReadBuilder::with_read_type` with that old Row type; this check passes, and
`data_file_reader::prune_data_type` recursively selects the requested old child
by id, so `profile.secret` is decoded even though it is absent from the
schema/column set the server authorized. The planning check at lines 87-92 also
passes the old file for the same reason.
Please validate canonical fields recursively (including Row children and
nested Array/Map/Multiset element types, allowing only explicitly safe
evolution), and make the old-file containment check recursive too. An
end-to-end test with a dropped nested field and a crafted old read type should
be rejected.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]