jiacai2050 commented on code in PR #1531:
URL: 
https://github.com/apache/incubator-horaedb/pull/1531#discussion_r1598122387


##########
src/proxy/src/auth/mod.rs:
##########
@@ -0,0 +1,76 @@
+// 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.
+
+//! The proxy module provides features such as forwarding and authentication,
+//! adapts to different protocols.
+
+use std::sync::{Arc, Mutex};
+
+use macros::define_result;
+use serde::{Deserialize, Serialize};
+use snafu::Snafu;
+
+pub mod auth_with_file;
+
+#[derive(Debug, Snafu)]
+pub enum Error {
+    #[snafu(display("Failed to open file, err:{}.", source))]
+    OpenFile { source: std::io::Error },
+
+    #[snafu(display("Failed to read line, err:{}.", source))]
+    ReadLine { source: std::io::Error },
+
+    #[snafu(display("File not existed, file path:{}", path))]
+    FileNotExisted { path: String },
+}
+
+define_result!(Error);
+
+pub type AuthRef = Arc<Mutex<dyn Auth>>;
+
+/// Header of tenant name
+pub const TENANT_HEADER: &str = "x-horaedb-access-tenant";
+/// Header of tenant name
+pub const TENANT_TOKEN_HEADER: &str = "x-horaedb-access-token";
+
+/// Admin tenant name
+pub const ADMIN_TENANT: &str = "admin";
+
+#[derive(Debug, Clone, Deserialize, Serialize, Default)]
+pub struct Config {
+    pub enable: bool,
+    pub auth_type: String,
+    pub source: String,
+}
+
+pub trait Auth: Send + Sync {
+    fn load_credential(&mut self) -> Result<()>;
+    fn identify(&self, tenant: Option<String>, token: Option<String>) -> bool;
+}
+
+#[derive(Default)]
+pub struct AuthBase;
+
+impl Auth for AuthBase {
+    fn load_credential(&mut self) -> Result<()> {

Review Comment:
   Remove default implementation.



##########
src/proxy/src/auth/mod.rs:
##########
@@ -0,0 +1,76 @@
+// 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.
+
+//! The proxy module provides features such as forwarding and authentication,
+//! adapts to different protocols.
+
+use std::sync::{Arc, Mutex};
+
+use macros::define_result;
+use serde::{Deserialize, Serialize};
+use snafu::Snafu;
+
+pub mod auth_with_file;
+
+#[derive(Debug, Snafu)]
+pub enum Error {
+    #[snafu(display("Failed to open file, err:{}.", source))]
+    OpenFile { source: std::io::Error },
+
+    #[snafu(display("Failed to read line, err:{}.", source))]
+    ReadLine { source: std::io::Error },
+
+    #[snafu(display("File not existed, file path:{}", path))]
+    FileNotExisted { path: String },
+}
+
+define_result!(Error);
+
+pub type AuthRef = Arc<Mutex<dyn Auth>>;
+
+/// Header of tenant name
+pub const TENANT_HEADER: &str = "x-horaedb-access-tenant";
+/// Header of tenant name
+pub const TENANT_TOKEN_HEADER: &str = "x-horaedb-access-token";
+
+/// Admin tenant name
+pub const ADMIN_TENANT: &str = "admin";
+
+#[derive(Debug, Clone, Deserialize, Serialize, Default)]
+pub struct Config {
+    pub enable: bool,
+    pub auth_type: String,

Review Comment:
   Define this with an Enum.



##########
src/proxy/src/grpc/prom_query.rs:
##########
@@ -81,6 +81,21 @@ impl Proxy {
             msg: "Missing context",
             code: StatusCode::BAD_REQUEST,
         })?;
+
+        // Check if the tenant is authorized to access the database.
+        if !self

Review Comment:
   Use interceptor to do auth check for gRPC
   
https://github.com/hyperium/tonic/blob/master/examples/src/interceptor/server.rs
   
   For HTTP, see 
https://stackoverflow.com/questions/54988438/how-to-check-the-authorization-header-using-warp



##########
src/proxy/src/auth/mod.rs:
##########
@@ -0,0 +1,76 @@
+// 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.
+
+//! The proxy module provides features such as forwarding and authentication,
+//! adapts to different protocols.
+
+use std::sync::{Arc, Mutex};
+
+use macros::define_result;
+use serde::{Deserialize, Serialize};
+use snafu::Snafu;
+
+pub mod auth_with_file;
+
+#[derive(Debug, Snafu)]
+pub enum Error {
+    #[snafu(display("Failed to open file, err:{}.", source))]
+    OpenFile { source: std::io::Error },
+
+    #[snafu(display("Failed to read line, err:{}.", source))]
+    ReadLine { source: std::io::Error },
+
+    #[snafu(display("File not existed, file path:{}", path))]
+    FileNotExisted { path: String },
+}
+
+define_result!(Error);
+
+pub type AuthRef = Arc<Mutex<dyn Auth>>;
+
+/// Header of tenant name
+pub const TENANT_HEADER: &str = "x-horaedb-access-tenant";
+/// Header of tenant name
+pub const TENANT_TOKEN_HEADER: &str = "x-horaedb-access-token";
+
+/// Admin tenant name
+pub const ADMIN_TENANT: &str = "admin";
+
+#[derive(Debug, Clone, Deserialize, Serialize, Default)]
+pub struct Config {
+    pub enable: bool,
+    pub auth_type: String,
+    pub source: String,
+}
+
+pub trait Auth: Send + Sync {
+    fn load_credential(&mut self) -> Result<()>;
+    fn identify(&self, tenant: Option<String>, token: Option<String>) -> bool;
+}
+
+#[derive(Default)]
+pub struct AuthBase;

Review Comment:
   Authorizator



##########
src/proxy/src/auth/mod.rs:
##########
@@ -0,0 +1,76 @@
+// 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.
+
+//! The proxy module provides features such as forwarding and authentication,
+//! adapts to different protocols.
+
+use std::sync::{Arc, Mutex};
+
+use macros::define_result;
+use serde::{Deserialize, Serialize};
+use snafu::Snafu;
+
+pub mod auth_with_file;
+
+#[derive(Debug, Snafu)]
+pub enum Error {
+    #[snafu(display("Failed to open file, err:{}.", source))]
+    OpenFile { source: std::io::Error },
+
+    #[snafu(display("Failed to read line, err:{}.", source))]
+    ReadLine { source: std::io::Error },
+
+    #[snafu(display("File not existed, file path:{}", path))]
+    FileNotExisted { path: String },
+}
+
+define_result!(Error);
+
+pub type AuthRef = Arc<Mutex<dyn Auth>>;
+
+/// Header of tenant name
+pub const TENANT_HEADER: &str = "x-horaedb-access-tenant";

Review Comment:
   Basic authorization use `authorization` header, we should avoid those custom 
headers.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to