Skip to content

Commit 61cd613

Browse files
committed
refactor: us S6 process supervisor
* use `s6-overlay` as process supervisor * install `go-exploitdb` instead of using teh official Docker image as it is based on EOL Alpine Linux version (3.15)
1 parent 40fb685 commit 61cd613

File tree

23 files changed

+153
-99
lines changed

23 files changed

+153
-99
lines changed

Dockerfile

Lines changed: 90 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,96 @@
1-
# v0.4.5
2-
FROM vuls/go-exploitdb@sha256:4738ca739083d41b89aab11012e283f89645f5cdbb5c021f2fbb6584bd5fe423
1+
FROM alpine:3.18
32

4-
# Make directory to store DB if not volume mounted
5-
RUN mkdir /vuls
3+
ARG TARGETPLATFORM
64

7-
# Set up a cron job to update the database files every 3 hours
8-
RUN echo "0 */3 * * * /update.sh" >> /var/spool/cron/crontabs/root
5+
RUN apk --no-cache add git ca-certificates
96

10-
# Make sure the cron job file has proper permissions
11-
RUN chmod 0600 /var/spool/cron/crontabs/root
7+
ADD --link --chmod=600 crontabs/root /var/spool/cron/crontabs/root
128

13-
# Copy updater script and make it executable
14-
COPY update.sh /update.sh
15-
RUN chmod +x /update.sh
9+
RUN <<EOT
10+
set -e
1611

17-
# Copy entry point script and make it executable
18-
COPY entrypoint.sh /entrypoint.sh
19-
RUN chmod +x /entrypoint.sh
12+
version=0.4.6
13+
## Install s6-overlay binaries
14+
case "$TARGETPLATFORM" in
15+
"linux/amd64")
16+
url=https://github.com/vulsio/go-exploitdb/releases/download/v${version}/go-exploitdb_${version}_linux_amd64.tar.gz
17+
checksum=b27cd43a1c194bb365c73d6e4bd199911d83aab4bf48a5eca4ecb8838c0daa9c
18+
;;
19+
"linux/arm64")
20+
url=https://github.com/vulsio/go-exploitdb/releases/download/v${version}/go-exploitdb_${version}_linux_arm64.tar.gz
21+
checksum=432a51a12aebcd4350c4d10c1435cb0d7a5720a7a9bb204a109ccd6c10553184
22+
;;
23+
*)
24+
printf "ERROR: %s" "invalid architecture"
25+
exit 1
26+
esac
2027

21-
# Use the entrypoint script to start freshclam, cron, and Nginx
22-
ENTRYPOINT ["/entrypoint.sh"]
28+
archive="$(basename ${url})"
29+
wget -q -O "${archive}" "${url}"
30+
printf "%s %s" "${checksum}" "${archive}" | sha256sum -c -
31+
tar xzvf "${archive}" -C /usr/local/bin 'go-exploitdb'
32+
rm -f "${archive}"
33+
34+
chown root:root /usr/local/bin/go-exploitdb
35+
chmod +x /usr/local/bin/go-exploitdb
36+
37+
mkdir -p /etc/go-exploitdb /var/lib/go-exploitdb /var/log/go-exploitdb
38+
EOT
39+
40+
ADD --link --chmod=644 go-exploitdb/go-exploitdb.yaml /etc/go-exploitdb/go-exploitdb.yaml
41+
ADD --link --chmod=755 go-exploitdb/go-exploitdb-update.sh /usr/local/bin/go-exploitdb-update
42+
43+
VOLUME ["/etc/go-exploitdb", "/var/lib/go-exploitdb", "/var/log/go-exploitdb"]
44+
45+
RUN <<EOT
46+
set -e
47+
48+
version=3.1.6.2
49+
url=
50+
checksum=
51+
52+
## Install s6-overlay scripts
53+
url=https://github.com/just-containers/s6-overlay/releases/download/v${version}/s6-overlay-noarch.tar.xz
54+
checksum=05af2536ec4fb23f087a43ce305f8962512890d7c71572ed88852ab91d1434e3
55+
56+
archive="$(basename ${url})"
57+
wget -q -O "${archive}" "${url}"
58+
printf "%s %s" "${checksum}" "${archive}" | sha256sum -c -
59+
tar -C / -Jxpf "${archive}"
60+
rm -f "${archive}"
61+
62+
## Install s6-overlay binaries
63+
case "$TARGETPLATFORM" in
64+
"linux/amd64")
65+
url=https://github.com/just-containers/s6-overlay/releases/download/v${version}/s6-overlay-x86_64.tar.xz
66+
checksum=95081f11c56e5a351e9ccab4e70c2b1c3d7d056d82b72502b942762112c03d1c
67+
;;
68+
"linux/arm64")
69+
url=https://github.com/just-containers/s6-overlay/releases/download/v${version}/s6-overlay-aarch64.tar.xz
70+
checksum=3fc0bae418a0e3811b3deeadfca9cc2f0869fb2f4787ab8a53f6944067d140ee
71+
;;
72+
*)
73+
printf "ERROR: %s" "invalid architecture"
74+
exit 1
75+
esac
76+
77+
archive="$(basename ${url})"
78+
wget -q -O "${archive}" "${url}"
79+
printf "%s %s" "${checksum}" "${archive}" | sha256sum -c -
80+
tar -C / -Jxpf "${archive}"
81+
rm -f "${archive}"
82+
EOT
83+
84+
ADD --link --chmod=755 s6-rc.d/cron /etc/s6-overlay/s6-rc.d/cron
85+
ADD --link --chmod=755 s6-rc.d/go-exploitdb /etc/s6-overlay/s6-rc.d/go-exploitdb
86+
ADD --link --chmod=755 s6-rc.d/go-exploitdb-updater /etc/s6-overlay/s6-rc.d/go-exploitdb-updater
87+
ADD --link --chmod=755 s6-rc.d/user/contents.d/* /etc/s6-overlay/s6-rc.d/user/contents.d/
88+
89+
ENV S6_KEEP_ENV 1
90+
# Stop container if any of the services fail to start at boot.
91+
ENV S6_BEHAVIOUR_IF_STAGE2_FAILS 2
92+
ENV S6_VERBOSITY 1
93+
# Stop container if services are not started in 10 mins.
94+
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME 600000
95+
96+
ENTRYPOINT ["/init"]

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ To persist the database between container runs:
3333

3434
```
3535
mkdir /opt/exploit-db
36-
docker run -d -p 1326:1326 -v /opt/exploit-db:/vuls -name exploit-db-server <registry>/exploit-db-server:<tag>
36+
docker run -d -p 1326:1326 -v /opt/exploit-db:/var/lib/go-exploitdb -name exploit-db-server <registry>/exploit-db-server:<tag>
3737
```
3838

3939
## Querying

crontabs/root

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0 */3 * * * go-exploitdb-update

