Skip to content

Commit 9cc805b

Browse files
Alpine and NGINX Basic Auth Enabled (#22)
* switched to alpine image * alpine:3.15 shout out to @martadinata666 for the help * add nginx basic authentication * readme update for basic auth
1 parent b3e645b commit 9cc805b

File tree

5 files changed

+88
-23
lines changed

5 files changed

+88
-23
lines changed

Dockerfile

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
FROM ubuntu:20.04
1+
FROM alpine:3.15 AS builder
22

3-
RUN export DEBIAN_FRONTEND=noninteractive
4-
RUN apt-get update -y
5-
6-
# install nginx
7-
RUN apt-get install -y nginx
8-
9-
# install deps
10-
RUN apt-get install -y build-essential libmaxminddb-dev libncurses-dev
11-
RUN apt-get install -y tini ca-certificates wget curl
12-
13-
# clean up
14-
RUN apt-get autoremove -qy
3+
RUN apk add --no-cache \
4+
build-base \
5+
libmaxminddb-dev \
6+
ncurses-dev \
7+
musl-libintl
158

169
# set up goacess
1710
WORKDIR /goaccess
@@ -20,17 +13,30 @@ RUN tar --strip-components=1 -xzvf goaccess-1.5.5.tar.gz
2013
RUN ./configure --enable-utf8 --enable-geoip=mmdb --with-getline
2114
RUN make
2215
RUN make install
16+
17+
FROM alpine:3.15
18+
RUN apk add --no-cache \
19+
bash \
20+
nginx \
21+
tini \
22+
wget \
23+
curl \
24+
apache2-utils\
25+
libmaxminddb \
26+
ncurses && \
27+
rm -rf /var/lib/apt/lists/* && \
28+
rm /etc/nginx/nginx.conf
29+
30+
COPY --from=builder /goaccess /goaccess
2331
COPY /resources/goaccess/goaccess.conf /goaccess-config/goaccess.conf
2432
COPY /resources/goaccess/GeoLite2-City.mmdb /goaccess-config/GeoLite2-City.mmdb
2533

2634
# set up nginx
27-
RUN rm /etc/nginx/sites-enabled/default
2835
COPY /resources/nginx/index.html /var/www/html/index.html
2936
COPY /resources/nginx/nginx.conf /etc/nginx/nginx.conf
37+
ADD /resources/nginx/.htpasswd /opt/auth/.htpasswd
3038

39+
COPY /resources/scripts/start.sh /start.sh
3140
VOLUME ["/opt/log"]
3241
EXPOSE 7880
33-
34-
COPY /resources/scripts/start.sh /start.sh
35-
RUN ["chmod", "+x", "/start.sh"]
36-
CMD ["bash", "/start.sh"]
42+
CMD ["sh", "/start.sh"]

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ goaccess:
4242
restart: always
4343
environment:
4444
- TZ=America/New_York
45+
- SKIP_ARCHIVED_LOGS=False #optional
46+
- BASIC_AUTH=False #optional
47+
- BASIC_AUTH_USERNAME=user #optional
48+
- BASIC_AUTH_PASSWORD=pass #optional
4549
ports:
4650
- '7880:7880'
4751
volumes:
@@ -61,8 +65,19 @@ goaccess:
6165
- PUID=0
6266
- PGID=0
6367
- TZ=America/New_York
68+
- SKIP_ARCHIVED_LOGS=False #optional
69+
- BASIC_AUTH=False #optional
70+
- BASIC_AUTH_USERNAME=user #optional
71+
- BASIC_AUTH_PASSWORD=pass #optional
6472
```
6573
74+
| Parameter | Function |
75+
|-----------|----------|
76+
| `-e SKIP_ARCHIVED_LOGS=True/False` | (Optional) Defaults to False. Set to True to skip archived logs, i.e. proxy-host*.gz |
77+
| `-e BASIC_AUTH=True/False` | (Optional) Defaults to False. Set to True to enable nginx basic authentication. Docker container needs to stopped or restarted each time this flag is modified. This allows for the .htpasswd file to be changed accordingly. |
78+
| `-e BASIC_AUTH_USERNAME=user` | (Optional) Requires BASIC_AUTH to bet set to True. Username for basic authentication. |
79+
| `-e BASIC_AUTH_PASSWORD=pass` | (Optional) Requires BASIC_AUTH to bet set to True. Password for basic authentication. |
80+
6681
Thanks to https://github.com/GregYankovoy for the inspiration, and for their nginx.conf :)
6782

6883
This product includes GeoLite2 data created by MaxMind, available from

resources/nginx/.htpasswd

Whitespace-only changes.

resources/nginx/nginx.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ http {
2424
access_log off;
2525

2626
location / {
27+
#goan_authbasic
2728
try_files /nonexistent @$type;
2829
}
2930

resources/scripts/start.sh

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,41 @@
11
#!/bin/bash
2-
/usr/bin/tini -s -- nginx
32

4-
#load archived logs
3+
#BEGIN - Set NGINX basic authentication
4+
if [[ "${BASIC_AUTH}" == "True" ]]
5+
then
6+
echo "Setting up basic auth in NGINX..."
7+
if [[ -z "$BASIC_AUTH_USERNAME" || -z "$BASIC_AUTH_PASSWORD" ]]
8+
then
9+
echo "Username or password is blank or not set."
10+
else
11+
nginx_auth_basic_s="#goan_authbasic"
12+
nginx_auth_basic_r="auth_basic \"GoAccess WebUI\";\n auth_basic_user_file \/opt\/auth\/.htpasswd; \n"
13+
sed -i "s/$nginx_auth_basic_s/$nginx_auth_basic_r/" /etc/nginx/nginx.conf
14+
15+
htpasswd -b /opt/auth/.htpasswd $BASIC_AUTH_USERNAME $BASIC_AUTH_PASSWORD
16+
fi
17+
fi
18+
#END - Set NGINX basic authentication
19+
20+
#BEGIN - Load archived logs
21+
if [[ "${SKIP_ARCHIVED_LOGS}" == "True" ]]
22+
then
23+
echo "Skipping archived logs as requested..."
24+
touch /goaccess/access_archive.log
25+
else
26+
count=`ls -1 /opt/log/proxy-host-*_access.log*.gz 2>/dev/null | wc -l`
27+
if [ $count != 0 ]
28+
then
29+
echo "Loading (${count}) archived logs..."
530
zcat -f /opt/log/proxy-host-*_access.log*.gz > /goaccess/access_archive.log
31+
else
32+
echo "No archived logs found..."
33+
touch /goaccess/access_archive.log
34+
fi
35+
fi
36+
#END - Load archived logs
637

7-
#find active logs
38+
#BEGIN - Find active logs and check for read access
839
proxy_host=""
940

1041
echo "Checking active logs..."
@@ -15,7 +46,12 @@ do
1546
then
1647
if [ -r $file ] && R="Read = yes" || R="Read = No"
1748
then
18-
proxy_host+=" $file"
49+
if [ -z "$proxy_host" ]
50+
then
51+
proxy_host="${proxy_host}${file}"
52+
else
53+
proxy_host="${proxy_host} ${file}"
54+
fi
1955
echo "Filename: $file | $R"
2056
else
2157
echo "Filename: $file | $R"
@@ -30,6 +66,13 @@ if [ -z "$proxy_host" ]
3066
then
3167
touch /goaccess/access.log
3268
proxy_host="/goaccess/access.log"
69+
else
70+
echo "Loading proxy-host logs..."
3371
fi
72+
#END - Find active logs and check for read access
73+
74+
#RUN NGINX
75+
tini -s -- nginx
3476

35-
/usr/bin/tini -s -- /goaccess/goaccess /goaccess/access_archive.log ${proxy_host} --no-global-config --config-file=/goaccess-config/goaccess.conf
77+
#RUN GOACCESS
78+
tini -s -- /goaccess/goaccess /goaccess/access_archive.log ${proxy_host} --no-global-config --config-file=/goaccess-config/goaccess.conf

0 commit comments

Comments
 (0)