diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..f4b1198
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,2 @@
+.git
+.github
diff --git a/.github/scripts/smoke.sh b/.github/scripts/smoke.sh
new file mode 100644
index 0000000..97ba9fd
--- /dev/null
+++ b/.github/scripts/smoke.sh
@@ -0,0 +1,101 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+image=$1
+scratch=$(mktemp -d)
+network="nginx-auth-smoke-${scratch##*.}"
+backend="$network-backend"
+proxy="$network-proxy"
+
+cleanup() {
+ local status=$?
+ if (( status != 0 )); then
+ docker logs "$proxy" 2>/dev/null || true
+ docker logs "$backend" 2>/dev/null || true
+ fi
+ docker rm -f "$proxy" "$backend" >/dev/null 2>&1 || true
+ docker network rm "$network" >/dev/null 2>&1 || true
+ rm -rf "$scratch"
+}
+trap cleanup EXIT
+
+# Keep the inherited entrypoint, working directory, command, port and signal.
+docker image inspect "$image" --format '{{json .Config}}' | jq -e '
+ .Entrypoint == ["/docker-entrypoint.sh"]
+ and .Cmd == ["./launch.sh"]
+ and .WorkingDir == "/opt"
+ and .StopSignal == "SIGQUIT"
+ and (.ExposedPorts | keys) == ["80/tcp"]
+' >/dev/null
+docker run --rm "$image" sh -ec '
+ test "$PWD" = /opt
+ test -x ./launch.sh && test -f auth.conf && test -f auth.htpasswd
+ command -v envsubst >/dev/null
+ command -v curl >/dev/null
+ test -f /docker-entrypoint.d/20-envsubst-on-templates.sh
+'
+docker run --rm --user 65534:65534 "$image" sh -ec '
+ test -r auth.conf && test -r auth.htpasswd && test -x launch.sh
+'
+docker run --rm "$image" nginx -v
+
+cat > "$scratch/backend.conf" <<'NGINX'
+server {
+ listen 80;
+ listen 1337;
+ location / {
+ return 200 "auth=$http_authorization port=$server_port uri=$request_uri";
+ }
+}
+NGINX
+
+docker network create "$network" >/dev/null
+docker run -d --name "$backend" --network "$network" --network-alias web --network-alias custom \
+ --mount "type=bind,src=$scratch/backend.conf,dst=/etc/nginx/conf.d/default.conf,readonly" \
+ --entrypoint nginx "$image" -g 'daemon off;' >/dev/null
+
+start_proxy() {
+ docker run -d --name "$proxy" --network "$network" -p 127.0.0.1::80 "$@" "$image" >/dev/null
+ endpoint="http://$(docker port "$proxy" 80/tcp)/probe?one=two"
+
+ local status=
+ for _ in {1..20}; do
+ if status=$(curl --noproxy '*' -s -o /dev/null -w '%{http_code}' --max-time 2 "$endpoint") &&
+ [[ "$status" == 401 ]]; then
+ return
+ fi
+ sleep 1
+ done
+ printf 'Expected an anonymous 401, received %s\n' "$status" >&2
+ return 1
+}
+
+check_credentials() {
+ local credentials=$1
+ local upstream_port=$2
+ local authorization
+ authorization=$(printf '%s' "$credentials" | base64 -w 0)
+ [[ $(curl --noproxy '*' -fsS --max-time 3 -u "$credentials" "$endpoint") \
+ == "auth=Basic $authorization port=$upstream_port uri=/probe?one=two" ]]
+}
+
+start_proxy
+[[ $(curl --noproxy '*' -s -o /dev/null -w '%{http_code}' --max-time 3 \
+ -u foo:wrong-password "$endpoint") == 401 ]]
+curl --noproxy '*' -s -o /dev/null -D "$scratch/headers" --max-time 3 "$endpoint"
+grep -Fiq 'WWW-Authenticate: Basic realm="Restricted"' "$scratch/headers"
+check_credentials foo:bar 80
+docker rm -f "$proxy" >/dev/null
+
+printf -v records 'one:%s\ntwo:%s' "$(openssl passwd -apr1 first)" "$(openssl passwd -apr1 second)"
+start_proxy -e FORWARD_HOST=custom -e FORWARD_PORT=1337 -e HTPASSWD="$records"
+check_credentials one:first 1337
+check_credentials two:second 1337
+[[ $(curl --noproxy '*' -s -o /dev/null -w '%{http_code}' --max-time 3 -u foo:bar "$endpoint") == 401 ]]
+docker rm -f "$proxy" >/dev/null
+
+start_proxy -e HTPASSWD= -e FORWARD_HOST='[::1]' -e FORWARD_PORT=000080
+docker exec "$proxy" grep -Fq 'http://[::1]:000080' /etc/nginx/conf.d/auth.conf
+[[ $(curl --noproxy '*' -s -o /dev/null -w '%{http_code}' --max-time 3 -u foo:bar "$endpoint") == 401 ]]
+
+printf 'Legacy defaults, inline authentication, upstream forwarding, and command overrides passed.\n'
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 515a7f8..f7b41b2 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -2,63 +2,92 @@ name: Docker Image
on:
schedule:
- - cron: "0 10 * * *" # everyday at 10am
+ - cron: '0 10 * * *'
workflow_dispatch:
pull_request:
- branches: ["**"]
push:
- branches: ["**"]
- tags: ["v*.*.*"]
+ # Validate the winter clean through its pull request without publishing a review tag.
+ branches-ignore: [winter-clean-2026]
+ tags: ['v*.*.*']
+
+permissions:
+ contents: read
+
+concurrency:
+ group: ${{ github.workflow }}-${{ github.ref }}
+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}
env:
- platforms: linux/amd64,linux/arm64/v8,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6
+ PLATFORMS: linux/amd64,linux/arm64/v8,linux/ppc64le,linux/s390x,linux/386,linux/arm/v7,linux/arm/v6
+ PUBLISH: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
jobs:
main:
- runs-on: ubuntu-22.04
- timeout-minutes: 10
+ runs-on: ubuntu-24.04
+ timeout-minutes: 30
steps:
- - name: Check out the repo
- uses: actions/checkout@v7
+ - name: Check out the repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
- ref: ${{ github.head_ref || github.ref }}
- - name: Set imageName based on the repository name
- id: step_one
- run: |
- imageName="${GITHUB_REPOSITORY/docker-/}"
- echo $imageName
- echo "imageName=$imageName" >> $GITHUB_ENV
- - name: Docker meta
- id: docker_meta
- uses: docker/metadata-action@v6
- with:
- images: ${{ env.imageName }}
+ persist-credentials: false
+
+ - name: Set image name
+ run: printf 'IMAGE=%s\n' "${GITHUB_REPOSITORY/docker-/}" >> "$GITHUB_ENV"
+
- name: Set up QEMU
- uses: docker/setup-qemu-action@v4
+ uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4.4.0
+ with:
+ platforms: arm64,arm,ppc64le,s390x
+
- name: Set up Docker Buildx
- uses: docker/setup-buildx-action@v4
- - name: Login to DockerHub
- if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
- uses: docker/login-action@v4.8.0
+ uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
+
+ - name: Check Dockerfile
+ run: docker buildx build --check .
+
+ - name: Build smoke-test image
+ uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
+ with:
+ context: .
+ platforms: linux/amd64
+ pull: true
+ load: true
+ tags: nginx-basic-auth:smoke
+
+ - name: Test the existing proxy contract
+ run: bash .github/scripts/smoke.sh nginx-basic-auth:smoke
+
+ - name: Generate image tags and labels
+ if: env.PUBLISH == 'true'
+ id: meta
+ uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
+ with:
+ images: ${{ env.IMAGE }}
+
+ - name: Log in to Docker Hub
+ if: env.PUBLISH == 'true'
+ uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4.8.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- - name: Build and push
- id: docker_build
- uses: docker/build-push-action@v7
+ - name: Build all supported platforms
+ id: release
+ uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
- platforms: ${{ env.platforms }}
- push: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
+ context: .
+ platforms: ${{ env.PLATFORMS }}
pull: true
- tags: ${{ steps.docker_meta.outputs.tags }}
- labels: ${{ steps.docker_meta.outputs.labels }}
- - name: Docker Scout
- id: docker-scout-cves
- if: ${{ github.event_name != 'pull_request' && github.actor != 'dependabot[bot]' }}
- uses: docker/scout-action@v1.29.0
+ push: ${{ env.PUBLISH == 'true' }}
+ outputs: ${{ env.PUBLISH != 'true' && 'type=cacheonly' || '' }}
+ tags: ${{ steps.meta.outputs.tags }}
+ labels: ${{ steps.meta.outputs.labels }}
+
+ - name: Report critical and high CVEs with Docker Scout
+ if: env.PUBLISH == 'true'
+ uses: docker/scout-action@b265cd48f8a1451d2680815b3e8dc4ed65ee16e7 # v1.30.0
with:
command: cves
- image: ${{ env.imageName }}:${{ steps.docker_meta.outputs.version }}
+ image: ${{ env.IMAGE }}@${{ steps.release.outputs.digest }}
only-severities: critical,high
exit-code: false
diff --git a/Dockerfile b/Dockerfile
index f06887e..04515b3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,4 +1,4 @@
-FROM nginx:alpine
+FROM nginx:1.31.10-alpine@sha256:7fc0fb4af7bf006aeb31aea88069976060f8f0a0a86b667126742cc17f4e31ae
ENV HTPASSWD='foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.' \
FORWARD_PORT=80 \
@@ -10,7 +10,9 @@ RUN apk add --no-cache gettext
COPY auth.conf auth.htpasswd launch.sh ./
-# make sure root login is disabled
-RUN sed -i -e 's/^root::/root:!:/' /etc/shadow
+# Preserve the published file permissions and disable root login.
+RUN chmod 0644 auth.conf auth.htpasswd \
+ && chmod 0755 launch.sh \
+ && sed -i -e 's/^root::/root:!:/' /etc/shadow
CMD ["./launch.sh"]
diff --git a/README.md b/README.md
index 005b442..7637d77 100644
--- a/README.md
+++ b/README.md
@@ -1,85 +1,64 @@
-
-
-
-
-
-[](https://github.com/beevelop/docker-nginx-basic-auth/releases)
-
-
-[](https://beevelop.com)
+[](https://github.com/beevelop/docker-nginx-basic-auth/actions/workflows/docker.yml)
+[](https://hub.docker.com/r/beevelop/nginx-basic-auth)
+[](https://github.com/beevelop/docker-nginx-basic-auth/releases)
-# Docker Nginx Basic Auth - Simple Authentication Proxy
+# Nginx Basic Auth proxy
-> Lightweight nginx reverse proxy with HTTP basic authentication for securing Docker containers and web applications.
+Protect an HTTP service behind nginx with HTTP Basic authentication. This image uses the full nginx 1.31.10 Alpine base and listens on container port 80.
## Quickstart
-```bash
-docker run -d --name web dockercloud/hello-world
-docker run -d -p 80:80 --link web:web --name auth beevelop/nginx-basic-auth
-```
-
-Try accessing and logging in with username `foo` and password `bar`.
+Run the proxy and an example upstream on the same Docker network.
-## Advanced
-
-```bash
-docker run -d \
- -e HTPASSWD='foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.' \
- -e FORWARD_PORT=1337 \
- --link web:web -p 8080:80 \
- --name auth \
- beevelop/nginx-basic-auth
+```sh
+docker network create nginx-auth-demo
+docker run -d --network nginx-auth-demo --name web nginx:alpine
+docker run -d --network nginx-auth-demo --name auth \
+ -p 127.0.0.1:8080:80 beevelop/nginx-basic-auth
+curl -u foo:bar http://127.0.0.1:8080/
```
-> Use single quotes to prevent unwanted interpretation of `$` signs!
+The example credentials are `foo` and `bar`. Supply your own password records with `HTPASSWD` when deploying the proxy. The existing [Compose and Swarm example](docker-stack.yml) can also run the demo.
## Configuration
-- `HTPASSWD` (default: `foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.`): Will be written to the .htpasswd file on launch (non-persistent)
-- `FORWARD_PORT` (default: `80`): Port of the **source** container that should be forwarded
-- `FORWARD_HOST` (default: `web`): Hostname of the **source** container that should be forwarded
- > The container does not need any volumes to be mounted! Nonetheless you will find all interesting files at `/etc/nginx/*`.
-
-## Multiple Users
+| Variable | Default | Description |
+| --- | --- | --- |
+| `HTPASSWD` | `foo` / `bar` | Inline htpasswd records separated by newlines. Single-quote literal records to preserve dollar signs in hashes. |
+| `FORWARD_HOST` | `web` | Upstream address reachable from the container. |
+| `FORWARD_PORT` | `80` | Upstream HTTP port. |
-Multiple Users are possible by separating the users by newline. To pass the newlines properly you need to use Shell Quoting (like `$'foo\nbar'`):
-
-```
-docker run -d --link web:web --name auth \
- -e HTPASSWD=$'foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.\ntest:$apr1$LKkW8P4Y$P1X/r2YyaexhVL1LzZAQm.' \
- beevelop/nginx-basic-auth
-```
+For a custom login, create an htpasswd file with a tool such as `htpasswd -cB users.htpasswd alice`, then pass its contents as `-e HTPASSWD="$(cat users.htpasswd)"` when creating the container. One record per line enables multiple users. Compose YAML requires literal dollar signs in inline hashes to be escaped as `$$`.
-results in 2 users (`foo:bar` and `test:test`).
+The proxy forwards the client's Authorization header to the upstream after successful authentication. The launcher renders the templates from `/opt` into `/etc/nginx` on startup.
-## Troubleshooting
+## Build and test
-**Error: `nginx: [emerg] host not found in upstream "web"`**
-- Ensure you link the container as `web` using `--link foobar:web`
-
-## Limitations
-
-- SSL/HTTPS is not currently supported
-- For SSL requirements, consider using `jwilder/nginx-proxy` as a central gateway with `VIRTUAL_HOST` environment variable
-
----
-
-# All Docker Images
+```sh
+docker build -t nginx-basic-auth:local .
+bash .github/scripts/smoke.sh nginx-basic-auth:local
+```
-| Badge | Pulls | Build Status | Release Date | Release |
-| --- | --- | --- | --- | --- |
-| [](https://github.com/beevelop/docker-base) |  |  |  |  |
-| [](https://github.com/beevelop/docker-java) |  |  |  |  |
-| [](https://github.com/beevelop/docker-android) |  |  |  |  |
-| [](https://github.com/beevelop/docker-android-nodejs) |  |  |  |  |
-| [](https://github.com/beevelop/docker-cordova) |  |  |  |  |
-| [](https://github.com/beevelop/docker-ionic) |  |  |  |  |
-| [](https://github.com/beevelop/docker-nginx-basic-auth) |  |  |  |  |
+Pull requests exercise the existing proxy contract and build all seven supported platforms. Scheduled builds refresh `latest` and `nightly` daily at 10:00 UTC. Branch pushes, version tags, and manual runs can publish as before. Use a release tag or digest when you need to pin a deployment.
---
-
+## All Docker images
+
+| Badge | Docker Hub | Build Status | Published | Release / Tag | License |
+| --- | --- | --- | --- | --- | --- |
+| [](https://github.com/beevelop/docker-base) | [](https://hub.docker.com/r/beevelop/base)
[](https://hub.docker.com/r/beevelop/base)
[](https://hub.docker.com/r/beevelop/base/tags?name=latest) | [](https://github.com/beevelop/docker-base/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-base/releases/latest) | [](https://github.com/beevelop/docker-base/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-base/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-java) | [](https://hub.docker.com/r/beevelop/java)
[](https://hub.docker.com/r/beevelop/java)
[](https://hub.docker.com/r/beevelop/java/tags?name=latest) | [](https://github.com/beevelop/docker-java/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-java/releases/latest) | [](https://github.com/beevelop/docker-java/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-java/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-android) | [](https://hub.docker.com/r/beevelop/android)
[](https://hub.docker.com/r/beevelop/android)
[](https://hub.docker.com/r/beevelop/android/tags?name=latest) | [](https://github.com/beevelop/docker-android/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-android/releases/latest) | [](https://github.com/beevelop/docker-android/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-android/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-android-nodejs) | [](https://hub.docker.com/r/beevelop/android-nodejs)
[](https://hub.docker.com/r/beevelop/android-nodejs)
[](https://hub.docker.com/r/beevelop/android-nodejs/tags?name=latest) | [](https://github.com/beevelop/docker-android-nodejs/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-android-nodejs/releases/latest) | [](https://github.com/beevelop/docker-android-nodejs/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-android-nodejs/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-cordova) | [](https://hub.docker.com/r/beevelop/cordova)
[](https://hub.docker.com/r/beevelop/cordova)
[](https://hub.docker.com/r/beevelop/cordova/tags?name=latest) | [](https://github.com/beevelop/docker-cordova/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-cordova/releases/latest) | [](https://github.com/beevelop/docker-cordova/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-cordova/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-ionic) | [](https://hub.docker.com/r/beevelop/ionic)
[](https://hub.docker.com/r/beevelop/ionic)
[](https://hub.docker.com/r/beevelop/ionic/tags?name=latest) | [](https://github.com/beevelop/docker-ionic/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-ionic/releases/latest) | [](https://github.com/beevelop/docker-ionic/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-ionic/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-nginx-basic-auth) | [](https://hub.docker.com/r/beevelop/nginx-basic-auth)
[](https://hub.docker.com/r/beevelop/nginx-basic-auth)
[](https://hub.docker.com/r/beevelop/nginx-basic-auth/tags?name=latest) | [](https://github.com/beevelop/docker-nginx-basic-auth/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-nginx-basic-auth/releases/latest) | [](https://github.com/beevelop/docker-nginx-basic-auth/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-nginx-basic-auth/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-claude) | [](https://hub.docker.com/r/beevelop/claude)
[](https://hub.docker.com/r/beevelop/claude)
[](https://hub.docker.com/r/beevelop/claude/tags?name=latest) | [](https://github.com/beevelop/docker-claude/actions/workflows/docker.yml) | [](https://hub.docker.com/r/beevelop/claude/tags) | [](https://hub.docker.com/r/beevelop/claude/tags?name=latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-claude/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-nodejs) | [](https://hub.docker.com/r/beevelop/nodejs)
[](https://hub.docker.com/r/beevelop/nodejs)
[](https://hub.docker.com/r/beevelop/nodejs/tags?name=latest) | [](https://github.com/beevelop/docker-nodejs/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-nodejs/releases/latest) | [](https://github.com/beevelop/docker-nodejs/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-nodejs/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-nodejs-python) | [](https://hub.docker.com/r/beevelop/nodejs-python)
[](https://hub.docker.com/r/beevelop/nodejs-python)
[](https://hub.docker.com/r/beevelop/nodejs-python/tags?name=latest) | [](https://github.com/beevelop/docker-nodejs-python/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-nodejs-python/releases/latest) | [](https://github.com/beevelop/docker-nodejs-python/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-nodejs-python/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-uniqush) | [](https://hub.docker.com/r/beevelop/uniqush)
[](https://hub.docker.com/r/beevelop/uniqush)
[](https://hub.docker.com/r/beevelop/uniqush/tags?name=latest) | [](https://github.com/beevelop/docker-uniqush/actions/workflows/docker.yml) | [](https://github.com/beevelop/docker-uniqush/releases/latest) | [](https://github.com/beevelop/docker-uniqush/releases/latest)
[](https://calver.org/) | [](https://github.com/beevelop/docker-uniqush/blob/latest/LICENSE) |
+| [](https://github.com/beevelop/docker-shields) | [](https://hub.docker.com/r/beevelop/shields)
[](https://hub.docker.com/r/beevelop/shields)
[](https://hub.docker.com/r/beevelop/shields/tags?name=latest) | [](https://github.com/beevelop/docker-shields/actions) | [](https://hub.docker.com/r/beevelop/shields/tags) | [](https://hub.docker.com/r/beevelop/shields/tags?name=latest) | [](https://github.com/beevelop/docker-shields) |
### Use tags where possible, because