Creating user password hash strings for user authorisation with traefik basic-auth middlewares ---------------------------------------------------------------------------------------------- # If not installed, install htpasswd: jlmkr shell docker apt update & apt install apache2-utils # The user credentials can be applied as a label entry in an app's compose.yml file or as a line entry in a text file; these two methods can co-exist # # When used as a label entry, all '$''s need to be escaped with a second '$'; sed can be used for this purpose # # Example: Create user authorisation credentials for users 'alice' with password 'test!234' and 'bob' with password 'test$678' for sonarr application using basic-auth # First, assign middlewares to router in sonarr compose.yml file; this is required irrespective of the method chosen below; add the following label to sonarr's compose.yml file: - "traefik.http.routers.ROUTER_NAME.middlewares=MIDDLEWARES_NAME" # replace ROUTER_NAME with appropriate name and replace MIDDLEWARES_NAME with whatever name you choose for this middlewares # # userList method # --------------- mkdir /opt/stacks/traefik/users echo $(htpasswd -nB alice) >> /opt/stacks/traefik/users/sonarr.txt echo $(htpasswd -nB bob) >> /opt/stacks/traefik/users/sonarr.txt # If not already present, add the following middlewares label to sonarr's compose.yml file (if newly added/modified, requires sonarr restart) - "traefik.http.middlewares.MIDDLEWARES_NAME.basicauth.usersfile=/mnt/users/sonarr.txt" # the above requires the following traefik compose file volume mount entry (if newly added/modified, requires traefik restart): /opt/stacks/traefik/users:/mnt/users # # app compose file label method # ----------------------------- echo $(htpasswd -nB alice) | sed -e s/\\$/\\$\\$/g echo $(htpasswd -nB bob) | sed -e s/\\$/\\$\\$/g # Edit/add output of above to the basicauth.users label to sonarr's compose.yml file as follows (comma separated): - "traefik.http.middlewares.MIDDLEWARES_NAME.basicauth.users=alice:$$2y$$05$$kvFK1SXs5mOzYLXiWT0Bku8rLeUoZWZxBI5./jX/vkhEiYlN/xB1W, bob:$$2y$$05$$E2DeZC3L.wQxYMWlxhtTRusys23y4fabhvzOKTgKNMSzw9cweBeJK" # above edit to sonarr's compose file requires sonarr restart