Ash Policy DSL Syntax Issues - Need Help with authorize_if and policy_group
I'm implementing role-based authorization in an Ash 3.5.42 application but running into compilation errors with the policy DSL. Despite following the documentation examples, I'm getting
undefined function authorize_if/1
errors.
Current Setup:
Error Message:
error: undefined function authorize_if/1
(there is no such import)
error: undefined function actor_attribute_equals/2
(there is no such import)
What I've Tried:
- Added authorizers: [Ash.Policy.Authorizer]
to resource
- Tried importing Ash.Policy.Check.Builtins
- Tried use Ash.Policy.Authorizer
Domain Configuration:
All in all, the authorization framework compiles fine, but the policy DSL functions aren't available.6 Replies
At first glance that looks correct 🤔
Have you tried
rm -rf _build
in the root of your project and recompiling?
another thing that you could try is adding your resource to your domain (if your domain snippet is indeed the entirety of that file)
e.g.
thanks for the suggestion for clean build. All the undefined function errors are gone and the policy DSL compiles perfectly.
while the policies compile, the actor context from RPC calls isn't reaching the policy evaluation. Even
bypass actor_present()
fails when an actor is provided via RPC:
this still returns forbidden! wondering if actor context isn't being passed from AshTypescript.Rpc to the Ash policy system
the issue is not with policies. they work perfectly when called directly with Ash.read(Resource, actor: actor)
the issue should be with AshTypescript.Rpc - it doesn't forward the "actor" parameter from RPC calls to the underlying Ash.read()
callsAannddd seems like i found the issue. Following the documentation again,
AshTypescript
expects the actor to be set on the connection/socket, not passed as a parameter in the RPC call!
I tested all the flows now and it works flawlessly 🎉
You might be interested in https://hexdocs.pm/ash_rbac/getting_started.html
i have seen this but then i assumed ash's one was superior
https://hexdocs.pm/ash/actors-and-authorization.html
https://hexdocs.pm/ash/policies.html
i will check this again
it's just a small wrapper that creates ash policies for you