Skip to content

Commit

Permalink
have threat intel happen once under supervisord on startup, not in co…
Browse files Browse the repository at this point in the history
…ntainer entrypoint for zeek non-live container, to support cisagov#358
  • Loading branch information
mmguero committed Nov 7, 2024
1 parent fcd95d8 commit 68f416a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
7 changes: 4 additions & 3 deletions Dockerfiles/zeek.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,9 @@ ARG ZEEK_PCAP_PROCESSOR=true
#Whether or not to run "zeek -r XXXXX.pcap local" on each pcap file
ARG ZEEK_AUTO_ANALYZE_PCAP_FILES=false
ARG ZEEK_AUTO_ANALYZE_PCAP_THREADS=1
#Whether or not to refresh intel at various points during processing
ARG ZEEK_INTEL_REFRESH_ON_ENTRYPOINT=false
#Whether or not to do first intel refresh under supervisord
ARG ZEEK_INTEL_REFRESH_ON_STARTUP=false
#Whether or not to do first intel refresh under zeekdeploy.sh
ARG ZEEK_INTEL_REFRESH_ON_DEPLOY=false
ARG ZEEK_INTEL_REFRESH_CRON_EXPRESSION=
ARG ZEEK_INTEL_ITEM_EXPIRATION=-1min
Expand All @@ -227,7 +228,7 @@ ARG PCAP_NODE_NAME=malcolm

ENV AUTO_TAG $AUTO_TAG
ENV ZEEK_PCAP_PROCESSOR $ZEEK_PCAP_PROCESSOR
ENV ZEEK_INTEL_REFRESH_ON_ENTRYPOINT $ZEEK_INTEL_REFRESH_ON_ENTRYPOINT
ENV ZEEK_INTEL_REFRESH_ON_STARTUP $ZEEK_INTEL_REFRESH_ON_STARTUP
ENV ZEEK_INTEL_REFRESH_ON_DEPLOY $ZEEK_INTEL_REFRESH_ON_DEPLOY
ENV ZEEK_INTEL_REFRESH_CRON_EXPRESSION $ZEEK_INTEL_REFRESH_CRON_EXPRESSION
ENV ZEEK_AUTO_ANALYZE_PCAP_FILES $ZEEK_AUTO_ANALYZE_PCAP_FILES
Expand Down
6 changes: 3 additions & 3 deletions config/zeek-offline.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ ZEEK_ROTATED_PCAP=true

ZEEK_PCAP_PROCESSOR=true

# Specifies whether or not to refresh Zeek Intelligence Framework files in
# the container entrypoint
ZEEK_INTEL_REFRESH_ON_ENTRYPOINT=true
# Specifies whether or not to refresh Zeek Intelligence Framework files
# as soon as the container starts up
ZEEK_INTEL_REFRESH_ON_STARTUP=true
# Specifies a cron expression indicating the refresh interval for generating the
# Zeek Intelligence Framework files (or blank to disable automatic refresh)
ZEEK_INTEL_REFRESH_CRON_EXPRESSION=
2 changes: 1 addition & 1 deletion zeek/scripts/container_health.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
if [[ "${ZEEK_LIVE_CAPTURE:-false}" == "true" ]]; then
supervisorctl status live-zeek >/dev/null 2>&1
else
if [[ "${ZEEK_INTEL_REFRESH_ON_ENTRYPOINT:-false}" == "true" ]]; then
if [[ "${ZEEK_INTEL_REFRESH_ON_STARTUP:-false}" == "true" ]]; then
( ps a 2>/dev/null | grep -q '[z]eek_intel_from_threat_feed.py' ) || supervisorctl status pcap-zeek >/dev/null 2>&1
else
supervisorctl status pcap-zeek >/dev/null 2>&1
Expand Down
11 changes: 0 additions & 11 deletions zeek/scripts/docker_entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,5 @@ ZEEK_DIR=${ZEEK_DIR:-"/opt/zeek"}
setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' "${ZEEK_DIR}"/bin/zeek 2>/dev/null || true
setcap 'CAP_NET_RAW+eip CAP_NET_ADMIN+eip' "${ZEEK_DIR}"/bin/capstats 2>/dev/null || true

if [[ "${ZEEK_INTEL_REFRESH_ON_ENTRYPOINT:-false}" == "true" ]] && \
[[ -x "${ZEEK_DIR}"/bin/zeek_intel_setup.sh ]]; then
if [[ "$(id -u)" == "0" ]] && [[ -n "$PUSER" ]]; then
su -s /bin/bash -p ${PUSER} << EOF
"${ZEEK_DIR}"/bin/zeek_intel_setup.sh /bin/true
EOF
else
"${ZEEK_DIR}"/bin/zeek_intel_setup.sh /bin/true
fi
fi

# start supervisor (which will spawn pcap-zeek, cron, etc.) or whatever the default command is
exec "$@"
11 changes: 11 additions & 0 deletions zeek/supervisord.conf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ stdout_logfile_maxbytes=0
redirect_stderr=true
user=%(ENV_PUSER)s

[program:intel-initialization]
command="%(ENV_ZEEK_DIR)s"/bin/zeek_intel_setup.sh /bin/true
autostart=%(ENV_ZEEK_INTEL_REFRESH_ON_STARTUP)s
autorestart=false
stopasgroup=true
killasgroup=true
stdout_logfile=/dev/fd/1
stdout_logfile_maxbytes=0
redirect_stderr=true
user=%(ENV_PUSER)s

[program:live-zeek]
command=/opt/zeek/bin/zeekdeploy.sh
autostart=%(ENV_ZEEK_LIVE_CAPTURE)s
Expand Down

0 comments on commit 68f416a

Please sign in to comment.