GithubHelp home page GithubHelp logo

fractos / heimdal Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 12 KB

Python quick-and-dirty layer 7 web application firewall that applies a list of CIDR and HTTP method rules.

License: MIT License

Python 89.04% Shell 2.31% Dockerfile 8.65%
python firewall layer7 cidr http tornado tornado-web quickproxy

heimdal's Introduction

Heimdal

Docker Pulls Build Status

Heimdal is a Layer 7 web application firewall that selectively proxies traffic onto a target host based on CIDR matches for IP addresses and the HTTP methods allowed for that match.

It uses the X-Forwarded-For HTTP header to determine the remote IP address of a connection.

For example, in AWS an Elastic Load Balancer might add two entries to an X-Forwarded-For header:

X-Forwarded-For: 37.59.40.223, 172.140.17.1

Where the first dotted IP address is the actual remote IP of the request and the second is the load balancer appliance itself.

Rule configuration

The rules are encoded in a basic JSON format:

{
  "rules": [
    {
      "effect": "ALLOW",
      "methods": [
        "GET", "HEAD", "OPTIONS"
      ],
      "source": [
        "0.0.0.0/0"
      ]
    },
    {
      "effect": "ALLOW",
      "methods": [
        "PUT", "POST", "PATCH"
      ],
      "source": [
        "46.102.195.175/32",
        "62.254.125.126/32"
      ]
    }
  ]
}

This allows GET, HEAD, OPTIONS requests from anywhere, but only allows PUT, POST, PATCH operations from two distinct IP addresses.

All non-matching traffic will receive a 403 Forbidden response immediately, without consulting the target.

Installation and Running

Heimdal needs to be installed behind a load balancer appliance or other proxy that adds an X-Forwarded-For header.

You can pass a rules file for Heimdal to use with a Docker volume command, mapping a file into the container as /etc/heimdal/rules.json.

Environment Variable Description Mandatory
LISTENER_PORT Heimdal's listening port for requests Yes
TARGET_HOST Proxy target hostname Yes
TARGET_PORT Proxy target port Yes
RULES_FILE Location of the rules file to use - defaults to /etc/heimdal/rules.json No
sudo docker run -d --rm \
    --env LISTENER_PORT='<listener port>' \
    --env TARGET_HOST='<target host>' \
    --env TARGET_PORT='<target port>' \
    -v <absolute path to rules file>:/etc/heimdal/rules.json \
    heimdal

Note

Input for -v needs to be an absolute path.

Etymology

Heimdal uses the quickproxy library which in turn uses the Tornado web server.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.