Ghostwriter icon indicating copy to clipboard operation
Ghostwriter copied to clipboard

Idea: implement fine-tuned access control

Open fastlorenzo opened this issue 4 years ago • 4 comments

The idea would be to create access-controls per project and only give specific operators access to specific projects and its findings, reports, etc.

Not sure how easy this is to implement, but happy to help there where needed.

fastlorenzo avatar Apr 07 '20 09:04 fastlorenzo

As an update on this, the upcoming release has some features that lay groundwork for RBAC. Access control options will grow in the near future.

chrismaddalena avatar Nov 18 '20 23:11 chrismaddalena

Awesome! Thanks for the great work @chrismaddalena !

fastlorenzo avatar Nov 20 '20 19:11 fastlorenzo

@chrismaddalena any plans to work on this? I'm happy to help. If you don't have this in the pipeline, I'll start working on something on my side and probably make a PR 😄

fastlorenzo avatar Jul 21 '21 17:07 fastlorenzo

Please do make a PR @fastlorenzo (and thanks for your contributions)! There are definitely plans to work on RBAC and granular access control, but we are not actively working on it yet and don't have an exact timeline for when that'll start.

andrewchiles avatar Jul 23 '21 18:07 andrewchiles

@chrismaddalena howdy howdy, i would gladly implement a wrapper around functions where only operators can access a specific project (kinda like RBAC). Is there some guide or document on architectural choices in case of PR (like the use of wrappers and other stuff...) ?

ionut2497 avatar Jun 02 '23 14:06 ionut2497

@ionut2497 Thanks for offering! This is actually underway right now!

You can see the progress in the ui-rbac feature branch: https://github.com/GhostManager/Ghostwriter/tree/feature/ui-rbac

My goal is to complete the transition by the end of the month, but that may be a little ambitious with everything else I have going on. It's the top priority so Ghostwriter can better meet compliance needs and offer the access controls available in the GraphQL API in the web UI.

This is the authorization model: https://www.ghostwriter.wiki/features/graphql-api/authorization

So far, I have added some helper functions to test access to various things and filter querysets. Django's built-in UserPassesTestMixin offers what we need for both views. We can implement the test_func and handle_no_permission methods to check the user's role and respond. It looks like this:

class SomeProjectView(LoginRequiredMixin, SingleObjectMixin, UserPassesTestMixin, View):
    model = ProjectObjective

    def test_func(self):
        return verify_project_access(self.request.user, self.get_object())

    def handle_no_permission(self):
        raise PermissionDenied

    def post(self, *args, **kwargs):
         # Do Stuff

The ghostwriter.api.utils module contains these helper functions.

That view tests if the user is authenticated and then checks if they pass the test (if test_func returns true). If they fail the test, it calls handle_no_permission and returns a 403 by raising Django's PermissionDenied exception.

It's mostly a lot of copying, pasting, and updating unit tests which all take more time than it engineering, but some views will require extra care. For example, I need to figure out how best to acknowledge a domain has usage history when someone viewing that domain's history does not have access to the related client or projects.

chrismaddalena avatar Jun 05 '23 18:06 chrismaddalena

FYSA, the ui-rbac branch is likely feature complete and will become a v4.0.0-beta release soon. It may stay a pre-release until September because I have a web assessment scheduled for this release near the end of August.

chrismaddalena avatar Jul 03 '23 19:07 chrismaddalena

We merged the above-mentioned branch and the feature is released in v4.x, so I'm closing this.

chrismaddalena avatar Nov 09 '23 22:11 chrismaddalena