Fork me on GitHub
#datomic
<
2018-03-13
>
chrisblom13:03:40

are there any libraries for ACL-like authorisation using datomic?

chrisblom13:03:21

another question: what is a good way to debug datalog query rules? I find it quite hard to diagnose & fix mistakes in them.

chrisblom13:03:50

no, debugging problems with datalog rules

jaret13:03:01

What kind of problems are you running into? I often find that I have to separately break up the group of clauses to confirm I have exactly what I am after. I am just curious if you are having a different problem debugging rules.

chrisblom13:03:36

i’m developing some rules for an authorisation scheme, i have a rule

[[check-permission ?p ?action ?resource]
    [?p :permission/action ?action]
    [?p :permission/resource ?resource]]

chrisblom13:03:51

which can be used to check if a permission is granted to perform an action on some resource

chrisblom13:03:29

where actions are a fixes set of idents, like :action/read, :action/update, action/delete

chrisblom13:03:05

and resources can be any entity in the db

chrisblom13:03:39

this works fine, but i want to add a special wildcard action :action/ANY

chrisblom13:03:49

such that when a permission grants :action/ANY on a resources, check-permission will match any action

chrisblom13:03:23

i’ve tried adding

[[check-permission ?p _ ?resource]
    [?p :permission/resource ?resource]
    [?p :permission/action :action/ANY]]
but it does not work

chrisblom13:03:38

i’ve also tried a bunch of other rules, but as the rules engine is a black box, i have no idea when a rule matches or not

marshall13:03:47

i would try something like

[[check-permission ?p ?action ?resource]
[?p :permission/resource ?resource]
[(= ?action :action/ANY]]

chrisblom13:03:58

thanks, but thats not what i’m looking for. I’m looking for a rule such that [check-permission ?p ?action ?resource] will match when ?action is :action/read | :action/write | :action/…

chrisblom13:03:56

provided that

{:db/id ?p 
 :permission/resource ?resource
 :permission/action :action/ANY}

chrisblom13:03:41

so when a permission has :permission/action :action/ANY it should not unify the ?action variable of check-permission, but i’m not able to achieve this

marshall13:03:35

i think youll need to use an OR in the rule

marshall13:03:50

[[check-permission ?p ?action ?resource]
    (or [?p :permisison/action :action/ANY]
        [?p :permission/action ?action])
    [?p :permission/resource ?resource]]

marshall13:03:02

if entity p has either the specified action or the ANY action set, then match

chrisblom13:03:59

ok, seems logical, but datomic does not allow it

Assert failed: All clauses in 'or' must use same set of vars, had
   [#{?p} #{?action ?p}] (apply = uvs)

marshall13:03:19

erm. one sec

marshall14:03:53

actually, i think i was closer the first time

marshall14:03:48

[[check-permission ?p ?action ?resource]
    [?p :permission/action ?action]
    [?p :permission/resource ?resource]]
[[check-permission ?p ?action ?resource]
    [?p :permission/action :action/ANY]
    [?p :permission/resource ?resource]]

marshall14:03:01

multiple rule heads are treated as logical OR

chrisblom14:03:12

ah, yeah that works, thanks

chrisblom14:03:22

i had an underscore instead of ?action

marshall14:03:26

you were pretty much right the first time, just minus the _

marshall14:03:55

i’d have to think about why that didnt work

chrisblom14:03:16

yeah, i’d expect that _ would unify with anything

marshall14:03:17

did you get an error or did it just not work?

chrisblom14:03:32

it just did not work, no error

marshall14:03:42

following the grammar, the rule head is:

chrisblom14:03:45

fyi, an or-join is also possible:

'[[check-permission ?p ?action ?resource]
    (or-join [?p ?action]
             [?p :permission/action :action/ANY]
             [?p :permission/action ?action])
    [?p :permission/resource ?resource]]

marshall14:03:54

[rule-name rule-vars]

marshall14:03:08

yeah, an or-join would do the same thing

marshall14:03:04

anyway, the grammar does say that a rule head is [rule-name rule-vars] , rule vars is [variable+ | ([variable+] variable*)] and variable is symbol starting with ?

marshall14:03:18

so an underscore isn’t actually permitted in a rule-var list

chrisblom14:03:27

ah ok, yeah i see it now in the grammar

chrisblom14:03:47

i expected that using _ in a rule should work, it works in queries

chrisblom14:03:30

some other datalog query engines, and prolog allow it

chrisblom14:03:02

can i file a bug for this? It kept me busy for a few hours and i’d like to avoid others from experiencing the same.

chrisblom14:03:27

@marshall thanks a lot for your help!

marshall14:03:32

np. yeah, i’ll pass it along

marshall20:03:05

Looks like a deps conflict @donmullen

donmullen20:03:43

Yep - just seeing that — some conflict with com.socrata/soda-api-java — sorry for the noise.