entrypoint.sh

Lines changed: 0 additions & 67 deletions
This file was deleted.

go-exploitdb/go-exploitdb-update.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env sh
2+
3+
set -e
4+
5+
info () {
6+
printf "INFO [go-exploitdb-update]: %s\n" "${1}"
7+
}
8+
9+
error () {
10+
printf "ERROR [go-exploitdb-update]: %s\n" "${1}"
11+
}
12+
13+
update () {
14+
local config
15+
config=/etc/go-exploitdb/go-exploitdb.yaml
16+
17+
for db in awesomepoc exploitdb githubrepos inthewild; do
18+
info "updating database: ${db}"
19+
go-exploitdb --config="${config}" fetch "${db}" || error "failed to update database: ${db}"
20+
done
21+
}
22+
23+
main () {
24+
(
25+
flock -n 200 || error "failed to acquire lock."
26+
update
27+
) 200>/var/lock/go-exploitdb-update.lock
28+
}
29+
30+
main

go-exploitdb/go-exploitdb.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
dbtype: sqlite3
3+
dbpath: /var/lib/go-exploitdb/go-exploitdb.sqlite3
4+
log-json: false
5+
debug: false

s6-rc.d/cron/dependencies.d/base

Whitespace-only changes.

s6-rc.d/cron/dependencies.d/go-exploitdb-updater

Whitespace-only changes.

s6-rc.d/cron/finish

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/command/execlineb -S0
2+
3+
foreground {
4+
redirfd -w 1 /run/s6-linux-init-container-results/exitcode echo "$1"
5+
}
6+
7+
/run/s6/basedir/bin/halt

s6-rc.d/cron/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/command/execlineb -P
2+
3+
exec crond -f -d 7

s6-rc.d/cron/type

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
longrun

s6-rc.d/go-exploitdb-updater/dependencies.d/base

Whitespace-only changes.

s6-rc.d/go-exploitdb-updater/type

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
oneshot

s6-rc.d/go-exploitdb-updater/up

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/command/execlineb -P
2+
3+
exec go-exploitdb-update

s6-rc.d/go-exploitdb/dependencies.d/base

Whitespace-only changes.

s6-rc.d/go-exploitdb/dependencies.d/go-exploitdb-updater

Whitespace-only changes.

s6-rc.d/go-exploitdb/finish

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/command/execlineb -S0
2+
3+
foreground {
4+
redirfd -w 1 /run/s6-linux-init-container-results/exitcode echo "$1"
5+
}
6+
7+
/run/s6/basedir/bin/halt

s6-rc.d/go-exploitdb/run

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/command/execlineb -P
2+
3+
exec go-exploitdb server --bind 0.0.0.0 --config=/etc/go-exploitdb/go-exploitdb.yaml

s6-rc.d/go-exploitdb/type

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
longrun

s6-rc.d/user/contents.d/cron

Whitespace-only changes.

s6-rc.d/user/contents.d/go-exploitdb

Whitespace-only changes.

s6-rc.d/user/contents.d/go-exploitdb-updater

Whitespace-only changes.

update.sh

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)