-
Notifications
You must be signed in to change notification settings - Fork 46
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
add draft OpenFGA client #10504
base: dev
Are you sure you want to change the base?
add draft OpenFGA client #10504
Conversation
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## dev #10504 +/- ##
==========================================
- Coverage 82.56% 82.20% -0.37%
==========================================
Files 1084 1085 +1
Lines 107257 107811 +554
Branches 729 729
==========================================
+ Hits 88559 88622 +63
- Misses 18656 19147 +491
Partials 42 42
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
131388a
to
ac0adfd
Compare
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.
Only a first pass on src/client.rs
. I'll take a look at the rest later.
a767ba2
to
4ee9be3
Compare
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.
Small review of the docker-compose
fga/src/model.rs
Outdated
format!("{}:{}", Self::NAMESPACE, self.id()) | ||
} | ||
|
||
fn tbpa() -> Tbpa<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.
Maybe need to be renamed all
? Or wildcard
?
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.
wildcard, as discussed
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.
fga/Cargo.toml
Outdated
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're missing an additionnal step in the CI to launch the tests? (or do we wait for this crate to be merged into editoast
's workspace?
fga/src/doctest_setup.rs
Outdated
|
||
use fga::model::Relation as _; |
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 be move at the top.
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.
fga/src/model.rs
Outdated
const NAMESPACE: &'static str; | ||
|
||
fn id(&self) -> &str; | ||
|
||
fn fga_ident(&self) -> String { | ||
format!("{}:{}", Self::NAMESPACE, self.id()) | ||
} |
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 piece of code is the same between User
and Object
. How about making an trait Id
that both Object
and User
would be a subset of?
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.
done, by yourself
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.
trait Type
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.
fga/src/model.rs
Outdated
pub trait AsUser { | ||
type User: User; | ||
|
||
fn id(&self) -> &str; | ||
|
||
fn fga_ident(&self) -> String { | ||
let id = self.id(); | ||
if id == "*" { | ||
panic!( | ||
"Refusing to generate an identifier for a type-bound public access\n\ | ||
without using the `fga::model::Tpba` type.\n\ | ||
This is a security measure to avoid having user identifiers coerced to\n\ | ||
public accesses maliciously." | ||
); | ||
} | ||
format!("{}:{}", Self::User::NAMESPACE, id) | ||
} | ||
} |
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 don't understand why we need this trait
. It's exactly the same than User
(except User
has a bit more). It feels that everywhere a AsUser
would be expected, a User
bound would be enough.
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Jean SIMARD <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Jean SIMARD <[email protected]>
Signed-off-by: Jean SIMARD <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Co-authored-by: Florian Amsallem <[email protected]> Signed-off-by: Léo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
d95db11
to
9da4085
Compare
Co-authored-by: Jean SIMARD <[email protected]> Signed-off-by: Léo Valais <[email protected]>
Signed-off-by: Florian Amsallem <[email protected]>
Signed-off-by: Florian Amsallem <[email protected]>
6ea7ac1
to
73606ae
Compare
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Signed-off-by: Leo Valais <[email protected]>
Note
This is a lengthy PR which also requires some amount of OpenFGA knowledge to be understood. It's probably better to peer review it.
Draft OpenFGA client.
editoast_authz
(in which we'll map the authorization model, define our objects, their conversion, relations, etc.)fga
binary is necessary to run unit tests for now: https://github.com/openfga/cliTODO:
POST /stores/{}/list-users
POST /stores/{}/stream-list-objects
POST /stores/{}/expand
POST /stores/{}/read
POST /stores/{}/batch-check
authorization_model_id
in the client to forward it to requests—as advised by OpenFGAcheck
assertions (make them public + async variant?)compile_model
?mod client
mod model
crate
(ongoing)docker compose
User.id ≠ '*'
User.id
andObject.id
? Not really required for us.list-users
as this will change thetrait User
APIfga!
relations!
derive(User)
derive(Object)
About macros
This crates introduces a few macro_rules, which are only used for tests currently.
relations!
allows defining typed relations concisely to allow quick comparisons with the OpenFGA schema. I think we should keep this one, that'll help the review process and reduce straightforward boilerplate.fga_type!
declares the newtype structs representing thetypes
of OpenFGA and generates a few implementations. I think this one should remain a#[cfg(test)]
definition. However I think derive macrosderive(fga::User, fga::Object)
would help us and cost nothing as they are trivial to implement.fga!
allows manipulating and instantiating types and relations with the same syntax as OpenFGA, but in a type-safe way. This is particularly useful for the conciseness of unit tests. I think it should be exported.