-
Notifications
You must be signed in to change notification settings - Fork 5
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
Predicate on our "well-known attributes" #113
Conversation
This may need to supersede #110 ... stil wip tho |
tl;dr this replaces Of interest if probably this change as well, where the whole |
doc missing. At the very least on README.md. Doc about |
I would change the PR tittle. That goes on the auto-generated release notes. |
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.
review still WIP
Just to be clear about the state of this... now that #110 was merged, while broken, let's not merge this quite yet. |
this change has the first step, but I think the latter step is not required because of how the |
src/data/property.rs
Outdated
["source", "remote_address"] => remote_address(), | ||
// todo, unsure whether to drop the "auth" part here... |
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.
If auth
isn't indeed part of it, which I think it may well not be, then I think it should be added when we store_metadata
... rather than shoving what comes back from Authorino in the metadata struct straight into the KUADRANT_NAMESPACE
...
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.
nice peace of work!
Some minor comments dropped.
Doc is required
} | ||
|
||
impl AttributeMap { | ||
pub fn new(attributes: Vec<Attribute>) -> Self { |
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.
Consider adding some comment to explain this high level.
Some example can help like
A map from properties [["auth", "identity", "user"], ["auth", "identity", "group"]] would be
{
"auth": Node(
{
"identity": Node(
{
"user": Value(["auth", "identity", "c"]),
"group": Value(["auth", "identity", "group"])
}
)
}
)
}
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Alright, it should "all" work. i.e. now we store JSON representation of the |
} | ||
} | ||
|
||
#[cfg(not(test))] |
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 this way of defining the fn when it's meant to be mocked for testing and not. Might be worthy to follow the same pattern for the operation dispatcher and grpc message req/res //TODO:(didierofrivia)
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.
LGTM. 💪🏼 🥇 🙏🏼
Signed-off-by: Alex Snaps <[email protected]>
.get() | ||
.expect("Expression must be compiled by now") | ||
.eval() | ||
{ |
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.
This is how we've send data to limitador so far, losing the type information... just a string: true
, 42
, bob looks "good" today
// todo this probably should be a proper string literal! | ||
Value::String(s) => (*s).clone(), | ||
Value::Bool(b) => format!("{b}"), | ||
Value::Null => "null".to_owned(), |
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.
Wondering if we should skip that descriptor entry... this could happen if a value is explicitly set to null
in auth
...
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Signed-off-by: Alex Snaps <[email protected]>
Status update: this 🔥 the need for anything but CEL. While the previous ways are still there, they should NOT be used anymore and comes with bunch of caveat... I'll let the code speak for itself as how one can shoot themselves in the foot by going to raw properties/attribute values. |
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.
Left some comments and food for thoughts.
This is not about requesting changes.
From my side, this is ready to be merged
@@ -128,7 +129,7 @@ pub fn set_attribute(attr: &str, value: &[u8]) { | |||
pub fn store_metadata(metastruct: &Struct) { | |||
let metadata = process_metadata(metastruct, String::new()); | |||
for (key, value) in metadata { | |||
let attr = format!("{KUADRANT_NAMESPACE}\\.{key}"); | |||
let attr = format!("{KUADRANT_NAMESPACE}\\.auth\\.{key}"); |
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 thinking that the auth
prefix should come from pub fn process_auth_grpc_response
method.
Then, pub fn store_metadata(metastruct: &Struct)
could be pub fn store_metadata(prefix: &str, metastruct: &Struct)
My diff
diff --git a/src/data/attribute.rs b/src/data/attribute.rs
index 9e65caa..7888462 100644
--- a/src/data/attribute.rs
+++ b/src/data/attribute.rs
@@ -126,10 +126,10 @@ pub fn set_attribute(attr: &str, value: &[u8]) {
};
}
-pub fn store_metadata(metastruct: &Struct) {
+pub fn store_metadata(prefix: &str, metastruct: &Struct) {
let metadata = process_metadata(metastruct, String::new());
for (key, value) in metadata {
- let attr = format!("{KUADRANT_NAMESPACE}\\.auth\\.{key}");
+ let attr = format!("{KUADRANT_NAMESPACE}\\.{prefix}\\.{key}");
debug!("set_attribute: {attr} = {value}");
set_attribute(attr.as_str(), value.into_bytes().as_slice());
}
diff --git a/src/service/auth.rs b/src/service/auth.rs
index c8e4a4d..8364a8b 100644
--- a/src/service/auth.rs
+++ b/src/service/auth.rs
@@ -128,7 +128,7 @@ impl AuthService {
) -> Result<(), StatusCode> {
if let GrpcMessageResponse::Auth(check_response) = auth_resp {
// store dynamic metadata in filter state
- store_metadata(check_response.get_dynamic_metadata());
+ store_metadata("auth", check_response.get_dynamic_metadata());
match check_response.http_response {
Some(CheckResponse_oneof_http_response::ok_response(ok_response)) => {
@@ -128,7 +129,7 @@ pub fn set_attribute(attr: &str, value: &[u8]) { | |||
pub fn store_metadata(metastruct: &Struct) { | |||
let metadata = process_metadata(metastruct, String::new()); | |||
for (key, value) in metadata { | |||
let attr = format!("{KUADRANT_NAMESPACE}\\.{key}"); | |||
let attr = format!("{KUADRANT_NAMESPACE}\\.auth\\.{key}"); | |||
debug!("set_attribute: {attr} = {value}"); |
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.
What about this debug!
macro in pub fn set_attribute(attr: &str, value: &[u8])
?
@@ -128,7 +129,7 @@ pub fn set_attribute(attr: &str, value: &[u8]) { | |||
pub fn store_metadata(metastruct: &Struct) { | |||
let metadata = process_metadata(metastruct, String::new()); | |||
for (key, value) in metadata { | |||
let attr = format!("{KUADRANT_NAMESPACE}\\.{key}"); | |||
let attr = format!("{KUADRANT_NAMESPACE}\\.auth\\.{key}"); |
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.
Can you please add a comment saying that attributes set here are accessible with wasm.*
prefix?
@@ -22,6 +23,23 @@ pub mod action; | |||
pub mod action_set; | |||
mod action_set_index; | |||
|
|||
#[derive(Deserialize, Debug, Clone)] | |||
pub struct ExpressionItem { | |||
pub key: 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.
can we make key
optional? it would default to the expression value (not the referenced value, though).
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 think it makes for a very horrible default, but... 🤷
@eguzki This is my gift to you... you all of course :) |
fix to #112