|
| 1 | +# This Dockerfile aims to make building Hubble v4 packages easier. |
| 2 | +# Starting with version 4 building osquery is removed from individual Dockerfiles to its own. |
| 3 | +# osquery needs to be built once. Resulting tar file can be used in hubblev4 Dockerfiles. |
| 4 | +# Before building hubble, build osquery using a Dockerfile in pkg/osquery/ directory. |
| 5 | +# To build this image: 1. copy previously built osquery_4hubble.x86_64.tar to directory with this Dockerfile |
| 6 | +# 2. docker build -t <image_name> --build-arg HUBBLE_CHECKOUT=<tag or commit> --build-arg HUBBLE_VERSION=<Hubble Version> . |
| 7 | +# The resulting image is ready to build and run pyinstaller on container start that should |
| 8 | +# create hubble<version>-debian.tar.gz in the /data directory inside the container. |
| 9 | +# Mount /data volume into a directory on the host to access the package. |
| 10 | +# To run the container: docker run -it --rm -v `pwd`:/data <image_name> |
| 11 | + |
| 12 | +FROM debian:9 |
| 13 | + |
| 14 | +RUN apt-get update \ |
| 15 | + && apt-get -y upgrade \ |
| 16 | + && apt-get clean \ |
| 17 | + && rm -rf /var/cache/apt |
| 18 | + |
| 19 | +# paths that hubble or hubble parts need in the package |
| 20 | +RUN mkdir -p /etc/hubble/hubble.d /opt/hubble /opt/osquery /var/log/hubble_osquery/backuplogs |
| 21 | + |
| 22 | +# install packages that should be needed for ligbit2 compilation and successful pyinstaller run |
| 23 | +RUN apt-get update \ |
| 24 | + && apt-get -y install git curl \ |
| 25 | + python-dev libffi-dev libssl-dev libyaml-dev libssh2-1 libssh2-1-dev autoconf automake libtool \ |
| 26 | + libxml2-dev libxslt1-dev python-cffi zlib1g-dev python-setuptools \ |
| 27 | + cmake gcc wget python-pip openssl \ |
| 28 | + && apt-get clean \ |
| 29 | + && rm -rf /var/cache/apt |
| 30 | + |
| 31 | +# libcurl install start |
| 32 | +# install libcurl to avoid depending on host version |
| 33 | +# requires autoconf libtool libssh2-devel zlib-devel autoconf |
| 34 | +ENV LIBCURL_SRC_URL=https://github.com/curl/curl.git |
| 35 | +ENV LIBCURL_SRC_VERSION=curl-7_64_1 |
| 36 | +ENV LIBCURL_TEMP=/tmp/libcurl |
| 37 | +ENV PATH=/opt/hubble/bin/:/opt/hubble/include:/opt/hubble/lib:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin |
| 38 | +RUN mkdir -p "$LIBCURL_TEMP" \ |
| 39 | + && cd "$LIBCURL_TEMP" \ |
| 40 | + && git clone "$LIBCURL_SRC_URL" \ |
| 41 | + && cd curl \ |
| 42 | + && git checkout "$LIBCURL_SRC_VERSION" \ |
| 43 | + && ./buildconf \ |
| 44 | + && ./configure --prefix=/opt/hubble --disable-ldap --without-nss --disable-manual --disable-gopher --disable-smtp --disable-smb --disable-imap --disable-pop3 --disable-tftp --disable-telnet --disable-dict --disable-ldaps --disable-ldap --disable-rtsp --with-libssh2 \ |
| 45 | + && make \ |
| 46 | + && make install \ |
| 47 | + && rm -rf "$LIBCURL_TEMP" |
| 48 | + |
| 49 | +# git install start |
| 50 | +# install git so that git package won't be a package dependency |
| 51 | +# requires make git libcurl-devel autoconf zlib-devel gcc |
| 52 | +ENV GIT_SRC_URL=https://github.com/git/git.git |
| 53 | +ENV GIT_SRC_VERSION=v2.21.0 |
| 54 | +ENV GITTEMP=/tmp/gittemp |
| 55 | +RUN mkdir -p "$GITTEMP" \ |
| 56 | + && cd "$GITTEMP" \ |
| 57 | + && git clone "$GIT_SRC_URL" \ |
| 58 | + && cd git \ |
| 59 | + && git checkout "$GIT_SRC_VERSION" \ |
| 60 | + && make configure \ |
| 61 | + && ./configure --prefix=/opt/hubble --with-tcltk=no --with-expat=no --with-python=no --with-curl=/opt/hubble \ |
| 62 | + && echo "NO_TCLTK=YesPlease" >> config.mak.autogen \ |
| 63 | + && echo "NO_PERL=YesPlease" >> config.mak.autogen \ |
| 64 | + && sed -i '0,/^NO_GETTEXT/s/^NO_GETTEXT.*/NO_GETTEXT=YesPlease/' config.mak.autogen \ |
| 65 | + && make \ |
| 66 | + && make install \ |
| 67 | + && rm -rf "$GITTEMP" |
| 68 | + |
| 69 | +# clean up of /opt/hubble |
| 70 | +RUN rm /opt/hubble/bin/curl* \ |
| 71 | + && rm -rf /opt/hubble/include /opt/hubble/share |
| 72 | + |
| 73 | +# libgit2 install start |
| 74 | +# must precede pyinstaller requirements |
| 75 | +ENV LIBGIT2_SRC_VERSION=1.1.0 |
| 76 | +ENV LIBGIT2_SRC_URL=https://github.com/libgit2/libgit2/archive/v${LIBGIT2_SRC_VERSION}.tar.gz |
| 77 | +# it turns out github provided release files can change. so even though the |
| 78 | +# code hopefully hasn't changed, the hash has. |
| 79 | +ENV LIBGIT2_SRC_SHA256=41a6d5d740fd608674c7db8685685f45535323e73e784062cf000a633d420d1e |
| 80 | +ENV LIBGIT2TEMP=/tmp/libgit2temp |
| 81 | +RUN mkdir -p "$LIBGIT2TEMP" \ |
| 82 | + && cd "$LIBGIT2TEMP" \ |
| 83 | + && wget -q "$LIBGIT2_SRC_URL" -O libgit2.tar.gz \ |
| 84 | + && echo "$LIBGIT2_SRC_SHA256 libgit2.tar.gz" | sha256sum -c - \ |
| 85 | + && tar xzf libgit2.tar.gz \ |
| 86 | + && cd libgit2-"$LIBGIT2_SRC_VERSION"/ \ |
| 87 | + && export LIBGIT2=/usr/local/ \ |
| 88 | + && cmake . -DCMAKE_INSTALL_PREFIX=$LIBGIT2 \ |
| 89 | + && make \ |
| 90 | + && make install \ |
| 91 | + && rm -rf "$LIBGIT2TEMP" |
| 92 | + |
| 93 | +# fpm package making requirements start |
| 94 | +RUN apt-get install -y ruby ruby-dev rubygems gcc make \ |
| 95 | + && gem install --no-ri --no-rdoc ffi --version 1.12.2 \ |
| 96 | + && gem install --no-ri --no-rdoc fpm \ |
| 97 | + && apt-get clean \ |
| 98 | + && rm -rf /var/cache/apt |
| 99 | + |
| 100 | +RUN apt-get install -y libbz2-dev libsqlite3-dev \ |
| 101 | + && apt-get clean \ |
| 102 | + && rm -rf /var/cache/apt |
| 103 | + |
| 104 | +# use pyenv |
| 105 | +ARG PYENV_VERSION=3.7.9 |
| 106 | +ENV PYENV_INSTALLER_URL=https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer |
| 107 | +ENV PYENV_ROOT=/opt/hubble/pyenv |
| 108 | +ENV PATH=$PYENV_ROOT/bin:$PATH |
| 109 | +ENV PYTHON_CONFIGURE_OPTS="--enable-shared" |
| 110 | +RUN umask 022 \ |
| 111 | + && curl -s -S -L "$PYENV_INSTALLER_URL" -o /usr/bin/pyenv-installer \ |
| 112 | + && chmod 0755 /usr/bin/pyenv-installer \ |
| 113 | + && /usr/bin/pyenv-installer \ |
| 114 | + && eval "$(pyenv init --path)" \ |
| 115 | + && pyenv install $PYENV_VERSION \ |
| 116 | + && pyenv global $PYENV_VERSION |
| 117 | + |
| 118 | +RUN eval "$(pyenv init --path)" \ |
| 119 | + && pip -v install --upgrade pip |
| 120 | + |
| 121 | +# pyinstaller start |
| 122 | +# commands specified for ENTRYPOINT and CMD are executed when the container is run, not when the image is built |
| 123 | +# use the following variables to choose the version of hubble |
| 124 | +ARG HUBBLE_CHECKOUT=v4.5.0 |
| 125 | +ARG HUBBLE_VERSION=4.5.0 |
| 126 | +ARG HUBBLE_GIT_URL=https://github.com/hubblestack/hubble.git |
| 127 | +ENV HUBBLE_ITERATION=1 |
| 128 | +ENV HUBBLE_URL=https://github.com/hubblestack/hubble |
| 129 | +ENV HUBBLE_SRC_PATH=/hubble_src |
| 130 | +ENV _HOOK_DIR="./pkg/" |
| 131 | +ENV _BINARY_LOG_LEVEL="INFO" |
| 132 | +ENV _INCLUDE_PATH="" |
| 133 | +ENV LD_LIBRARY_PATH=/opt/hubble/lib:/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64 |
| 134 | +ENV HUBBLE_CHECKOUT=$HUBBLE_CHECKOUT |
| 135 | +ENV HUBBLE_VERSION=$HUBBLE_VERSION |
| 136 | +ENV HUBBLE_GIT_URL=$HUBBLE_GIT_URL |
| 137 | + |
| 138 | +# leaving this blank will cause the entrypoint to look for either osquery_4hubble.tar |
| 139 | +# or osquery_4_hubble.$(uname -m).tar |
| 140 | +ARG OSQUERY_TAR_FILENAME= |
| 141 | +ENV OSQUERY_TAR_FILENAME=$OSQUERY_TAR_FILENAME |
| 142 | + |
| 143 | +VOLUME /data |
| 144 | +WORKDIR /hubble_build |
| 145 | +COPY entrypoint.sh /entrypoint.sh |
| 146 | +ENTRYPOINT [ "/bin/bash", "/entrypoint.sh" ] |
0 commit comments