Skip to main content

Policy middleware for Falcon APIs

Project description

The falcon-policy package provides a middleware component that enables simple policy controls such as role-based access on routes via configuration.

The configuration approach to policy rules enables dynamic authorization use-cases where the policy needs to be adjusted on-demand without a new service deployment.

Installation

$ pip install falcon-policy

Usage

The RoleBasedPolicy middleware class examines each incoming request and verifies the X-Roles header for the appropriate role given the request being made.

Getting Started:

  • Create a policy configuration

  • Create an instance of RoleBasedPolicy using the configuration

  • Pass the instance to the falcon.API() initializer:

from falcon_policy import RoleBasedPolicy

policy_config = {
    'roles': [
        'admin',
        'creator',
        'observer',
    ],
    'groups': {
        'create': ['admin', 'creator'],
        'update': ['admin', 'creator'],
        'read': ['admin', 'creator', 'observer'],
        'delete': ['admin'],
    },
    'routes': {
        '/quote': {
            'GET': ['read'],
            'POST': ['create'],
            'PUT': ['update'],
            'DELETE': ['delete'],
        },
        '/quote/{id}': {
            'GET': ['read'],
            'POST': ['create'],
            'PUT': ['update'],
            'DELETE': ['delete'],
        },
        '/status': {
            'GET': ['@any-role'],
            'HEAD': ['@passthrough'],
        },
    },
}

app = falcon.API(
    middleware=[
        RoleBasedPolicy(policy_config)
    ]
)

If validation fails an instance of falcon.HTTPForbidden is raised.

Configuration

The policy configuration is separated into three sections:

  • Roles: Is a list of names that correspond with Role values provided by your authentication system.

  • Groups: Is an alias/grouping of multiple role names for convenience.

  • Routes: A structure containing role and/or group permissions for a given Falcon route and method.

Specialty Roles:

falcon-policy offers two specialty roles types that should be used with care:

  • @any-role: Allows any defined role

  • @passthrough: Allows all users (authenticated and unauthenticated)

About Falcon

Falcon is a bare-metal Python web framework for building lean and mean cloud APIs and app backends. It encourages the REST architectural style, and tries to do as little as possible while remaining highly effective.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

falcon-policy-0.1.0.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

falcon_policy-0.1.0-py2.py3-none-any.whl (6.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file falcon-policy-0.1.0.tar.gz.

File metadata

File hashes

Hashes for falcon-policy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1b88746fe376854abf89c821ea5d3a7814e678ce55a5629f9720d9551e25f14c
MD5 4a52b78414c90abf5183d323cdf3094e
BLAKE2b-256 d4ea0eeae53a426321e11fef514d525fcda5d6de0280990c8bdd469d2138c095

See more details on using hashes here.

File details

Details for the file falcon_policy-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for falcon_policy-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 61b3674f9bcb4b76e0c69ac1048f2e4df1be52dce6ff396cafd5f55f0bde363d
MD5 93c606b88f4600052ae46752969b68a1
BLAKE2b-256 15564e13a369eb51753af78cc9e73ff014d19580722683f476d0232df191a913

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page