Simple authentication gateway with webauthn
version: '3'
services:
app:
container_name: authenhub
image: elquimista/authenhub:latest
restart: unless-stopped
ports:
- 127.0.0.1:9696:9696
env_file: .env
Copy example.env
file to .env
and fill and/or change values appropriately. And then run:
docker-compose up -d
When you are running the app for the first time, you probably want to register your Yubikey:
- Set
SIGNUP_ENABLED="true"
in.env
file. - Run
docker-compose down; docker-compose up -d
- Go to
"https://<authenhub_app_domain>/signup"
in the browser. If you are running this app locally, it's best to run it behind Nginx proxy along withLet's Encrypt
free SSL. - Once you are done interacting with your Yubikey, copy
webauthn_id
andpublic_key
values, and append the pair toADMIN_WEBAUTHN_CREDS
in.env
file. - Disable signup by reverting
SIGNUP_ENABLED
to"false"
in.env
file. - Start a fresh container again:
docker-compose down; docker-compose up -d
It is assumed these files are called in from the main nginx conf file.
/usr/local/etc/nginx/sites-enabled/authenhub.conf
(nginx conf path in homebrew with Intel mac looks like this):
server {
server_name iam.example.com;
proxy_buffering off;
listen 443 ssl; # managed by Certbot
ssl_certificate /Users/<username>/.lets-encrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /Users/<username>/.lets-encrypt/live/example.com/privkey.pem; # managed by Certbot
include /Users/<username>/.lets-encrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /Users/<username>/.lets-encrypt/ssl-dhparams.pem; # managed by Certbot
location / {
proxy_pass http://127.0.0.1:9696;
proxy_set_header Host $host;
}
}
server {
listen 80;
server_name iam.example.com;
return 301 https://$host$request_uri;
}
/usr/local/etc/nginx/sites-enabled/app1.conf
:
server {
server_name app1.example.com;
proxy_buffering off;
listen 443 ssl; # managed by Certbot
ssl_certificate /Users/<username>/.lets-encrypt/live/example.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /Users/<username>/.lets-encrypt/live/example.com/privkey.pem; # managed by Certbot
include /Users/<username>/.lets-encrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /Users/<username>/.lets-encrypt/ssl-dhparams.pem; # managed by Certbot
location / {
auth_request /auth;
error_page 401 = @error401;
proxy_set_header Host $host;
...
}
location = /auth {
internal;
proxy_pass http://127.0.0.1:9696;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Authenhub-Host iam.example.com;
}
location @error401 {
return 302 $scheme://iam.example.com/login?redirect_uri=$scheme://$http_host$request_uri;
}
}
server {
listen 80;
server_name app1.example.com;
return 301 https://$host$request_uri;
}
Clone this repository and run:
docker-compose build
docker-compose up -d
docker-compose exec -it app bash
(docker) $ rackup -o0.0.0.0 -p9696
(docker) $ rake assets:precompile
docker buildx create --use --platform=linux/amd64,linux/arm64
docker buildx build --platform linux/amd64,linux/arm64 --push -t elquimista/authenhub:latest .