Skip to content

Commit 82d4e86

Browse files
authored
Merge pull request #807 from jettero/4.0-pkg-fix
4.0 pkg fix
2 parents 2fd4f76 + f5cbe34 commit 82d4e86

File tree

73 files changed

+3752
-1343
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+3752
-1343
lines changed

.travis.yml

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11

2+
version: 1.0
3+
24
language: python
35

46
cache: pip
57

68
env:
7-
- 'PYLINT_ENABLE=1'
9+
global:
10+
LIBGIT2_VERSION: "0.26.5"
11+
LIBGIT2_SRC_URL: https://github.com/libgit2/libgit2/archive/v${LIBGIT2_VERSION}.tar.gz
12+
LIBGIT2_DIR_NAME: libgit2-${LIBGIT2_VERSION}
13+
LIBGIT2_TAR_NAME: ${LIBGIT2_DIR_NAME}.tar.gz
14+
LIBGIT2: ~/libgit2/_install
15+
LD_LIBRARY_PATH: ${LIBGIT2}/lib:${LD_LIBRARY_PATH}
816

917
python:
10-
- "2.7"
11-
- "3.6"
12-
13-
matrix:
14-
allow_failures:
15-
- python: "3.6"
18+
- "3.6.10"
19+
- "3.7"
20+
- "3.8"
1621

1722
install:
18-
- pip install -r test-requirements.txt
23+
- pip --upgarde pip
24+
- ./mk-requires.sh
25+
- pip install -r requirements.txt
1926

2027
script:
21-
- bash tests/travis-runner.sh
28+
- wget -q "$LIBGIT2_SRC_URL" -O $LIBGIT2_TAR_NAME
29+
- tar -xzf $LIBGIT2_TAR_NAME
30+
- (cd $LIBGIT2_DIR_NAME; cmake . -DMAKE_INSTALL_PREFIX=${LIBGIT2} && make -j 5 install)
31+
- pytest tests/unittests

