0
votes

I'm trying to figure out the best way to manage HTTPS for an EB docker application.

At the moment I'm using the following approach.

  1. ELB accepts HTTPS connections on 443, and forwards to HTTP port 80 on the instance.
  2. ELB accepts HTTP connections on 80, and forwards to HTTP port 8080 on the instance.
  3. Instance accepts HTTP connections on port 80 and forwards to docker app.
  4. Instance accepts HTTP connections on port 8080 and redirects them to HTTPS.

This all works reasonably well. It means the docker app doesn't have to worry about redirects at all. It just listens on port 80, and does it's thing. The ELB and docker host do the rest.

My only concern with this setup, is the docker app doesn't know that it's running secure. If within my application I check for this, it'll fail.

I want to completely separate my docker app from domain names, and SSL certificates that may change, so I would prefer to continue terminating the original HTTPS connection at the ELB. I'm wondering if there is some way I can get the docker host (or ELB) to forward (re-encrypt) request in HTTPS protocol, but using a self-signed certificate, so I can keep it completely generic.

Just to be clear, this would only be between the ELB and/or docker host, and my docker app, not to the browser.

If I create a non-expiring self-signed certificate, and then register this with the web-server in the docker app (currently using Apache2, but could potentially use nginx), and then simply tell the ELB, or docker host to forward requests as HTTPS, will this work? Or would it fall over at some point because the certificate isn't trusted?

Or is there some way to be able to terminate a HTTPS connection at the docker app web-server without actually needing to pre-generate a certificate (I'm guessing no on this, as presumably it'd need to generate a certificate on the fly or something).

Is there a recommended best practice way to do this kind of thing?

1

1 Answers

0
votes

A common solution when you have a load balancer terminating client connections and forwarding to backend is for the load balancer to add headers onto the backend requests to fill in any information stripped by having the load balancer there.

ELB has a page on this and uses the following headers:

  • X-Forwarded-For - The client IP
  • X-Forwarded-Proto - The scheme/protocol
  • X-Forwarded-Port - The incoming port.

You would generally not allow these headers directly from the client, unless they were a trusted client. I assume ELB takes care of that for you.