Assigning user roles and RBAC proposal #535
Replies: 7 comments
-
Which AWS resources would a role have direct access to? |
Beta Was this translation helpful? Give feedback.
-
Using Cognito groups seems like a good choice because user management is self contained within Cognito. Be sure to note somewhere that the token passed from the client needs to be validated/verified in the decorator. AWS has a Lambda example showing the use of python-jose to verify JWTs. |
Beta Was this translation helpful? Give feedback.
-
Regarding the process around managing the roles: Since this app has clearly defined roles already (Host, Coordinator, Guest), managing the Cognito user groups (roles) is going to be a one time event for each environment, right? Would the app need any other roles such as a "customer support" role or tenant administrator role? Who/how will the roles be managed in Cognito? Do we have separate Cognito accounts for each environment (dev, qa, prod, etc)? |
Beta Was this translation helpful? Give feedback.
-
@paulespinosa great questions!
I can't say for certain right now. We'll have to determine that based on the resources they'll need access to and the privileges we want to grant them. For example, reading and writing to RDS, S3, access to SNS, etc.
Good point!
By "one-time event" are you asking if the groups are editable or adjustable? User groups can be added, edited, or removed at any time and not just when you initialize the Cognito client. I could potentially see us needing more distinct roles down the line, but I can't say for sure what those are right now. One thing I've been reading about when it comes to RBAC is parent and child relationships and I'm not sure how that would play into defining roles in Cognito. I believe a developer with access to the AWS console would manage the roles.
This is something I've been thinking about as well, and I think goes hand in hand with configuration tasks being worked on right now. It might be a good idea to set up different clients for different environments so we aren't messing with production users during development or testing, and we could pre-populate environments with test users. |
Beta Was this translation helpful? Give feedback.
-
Yes, generally, I was trying to imagine how the process and procedure of adding, editing, and removing would work. A Project Manager would likely request and approve of a role and define the actions to take for its implementation. The actions would be:
These steps might need to be bundled together in a release. |
Beta Was this translation helpful? Give feedback.
-
thanks for writing this up Erik this is awesome. i'm with y'all on the first approach. and we could incrementally build off of it if we need to consider the third approach.
looking at |
Beta Was this translation helpful? Give feedback.
-
A note about something I was reading and needs to be scrutinized carefully: We might not need to implement a decorator but a function instead. If I understand the connexion security documentation correctly, it will take care of authorization for us if we write the security requirements into the OpenAPI spec and implement a function to return the scopes within the token. The function still needs to validate the token is authentic, though. If using OAuth 2.0
If using Bearer Authentication (JWT)
In the OpenAPI spec For the Cognito case
scope is a type of claim. So for the Cognito case, the function can return the values for It so happens that the code base is already almost there: |
Beta Was this translation helpful? Give feedback.
-
Overview
As we’re wrapping up Section 1 one aspect of account management we still need to tackle is assigning users to their specific roles (e.g. Guest, Host, Coordinator, Admin) and Role Based Access Control. This will help set the groundwork for the role-specific features we will be developing in Section 2 and beyond.
I’ve broken down the requirements for this into a couple of high-level key features:
These requirements can be broken down further depending on the approach we decide to take.
Approach 1: Using AWS Cognito user groups
AWS Cognito allows you to define user groups within which you can add users and define permissions for each user type. Once a user is added to a group/s you can access the list of groups from the id token returned from AWS when signing up. We can then control access to routes on our server by creating a decorator that decodes the token and check the groups against the ones allowed for that resource.
Pros:
Cons:
Resources:
https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-user-groups.html
Approach 2: Using Flask RBAC
Flask RBAC is a library that provides some helpful functionality for setting up and utilizing RBAC. The library shows you how to set up tables for roles and users, and provides the decorators that control access to routes.
Pros:
Cons:
Resources:
https://flask-rbac.readthedocs.io/en/latest/
Approach 3: Hybrid Approach
We use AWS Cognito groups to assign roles and define access to AWS resources, and we use Flask RBAC to assign users to roles in the database and protect routes. This approach covers a lot of functionality but requires us to track roles and groups across the database and in AWS, which could add some complexity.
I’m leaning towards Approach 1. I think cutting back on DB transactions is valuable and since AWS provides us with a way to define groups we might as well use it. I also don’t foresee creating our own decorators being a massive on taking. Interested to hear others thoughts and opinions!
Beta Was this translation helpful? Give feedback.
All reactions