Skip to content

Add user and password as env support #24

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from
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
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ Try accessing and logging in with username `foo` and password `bar`.

```bash
docker run -d \
-e HTPASSWD='foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn.' \
-e FORWARD_PORT=1337 \
-e BASIC_USERNAME=myuser \
-e BASIC_PASSWORD=passw0rd123
--link web:web -p 8080:80 \
--name auth \
beevelop/nginx-basic-auth
Expand All @@ -55,6 +56,66 @@ docker run -d --link web:web --name auth \

results in 2 users (`foo:bar` and `test:test`).

## K8s
Create secret

```
apiVersion: v1
kind: Secret
metadata:
name: prometheus-auth
type: Opaque
data:
username: bXl1c2Vy #base64 username
password: cGFzc3cwcmQxMjM= #base64 password

```

Create your deployment

```
...

- name: nginx
image: beevelop/nginx-basic-auth
securityContext:
runAsUser: 0
runAsNonRoot: false
env:
- name: BASIC_USERNAME
valueFrom:
secretKeyRef:
name: auth
key: username
- name: BASIC_PASSWORD
valueFrom:
secretKeyRef:
name: auth
key: password
- name: FORWARD_PORT
value: "9090"
- name: FORWARD_HOST
value: "localhost"
ports:
- containerPort: 80
- name: prometheus-server
image: "prom/prometheus:v2.13.1"
imagePullPolicy: "IfNotPresent"
args:
- --storage.tsdb.retention.time=120d
- --config.file=/etc/config/prometheus.yml
- --storage.tsdb.path=/data
- --web.console.libraries=/etc/prometheus/console_libraries
- --web.console.templates=/etc/prometheus/consoles
- --web.enable-lifecycle
- --web.external-url=https://host.domain.com/prometheus
- --web.route-prefix=/prometheus
ports:
- containerPort: 9090
...

```

## Troubleshooting

```
Expand Down
2 changes: 1 addition & 1 deletion launch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

rm /etc/nginx/conf.d/default.conf || :
envsubst < auth.conf > /etc/nginx/conf.d/auth.conf
envsubst < auth.htpasswd > /etc/nginx/auth.htpasswd
htpasswd -bc /etc/nginx/auth.htpasswd $BASIC_USERNAME $BASIC_PASSWORD

exec nginx -g "daemon off;"