Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix index create privilege check and ensure consistency between the owner and its associated table #19252

Merged
merged 2 commits into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions src/frontend/src/handler/create_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ use either::Either;
use fixedbitset::FixedBitSet;
use itertools::Itertools;
use pgwire::pg_response::{PgResponse, StatementType};
use risingwave_common::acl::AclMode;
use risingwave_common::catalog::{IndexId, TableDesc, TableId};
use risingwave_common::util::sort_util::{ColumnOrder, OrderType};
use risingwave_pb::catalog::{PbIndex, PbIndexColumnProperties, PbStreamJobStatus, PbTable};
use risingwave_pb::user::grant_privilege::Object;
use risingwave_sqlparser::ast;
use risingwave_sqlparser::ast::{Ident, ObjectName, OrderByExpr};

Expand All @@ -34,7 +32,6 @@ use crate::binder::Binder;
use crate::catalog::root_catalog::SchemaPath;
use crate::error::{ErrorCode, Result};
use crate::expr::{Expr, ExprImpl, ExprRewriter, InputRef};
use crate::handler::privilege::ObjectCheckItem;
use crate::handler::HandlerArgs;
use crate::optimizer::plan_expr_rewriter::ConstEvalRewriter;
use crate::optimizer::plan_node::{Explain, LogicalProject, LogicalScan, StreamMaterialize};
Expand Down Expand Up @@ -83,11 +80,11 @@ pub(crate) fn gen_create_index_plan(
);
}

session.check_privileges(&[ObjectCheckItem::new(
table.owner,
AclMode::Select,
Object::TableId(table.id.table_id),
)])?;
if !session.is_super_user() && session.user_id() != table.owner {
return Err(
ErrorCode::PermissionDenied(format!("must be owner of table {}", table.name)).into(),
);
}

let mut binder = Binder::new_for_stream(session);
binder.bind_table(Some(&schema_name), &table_name, None)?;
Expand Down Expand Up @@ -202,7 +199,7 @@ pub(crate) fn gen_create_index_plan(
&index_columns_ordered_expr,
&include_columns_expr,
// We use the first index column as distributed key by default if users
// haven't specify the distributed by columns.
// haven't specified the distributed by columns.
if distributed_columns_expr.is_empty() {
1
} else {
Expand All @@ -221,7 +218,7 @@ pub(crate) fn gen_create_index_plan(
index_table_prost.retention_seconds = table.retention_seconds;
}

index_table_prost.owner = session.user_id();
index_table_prost.owner = table.owner;
index_table_prost.dependent_relations = vec![table.id.table_id];

let index_columns_len = index_columns_ordered_expr.len() as u32;
Expand Down
Loading