|
1 |
| -# This Dockerfile aims to make building Hubble v2 packages easier. |
2 |
| -# To build an image: 1. copy pkg/scripts/pyinstaller-requirements.txt to directory with this Dockerfile |
3 |
| -# 2. docker build -t <image_name> . |
4 |
| -# The resulting image is ready to run the pyinstaller on container start and drop hubble<version>-coreos.tar.gz |
5 |
| -# in the /data directory. Mount /data volume into a directory on the host to access the package. |
| 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.tar to directory with this Dockerfile |
| 6 | +# 2. docker build -t <image_name> --build-arg=HUBBLE_CHECKOUT=<tag or commit> . |
| 7 | +# The resulting image is ready to build and run pyinstaller on container start that should |
| 8 | +# create hubble<version>-centos7.tar.gz in the /data directory inside the container. |
| 9 | +# Mount /data volume into a directory on the host to access the package. |
6 | 10 | # To run the container: docker run -it --rm -v `pwd`:/data <image_name>
|
7 |
| -# Requires docker 17.05 or higher |
8 | 11 |
|
9 |
| -# Set this argument to "local" if you want to build osquery for local code. |
10 |
| -# In that case, osquery folder must exist besides Dockerfile |
11 |
| -ARG OSQUERY_BUILD_ENV=remote |
12 |
| - |
13 |
| -#--------------- TEMP CONTAINER FOR LOCAL OSQUERY ------------------------- |
14 |
| -FROM alpine as osquery_local |
15 |
| -ONBUILD COPY osquery /osquery |
16 |
| -ONBUILD RUN echo "Copying osquery from local folder" |
17 |
| - |
18 |
| - |
19 |
| - |
20 |
| -#--------------- TEMP CONTAINER FOR GIT OSQUERY ---------------------------- |
21 |
| -FROM alpine/git as osquery_remote |
22 |
| -#to pin osquery to a different version change the following envirnment variable |
23 |
| -ENV OSQUERY_SRC_VERSION=3.3.2 |
24 |
| -ENV OSQUERY_GIT_URL=https://github.com/facebook/osquery.git |
25 |
| -ONBUILD RUN cd / \ |
26 |
| - && git clone "$OSQUERY_GIT_URL" \ |
27 |
| - && cd osquery/ \ |
28 |
| - && git checkout "$OSQUERY_SRC_VERSION" \ |
29 |
| - && echo "Fetching osquery from git" |
30 |
| - |
31 |
| - |
32 |
| -#--------------- TEMP CONTAINER FOR OSQUERY ( BASED ON ARGUMENT ) --------------- |
33 |
| -FROM osquery_"$OSQUERY_BUILD_ENV" as osquery_image |
34 |
| - |
35 |
| - |
36 |
| -#--------------- ACTUAL DOCKERFILE FOR BUILD CREATION -------------------------- |
37 | 12 | FROM centos:7
|
38 | 13 |
|
39 | 14 | RUN yum makecache fast && yum -y update
|
40 | 15 |
|
41 | 16 | #paths that hubble or hubble parts need in the package
|
42 | 17 | RUN mkdir -p /etc/hubble/hubble.d /opt/hubble /opt/osquery /var/log/hubble_osquery/backuplogs
|
43 |
| -#osquery build start |
44 |
| -#osquery should be built first since requirements for other packages can interfere with osquery dependencies |
45 |
| -#to build, osquery scripts want sudo and a user to sudo with. |
46 |
| -ENV OSQUERY_BUILD_USER=osquerybuilder |
47 |
| -RUN yum -y install git make python ruby sudo which |
48 |
| -RUN useradd --shell /bin/bash --create-home --user-group --groups wheel "$OSQUERY_BUILD_USER" \ |
49 |
| - && sed -i '0,/^#\ %wheel/s/^#\ %wheel.*/%wheel\ ALL=\(ALL\)\ NOPASSWD:\ ALL/' /etc/sudoers |
50 |
| -COPY --from=osquery_image /osquery /home/"$OSQUERY_BUILD_USER"/osquery |
51 |
| -RUN mkdir -p /usr/local/osquery/ \ |
52 |
| - && chown "$OSQUERY_BUILD_USER":"$OSQUERY_BUILD_USER" -R /usr/local/osquery/ \ |
53 |
| - && chown "$OSQUERY_BUILD_USER":"$OSQUERY_BUILD_USER" -R /home/"$OSQUERY_BUILD_USER"/osquery |
54 |
| -USER $OSQUERY_BUILD_USER |
55 |
| -ENV SKIP_TESTS=1 |
56 |
| -RUN cd /home/"$OSQUERY_BUILD_USER"/osquery \ |
57 |
| - && make sysprep \ |
58 |
| -#have the default augeas lenses directory point to /opt/osquery/lenses, must be done after sysprep |
59 |
| - && sed -i '/augeas_lenses,/,/\"Directory\ that\ contains\ augeas\ lenses\ files\"\\)\;/ s/\/usr\/share\/osquery\/lenses/\/opt\/osquery\/lenses/' osquery/tables/system/posix/augeas.cpp \ |
60 |
| - && make deps \ |
61 |
| - && make \ |
62 |
| - && make strip |
63 |
| -USER root |
64 |
| -RUN cp -pr /home/"$OSQUERY_BUILD_USER"/osquery/build/linux/osquery/osqueryi /opt/osquery \ |
65 |
| - && cp -pr /home/"$OSQUERY_BUILD_USER"/osquery/build/linux/osquery/osqueryd /opt/osquery/hubble_osqueryd \ |
66 |
| - && chown -R root. /opt/osquery \ |
67 |
| - && chmod -R 500 /opt/osquery/* \ |
68 |
| -#put augeas lenses into the default directory that we changed earlier |
69 |
| - && mkdir -p /opt/osquery/lenses \ |
70 |
| - && cp -r /usr/local/osquery/share/augeas/lenses/dist/* /opt/osquery/lenses \ |
71 |
| - && chmod -R 400 /opt/osquery/lenses/* |
72 |
| -RUN ls -lahR /opt/osquery/ && /opt/osquery/osqueryi --version |
73 | 18 |
|
74 | 19 | #install packages that should be needed for ligbit2 compilation and successful pyinstaller run
|
75 |
| -RUN yum -y install \ |
76 |
| - libffi-devel openssl-devel libffi libssh2-devel autoconf automake libtool \ |
77 |
| - libxml2-devel libxslt-devel libjpeg-devel zlib-devel \ |
78 |
| - make cmake gcc python-devel python-setuptools wget openssl |
| 20 | +RUN yum -y install git \ |
| 21 | + libffi-devel openssl-devel libffi libssh2-devel autoconf automake libtool \ |
| 22 | + libxml2-devel libxslt-devel libjpeg-devel zlib-devel \ |
| 23 | + make cmake gcc python-devel python-setuptools wget openssl |
79 | 24 |
|
80 | 25 | #libcurl install start
|
81 | 26 | #install libcurl to avoid depending on host version
|
@@ -158,6 +103,11 @@ RUN umask 022 \
|
158 | 103 | RUN eval "$(pyenv init -)" \
|
159 | 104 | && pip -v install --upgrade pip
|
160 | 105 |
|
| 106 | +#extract osquery files. optionally pass in osquery filename with OSQUERY_TAR_FILENAME build-arg |
| 107 | +ARG OSQUERY_TAR_FILENAME=osquery_4hubble.tar |
| 108 | +ADD ${OSQUERY_TAR_FILENAME} /opt/osquery/ |
| 109 | +RUN /opt/osquery/osqueryi --version |
| 110 | + |
161 | 111 | #pyinstaller start
|
162 | 112 | #commands specified for ENTRYPOINT and CMD are executed when the container is run, not when the image is built
|
163 | 113 | #use the following variables to choose the version of hubble
|
|
0 commit comments