Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ENV HTPASSWD='foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.' \

WORKDIR /opt

RUN apk add --no-cache gettext
RUN apk add --no-cache gettext apache2-utils

COPY auth.conf auth.htpasswd launch.sh ./

Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ docker run -d --link web:web --name auth \
```
results in 2 users (`foo:bar` and `test:test`).

## Raw Credentials
If passing the contents of the HTPASSWD file is not convenient for you (because
you need to perform additional step of generating it via `htpasswd -nb foo
bar`), you can pass the credentials in a raw form and the contents of HTPASSWD
variable will be generated for you. The `RAW_CREDENTIALS=1` must be set to
enable this feature.

```
docker run -d --link web:web --name auth \
-e HTPASSWD=$'foo:bar\ntest:test' \
-e RAW_CREDENTIALS=1 \
beevelop/nginx-basic-auth
```

## Troubleshooting
```
nginx: [emerg] host not found in upstream "web" in /etc/nginx/conf.d/auth.conf:80
Expand Down
10 changes: 10 additions & 0 deletions launch.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
#!/bin/sh

if [ "$RAW_CREDENTIALS" = 1 ]; then
HTPASSWD=$(
for line in $(echo $HTPASSWD); do
USERNAME="$(echo "$line" | cut -d':' -f1)"
PASSWORD="$(echo "$line" | cut -d':' -f2)"
htpasswd -nb "$USERNAME" "$PASSWORD" | head -n1
done
)
fi

rm /etc/nginx/conf.d/default.conf || :
envsubst < auth.conf > /etc/nginx/conf.d/auth.conf
envsubst < auth.htpasswd > /etc/nginx/auth.htpasswd
Expand Down