Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(user_roles): Add User Roles/Permissions #276

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from

Conversation

flamingquaks
Copy link
Collaborator

@flamingquaks flamingquaks commented Dec 15, 2023

This PR is for work on Issue #99 - Please see issue for detailed documentation of changes to user interface

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

massi-ang and others added 30 commits December 5, 2023 16:00
removed unused API resources
correctly replacing api_handler function
for better code diff
@bigadsoleiman
Copy link
Collaborator

@flamingquaks #269 has been merged

@flamingquaks
Copy link
Collaborator Author

I'm currently working through merge conflict resolution and related patches. I aim to have this ready within the next few days

@abduljaleel
Copy link

Waiting for this PR to merge..

@flamingquaks
Copy link
Collaborator Author

Waiting for this PR to merge..

We are working through some bugs that came up with the latest updates. Once those are resolved, the PR will move forward. Hoping to have them wrapped quickly!

@flamingquaks

This comment was marked as resolved.

@flamingquaks flamingquaks marked this pull request as ready for review January 24, 2024 16:06
@flamingquaks
Copy link
Collaborator Author

This feature is now READY FOR REVIEW!

Overview of major functionality changes:

  • Cognito Users should now be added to one of the four user groups: chatbot_admin, chatbot_workspaces_manager, chatbot_workspaces_user, or chatbot_user. If a user isn't added, they will receive an error and provide instructions for the admin. Documentation has been updated for deployment and a new doc in docs/documentation/user-permissions.md has been added that breaks down the different permissions. If more than one of the four groups is added to the user, the group with the most permissions will be used.
  • After the initial user is added, users can be added, updated, removed by chatbot_admin users within the Chatbot solution.
  • In both the front-end UI and the back-end rest functions, there is now a notion of user permissions. In the front-end, leverage the UserContext within the react component to get the current role. In the back-end, there are now method decorators. Almost all rest-api endpoint functions have the method decorators to adjust/check permissions, especially the RAG management capabilities.
  • The API has new endpoints for User Administration. The front-end has an Administration section added which can have future admin features added.

It's recommended that an upgraded deployment and a fresh deployment are attempted. A full-sweep of functionality tests is recommended, including adjusting user permissions (you will need to logout/login to app after user group update)

response = genai_core.admin_user_management.delete_user(email)
if response:
return True
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else not needed here

return True
else:
return (
"The user is not disabled. To delete a user, first disable the user, then delete the user.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we safely assume that this is the case each time response is False?

GroupName=role,
)
return True
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else not needed

UserPoolId=COGNITO_USER_POOL_ID, GroupName="chatbot_admin"
)["Users"]
users = []
for user in response["Users"]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can rewrite this loop to be more dynamic and less verbose considering the following:

  • if you need to snake_case all attributes simply have a function snake_case, loop over all attributes keys and call it - instead of hardcoded if statements.

  • have a list of roles sorted by importance, loop over it, if username in ... and the first match will be the user role, also see if this function to derive role needs to be shared around..

  • let's use enums for roles from permissions instead of hardcoded strings

)
if response["ResponseMetadata"]["HTTPStatusCode"] == 200:
user_data = {}
for attribute in response["UserAttributes"]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

....shared function to derive_actual_role?

if user_details_response["Enabled"] == False:
idp.admin_delete_user(UserPoolId=COGNITO_USER_POOL_ID, Username=email)
return True
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else not needed


def update_user_details(current_email, **kwargs):
attributes = []
if "name" in kwargs and len(kwargs["name"]) > 0:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorter version if kwargs.get("name") or if len(kwargs.get("name", '')) (same for the below ones)

)
if response["ResponseMetadata"]["HTTPStatusCode"] == 200:
return True
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else not needed

return self.WORKSPACES_USER_ROLE
elif self.CHATBOT_USER_ROLE in user_groups:
return self.CHATBOT_USER_ROLE
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove else

@bigadsoleiman
Copy link
Collaborator

Neat PR

@Rob-Powell
Copy link
Contributor

I tested these changes and they worked as expected, good work

@flamingquaks flamingquaks marked this pull request as draft February 13, 2024 19:51
@flamingquaks
Copy link
Collaborator Author

I've shifted this back to Draft to allow time to refactor this work to use Amazon Verified Permissions. This will allow future access controls and permissions to be added more consistently.

@Amrib24
Copy link

Amrib24 commented Feb 22, 2024

@flamingquaks have you considered the cost implication of shifting the draft to AVP as the only option? Whats not working well with the current draft? Just some things to keep in mind

@massi-ang
Copy link
Collaborator

massi-ang commented Feb 23, 2024

Thanks @Amrib24 for raising this concern, but the cost of verified permissions is negligible compared to the running costs of an LLM based solution. Moreover, Verified Permissions provides out of the box, managed capabilities that you would need to account engineering and maintenance cost for in case you choose another solution.

@ystoneman
Copy link

@flamingquaks, are you still planning on refactoring this PR to use Amazon Verified Permissions (AVP)? Please let us know if there are any blockers or challenges the team could help you with! Excited about this feature. :)

@flamingquaks
Copy link
Collaborator Author

@ystoneman, Apologies for the delay, it took me a bit more time to upskill on AVP than I had planned. I'm aiming to pick up steam on this by end of week and provide an update on timeline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

None yet

8 participants