Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Security Policy modeled after SELinux
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Vlad K.  
View profile  
 More options Aug 30 2012, 10:47 am
From: "Vlad K." <v...@haronmedia.com>
Date: Thu, 30 Aug 2012 16:47:04 +0200
Local: Thurs, Aug 30 2012 10:47 am
Subject: Security Policy modeled after SELinux

Hello all,

I have an app with relatively complex security/permissions requirements
and I decided to build it modeled after SELinux.

The default Pyramid authz policy revolves around checking if a user
belongs to a group, or has certain principal, the check of which is
facilitated per view (with `permission` argument).

In my app I have several roles and each role can only access some
resources, and only perform some actions upon those resources (read,
write, delete, ...), and the permission is not static per view, but
depends on data retrieved from database according to some identifier
given through matchdict.

For example, "regular" users can create new and edit only own content of
class X, Y, Z. Users belonging to a "editor" role can view other
people's X, Y, Z but can't modify them except some properties thereof
(like active/inactive). Perhaps editors can't write their own content,
so they would only have `read` permission. Users belonging to a
"billing" role can only view billing data of users, create invoices,
activate/deactivate profiles, but not view or change their content, etc....

I decided to make a class which I reify as request.permits property (via
config.set_request_property()), then do a following check:

        @view_config(route_name="some_route", ...):
        def some_view(request):
             resource_id = int(request.matchdict["resource_id"])

             resource = DBSession().query(Resource).get(resource_id)
             if resource and not request.permit(resource, read=True):
                 raise Forbidden()

             if not resource:
                 raise NotFound()

             ...

The permit() method is a __call__ method of the policy class. It does
several things:

1. Checks the type of first parameter  (the "tcontext" in SELinux lingo)
2. According to its type (isinstance), delegates check to a private
method responsible for that resource class (content classes, menu links,
...)
3. The private method does whatever check required to see if the user
(authenticated in the system with some principal like ID, the "scontext"
in SELinux lingo) has access to the resource for given action (read,
write, delete)

Example checks (which would be policy rules in SELinux):

        # request.userauth is also an object created with
        config.set_request_property()
        if resource.owner_id == request.userauth.user_id and (read or
        write):
             return True
        if "required_role" in request.userauth.roles and (read and not
        write):
             return True

etc... The default, of course, being no permission at all. It can be
more DRY if the `permits` callable threw Forbidden() automatically, but
I need it in the templates to return True or False which defines parts
to be rendered. Alternatively I can supply a `nothrow=True` kwarg to
return False instead of raising Forbidden().

This way I maintain the policy in single file, the policy can be
"pluggable" if required (instantiate different policy depending on
configuration) and it can even be compounded with the view_config's
permission argument, and the custom authorization policy factory which
implements the proper interface.

Too complicated? Overkill? Anyone doing something similar?

--

.oO V Oo.

Work Hard,
Increase Production,
Prevent Accidents,
and
Be Happy!  ;)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Forkel  
View profile  
 More options Aug 31 2012, 5:37 am
From: Robert Forkel <xrotw...@googlemail.com>
Date: Fri, 31 Aug 2012 11:37:13 +0200
Local: Fri, Aug 31 2012 5:37 am
Subject: Re: Security Policy modeled after SELinux
I guess I'm doing something similar. At least as far as having
resource specific permissions. But I've chosen to implement this using
context factories. So the

    resource_id = int(request.matchdict["resource_id"])
    resource = DBSession().query(Resource).get(resource_id)
    if not resource:
        raise NotFound()

code which you have in the view is in my case part of the context
factory. Additionally, the context factory attaches a trivial  __acl__
attribute to the context (allowing or denying the current user) to
make the standard authorization policy work.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Robert Forkel  
View profile  
 More options Aug 31 2012, 5:42 am
From: Robert Forkel <xrotw...@googlemail.com>
Date: Fri, 31 Aug 2012 11:42:44 +0200
Local: Fri, Aug 31 2012 5:42 am
Subject: Re: Security Policy modeled after SELinux
Route Factory seems to be the proper term, see
http://pyramid.readthedocs.org/en/latest/narr/urldispatch.html#route-...


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vlad K.  
View profile  
 More options Sep 12 2012, 9:00 am
From: "Vlad K." <v...@haronmedia.com>
Date: Wed, 12 Sep 2012 14:59:59 +0200
Local: Wed, Sep 12 2012 8:59 am
Subject: Re: Security Policy modeled after SELinux
On 08/31/2012 11:37 AM, Robert Forkel wrote:

> I guess I'm doing something similar. At least as far as having
> resource specific permissions. But I've chosen to implement this using
> context factories.

Thanks for your reply.

That would work except it is limited to checks at routing / view
mapping. The approach I'm having is a completely separate policy class
that can be queried by any part of the code, specifically:

- view config to get general view permission
- view handlers to get permission based on loaded resource (this would
also work well with traversal)
- templates to know which parts to render (menu options, content boxes,
etc...)
- other parts of the code

with the policy neatly defined in single file / class. So when you query
the policy, you basically ask it to:

1. verify action named X  (eg. "article.edit")
2. with source context Y  (eg. user profile ID and/or user's role(s) )
3. with target context Z (eg. SQLA article model)

--

.oO V Oo.

Work Hard,
Increase Production,
Prevent Accidents,
and
Be Happy!  ;)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »