Skip to content

Commit e99dfcd

Browse files
committed
Move accessor permission check to InterpreterFactory::get, make the denied query won't insert into the query_log
1 parent 9286571 commit e99dfcd

File tree

4 files changed

+22
-34
lines changed

4 files changed

+22
-34
lines changed

src/query/service/src/interpreters/access/accessor.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ impl Accessor {
4242
Accessor { accessors }
4343
}
4444

45-
pub fn check(&self, new_plan: &Option<Plan>, plan: &PlanNode) -> Result<()> {
45+
pub fn check(&self, plan: &PlanNode) -> Result<()> {
4646
for accessor in self.accessors.values() {
47-
match new_plan {
48-
None => {
49-
accessor.check(plan)?;
50-
}
51-
Some(new) => {
52-
accessor.check_new(new)?;
53-
}
54-
}
47+
accessor.check(plan)?;
48+
}
49+
Ok(())
50+
}
51+
52+
pub fn check_new(&self, plan: &Plan) -> Result<()> {
53+
for accessor in self.accessors.values() {
54+
accessor.check_new(plan)?;
5555
}
5656
Ok(())
5757
}

src/query/service/src/interpreters/interpreter_factory.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use common_exception::ErrorCode;
1818
use common_exception::Result;
1919
use common_legacy_planners::PlanNode;
2020

21+
use crate::interpreters::access::Accessor;
2122
use crate::interpreters::DeleteInterpreter;
2223
use crate::interpreters::EmptyInterpreter;
2324
use crate::interpreters::ExplainInterpreter;
@@ -35,10 +36,14 @@ pub struct InterpreterFactory;
3536
/// Such as: SelectPlan -> SelectInterpreter, ExplainPlan -> ExplainInterpreter, ...
3637
impl InterpreterFactory {
3738
pub fn get(ctx: Arc<QueryContext>, plan: PlanNode) -> Result<Arc<dyn Interpreter>> {
39+
// Check the access permission.
40+
let access_checker = Accessor::create(ctx.clone());
41+
access_checker.check(&plan)?;
42+
3843
let inner = Self::create_interpreter(ctx.clone(), &plan)?;
3944
let query_kind = plan.name().to_string();
4045
Ok(Arc::new(InterceptorInterpreter::create(
41-
ctx, inner, plan, None, query_kind,
46+
ctx, inner, query_kind,
4247
)))
4348
}
4449

src/query/service/src/interpreters/interpreter_factory_interceptor.rs

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ use std::time::SystemTime;
1717

1818
use common_datavalues::DataSchemaRef;
1919
use common_exception::Result;
20-
use common_legacy_planners::PlanNode;
2120
use common_streams::ErrorStream;
2221
use common_streams::ProgressStream;
2322
use common_streams::SendableDataBlockStream;
2423
use parking_lot::Mutex;
2524

26-
use crate::interpreters::access::Accessor;
2725
use crate::interpreters::Interpreter;
2826
use crate::interpreters::InterpreterPtr;
2927
use crate::interpreters::InterpreterQueryLog;
@@ -32,34 +30,21 @@ use crate::pipelines::SourcePipeBuilder;
3230
use crate::sessions::QueryContext;
3331
use crate::sessions::SessionManager;
3432
use crate::sessions::TableContext;
35-
use crate::sql::plans::Plan;
3633

3734
pub struct InterceptorInterpreter {
3835
ctx: Arc<QueryContext>,
39-
plan: PlanNode,
40-
new_plan: Option<Plan>,
4136
inner: InterpreterPtr,
4237
query_log: InterpreterQueryLog,
4338
source_pipe_builder: Mutex<Option<SourcePipeBuilder>>,
44-
accessor_checker: Accessor,
4539
}
4640

4741
impl InterceptorInterpreter {
48-
pub fn create(
49-
ctx: Arc<QueryContext>,
50-
inner: InterpreterPtr,
51-
plan: PlanNode,
52-
new_plan: Option<Plan>,
53-
query_kind: String,
54-
) -> Self {
42+
pub fn create(ctx: Arc<QueryContext>, inner: InterpreterPtr, query_kind: String) -> Self {
5543
InterceptorInterpreter {
5644
ctx: ctx.clone(),
57-
plan,
58-
new_plan,
5945
inner,
60-
query_log: InterpreterQueryLog::create(ctx.clone(), query_kind),
46+
query_log: InterpreterQueryLog::create(ctx, query_kind),
6147
source_pipe_builder: Mutex::new(None),
62-
accessor_checker: Accessor::create(ctx),
6348
}
6449
}
6550
}
@@ -75,9 +60,6 @@ impl Interpreter for InterceptorInterpreter {
7560
}
7661

7762
async fn execute(&self, ctx: Arc<QueryContext>) -> Result<SendableDataBlockStream> {
78-
// Access check.
79-
self.accessor_checker.check(&self.new_plan, &self.plan)?;
80-
8163
let _ = self
8264
.inner
8365
.set_source_pipe_builder((*self.source_pipe_builder.lock()).clone());

src/query/service/src/interpreters/interpreter_factory_v2.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,11 @@
1515
use std::sync::Arc;
1616

1717
use common_exception::Result;
18-
use common_legacy_planners::EmptyPlan;
19-
use common_legacy_planners::PlanNode;
2018

2119
use super::interpreter_share_desc::DescShareInterpreter;
2220
use super::interpreter_user_stage_drop::DropUserStageInterpreter;
2321
use super::*;
22+
use crate::interpreters::access::Accessor;
2423
use crate::interpreters::interpreter_copy_v2::CopyInterpreterV2;
2524
use crate::interpreters::interpreter_presign::PresignInterpreter;
2625
use crate::interpreters::interpreter_table_create_v2::CreateTableInterpreterV2;
@@ -44,13 +43,15 @@ impl InterpreterFactoryV2 {
4443
}
4544

4645
pub fn get(ctx: Arc<QueryContext>, plan: &Plan) -> Result<InterpreterPtr> {
46+
// Check the access permission.
47+
let access_checker = Accessor::create(ctx.clone());
48+
access_checker.check_new(plan)?;
49+
4750
let inner = InterpreterFactoryV2::create_interpreter(ctx.clone(), plan)?;
4851

4952
Ok(Arc::new(InterceptorInterpreter::create(
5053
ctx,
5154
inner,
52-
PlanNode::Empty(EmptyPlan::create()),
53-
Some(plan.clone()),
5455
plan.to_string(),
5556
)))
5657
}

0 commit comments

Comments
 (0)