Skip to content
Merged
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: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
.github
101 changes: 101 additions & 0 deletions .github/scripts/smoke.sh
Original file line number Diff line number Diff line change
@@ -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'
105 changes: 67 additions & 38 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM nginx:alpine
FROM nginx:1.31.10-alpine@sha256:7fc0fb4af7bf006aeb31aea88069976060f8f0a0a86b667126742cc17f4e31ae

ENV HTPASSWD='foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.' \
FORWARD_PORT=80 \
Expand All @@ -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"]
Loading