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 1 commit
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
15 changes: 8 additions & 7 deletions src/frontend/src/handler/create_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ 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(),
)
.into());
}

let mut binder = Binder::new_for_stream(session);
binder.bind_table(Some(&schema_name), &table_name, None)?;
Expand Down Expand Up @@ -202,7 +203,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 +222,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