Setup and Installation of Zen Firewall for Ruby
This guide will walk you through installing and setting up Zen Firewall by Aikido for your application. Follow the steps below to protect your application.
We have first class support for multiple frameworks and database drivers, for the full list check our README on GitHub.
Installation
Create an app in the dashboard and generate a token
Create your Aikido account if you haven't done so already
Go to the Zen section in Aikido.
Click on Add app.
Choose a name for your app and click Generate token.
Copy the generated token

Configure your application to initiate the Zen firewall.
For Ruby on Rails you can install Zen by requiring it before Bundler.require
in config/application.rb
:
# config/application.rb
require_relative "boot"
require "rails/all"
require "aikido-zen"
Aikido::Zen.protect!
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
Start Zen Firewall in dry / detection-only mode
Set the token as an environment variable:
AIKIDO_TOKEN=YOUR_SECRET_TOKEN
Start your app in dry mode
AIKIDO_BLOCK=false
to ensure it works as expected without blocking any requests. We advise to run Aikido Zen in staging for two weeks to avoid any false positives.
Alternatively, if you're using Rails' encrypted credentials, and prefer not storing sensitive values in your env vars, you can easily configure Zen for it. For example, assuming the following credentials structure:
# config/credentials.yml.enc
zen:
token: "AIKIDO_RUNTIME_..."
You can just tell Zen to use it like so:
# config/initializers/zen.rb
Rails.application.config.zen.token = Rails.application.credentials.zen.token
Test your app
Browse to your application and perform a couple of actions or open a couple of pages. Zen will automatically discover the routes in your application.
You can verify a working agent by looking at the following pages of your Zen application:
Events: Should show an "Application started" event.
Routes: After some time your application routes will start showing here with the method, route and requests.
Instances: Should show the number of active instances for your application where Zen is installed.

Enable Rate limiting and User blocking
Enable additional features like Rate limiting and User blocking from within your code. Check out these examples below. Keep in mind that your specific setup might need adjustments based on your framework and configuration.
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
private
def current_user
return unless session[:user_id]
User.find(session[:user_id])
end
def authenticate_user!
# Your authentication logic here
# ...
# Optional, if you want to use user based rate limiting or block specific users
Aikido::Zen.set_user(
id: current_user.id,
name: current_user.name
)
end
end
Setup rate limiting in the dashboard
After you've added the Aikido middleware, you can test it out by logging in to your Aikido account and navigating to the Zen dashboard.

To protect a route from brute force attacks, set up rate limiting in the Aikido Dashboard:
Click on the created app.
Go to the Routes tab.
Find the route you would like to limit and click Setup rate limiting.
Follow the instructions to configure the rate limit (e.g., 5 requests per minute).


5. Verify Rate Limiting
Start your app and try to access the route you've rate limited 5 times within a minute. After the fifth attempt, you should receive a rate limit error:
You are rate limited by Aikido firewall. (Your IP: 1.2.3.4)
Next steps
Congrats you've successfully installed Aikido Zen. If you encountered any problems, have concerns or have feature requests, don't hesitate to reach out to support.
You can now go and explore the many features that Zen provides:
Additional information:
Last updated
Was this helpful?