-
Notifications
You must be signed in to change notification settings - Fork 77
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
feat(jans-cedarling): Policy Store: Parse Schema and Policies #9575
Conversation
…coding from json. Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
…eserialize cedar schema from json) Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
…anOnePolicy Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
DryRun Security SummaryThe pull request focuses on enhancing the Cedarling application, a Rust-based local authorization service, by improving the handling of policy management and configuration, including the introduction of a new Expand for full summarySummary: The code changes in this pull request are focused on enhancing the Cedarling application, a Rust-based local authorization service, by improving the handling of policy management and configuration. The key changes include:
From an application security perspective, the changes appear to be focused on improving the security and maintainability of the Cedarling application's policy management and authorization functionality. The introduction of the However, it's important to review the implementation details of the new modules and components to ensure that they are properly designed and implemented from a security perspective. This includes verifying input validation, secure data storage, and the overall integrity of the policy evaluation and authorization processes. Files Changed:
Code AnalysisWe ran Riskiness🟢 Risk threshold not exceeded. |
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
/// Error cases for loading policy | ||
#[derive(Debug, thiserror::Error)] | ||
pub enum ErrorLoadPolicyStore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than creating different enums for showing error messages, can we just make a single enum for all error messages inside \jans-cedarling\cedarling\src\models\enum\error
.
for Example:
pub enum CedarlingApplicationError {
#[error("{0}")]
LoadPolicyStoreJsonParseError(#[from] serde_json::Error),
#[error("store policy is empty")]
LoadPolicyStoreWithEmptyPolicy,
#[error("the `store_key` is not specified and the count on policies more than 1")]
LoadPolicyStoreMoreThanOnePolicy,
#[error("could not found policy by id: {0}")]
LoadPolicyStorePolicyNotFound(String),
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the idea to return the error struct in functions that cover all possible error cases for only the current situation. Because it will be easier to maintain when application grows.
And If we have somethinglike CedarlingApplicationError
It will have all possible errors for all application.
And when we will be wanted to handle the error cases with match statement, it will be hard to understand what exactly cases current function returns. Because CedarlingApplicationError
have all possible cases in the application.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And If we have something like CedarlingApplicationError
It will have all possible errors for all application.
This is what we practise in most of applications. We do not clutter our project with multiple Enums for error messages.
And when we will be wanted to handle the error cases with match statement, it will be hard to understand what exactly cases current function returns. Because CedarlingApplicationError have all possible cases in the application.
The naming convention of enum items should be sufficient of make its purpose clear. We don't need to make multiple error enums for this.
And I could see ErrorLoadPolicyStore
in cedar_schem.rs and policy_store.rs. Code duplication does not make sense.
|
||
use base64::prelude::*; | ||
|
||
const MSG_UNABLE_DECODE_SCHEMA_BASE64: &str = "unable to decode cedar policy schema base64"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These errors should be handled using the CedarlingApplicationError
enum . ( as discussed in #9575 (comment))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use it in the function parse_cedar_schema
. It is wrapper to seamless deserialize cedar_policy::Schema
from out JSON policy store.
Here how it is used in the macros:
#[derive(Debug, serde::Deserialize)]
pub struct PolicyStore {
#[serde(deserialize_with = "parse_cedar_schema")]
pub schema: cedar_policy::Schema,
}
In function, we can't return our custom type. Because we return generic of serde::Deserializer
pub(crate) fn parse_cedar_schema<'de, D>(deserializer: D) -> Result<cedar_policy::Schema, D::Error>
where
D: serde::Deserializer<'de>,
{
...
Here is link with documentation about custom error handling in the serde
.
So to return error from custom Deserializer
we need to use implementation
impl de::Error for Error {
fn custom<T: Display>(msg: T) -> Self {
Error::Message(msg.to_string())
}
}
Where error is casting to the string.
And actually it was made with
serde::de::Error::custom(format!("{MSG_UNABLE_DECODE_SCHEMA_BASE64}: {}", err,))
and it was cowered by:
pub enum ErrorLoadPolicyStore {
#[error("{0}")]
JsonParce(#[from] serde_json::Error),
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just saying that we should maintain uniformity of code everywhere. If we are taking the error messages as enum items somewhere then let's make it a practice everywhere. and we can easily convert an enum to a string. ref: https://stackoverflow.com/questions/32710187/how-do-i-get-an-enum-as-a-string
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, we need to create struct with RAW data and manually call a function to decode each field.
Which approach do you think is better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as discussed, we can do something like the below to solve serde
error handling
fn custom_deserialization_error(err: base64::DecodeError, errorEnum: ErrorLoadPolicyStore) -> de::value::Error {
let message = errorEnum.to_string(); // Using the enum variant
serde::de::Error::custom(format!("{}: {}", message, err))
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed and decided to stay with const messages approach
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
10e79c1
to
e724090
Compare
Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cedarling should not init if the schema is invalid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
requested changes have been made in #9584
* feat(jans-cedarling): add PolicyStore and field schema. Also added decoding from json. Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * test(jans-cedarling): add unit tests to check `parse_cedar_schema` (deserialize cedar schema from json) Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add docs for PolicyStore Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * feat(jans-cedarling): add loading policy store based on config Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * feat(jans-cedarling): add loading policy store to Cedarling Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): rename LogType to LogTypeConfig Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): fix `log_init` example after updating config Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add allow(dead_code) on schema Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add copyright notice Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add README to init module Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add README to authz module Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): update message in ErrorLoadPolicyStore::MoreThanOnePolicy Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add comments to Cedarling::new Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): remove unnecessary code Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): in README removed `Cedarling bindings` section Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): move position of PolicyStoreMap to be first Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): refactor, move errors messages to the enum Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> --------- Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com>
* feat(jans-cedarling): add PolicyStore and field schema. Also added decoding from json. Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * test(jans-cedarling): add unit tests to check `parse_cedar_schema` (deserialize cedar schema from json) Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add docs for PolicyStore Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * feat(jans-cedarling): add loading policy store based on config Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * feat(jans-cedarling): add loading policy store to Cedarling Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): rename LogType to LogTypeConfig Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): fix `log_init` example after updating config Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add allow(dead_code) on schema Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add copyright notice Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add README to init module Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add README to authz module Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): update message in ErrorLoadPolicyStore::MoreThanOnePolicy Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add comments to Cedarling::new Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): remove unnecessary code Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): in README removed `Cedarling bindings` section Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): move position of PolicyStoreMap to be first Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): refactor, move errors messages to the enum Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> --------- Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com> Former-commit-id: 66c5159
* feat(jans-cedarling): add PolicyStore and field schema. Also added decoding from json. Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * test(jans-cedarling): add unit tests to check `parse_cedar_schema` (deserialize cedar schema from json) Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add docs for PolicyStore Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * feat(jans-cedarling): add loading policy store based on config Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * feat(jans-cedarling): add loading policy store to Cedarling Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): rename LogType to LogTypeConfig Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): fix `log_init` example after updating config Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add allow(dead_code) on schema Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add copyright notice Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add README to init module Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add README to authz module Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): update message in ErrorLoadPolicyStore::MoreThanOnePolicy Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add comments to Cedarling::new Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): remove unnecessary code Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): in README removed `Cedarling bindings` section Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): move position of PolicyStoreMap to be first Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): refactor, move errors messages to the enum Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> --------- Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com>
* feat(jans-cedarling): add PolicyStore and field schema. Also added decoding from json. Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * test(jans-cedarling): add unit tests to check `parse_cedar_schema` (deserialize cedar schema from json) Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add docs for PolicyStore Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * feat(jans-cedarling): add loading policy store based on config Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * feat(jans-cedarling): add loading policy store to Cedarling Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): rename LogType to LogTypeConfig Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): fix `log_init` example after updating config Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add allow(dead_code) on schema Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add copyright notice Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add README to init module Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): add README to authz module Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): update message in ErrorLoadPolicyStore::MoreThanOnePolicy Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): add comments to Cedarling::new Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): remove unnecessary code Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * docs(jans-cedarling): in README removed `Cedarling bindings` section Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): move position of PolicyStoreMap to be first Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> * chore(jans-cedarling): refactor, move errors messages to the enum Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> --------- Signed-off-by: Oleh Bohzok <olehbozhok@gmail.com> Co-authored-by: Mohammad Abudayyeh <47318409+moabu@users.noreply.github.com>
Prepare
Description
Target issue
link
closes #9568
Implementation Details
Added parsing a policy store with only schema key.
Currently, support loading only from memory
Test and Document the changes
Please check the below before submitting your PR. The PR will not be merged if there are no commits that start with
docs:
to indicate documentation changes or if the below checklist is not selected.