Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
A library that provides both authentication and authorization functionalities.
pip install auth-checker
Currently, there is only a single authentication method available, which is token based via Google Authentication. But
the library is designed to be extensible, by extending the Authenticator
class and implementing the authenticate
method.
The library provides two FastAPI routes that provide initial authentication and token refresh functionalities.
You can bring them into your FastAPI app by using the auth_checker.authn.routes.router
.
from auth_checker.authn.routes import router as auth_router
from fastapi import FastAPI
app = FastAPI()
...
app.include_router(auth_router, prefix="/auth")
The library provides a plugin system for authorization. You can create your own authorization plugins by inheriting from
the BaseAuthorizer
class and implementing the required methods.
At this time this library provides a primary authorization plugin (casbin_pl
) that is based on the Casbin Authorization Library.
There is a satauth_pl
plugin that is provided, but it is primarily meant as a demo port of the original
Authorization Service
. It can be used as a reference for creating your own plugins.
The library provides two fastapi routes for authorization:
/casbin
The root route provides casbin enforcer authorization route./roles
The roles route provides roles route for the user. This endpoint is not casbin specific.from auth_checker.authz.authorizer import Authorizer
authz = Authorizer()
# Check if a user is authorized to perform an action
if authz.authorize("user@company.com", "my_app", "read"):
print("User is authorized")
else:
print("User is not authorized")
In projects that use this library the following environment variables should be set:
The AUTHORIZER
tells the system which of the installed plugins to use. In this case, use the casbin_authorizer
.
export AUTHORIZER=casbin_authorizer
After that refer to the plugins themselves for the required environment variables.
The CASBIN_AUTHORIZER_POLICY_ADAPTER
tells the plugin which policy store to use. There are three initial options:
file
- This stores the policy in a file.mongo
- This stores the policy in a MongoDB database.redis
- This stores the policy in a Redis database.The file
Policy Adapter requires the following environment variables:
The mongo
Policy Adapter requires the following environment variables:
The redis
Policy Adapter requires the following environment variables:
Right now there is no frontend for adding policies. You can add policies by using the Casbin library directly. The functions required to manage the policy store can be found here: Casbin Policy Management
from auth_checker.authz.authorizer import Authorizer
authz = Authorizer()
# First lets create a staff role for an application called `my_app`
authz.enforcer.add_policy("staff", "my_app", "read")
authz.enforcer.add_policy("staff", "my_app", "write")
# Now let's add a user to the staff role
authz.enforcer.add_role_for_user("user@company.com", "staff")
There are more examples of how to organize the policy structure in notebooks/setup_casbin_policy_store.ipynb
.
To use the notebook, you will need to make sure the required environment variables are set. Then bring up jupyter lab and open the notebook.
$> make lab
FAQs
Contains the AuthChecker class for apps using the Auth Service
We found that auth-checker demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.