Skip to content

CGarces-Apser/python-cognito-cerbos

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-cognito-cerbos

An example application of integrating Cerbos with a FastAPI server using AWS Cognito for authentication.

Dependencies

Getting Started

  1. Start up the Cerbos PDP instance docker container. This will be called by the FastAPI app to check authorization.
cd cerbos
./start.sh
  1. Install python dependencies
# from project root
./pw install
  1. Set the appropriate environment variables
AWS_COGNITO_POOL_ID
AWS_COGNITO_CLIENT_ID
AWS_DEFAULT_REGION
AWS_COGNITO_POOL_NAME

# if you've configured your user pool with a client secret
AWS_COGNITO_CLIENT_SECRET

# optionally, to enable the hosted UI:
AWS_COGNITO_HOSTED_UI_CALLBACK_URL # this needs to match the callback URL configured for the hosted UI
AWS_COGNITO_HOSTED_UI_LOGOUT_URL
  1. Start the FastAPI dev server
./pw demo

Cognito Configuration

Groups

This demo maps Cognito User Pool groups to Cerbos roles. The app will retrieve the groups from the access token, and use them to determine authorization.

Any test users in your pool should be added to one or both of admin and/or user groups to demonstrate different access to the demo resources.

Policies

This example has a simple CRUD policy in place for a resource kind of contact - like a CRM system would have. The policy file can be found in the cerbos/policies folder here.

Should you wish to experiment with this policy, you can try it in the Cerbos Playground.

The policy expects one of two roles to be set on the principal - admin and user. These roles are authorized as follows:

Action User Admin
list Y Y
read Y Y
create Y Y
update If owner Y
delete If owner Y

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 64.3%
  • HTML 33.1%
  • Shell 1.9%
  • Other 0.7%