From eb22c33a7dd20e88a2e615176cfab7354862178f Mon Sep 17 00:00:00 2001 From: Quentin Gliech Date: Fri, 3 Jun 2022 12:46:05 +0200 Subject: [PATCH] Remove the login policy (since it is not implemented yet) --- crates/cli/src/commands/server.rs | 1 - crates/config/src/sections/policy.rs | 9 --------- crates/policy/policies/Makefile | 4 ++-- crates/policy/policies/login.rego | 3 --- crates/policy/src/lib.rs | 24 +----------------------- 5 files changed, 3 insertions(+), 38 deletions(-) delete mode 100644 crates/policy/policies/login.rego diff --git a/crates/cli/src/commands/server.rs b/crates/cli/src/commands/server.rs index 3a9dc1ae..b998713a 100644 --- a/crates/cli/src/commands/server.rs +++ b/crates/cli/src/commands/server.rs @@ -194,7 +194,6 @@ impl Options { let policy_factory = PolicyFactory::load( &mut policy, config.policy.data.clone().unwrap_or_default(), - config.policy.login_entrypoint.clone(), config.policy.register_entrypoint.clone(), config.policy.client_registration_entrypoint.clone(), ) diff --git a/crates/config/src/sections/policy.rs b/crates/config/src/sections/policy.rs index 5bdd6a0d..49cf6bb5 100644 --- a/crates/config/src/sections/policy.rs +++ b/crates/config/src/sections/policy.rs @@ -25,10 +25,6 @@ fn default_client_registration_endpoint() -> String { "client_registration/violation".to_string() } -fn default_login_endpoint() -> String { - "login/violation".to_string() -} - fn default_register_endpoint() -> String { "register/violation".to_string() } @@ -45,10 +41,6 @@ pub struct PolicyConfig { #[serde(default = "default_client_registration_endpoint")] pub client_registration_entrypoint: String, - /// Entrypoint to use when evaluating user logins - #[serde(default = "default_login_endpoint")] - pub login_entrypoint: String, - /// Entrypoint to use when evaluating user registrations #[serde(default = "default_register_endpoint")] pub register_entrypoint: String, @@ -63,7 +55,6 @@ impl Default for PolicyConfig { Self { wasm_module: None, client_registration_entrypoint: default_client_registration_endpoint(), - login_entrypoint: default_login_endpoint(), register_entrypoint: default_register_endpoint(), data: None, } diff --git a/crates/policy/policies/Makefile b/crates/policy/policies/Makefile index 199cc3a6..7aebbfe1 100644 --- a/crates/policy/policies/Makefile +++ b/crates/policy/policies/Makefile @@ -9,8 +9,8 @@ else OPA_RW := docker run -v $(shell pwd):/policies -w /policies --rm docker.io/openpolicyagent/opa:0.40.0 endif -policy.wasm: client_registration.rego login.rego register.rego - $(OPA_RW) build -t wasm -e "client_registration/violation" -e "login/violation" -e "register/violation" $^ +policy.wasm: client_registration.rego register.rego + $(OPA_RW) build -t wasm -e "client_registration/violation" -e "register/violation" $^ tar xzf bundle.tar.gz /policy.wasm $(RM) bundle.tar.gz touch $@ diff --git a/crates/policy/policies/login.rego b/crates/policy/policies/login.rego deleted file mode 100644 index 94dac6df..00000000 --- a/crates/policy/policies/login.rego +++ /dev/null @@ -1,3 +0,0 @@ -package login - -violation := [] diff --git a/crates/policy/src/lib.rs b/crates/policy/src/lib.rs index 86835622..fd2eb36d 100644 --- a/crates/policy/src/lib.rs +++ b/crates/policy/src/lib.rs @@ -50,7 +50,6 @@ pub struct PolicyFactory { engine: Engine, module: Module, data: serde_json::Value, - login_entrypoint: String, register_entrypoint: String, client_registration_entrypoint: String, } @@ -59,7 +58,6 @@ impl PolicyFactory { pub async fn load( mut source: impl AsyncRead + std::marker::Unpin, data: serde_json::Value, - login_entrypoint: String, register_entrypoint: String, client_registration_entrypoint: String, ) -> Result { @@ -84,7 +82,6 @@ impl PolicyFactory { engine, module, data, - login_entrypoint, register_entrypoint, client_registration_entrypoint, }; @@ -106,8 +103,8 @@ impl PolicyFactory { let entrypoints = runtime.entrypoints(); for e in [ - self.login_entrypoint.as_str(), self.register_entrypoint.as_str(), + self.client_registration_entrypoint.as_str(), ] { if !entrypoints.contains(e) { bail!("missing entrypoint {e}") @@ -119,7 +116,6 @@ impl PolicyFactory { Ok(Policy { store, instance, - login_entrypoint: self.login_entrypoint.clone(), register_entrypoint: self.register_entrypoint.clone(), client_registration_entrypoint: self.client_registration_entrypoint.clone(), }) @@ -148,28 +144,11 @@ impl EvaluationResult { pub struct Policy { store: Store<()>, instance: opa_wasm::Policy, - login_entrypoint: String, register_entrypoint: String, client_registration_entrypoint: String, } impl Policy { - #[tracing::instrument] - pub async fn evaluate_login( - &mut self, - user: &mas_data_model::User<()>, - ) -> Result { - let user = serde_json::to_value(user)?; - let input = serde_json::json!({ "user": user }); - - let [res]: [EvaluationResult; 1] = self - .instance - .evaluate(&mut self.store, &self.login_entrypoint, &input) - .await?; - - Ok(res) - } - #[tracing::instrument] pub async fn evaluate_register( &mut self, @@ -226,7 +205,6 @@ mod tests { "allowed_domains": ["element.io", "*.element.io"], "banned_domains": ["staging.element.io"], }), - "login/violation".to_string(), "register/violation".to_string(), "client_registration/violation".to_string(), )