From 792081212d0745ca81a996e49657bca77910461a Mon Sep 17 00:00:00 2001 From: Mike Heijmans Date: Wed, 18 May 2016 09:47:23 -0700 Subject: [PATCH] add basic auth support fixes #8 --- README.md | 12 ++++++++++++ server.rb | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 19b8280..3633303 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,15 @@ docker run -d -p 80:80 parabuzzle/craneoperator:latest ## How do I configure it? +Available Environment Variables: + + * **REGISTRY_HOST** - the registry host to browse (default: `localhost`) + * **REGISTRY_PORT** - the port of the registry host (default: `5000`) + * **REGISTRY_PROTO** - the protocol to use (ie: `http` or `https`) (default: `https`) + * **REGISTRY_SSL_VERIFY** - should the certificate be verified if using SSL (default: `true`) + * **USERNAME** - setting this will activate BASIC AUTH and require this username + * **PASSWORD** - optional password for BASIC AUTH (you must set the `USERNAME` for this to work) + ``` docker run -d \ -p 80:80 \ @@ -24,6 +33,9 @@ docker run -d \ -e REGISTRY_PORT=443 \ -e REGISTRY_PROTO=https \ -e REGISTRY_SSL_VERIFY=false \ + -e USERNAME=admin \ + -e PASSWORD=s3cr3t \ parabuzzle/craneoperator:latest ``` + ![screenshots/Crane_Operator.jpg](screenshots/Crane_Operator.jpg) diff --git a/server.rb b/server.rb index e7559e3..7add2c0 100644 --- a/server.rb +++ b/server.rb @@ -41,6 +41,14 @@ def registry_ssl_verify ENV['REGISTRY_SSL_VERIFY'] || 'true' end + ## Authentication ## + + if ENV['USERNAME'] + use Rack::Auth::Basic, "Please Authenticate to View" do |username, password| + username == ENV['USERNAME'] and password == ( ENV['PASSWORD'] || '' ) + end + end + ## Helpers ## def to_bool(str)