0.0
No commit activity in last 3 years
No release in over 3 years
Refuse access if X-API-SECRET header does not contain required value. Allow unrestricted access to selected paths.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
>= 0
~> 10.0
>= 0

Runtime

>= 0
 Project Readme

HerokuLockdown

Rack middleware to add to a micro service to prevent access to the Heroku servers without a key.

  • a valid key must be supplied in the x-api-secret header.
  • exceptions are allowed for:
    • /status.json and
    • /status_all.json
  • additional exceptions can be defined at initialization.
  • errors are currently returned in Westfield V1 format. Other versions will be supplied in a later revision.

Installation

Add this line to your application's Gemfile:

gem 'heroku_lockdown'

And then execute:

$ bundle

Or install it yourself as:

$ gem install heroku_lockdown

Usage

In config/application.rb configuration block, add

module SomeService
  REPORTING_VERSION = '1.4'
  class Application < Rails::Application

    config.middleware.insert_before(Rack::Runtime, 'HerokuLockdown::SecureAccess', ENV['X_API_SECRET'], REPORTING_VERSION, [ additional_path_regexs ])

  end
end

This places the middlware at the beginning of the list of Rails middleware. It is desirable to have this as early as possible. With the development of Rails, this location may need to change.

The key that the service expects is stored in the environment variable X_API_SECRET. Each service should have its own unique key.

additional_path_regexes are regular expressions for any other paths (no host) that should be allowed without supplying the required key. For security it is best if they are complete and anchored at both ends, e.g. /\A/v\d\/swagger\z/i

In normal operation, the gateway routers insert the x-api-secret header and the appropriate key so operation is invisible. The effect is to require access to go through the gateway public endpoints and to not directly communicate with the Heroku servers.

If the X_API_SECRET environment variable is not defined in the service, then the key is not required. This allows local development without keys, and disabling the lock down when needed.