tomazbracic

tomazbracic

Thoughts on implementing RBAC (role-based access control) within a mixed environment?

Hi,

I am building a platform, where I have few services. Lets say I have 2 elixir services (as standalone releases), 1 rust/golang service… and probably one or two more comming.

I would like to implement RBAC on the level of platform. My question/dilema is how to approach this due to the fact that it would not be just elixir codebase.

Options I am thinking about:

  1. Implement RBAC withing one of the elixir services and expose this for instance via REST to others
  2. Implement RBAC as standalone service and expose functionalities via REST to others.
    2A. Here I was checking Casbin (https://casbin.org) and perhaps based on this (https://github.com/casbin/casbin-ex)
    2B. Implement kind of my own RBAC - haven’t really find any nice library yet

Right now I feel like … this Authentication / Authorization part of elixir ecosystem is still a bit unmature, where I don’t mean libraries that exists are unmature, but common best practices, approaches how to solve problems, design patterns around this are still not well documented.

For me as a beginner for instance… you have Phx.gen.auth, Guardian, Ueberauth, Pow, Pow_assent, Bodyguard, … and many more. Should I go with this or that… what would be best approach to easily maintain and further develop not just for weekend project, but for a something that would need to run in production next 2 years for instance.

Next, dilemas… if I go with this… would I be able to cover SPAs, liveview, channels, OAuth, stateless, statefull… and all other buzzwords and components. What combination would be best. And I guess this is really important for options above. I am pretty sure, I will use channels/liveview too in my services, as regular templates too. There will be probably React SPA too as part of this. What to choose, how to aproach this?

I know one could say I mixed everthing in the same basket, but intentionaly I want to emphasize what probably someone who starts with this see.

It would be really great if there would be more documentation on this, based on examples.
I apprechiate @josevalim suggestion few days back on documenting more use cases around Phx.gen.auth. That would be really awesome.

Until then, … dilemas like this make mess in my head. :wink:

So if someone can share a bit of feedback on my options above I would really appreciate.

Bye
Tomaz

Most Liked

tomazbracic

tomazbracic

Looks like I need to write first reply myself :slight_smile: though I really hope others with experience will follow.
I was told that all the buzzwords are in my post. But my comment on this would be, not all of us are building yet another Blog site.

In relation to what I already wrote above, about what @josevalim wrote a while back, I really want to share first of such blog posts that I was able to find. Thanks to @iacobson a blog about joining Phx_gen_auth with Oauth. If there are more like this, please share them here.

tomazbracic

tomazbracic

Hey,

another one!

Phx.gen.Auth + JWT

Regards,
Tomaz

Hannu

Hannu

Hi,

I have implemented a RBAC based authentication and authorization service in Elixir and it’s used in production in our company.

I would suggest that if the use-case is a real production use and your requirements allow it, use existing solutions like Keycloak. Their authorization overview guide.

At least authorization for websockets works with Keycloak when using Nginx (Example). I don’t know if Liveview works too.

If it’s not possible to use existing solutions and since you are already using microservices(?) then I would suggest going for option 2. I’m not familiar with libraries in this area but I can say that authentication is easy, authorization can be easy but with RBAC, it usually gets complicated.

If you have only few services and aren’t using API gateway/reverse proxy solution, then you need to handle parsing request data in each service and making validation request to the authentication&authorization service. This means that you can use whatever means of communication between services (backend and frontend) but there’s more work for each service.

If you are using API gateway/reverse proxy solution like Nginx, then services can just make requests to each other without worrying (too much) about authentication and authorization since the gateway will handle it. Of course you need to implement necessary code in the gateway. This varies for each solution.

As for those OAuth, stateless, stateful, and other buzzwords, I would suggest that you evaluate your requirements and try to keep everything as simple as possible. OAuth + OpenID is complex and if you don’t have clear use-cases for it, then I wouldn’t choose it.

There’s not much difference between stateful and stateless authentication. If your requirements mandate that you must be able to easily revoke authentication, then I would suggest going for stateful authentication.

Basic flow with stateful authentication:

  1. User logins to system
  2. Save all required information (at least user_id, session_key) in database
  3. Set user_id into httponly cookie which can be signed/encrypted
  4. SPA knows that login was a success the request returns 200
  5. The browser adds the cookie to each following request from the SPA to backend
  6. The authentication and authorization service checks that cookie is in the request, it’s valid, and the information is valid.
crockwave

crockwave

I was able to successfully integrate Phx_gen_auth and Ueberauth, using the referenced @iacobson blog post, using the Google strategy in a new project.

Where Next?

Popular in Questions Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

We're in Beta

About us Mission Statement