-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile.gcc
322 lines (283 loc) · 12.1 KB
/
Dockerfile.gcc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
########################################################################################################################
# Zeek and Spicy
# use the handy-dandy zeek-docker.sh or manually as per these examples
# Monitor a local network interface with Zeek:
#
# docker run --rm \
# -v "$(pwd):/zeek-logs" \
# --network host \
# --cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add=IPC_LOCK \
# mmguero/zeek:v7.0.0 \
# zeekcap -i enp6s0 local
# Analyze a PCAP file with Zeek:
#
# docker run --rm \
# -v "$(pwd):/zeek-logs" \
# -v "/path/containing/pcap:/data:ro" \
# mmguero/zeek:v7.0.0 \
# zeek -C -r /data/foobar.pcap local
# Use a custom policy:
#
# docker run --rm \
# -v "$(pwd):/zeek-logs" \
# -v "/path/containing/pcap:/data:ro" \
# -v "/path/containing/policy/local-example.zeek:/opt/zeek/share/zeek/site/local.zeek:ro" \
# mmguero/zeek:v7.0.0 \
# zeek -C -r /data/foobar.pcap local
########################################################################################################################
ARG TARGETPLATFORM=linux/amd64
FROM --platform=${TARGETPLATFORM} debian:12-slim as build
ENV DEBIAN_FRONTEND noninteractive
ENV TERM xterm
ARG ZEEK_DIST=Debian_12
ARG ZEEK_BRANCH=v7.0.1
ARG ZEEK_RELEASE_NUM=0
ARG ZEEK_RC=0
ARG ZEEK_DBG=0
ENV ZEEK_DIR $ZEEK_DIST
ENV ZEEK_BRANCH $ZEEK_BRANCH
ENV ZEEK_RELEASE_NUM $ZEEK_RELEASE_NUM
ENV ZEEK_RC $ZEEK_RC
ENV ZEEK_DBG $ZEEK_DBG
ARG SPICY_BRANCH=
ENV SPICY_BRANCH $SPICY_BRANCH
ARG BUILD_FROM_SOURCE=0
ARG BUILD_JOBS=0
ENV BUILD_FROM_SOURCE $BUILD_FROM_SOURCE
ENV BUILD_JOBS $BUILD_JOBS
ENV CCACHE_DIR "/var/spool/ccache"
ENV CCACHE_COMPRESS 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
COPY --chmod=755 zeek-deb-download.sh /usr/local/bin/
RUN export DEBARCH=$(dpkg --print-architecture) && \
apt-get -q update && \
if [ "$BUILD_FROM_SOURCE" = "1" ] || [ ! -z "$SPICY_BRANCH" ]; then \
echo "Building Zeek ${ZEEK_BRANCH} and Spicy ${SPICY_BRANCH} from source..." && \
apt-get -y -q --no-install-recommends upgrade && \
apt-get install -q -y --no-install-recommends \
bison \
ca-certificates \
ccache \
cmake \
curl \
flex \
g++ \
gcc \
git \
libfl-dev \
libgoogle-perftools-dev \
libgoogle-perftools4 \
libkrb5-3 \
libkrb5-dev \
libmaxminddb-dev \
libpcap-dev \
libssl-dev \
libtcmalloc-minimal4 \
make \
ninja-build \
python3 \
python3-dev \
python3-git \
python3-semantic-version \
sudo \
swig \
zlib1g-dev && \
mkdir -p /usr/share/src "${CCACHE_DIR}" && \
git clone \
--recurse-submodules \
--shallow-submodules \
--single-branch \
--depth 1 \
--branch "${ZEEK_BRANCH}" \
"https://github.com/zeek/zeek.git" \
/usr/share/src/zeek && \
cd /usr/share/src/zeek/auxil/spicy && \
if ! [ -z $SPICY_BRANCH ]; then git checkout --force $SPICY_BRANCH; fi && \
git rev-parse --short HEAD | tee /spicy-sha.txt && \
cd /usr/share/src/zeek && \
git rev-parse --short HEAD | tee /zeek-sha.txt && \
[ "$ZEEK_DBG" = "1" ] && \
./configure --prefix=/opt/zeek --generator=Ninja --ccache --enable-perftools --enable-debug || \
./configure --prefix=/opt/zeek --generator=Ninja --ccache --enable-perftools && \
ninja -C build -j "${BUILD_JOBS}" && \
cd ./build && \
cpack -G DEB; \
else \
apt-get install -q -y --no-install-recommends \
ca-certificates \
curl && \
mkdir -p /usr/share/src/zeek/build && \
cd /usr/share/src/zeek/build && \
/usr/local/bin/zeek-deb-download.sh -o /usr/share/src/zeek/build -z "$(echo "${ZEEK_BRANCH}-${ZEEK_RELEASE_NUM}" | sed 's/^v//')" && \
sha256sum *.deb > /zeek-sha.txt && \
touch /spicy-sha.txt; \
fi; \
ls -lh /usr/share/src/zeek/build/ | tail -n +2 | cat -n
########################################################################################################################
FROM --platform=${TARGETPLATFORM} debian:12-slim as base
LABEL maintainer="[email protected]"
LABEL org.opencontainers.image.authors='[email protected]'
LABEL org.opencontainers.image.url='https://github.com/mmguero/zeek-docker'
LABEL org.opencontainers.image.source='https://github.com/mmguero/zeek-docker'
LABEL org.opencontainers.image.title='oci.guero.org/zeek'
LABEL org.opencontainers.image.description='Dockerized Zeek and Spicy'
ENV DEBIAN_FRONTEND noninteractive
ENV TERM xterm
# put Zeek and Spicy in PATH
ENV ZEEK_DIR "/opt/zeek"
ENV PATH "${ZEEK_DIR}/bin:${PATH}"
# for build
ARG ZEEK_DBG=0
ENV ZEEK_DBG $ZEEK_DBG
ENV CCACHE_DIR "/var/spool/ccache"
ENV CCACHE_COMPRESS 1
ENV SPICY_ZKG_PROCESSES 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ARG MAXMIND_GEOIP_DB_LICENSE_KEY=""
COPY --from=build /usr/share/src/zeek/build/*.deb /tmp/zeek-deb/
COPY --from=build /zeek-sha.txt /zeek-sha.txt
COPY --from=build /spicy-sha.txt /spicy-sha.txt
RUN export BINARCH=$(uname -m) && \
apt-get -q update && \
apt-get -y -q --no-install-recommends upgrade && \
apt-get install -q -y --no-install-recommends \
bat \
binutils \
ca-certificates \
ccache \
cmake \
curl \
fd-find \
file \
g++ \
gcc \
git \
libcap2-bin \
libfl-dev \
libfl2 \
libgoogle-perftools-dev \
libgoogle-perftools4 \
libkrb5-dev \
libmaxminddb-dev \
libpcap-dev \
libssl-dev \
libtcmalloc-minimal4 \
make \
openssl \
procps \
psmisc \
python3 \
python3-git \
python3-semantic-version \
ripgrep \
rsync \
tini \
xxd \
zlib1g-dev && \
( dpkg -i /tmp/zeek-deb/*.deb || true ) && \
apt-get -f install -q -y --no-install-recommends && \
zkg autoconfig --force && \
if [ "$ZEEK_DBG" = "0" ]; then \
( find "${ZEEK_DIR}"/lib "${ZEEK_DIR}"/var/lib/zkg \( -path "*/build/*" -o -path "*/CMakeFiles/*" \) -type f -name "*.*" -print0 | xargs -0 -I XXX bash -c 'file "XXX" | sed "s/^.*:[[:space:]]//" | grep -Pq "(ELF|gzip)" && rm -f "XXX"' || true ) ; \
( find "${ZEEK_DIR}"/var/lib/zkg/clones -type d -name .git -execdir bash -c "pwd; du -sh; git pull --depth=1 --ff-only; git reflog expire --expire=all --all; git tag -l | xargs -r git tag -d; git gc --prune=all; du -sh" \; ) ; \
rm -rf "${ZEEK_DIR}"/var/lib/zkg/scratch ; \
rm -rf "${ZEEK_DIR}"/lib/zeek/python/zeekpkg/__pycache__ ; \
( find "${ZEEK_DIR}/" -type f -exec file "{}" \; | grep -Pi "ELF 64-bit.*not stripped" | sed 's/:.*//' | xargs -l -r strip --strip-unneeded ) ; \
( find "${ZEEK_DIR}"/lib/zeek/plugins/packages -type f -name "*.hlto" -exec chmod 755 "{}" \; || true ) ; \
fi && \
echo "@load packages" >> "${ZEEK_DIR}"/share/zeek/site/local.zeek && \
cd /usr/lib/locale && \
( ls | grep -Piv "^(en|en_US|en_US\.utf-?8|C\.utf-?8)$" | xargs -l -r rm -rf ) && \
cd /usr/bin && \
curl -sSL "https://github.com/eza-community/eza/releases/latest/download/eza_${BINARCH}-unknown-linux-gnu.tar.gz" | tar xzvf - >/dev/null 2>&1 && \
chmod 755 /usr/bin/eza && \
[ ${#MAXMIND_GEOIP_DB_LICENSE_KEY} -gt 1 ] && for DB in ASN Country City; do \
cd /tmp && \
curl -s -S -L -o "GeoLite2-$DB.mmdb.tar.gz" "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-$DB&license_key=$MAXMIND_GEOIP_DB_LICENSE_KEY&suffix=tar.gz" && \
tar xf "GeoLite2-$DB.mmdb.tar.gz" --wildcards --no-anchored '*.mmdb' --strip=1 && \
mkdir -p /usr/share/GeoIP/ && \
mv -v "GeoLite2-$DB.mmdb" /usr/share/GeoIP/; \
rm -f "GeoLite2-$DB*"; \
done; \
cd /tmp && \
apt-get -q -y autoremove && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
# configure unprivileged user and runtime parameters
ARG DEFAULT_UID=1000
ARG DEFAULT_GID=1000
ENV DEFAULT_UID $DEFAULT_UID
ENV DEFAULT_GID $DEFAULT_GID
ENV PUSER "zeekcap"
ENV PGROUP "zeekcap"
ENV PUSER_PRIV_DROP true
ARG ZEEK_LOGS_DIR=/zeek-logs
ENV ZEEK_LOGS_DIR $ZEEK_LOGS_DIR
ENV ZEEK_DISABLE_HASH_ALL_FILES ""
ENV ZEEK_DISABLE_LOG_PASSWORDS ""
ENV ZEEK_DISABLE_SSL_VALIDATE_CERTS ""
ENV ZEEK_DISABLE_TRACK_ALL_ASSETS ""
ENV ZEEK_DISABLE_SPICY_DHCP "true"
ENV ZEEK_DISABLE_SPICY_DNS "true"
ENV ZEEK_DISABLE_SPICY_FACEFISH ""
ENV ZEEK_DISABLE_SPICY_HTTP "true"
ENV ZEEK_DISABLE_SPICY_IPSEC ""
ENV ZEEK_DISABLE_SPICY_LDAP ""
ENV ZEEK_DISABLE_SPICY_OPENVPN ""
ENV ZEEK_DISABLE_SPICY_STUN ""
ENV ZEEK_DISABLE_SPICY_TAILSCALE ""
ENV ZEEK_DISABLE_SPICY_TFTP ""
ENV ZEEK_DISABLE_SPICY_WIREGUARD ""
ADD https://raw.githubusercontent.com/mmguero/docker/master/shared/docker-uid-gid-setup.sh /usr/local/bin/docker-uid-gid-setup.sh
ADD entrypoint.sh /usr/local/bin/
RUN chmod 755 /usr/local/bin/docker-uid-gid-setup.sh && \
groupadd --gid ${DEFAULT_GID} ${PUSER} && \
useradd -m --uid ${DEFAULT_UID} --gid ${DEFAULT_GID} ${PUSER} && \
mkdir -p "${ZEEK_LOGS_DIR}" \
"${ZEEK_DIR}"/share/zeek/site/intel \
"${ZEEK_DIR}"/share/zeek/site/custom && \
touch "${ZEEK_DIR}"/share/zeek/site/intel/__load__.zeek && \
touch "${ZEEK_DIR}"/share/zeek/site/custom/__load__.zeek && \
chown -R ${PUSER}:${PGROUP} \
"${ZEEK_LOGS_DIR}" \
"${ZEEK_DIR}"/share/zeek/site/intel \
"${ZEEK_DIR}"/share/zeek/site/custom && \
# make a setcap copy of zeek (zeekcap) for listening on an interface
cp "${ZEEK_DIR}"/bin/zeek "${ZEEK_DIR}"/bin/zeekcap && \
chown root:${PGROUP} "${ZEEK_DIR}"/bin/zeekcap && \
setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip CAP_IPC_LOCK+eip' "${ZEEK_DIR}"/bin/zeekcap
VOLUME "${ZEEK_DIR}/share/zeek/site/intel"
WORKDIR "${ZEEK_LOGS_DIR}"
ENTRYPOINT ["/usr/bin/tini", "--", "/usr/local/bin/docker-uid-gid-setup.sh", "/usr/local/bin/entrypoint.sh"]
########################################################################################################################
FROM base as plus
LABEL maintainer="[email protected]"
LABEL org.opencontainers.image.authors='[email protected]'
LABEL org.opencontainers.image.url='https://github.com/mmguero/zeek-docker'
LABEL org.opencontainers.image.source='https://github.com/mmguero/zeek-docker'
LABEL org.opencontainers.image.title='oci.guero.org/zeek:plus'
LABEL org.opencontainers.image.description='Dockerized Zeek and Spicy with extra plugins'
ENV DEBIAN_FRONTEND noninteractive
ENV TERM xterm
# put Zeek and Spicy in PATH
ENV ZEEK_DIR "/opt/zeek"
ENV PATH "${ZEEK_DIR}/bin:${PATH}"
# for build
ARG ZEEK_DBG=0
ENV ZEEK_DBG $ZEEK_DBG
ENV CCACHE_DIR "/var/spool/ccache"
ENV CCACHE_COMPRESS 1
ENV SPICY_ZKG_PROCESSES 1
RUN curl -fsSL -o /tmp/zeek_install_plugins.sh "https://raw.githubusercontent.com/mmguero-dev/Malcolm/development/shared/bin/zeek_install_plugins.sh" && \
bash /tmp/zeek_install_plugins.sh && \
if [ "$ZEEK_DBG" = "1" ]; then \
( find "${ZEEK_DIR}"/lib "${ZEEK_DIR}"/var/lib/zkg \( -path "*/build/*" -o -path "*/CMakeFiles/*" \) -type f -name "*.*" -print0 | xargs -0 -I XXX bash -c 'file "XXX" | sed "s/^.*:[[:space:]]//" | grep -Pq "(ELF|gzip)" && rm -f "XXX"' || true ) ; \
( find "${ZEEK_DIR}"/var/lib/zkg/clones -type d -name .git -execdir bash -c "pwd; du -sh; git pull --depth=1 --ff-only; git reflog expire --expire=all --all; git tag -l | xargs -r git tag -d; git gc --prune=all; du -sh" \; ) ; \
rm -rf "${ZEEK_DIR}"/var/lib/zkg/scratch ; \
rm -rf "${ZEEK_DIR}"/lib/zeek/python/zeekpkg/__pycache__ ; \
( find "${ZEEK_DIR}/" -type f -exec file "{}" \; | grep -Pi "ELF 64-bit.*not stripped" | sed 's/:.*//' | xargs -l -r strip --strip-unneeded ) ; \
( find "${ZEEK_DIR}"/lib/zeek/plugins/packages -type f -name "*.hlto" -exec chmod 755 "{}" \; || true ) ; \
fi && \
rm -rf /tmp/zeek_install_plugins.sh