In order to secure your website with Basic HTTP authentication in Traefik do the following.
sudo apt install apache2-utils
htpasswd -nB adam
n option will display the hash in stdout and the
B option will use more secure encryption.
devto password's hash is shown below:
labels: - "traefik.http.middlewares.yourservice-basicauth.basicauth.users=adam:$$2y$$05$$h9OxLeY20/5uiXjfPgdRxuFlrfqBf2QifYDgrwsR6rAEgX3/dpOGq"
Remember to use the escaped double
You may have existing rules for your HTTPS route, e.g. compressing, etc.
So create a new chain where you'll combine your existing middlewars and the newly created
labels: - "traefik.http.middlewares.yourservice-https-chain.chain.middlewares=yourservice-basicauth,yourservice-other-middleware-remove-or-replace-with-yours" - "traefik.http.routers.yourservice-https.middlewares=yourservice-https-chain"
Restart your service and your website will now prompt browsers for username and password.