contrib/gen-pretend-certs.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def gen_CA(fname='ca-root', cn='ca-root', path_length=0, authority=None, pdir=DE
4949
private_key = genkey(**args)
5050
public_key = private_key.public_key()
5151

52-
with open(os.path.join(pdir, fname + '.key'), 'w') as fh:
52+
with open(os.path.join(pdir, fname + '.key'), 'wb') as fh:
5353
fh.write( as_pem(private_key) )
5454

55-
with open(os.path.join(pdir, fname + '.unsigned'), 'w') as fh:
55+
with open(os.path.join(pdir, fname + '.unsigned'), 'wb') as fh:
5656
fh.write( as_pem(public_key) )
5757

5858
ksec_100 = datetime.timedelta(0, 100e3, 0)
@@ -114,7 +114,7 @@ def gen_CA(fname='ca-root', cn='ca-root', path_length=0, authority=None, pdir=DE
114114

115115
certificate = builder.sign(**signing_args)
116116

117-
with open(os.path.join(pdir, fname + '.crt'), 'w') as fh:
117+
with open(os.path.join(pdir, fname + '.crt'), 'wb') as fh:
118118
fh.write( as_pem(certificate) )
119119

120120
return Authority(private_key, certificate)
@@ -126,10 +126,10 @@ def gen_leaf(authority, fname_template='{}', cn='Certy Cert McCertFace', pdir=DE
126126
private_name = fname_template.format('private')
127127
public_name = fname_template.format('public')
128128

129-
with open(os.path.join(pdir, private_name + '.key'), 'w') as fh:
129+
with open(os.path.join(pdir, private_name + '.key'), 'wb') as fh:
130130
fh.write( as_pem(private_key) )
131131

132-
with open(os.path.join(pdir, public_name + '.unsigned'), 'w') as fh:
132+
with open(os.path.join(pdir, public_name + '.unsigned'), 'wb') as fh:
133133
fh.write( as_pem(public_key) )
134134

135135
ksec_100 = datetime.timedelta(0, 100e3, 0)
@@ -186,7 +186,7 @@ def gen_leaf(authority, fname_template='{}', cn='Certy Cert McCertFace', pdir=DE
186186

187187
certificate = builder.sign(**signing_args)
188188

189-
with open(os.path.join(pdir, public_name + '.crt'), 'w') as fh:
189+
with open(os.path.join(pdir, public_name + '.crt'), 'wb') as fh:
190190
fh.write( as_pem(certificate) )
191191

192192
return Authority(private_key, certificate)
@@ -203,9 +203,9 @@ def main(root_cn, int1_cn, int2_cn, **args):
203203
lf1 = gen_leaf(cn='Certy Cert #1', fname_template='{}-1', authority=ia1, **args)
204204
lf2 = gen_leaf(cn='Certy Cert #2', fname_template='{}-2', authority=ia2, **args)
205205

206-
with open(os.path.join(args['pdir'], 'bundle.pem'), 'w') as ofh:
206+
with open(os.path.join(args['pdir'], 'bundle.pem'), 'wb') as ofh:
207207
for i in range(1,3):
208-
with open(os.path.join(args['pdir'], 'intermediate-{}.crt'.format(i)), 'r') as ifh:
208+
with open(os.path.join(args['pdir'], 'intermediate-{}.crt'.format(i)), 'rb') as ifh:
209209
ofh.write(ifh.read())
210210

211211
if __name__ == '__main__':

cp-pyinstaller.bash

-10
This file was deleted.

hubblestack/extmods/modules/signing.py

+6
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ def verify(*targets, **kw):
5656

5757
return dict(HuS.verify_files(targets, mfname=mfname, sfname=sfname,
5858
public_crt=public_crt, ca_crt=ca_crt))
59+
60+
def enumerate():
61+
""" enumerate installed certificates """
62+
63+
x509 = HuS.X509AwareCertBucket()
64+
return [ ' '.join(x.split()[1:]) for x in x509.trusted ]

hubblestack/utils/signing.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ def authenticate_cert(self):
230230
return STATUS.VERIFIED
231231
return STATUS.UNKNOWN
232232

233-
def __init__(self, public_crt, ca_crt):
233+
def __init__(self, public_crt=None, ca_crt=None):
234234
try:
235235
import hubblestack.pre_packaged_certificates as HPPC
236236
# iff we have hardcoded certs then we're meant to ignore any other
@@ -244,6 +244,11 @@ def __init__(self, public_crt, ca_crt):
244244
except ImportError:
245245
pass
246246

247+
if public_crt is None:
248+
public_crt = Options.public_crt
249+
if ca_crt is None:
250+
ca_crt = Options.ca_crt
251+
247252
untrusted_crt = list()
248253

249254
if isinstance(ca_crt, (list, tuple)):

mk-requires.sh

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
3+
D="$(dirname "$0")"
4+
F="$D/requirements.txt"
5+
6+
echo "# This file was generated by $0" > "$F"
7+
echo "# $(date -u)" >> "$F"
8+
echo >> "$F"
9+
10+
bash "$D/pkg/generate-requirements.sh" "$@" | tee -a "$F"
11+
12+
CMD=( pip install --upgrade -r requirements.txt )
13+
14+
read -ep "issue ${CMD[*]}? [Y/n]" YN
15+
[[ "$YN" =~ [Nn] ]] || "${CMD[@]}"

optional-requirements.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
azure==4.0.0
3+
azure-storage-common==2.1.0
4+
azure-storage-blob==2.1.0
5+
6+
boto3
7+
botocore

package-requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyinstaller==3.6
2+
pyinstaller-hooks

pkg/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
osquery

pkg/debian7/Dockerfile pkg/abandoned/debian7/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ RUN apt-get install -y ruby ruby-dev rubygems gcc make \
199199
#commands specified for ENTRYPOINT and CMD are executed when the container is run, not when the image is built
200200
#use the following variables to choose the version of hubble
201201
ARG HUBBLE_CHECKOUT=v4.0.0
202-
ENV HUBBLE_GIT_URL=https://github.com/hubblestack/hubble.git
202+
ARG HUBBLE_GIT_URL=https://github.com/hubblestack/hubble.git
203203
ENV HUBBLE_VERSION=4.0.0
204204
ENV HUBBLE_ITERATION=1
205205
ENV HUBBLE_URL=https://github.com/hubblestack/hubble

pkg/debian7/pyinstaller-requirements.txt pkg/abandoned/debian7/pyinstaller-requirements.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
pyinstaller==3.3.1
22
Tornado>=4.0.0,<5.0.0
3-
Crypto
3+
crypto
4+
pycryptodome
5+
cryptography
46
pyopenssl>=16.2.0
57
argparse
68
requests>=2.13.0

pkg/amazonlinux2016.09/Dockerfile

+34-68
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# To run the container: docker run -it --rm -v `pwd`:/data <image_name>
77
# Requires docker 17.05 or higher
88

9-
# Set this arguement to "local" if you want to build osquery for local code.
9+
# Set this argument to "local" if you want to build osquery for local code.
1010
# In that case, osquery folder must exist besides Dockerfile
1111
ARG OSQUERY_BUILD_ENV=remote
1212

@@ -29,7 +29,7 @@ ONBUILD RUN cd / \
2929
&& echo "Fetching osquery from git"
3030

3131

32-
#--------------- TEMP CONTAINER FOR OSQUERY ( BASED ON ARGUMENT ) --------------
32+
#--------------- TEMP CONTAINER FOR OSQUERY ( BASED ON ARGUMENT ) ---------------
3333
FROM osquery_"$OSQUERY_BUILD_ENV" as osquery_image
3434

3535

@@ -40,7 +40,6 @@ RUN yum makecache fast && yum -y update
4040

4141
#paths that hubble or hubble parts need in the package
4242
RUN mkdir -p /etc/hubble/hubble.d /opt/hubble /opt/osquery /var/log/hubble_osquery/backuplogs
43-
4443
#osquery build start
4544
#osquery should be built first since requirements for other packages can interfere with osquery dependencies
4645
#to build, osquery scripts want sudo and a user to sudo with.
@@ -74,10 +73,9 @@ RUN ls -lahR /opt/osquery/ && /opt/osquery/osqueryi --version
7473

7574
#install packages that should be needed for ligbit2 compilation and successful pyinstaller run
7675
RUN yum -y install \
77-
python27-devel libffi-devel openssl-devel libssh2-devel autoconf automake libtool \
78-
libxml2-devel libxslt-devel libjpeg-devel \
79-
zlib-devel make cmake python27-setuptools \
80-
gcc python-devel python-setuptools wget openssl
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
8179

8280
#libcurl install start
8381
#install libcurl to avoid depending on host version
@@ -136,27 +134,29 @@ RUN mkdir -p "$LIBGIT2TEMP" \
136134
&& make \
137135
&& make install
138136

137+
#fpm package making requirements start
138+
RUN yum install -y ruby ruby-devel rpmbuild rpm-build rubygems gcc make \
139+
&& gem install --no-ri --no-rdoc fpm
140+
141+
# things we may need to build a python
142+
RUN yum install -y bzip2-devel
143+
139144
# use pyenv
140145
ARG PYENV_VERSION=3.6.10
141146
ENV PYENV_INSTALLER_URL=https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer
142-
ENV PYENV_ROOT=/usr/local/pyenv
147+
ENV PYENV_ROOT=/opt/hubble/pyenv
143148
ENV PATH=$PYENV_ROOT/bin:$PATH
149+
ENV PYTHON_CONFIGURE_OPTS="--enable-shared"
144150
RUN umask 022 \
145151
&& curl -s -S -L "$PYENV_INSTALLER_URL" -o /usr/bin/pyenv-installer \
146152
&& chmod 0755 /usr/bin/pyenv-installer \
147153
&& /usr/bin/pyenv-installer \
148154
&& eval "$(pyenv init -)" \
149-
&& env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install $PYENV_VERSION \
155+
&& pyenv install $PYENV_VERSION \
150156
&& pyenv global $PYENV_VERSION
151157

152-
COPY pyinstaller-requirements.txt /
153158
RUN eval "$(pyenv init -)" \
154-
&& pip -v install --upgrade pip \
155-
&& pip -v install -r pyinstaller-requirements.txt
156-
157-
#fpm package making requirements start
158-
RUN yum install -y ruby ruby-devel rpmbuild rpm-build rubygems gcc make \
159-
&& gem install --no-ri --no-rdoc fpm
159+
&& pip -v install --upgrade pip
160160

161161
#pyinstaller start
162162
#commands specified for ENTRYPOINT and CMD are executed when the container is run, not when the image is built
@@ -167,64 +167,30 @@ ENV HUBBLE_ITERATION=1
167167
ENV HUBBLE_URL=https://github.com/hubblestack/hubble
168168
ENV HUBBLE_DESCRIPTION="Hubble is a modular, open-source, security & compliance auditing framework which is built in python, using SaltStack as a library."
169169
ENV HUBBLE_SUMMARY="Profile based on-demand auditing and monitoring tool"
170-
ENV HUBBLE_GIT_URL=https://github.com/hubblestack/hubble.git
170+
ARG HUBBLE_GIT_URL=https://github.com/hubblestack/hubble.git
171171
ENV HUBBLE_SRC_PATH=/hubble_src
172172
ENV _HOOK_DIR="./pkg/"
173173
ENV _BINARY_LOG_LEVEL="INFO"
174174
ENV _INCLUDE_PATH=""
175175
ENV LD_LIBRARY_PATH=/opt/hubble/lib:/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
176-
RUN git clone "$HUBBLE_GIT_URL" "$HUBBLE_SRC_PATH" \
176+
177+
RUN set -x; git clone "$HUBBLE_GIT_URL" "$HUBBLE_SRC_PATH" \
177178
&& cd "$HUBBLE_SRC_PATH" \
178-
&& git checkout -B hubble-build && git reset --hard "$HUBBLE_CHECKOUT" && git clean -dfx \
179-
&& cp -rf "$HUBBLE_SRC_PATH" /hubble_build \
180-
&& sed -i "s/BRANCH_NOT_SET/${HUBBLE_CHECKOUT}/g" /hubble_build/hubblestack/__init__.py \
181-
&& sed -i "s/COMMIT_NOT_SET/`git describe`/g" /hubble_build/hubblestack/__init__.py
179+
&& git checkout -B hubble-build && git reset --hard "$HUBBLE_CHECKOUT" && git clean -dfx
180+
181+
RUN cp -rf "$HUBBLE_SRC_PATH" /hubble_build \
182+
&& rm -rf /hubble_build/.git
183+
184+
RUN cp /hubble_build/hubblestack/__init__.py /hubble_build/hubblestack/__init__.orig \
185+
&& sed -i -e "s/BRANCH_NOT_SET/${HUBBLE_CHECKOUT}/g" \
186+
-e "s/COMMIT_NOT_SET/$(cd $HUBBLE_SRC_PATH; git describe --long --always --tags)/g" \
187+
/hubble_build/hubblestack/__init__.py \
188+
&& cp /hubble_build/hubblestack/__init__.py /hubble_build/hubblestack/__init__.fixed
189+
182190
RUN mkdir /data
183191
VOLUME /data
192+
184193
WORKDIR /hubble_build
185-
ENTRYPOINT [ "/bin/bash", "-o", "xtrace", "-c" ]
186-
CMD [ "if [ -f /data/hubble_buildinfo ] ; then echo \"\" >> /hubble_build/hubblestack/__init__.py ; cat /data/hubble_buildinfo >> /hubble_build/hubblestack/__init__.py; fi \
187-
&& eval \"$(pyenv init -)\" \
188-
&& pyinstaller --onedir --noconfirm --log-level ${_BINARY_LOG_LEVEL} --additional-hooks-dir=${_HOOK_DIR} --runtime-hook=pkg/pyinstaller-runtimehooks/pathopthubble.py hubble.py \
189-
&& mkdir -p /var/log/hubble_osquery/backuplogs \
190-
# hubble default configuration file
191-
&& cp -rf /hubble_build/conf/hubble /etc/hubble/ \
192-
&& cp -rf /hubble_build/conf/hubble-profile.sh /etc/profile.d/ \
193-
&& cp -pr /hubble_build/dist/hubble /opt/hubble/hubble-libs \
194-
&& ln -s /opt/hubble/hubble-libs/hubble /opt/hubble/hubble \
195-
# make sure rpm shared libs are taken out to avoid mismatch between rpm database and shared libs that pyinstaller includes
196-
&& rm -rf /opt/hubble/hubble-libs/librpm* \
197-
#rpm pkg start
198-
&& tar -cPvzf /data/hubblestack-${HUBBLE_VERSION}.tar.gz /etc/hubble /opt/hubble /opt/osquery /etc/profile.d/hubble-profile.sh /var/log/hubble_osquery/backuplogs \
199-
&& mkdir -p /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION} \
200-
&& tar -xzvf /data/hubblestack-${HUBBLE_VERSION}.tar.gz -C /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION} \
201-
&& mkdir -p /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/init.d \
202-
&& if [ -f /data/hubble-autostart ] ; then mkdir -p /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/cron.d ; fi \
203-
&& cp /hubble_build/pkg/hubble /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/init.d/ \
204-
&& if [ -f /data/hubble-autostart ] ; then cp /hubble_build/pkg/hubble-autostart /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/cron.d/ ; fi \
205-
&& cp -f /hubble_build/conf/hubble /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/hubble/ \
206-
#during container run, if a configuration file exists in a /data copy it over the existing one so it would be
207-
#possile to optionally include a custom one with the package
208-
&& if [ -f /data/hubble ] ; then cp /data/hubble /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/etc/hubble/ ; fi \
209-
#also bring in anything from a /data/opt/ directory so we can bundle other executables if needed
210-
&& if [ -d /data/opt ] ; then cp -r /data/opt/* /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION}/opt/ ; fi \
211-
&& cd /hubble_build/debbuild/hubblestack-${HUBBLE_VERSION} \
212-
&& mkdir -p usr/bin \
213-
#symlink to have hubble binary in path
214-
&& ln -s /opt/hubble/hubble usr/bin/hubble \
215-
#fpm start
216-
&& fpm -s dir -t rpm \
217-
-n hubblestack \
218-
-v ${HUBBLE_VERSION} \
219-
--iteration ${HUBBLE_ITERATION} \
220-
--url ${HUBBLE_URL} \
221-
--description \"${HUBBLE_DESCRIPTION}\" \
222-
--rpm-summary \"${HUBBLE_SUMMARY}\" \
223-
--after-install /hubble_build/conf/afterinstall.sh \
224-
--after-upgrade /hubble_build/conf/afterupgrade.sh \
225-
--before-remove /hubble_build/conf/beforeremove.sh \
226-
etc opt usr /var/log/hubble_osquery/backuplogs \
227-
#edit to change iteration number, if necessary
228-
&& cp hubblestack-${HUBBLE_VERSION}-${HUBBLE_ITERATION}.x86_64.rpm /data/hubblestack-${HUBBLE_VERSION}-${HUBBLE_ITERATION}.al1609.x86_64.rpm \
229-
&& openssl dgst -sha256 /data/hubblestack-${HUBBLE_VERSION}-${HUBBLE_ITERATION}.al1609.x86_64.rpm \
230-
> /data/hubblestack-${HUBBLE_VERSION}-${HUBBLE_ITERATION}.al1609.x86_64.rpm.sha256" ]
194+
195+
COPY entrypoint.sh /entrypoint.sh
196+
ENTRYPOINT [ "/bin/bash", "/entrypoint.sh" ]

0 commit comments

Comments
 (0)