Hello !
# spicedb
s
Hello ! we are currently looking for solutions to integrate MFA enforcing in our systems. where all resources belonging to some workspace are only available if the user has some kind of MFA enabled. one of my ideas was to add a caveat to the relation between the user and the workspace. (caveat with 2 arguments : expected_amr, and provided_amr, where expected_amr is defined when configuring the relation, and provided_amr is provided in the context of the query) this works, but has a sizeable flaw : when the admin of a workspace changes the mfa requirements, we need to update all user relations. now, this shouldn't happen too often (well, basically only once per workspace at most) I tried to find a way to configure it only once for the specifice "workspace" ressource, but couldn't find a way. is there a way to do that ? is my first idea the only way to do that ? (probably not, I could handle this outside SpiceDB, but shouldn't access management use SpiceDB ?)
y
spicedb holds edges, not nodes, so you're on the right track with the caveat on the relation. one thing that you can do if you want to make everything go through a single relation is to add a synthetic definition that sits between the user and the resource, and that synthetic definition can be 1-1 with workspaces and then have a relationship between it and the workspace that holds the caveat you want. i don't completely understand the use case, though, so i'm kinda waving my hands here.
s
let's say I have this schema :
Copy code
zed
definition user {}

definition workspace {
    relation admin: user
    relation member: user

    permission read = write + member
    permission write = admin
}

definition picture {
    relation owner: workspace

    permission read = write + owner->read
    permission write = owner->write
}
and this caveat :
Copy code
zed
caveat mfa_match(expected_amr string, provided_amr list<any>) {
   size(provided_amr) > 0 && expected in provided_amr
}
now, the admin has the right to make any resource require mfa to access. one way to make that is to add the caveat to relations
admin
and
member
and then edit all of these relations to redefine them with the context
{"expected":"mfa"}
then all checks would provide the context. eg.
{"provided_amr":["mfa", "otp"]}
that implies that all relations with the users need to bear the caveat
mfa_match
and context
{"expected":"mfa"}
I am simply looking for a way to make the workspace itself somehow bearing this information, to avoid having to update all user relations on every checks.
hope this is clearer 🙂
y
yeah i'm saying that you'd have a
definition mfa_guard {}
or something equivalent that sits between the user and the workspace
such that rather than putting the context on the workspace (which isn't really something you can do in SpiceDB - it doesn't store any information about the nodes in its graph), you put it on the relation between the
mfa_guard
and the
workspace
, and then users are connected to the
mfa_guard
rather than the
workspace
or else use a self-edge
actually yeah i'd use a self-edge
Copy code
definition workspace {
    relation mfa_guard: workspace with mfa_match
    relation admin: user
    relation member: user

    permission read = mfa_guard->write + mfa_guard->member
    permission write = mfa_guard->admin
}
and then you'd write a rel that's:
workspace:someworkspace#mfa_guard@workspace:someworkspace{provided_amr:[1,2,3]}
(or whatever that syntax would be)
j
it should also be noted that MFA is an authentication concern; typically, you'd do it at the authn layer unless it impacts only explicit sets of perms
s
@Joey well in my case, I want to forbid access to some ressources if the user doesn't have MFA. (as in, he would then have to configure his account to use MFA, for the mfa auth to be enabled, then allowing him access to the data.) other ressources (from other workspaces) would still be accessible without the user having to set up mfa.
@yetitwo sounds interesting, I'll have to check how that would work. permissions would be the same, but refering to mfa_guard's relations instead of self relations then ?
y
oh right - when i say "self" here i'm not talking about the
self
keyword, but rather a relation that points from a definition to itself and from an object to itself
s
didn't even know there was a self keyword...
y
there isn't 😅 i thought you might be referring to a conversation below this one where we were talking about adding a
self
keyword
s
oh, well thanks
also, do you know where a list of functionas available on lists for the caveat exists ?
i'm not sure there's a better reference than this one
s
Thanks, that's what I was looking for. But this means I don't think what I wanted to do is gonna be possible ... What I wanted to do: Make the caveat take two lists. One for the allowed amr and one for the received amr. If any of the allowed amr is in the received amr, return true. Otherwise false. Unless macros are the answer? I'll have to check that...
Yeah, ok, macros should allow me to do what I want.
j
CEL allows that
s
yep, I was able to do it thanks again
10 Views