- Install
aikido_zen
package with pip :
pip install aikido_zen
- Add the following snippet to the top of your
app.py
file :
import aikido_zen
aikido_zen.protect()
Make sure this is above any other import, including above builtin package imports.
- Setting your environment variables : Make sure to set your token in order to communicate with Aikido's servers
AIKIDO_TOKEN="AIK_RUNTIME_YOUR_TOKEN_HERE"
If you're using gunicorn, please check our docs on that first : Click Here
By default, the firewall will run in non-blocking mode. When it detects an attack, the attack will be reported to Aikido and continue executing the call.
You can enable blocking mode by setting the environment variable AIKIDO_BLOCKING
to true
:
AIKIDO_BLOCKING=true
It's recommended to enable this on your staging environment for a considerable amount of time before enabling it on your production environment (e.g. one week).
If you want to add the rate limiting feature to your app, modify your code like this:
from aikido_zen.middleware import AikidoFlaskMiddleware
app = Flask(__name__)
# ...
app.wsgi_app = AikidoFlaskMiddleware(app.wsgi_app)
# ...
# Authorization middleware here (Make sure aikido middleware runs after this)
# ...
As soon as you identify the user in you authorization middleware, pass the identity info to Aikido.
from aikido_zen import set_user
# Set a user (presumably in middleware) :
set_user({"id": "123", "name": "John Doe"})
If you need to debug the firewall, you can run your code with the environment variable AIKIDO_DEBUG
set to true
:
AIKIDO_DEBUG=true
This will output debug information to the console (e.g. no token was found, unsupported packages, extra information, ...).