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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file falcon-policy-0.0.1.tar.gz
.
File metadata
- Download URL: falcon-policy-0.0.1.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0c6defb4c70d8c159e98490e5882a6202ee91627bf2367492c86a0cf532db4b |
|
MD5 | 1406b4be87bede7cabbf21ca27878f73 |
|
BLAKE2b-256 | 53b92edc95af2c983befc56beec8216099f434a12376c4da07b981b00f75dc34 |
File details
Details for the file falcon_policy-0.0.1-py2.py3-none-any.whl
.
File metadata
- Download URL: falcon_policy-0.0.1-py2.py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e2c3b674c46c184fcecd9f90b68220cd76ca644ce7ffeced11aaca33dbf465d |
|
MD5 | 4139efbad6423d9c9c9f469f89e8f465 |
|
BLAKE2b-256 | c3f187de92981b15c4a51beb842444b69bb20a30afc5545e1b5b352155099a44 |