GithubHelp home page GithubHelp logo

phase2 / docker-https-proxy Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 6.0 12 KB

Handles HTTPS proxying with automatic self-signed certs for SSL termination.

Home Page: https://hub.docker.com/r/outrigger/https-proxy/

Shell 100.00%
docker-image outrigger ssl-termination

docker-https-proxy's Introduction

Outrigger HTTPS Proxy

Handles HTTPS proxying with automatic self-signed serts for SSL termination.

GitHub tag Docker Stars Docker Pulls

This HTTPS proxy container is intended primarily for use with APIs (headless web services).

While many languages in which you write such services have a strong HTTP library, they are not full-featured, production-grade HTTP servers covering all the standard needs out-of-box, and it is easier to configure nginx and rely on it's maturity than build many of these features in custom code.

Usage

Docker Run

docker run --rm -it \
  -e "UPSTREAM_DOMAIN=api.projectname.vm" \
  -e "UPSTREAM_PORT=3773" \
  -e "PROXY_DOMAIN=proxy.projectname.vm" \
  -l "com.dnsdock.name=proxy" \
  -l "com.dnsdock.image=projectname" \
  outrigger/https-proxy:1.0

Docker Compose

  # docker-compose run --rm proxy
  # The UPSTREAM service must be running.
  # https://proxy.projectname.vm
  proxy:
    build: outrigger/https-proxy:1.0
    container_name: projectname_http_proxy
    depends_on:
      - api
    labels:
      com.dnsdock.name: proxy
      com.dnsdock.image: projectname
    environment:
      UPSTREAM_DOMAIN: api.projectname.vm
      UPSTREAM_PORT: 3773
      PROXY_DOMAIN: proxy.projectname.vm
    network_mode: bridge

Features

SSL Termination

This image was created after finding https://github.com/fsouza/docker-ssl-proxy was very difficult to customize, but the simple untrusted SSL for local development was still valuable.

In the future steps might be taken to facilitate more of a trust mechanism.

Certificates and CA location

The SSL certificate is generated using a own-ROOT-ca that is available in the directory /etc/nginx/ca. If made available to other containers or the local system this will serve as the basis to trust the application certificate.

Using Existing Certificate

You can use existing SSL certificates for your proxy domain by mounting a volume to /etc/nginx/certs with following files inside:

  • key.pem: Private key file
  • cert.pem: Certificate file

The certificate generator will abort if it finds an existing key.pem file.

gzip Compression

Responses of at least 1000 bytes will be subject to gzip compression at level 6.

Rate Limiting

Rate Limits are more common with API-based services than other webapps. It is a request throttle to ensure no one system monopolizes the available server resources.

This is defaulted to enabled (at 20 requests per second) but can be disabled by setting the RATE_LIMIT environment variable to "0".

In the event the limit is reached, nginx will respond with a 429 Too Many Requests response.

IP-based Access Example

There is a configuration file to impose IP-based Whitelisting and Blacklisting rules. These are best handled in the nginx layer rather than in your application, as your application is unlikely to handle it as efficiently as nginx can.

Follow the instructions in ./root/etc/nginx/conf.d/10-ip-access.conf to use it in your project.

Environment Variables

Outrigger images use Environment Variables and confd to templatize a number of Docker environment configurations. These templates are processed on startup with environment variables passed in via the docker run command-line or via your docker-compose.yml manifest file.

  • CLIENT_MAX_BODY_SIZE: [20M] Maximium size of client uploads.
  • GZIP_APPROVED_MIME_TYPES: [``] Additional MIME types to include in gzip compression.
  • PROXY_DOMAIN: [www.example.com] The domain in the SSL certificate. Relayed via X-Forwarded-Host HTTP header.
  • RATE_LIMIT: [20] Throttled requests per second per client IP address.
  • RATE_LIMIT_BURST_QUEUE: [10] Number of requests to delay before enforcing the limit.
  • UPSTREAM_DOMAIN: [proxied.example.com] The target host for the reverse proxy. Relayed via Host HTTP header.
  • UPSTREAM_PORT: [80] The target port for the proxied service.

Maintainers

Phase2 Logo

docker-https-proxy's People

Contributors

grayside avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

docker-https-proxy's Issues

Add support for multi-domain/wildcard domains

Goal

In order to proxy URLs that encode key parameter details as part of the domain, we need better built-in support for multiple domains or wildcard domains.

Environment

Local development, wherein the "multiple URL" nature leans on the implicit "wildcarding" provided by Outrigger DNSDock. For example, api.projectname.vm, fr.api.rojectname.vm, de.api.projectname.vm will all be routed to the same container.

Required Actions

Populated X-Forwarded-Host with the Request Domain

Provide instructions on how to get variable domains registered in the X-Forwarded-Host header so the upstream can examine the downstream request host, embedded with key request parameters.

Preferred: nginx-only (Not Working)

In our target environment context, the "wildcard DNS" approach works but I have not found how to populate the X-Forwarded-Host header with the full request domain, it is reduced to the actual DNS entry. nginx proxy requests are sent with an Origin header that includes the correct domain.

Fallback: nginx & docker-compose (Working)

  • nginx.conf.tmpl: Replace X-Forwarded-Host configuration of {{ getenv "PROXY_DOMAIN"}} with $host. In this way the forwarded host should use whatever reaches it. (This was not sufficient for the nginx-only approach above.)

  • docker-compose.yml: Add com.dnsdock.aliases, with comma-delimited entries for each variant domain

labels:
  com.dnsdock.aliases: fr.api.rojectname.vm, de.api.projectname.vm

Wildcard/Multi-domain CSR Certificate

Still researching.

X-Forwarded-Port Env var

Would it be possible to change X-Forwarded-Port to an environment var instead of statically set to 443?

I run multiple docker instances and usually have them on non-standard ports.

Thanks,

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.