Giter VIP home page Giter VIP logo

docker-client-ssl's Introduction

This repo is an example of how to create a docker environment with nginx serving as reverse proxy to nodejs app.

The Nginx server is configured to use ssl...

...delivering its content (through https://)

...and to authenticate its clients.

Disclaimer This is an example repo. Note that the commands below generate the files WITHOUT passphrases. You should look into using the -des3 option and adding the ssl_password_file directive to the nginx config.

Creating the keys and certificates

for both the server and an example client

Taken from here and here

You can run these commands inside the /auth folder. Then, copy the files that nginx needs into docker/web/auth.

Create the CA Key and Certificate for signing Client Certs

openssl genrsa -out ca.key 4096 # add -des3 to give the file a password
openssl req -new -x509 -days 365 -key ca.key -out ca.crt

Create the Server Key, CSR, and Certificate

openssl genrsa -out server.key 1024 # add -des3 to give the file a password
openssl req -new -key server.key -out server.csr

We're self signing our own server cert here. This is a no-no in production.

openssl x509 -req -days 365 -in server.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out server.crt

Create the Client Key and CSR

openssl genrsa -out client.key 1024 # add -des3 to give the file a password
openssl req -new -key client.key -out client.csr

Sign the client certificate with our CA cert. Unlike signing our own server cert, this is what we want to do.

openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -set_serial 01 -out client.crt

Create diffie hellman key for the server

openssl dhparam -out dhparam.pem 2048

Bundle the client certificate and key into p12 file

openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12

You'll need to give these to nginx (place them in docker/web/auth, the dockerfile will do the rest):

  • dhparam.pem
  • ca.crt
  • server.crt
  • server.key

You'll need to give these to your clients:

  • ca.crt
  • client.key + client.csr
  • (or) client.p12

if you want to use curl or some dev library, the certificate+key are enough. If you want to import the certificate into your keychain/firefos/client software, you'll need the p12 file.

  • you can remove the -des3 from the commands above if you don't want to use passphrases in your files.

After configuring nginx, your client should be able to acess the service. Anyone else (or the client without the certificates) should get a 400 - No required SSL certificate was sent error.

In order to run the containers

(you need to be inside the /docker directory)

(also, make sure to change the /docker/web/confs/nodeapi.conf file to suit your domain)

You'll need to build the containers first (also, run this ever time you make ANY changes inside the /docker directory)

docker-compose build --pull;

Run the containers

# Interactively
docker-compose up;
# Daemon
docker-compose up -d;

Stop the containers

docker-compose down

Test

In order to test the configuration, in your client, you can use curl...

# Authenticated
curl -v -s -k --key client.key --cert client.crt https://example.com

# Not Authenticated
curl -v -s -k https://example.com

... or import the p12 file into your system/browser and then navigate to your url.

docker-client-ssl's People

Contributors

pjsousa avatar

Watchers

 avatar  avatar

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.