Skip to content

Commit 27cd4b3

Browse files
authored
Merge pull request #4 from hubblestack/4.0
4.0
2 parents 765c16b + bb3a80c commit 27cd4b3

File tree

23 files changed

+274
-106
lines changed

23 files changed

+274
-106
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ __pycache__/
77
*.py[cod]
88
*$py.class
99

10+
# patch detritus
11+
*.rej
12+
*.orig
13+
1014
# C extensions
1115
*.so
1216

.pipeline

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ pipeline {
5151
else find hubblestack -name "*.py" -print0 | xargs -r0 git diff --name-only "$LHS" "$RHS"
5252
fi > relevant-files.txt
5353
'''
54-
sh '''mkdir -vp tests/unittests/output'''
54+
sh ''' mkdir -vp tests/unittests/output
55+
cp relevant-files.txt tests/unittests/output
56+
'''
5557
}
5658
}
5759
stage('lint/test') {
@@ -106,7 +108,7 @@ pipeline {
106108
alwaysLinkToLastBuild: false,
107109
keepAll: true,
108110
reportDir: 'tests/unittests/output',
109-
reportFiles: 'pytest.html, coverage/index.html, pylint.html, profile-diagram.svg, bandit.html',
111+
reportFiles: 'pytest.html, coverage/index.html, pylint.html, profile-diagram.svg, bandit.html, relevant-files.txt',
110112
reportName: "Test Reports"
111113
])
112114
}
File renamed without changes.

doc/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@
5959
# built documents.
6060
#
6161
# The short X.Y version.
62-
version = u'3.0.8'
62+
version = u'4.0.0'
6363
# The full version, including alpha/beta/rc tags.
64-
release = u'3.0.8-1'
64+
release = u'4.0.0-1'
6565

6666
# The language for content autogenerated by Sphinx. Refer to documentation
6767
# for a list of supported languages.

hubblestack/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
__version__ = '3.0.8'
1+
__version__ = '4.0.0'
22

33
__buildinfo__ = {'branch': 'BRANCH_NOT_SET', 'last_commit': 'COMMIT_NOT_SET'}

hubblestack/daemon.py

+3
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,9 @@ def refresh_grains(initial=False):
798798
hubblestack.utils.signing.__opts__ = __opts__
799799
hubblestack.utils.signing.__salt__ = __salt__
800800

801+
hubblestack.utils.signing.__opts__ = __opts__
802+
hubblestack.utils.signing.__salt__ = __salt__
803+
801804
if not initial and __salt__['config.get']('splunklogging', False):
802805
hubblestack.log.emit_to_splunk(__grains__, 'INFO', 'hubblestack.grains_report')
803806

hubblestack/extmods/fileserver/s3fs.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105

106106
log = logging.getLogger(__name__)
107107

108-
S3_CACHE_EXPIRE = 30 # cache for 30 seconds
108+
S3_CACHE_EXPIRE = 1800 # cache for 30 minutes
109109
S3_SYNC_ON_UPDATE = True # sync cache on update rather than jit
110110

111111

@@ -336,6 +336,7 @@ def _get_s3_key():
336336
'service_url': None,
337337
'keyid': None,
338338
'key': None,
339+
'cache_expire': S3_CACHE_EXPIRE,
339340
}
340341

341342
ret = dict()
@@ -351,14 +352,17 @@ def _get_s3_key():
351352

352353
return ret
353354

355+
354356
def _init():
355357
"""
356358
Connect to S3 and download the metadata for each file in all buckets
357359
specified and cache the data to disk.
358360
"""
359361
cache_file = _get_buckets_cache_filename()
360-
exp = time.time() - S3_CACHE_EXPIRE
362+
cache_expire_time = float(_get_s3_key().get('cache_expire'))
363+
exp = time.time() - cache_expire_time
361364

365+
log.debug('S3 cache expire time is %ds', cache_expire_time)
362366
# check mtime of the buckets files cache
363367
metadata = None
364368
try:
@@ -443,6 +447,9 @@ def __get_s3_meta(bucket, key=s3_key_kwargs['key'], keyid=s3_key_kwargs['keyid']
443447
path_style=s3_key_kwargs['path_style'],
444448
https_enable=s3_key_kwargs['https_enable'],
445449
params={'marker': marker})
450+
if not tmp:
451+
return None
452+
446453
headers = []
447454
for header in tmp:
448455
if 'Key' in header:

hubblestack/extmods/grains/cloud_details.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _get_aws_details():
7373
headers=aws_token_header, timeout=3, proxies=proxies)
7474
if r.status_code == requests.codes.ok:
7575
aws_extra['cloud_private_hostname'] = r.text
76-
for key in aws_extra.keys():
76+
for key in list(aws_extra):
7777
if not aws_extra[key]:
7878
aws_extra.pop(key)
7979

@@ -133,7 +133,7 @@ def _get_azure_details():
133133
grain_name_mac = "cloud_interface_{0}_mac_address".format(counter)
134134
azure_extra[grain_name_mac] = value['macAddress']
135135

136-
for key in azure_extra:
136+
for key in list(azure_extra):
137137
if not azure_extra[key]:
138138
azure_extra.pop(key)
139139

hubblestack/extmods/utils/s3.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
HAS_REQUESTS = False # pylint: disable=W0612
1818

1919
# Import Salt libs
20+
import os
2021
import salt.utils.aws
2122
import salt.utils.files
2223
import salt.utils.hashutils
@@ -203,6 +204,11 @@ def query(key, keyid, method='GET', params=None, headers=None,
203204
err_code = 'http-{0}'.format(result.status_code)
204205
err_msg = err_text
205206

207+
if os.environ.get('MOCK_SLOW_DOWN'):
208+
result.status_code = 503
209+
err_code = 'SlowDown'
210+
err_msg = 'MOCK_SLOW_DOWN environment variable set. All S3 queries will fail for testing purposes.'
211+
206212
log.debug('S3 Response Status Code: %s', result.status_code)
207213

208214
if method == 'PUT':
@@ -219,7 +225,7 @@ def query(key, keyid, method='GET', params=None, headers=None,
219225
log.debug('Uploaded from %s to %s', local_file, path)
220226
else:
221227
log.debug('Created bucket %s', bucket)
222-
return
228+
return None
223229

224230
if method == 'DELETE':
225231
if not six.text_type(result.status_code).startswith('2'):
@@ -235,7 +241,7 @@ def query(key, keyid, method='GET', params=None, headers=None,
235241
log.debug('Deleted %s from bucket %s', path, bucket)
236242
else:
237243
log.debug('Deleted bucket %s', bucket)
238-
return
244+
return None
239245

240246
# This can be used to save a binary object to disk
241247
if local_file and method == 'GET':
@@ -250,6 +256,10 @@ def query(key, keyid, method='GET', params=None, headers=None,
250256
return 'Saved to local file: {0}'.format(local_file)
251257

252258
if result.status_code < 200 or result.status_code >= 300:
259+
if err_code in ['SlowDown', 'ServiceUnavailable', 'RequestTimeTooSkewed',
260+
'RequestTimeout', 'OperationAborted', 'InternalError']:
261+
log.error('Failed s3 operation: %s, %s', err_code, err_msg)
262+
return None
253263
raise CommandExecutionError(
254264
'Failed s3 operation. {0}: {1}'.format(err_code, err_msg))
255265

@@ -268,7 +278,7 @@ def query(key, keyid, method='GET', params=None, headers=None,
268278
return ret, requesturl
269279
else:
270280
if result.status_code != requests.codes.ok:
271-
return
281+
return None
272282
ret = {'headers': []}
273283
if full_headers:
274284
ret['headers'] = dict(result.headers)

hubblestack/utils/signing.py

-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def split_certs(fh):
114114
115115
returns a generator, for list, use `list(split_cerst(fh))`
116116
"""
117-
118117
ret = None
119118
for line in fh.readlines():
120119
if ret is None:

pkg/amazonlinux2016.09/Dockerfile

+19-8
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,22 @@ RUN mkdir -p "$LIBGIT2TEMP" \
136136
&& make \
137137
&& make install
138138

139-
#pyinstaller requirements start
140-
#must be preceded by libgit2 install
139+
# use pyenv
140+
ARG PYENV_VERSION=3.6.10
141+
ENV PYENV_INSTALLER_URL=https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer
142+
ENV PYENV_ROOT=/usr/local/pyenv
143+
ENV PATH=$PYENV_ROOT/bin:$PATH
144+
RUN umask 022 \
145+
&& curl -s -S -L "$PYENV_INSTALLER_URL" -o /usr/bin/pyenv-installer \
146+
&& chmod 0755 /usr/bin/pyenv-installer \
147+
&& /usr/bin/pyenv-installer \
148+
&& eval "$(pyenv init -)" \
149+
&& env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install $PYENV_VERSION \
150+
&& pyenv global $PYENV_VERSION
151+
141152
COPY pyinstaller-requirements.txt /
142-
#default python-pip from yum does not like upgrading itself from pip. looking for better options other than wget.
143-
RUN wget -c https://bootstrap.pypa.io/get-pip.py \
144-
&& python get-pip.py \
153+
RUN eval "$(pyenv init -)" \
154+
&& pip -v install --upgrade pip \
145155
&& pip -v install -r pyinstaller-requirements.txt
146156

147157
#fpm package making requirements start
@@ -151,8 +161,8 @@ RUN yum install -y ruby ruby-devel rpmbuild rpm-build rubygems gcc make \
151161
#pyinstaller start
152162
#commands specified for ENTRYPOINT and CMD are executed when the container is run, not when the image is built
153163
#use the following variables to choose the version of hubble
154-
ENV HUBBLE_CHECKOUT=v3.0.8
155-
ENV HUBBLE_VERSION=3.0.8
164+
ARG HUBBLE_CHECKOUT=v4.0.0
165+
ENV HUBBLE_VERSION=4.0.0
156166
ENV HUBBLE_ITERATION=1
157167
ENV HUBBLE_URL=https://github.com/hubblestack/hubble
158168
ENV HUBBLE_DESCRIPTION="Hubble is a modular, open-source, security & compliance auditing framework which is built in python, using SaltStack as a library."
@@ -165,7 +175,7 @@ ENV _INCLUDE_PATH=""
165175
ENV LD_LIBRARY_PATH=/opt/hubble/lib:/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
166176
RUN git clone "$HUBBLE_GIT_URL" "$HUBBLE_SRC_PATH" \
167177
&& cd "$HUBBLE_SRC_PATH" \
168-
&& git checkout "$HUBBLE_CHECKOUT" \
178+
&& git checkout -B hubble-build && git reset --hard "$HUBBLE_CHECKOUT" && git clean -dfx \
169179
&& cp -rf "$HUBBLE_SRC_PATH" /hubble_build \
170180
&& sed -i "s/BRANCH_NOT_SET/${HUBBLE_CHECKOUT}/g" /hubble_build/hubblestack/__init__.py \
171181
&& sed -i "s/COMMIT_NOT_SET/`git describe`/g" /hubble_build/hubblestack/__init__.py
@@ -174,6 +184,7 @@ VOLUME /data
174184
WORKDIR /hubble_build
175185
ENTRYPOINT [ "/bin/bash", "-o", "xtrace", "-c" ]
176186
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 -)\" \
177188
&& pyinstaller --onedir --noconfirm --log-level ${_BINARY_LOG_LEVEL} --additional-hooks-dir=${_HOOK_DIR} --runtime-hook=pkg/pyinstaller-runtimehooks/pathopthubble.py hubble.py \
178189
&& mkdir -p /var/log/hubble_osquery/backuplogs \
179190
# hubble default configuration file

pkg/centos6/Dockerfile

+24-15
Original file line numberDiff line numberDiff line change
@@ -135,26 +135,34 @@ RUN mkdir -p "$LIBGIT2TEMP" \
135135
&& make \
136136
&& make install
137137

138-
#pyinstaller requirements start
139-
#must be preceded by libgit2 install
138+
# use pyenv
139+
ARG PYENV_VERSION=3.6.10
140+
ENV PYENV_INSTALLER_URL=https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer
141+
ENV PYENV_ROOT=/usr/local/pyenv
142+
ENV PATH=$PYENV_ROOT/bin:$PATH
143+
RUN umask 022 \
144+
&& curl -s -S -L "$PYENV_INSTALLER_URL" -o /usr/bin/pyenv-installer \
145+
&& chmod 0755 /usr/bin/pyenv-installer \
146+
&& /usr/bin/pyenv-installer \
147+
&& eval "$(pyenv init -)" \
148+
&& env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install $PYENV_VERSION \
149+
&& pyenv global $PYENV_VERSION
150+
140151
COPY pyinstaller-requirements.txt /
141-
#default python-pip from yum does not like upgrading itself from pip. looking for better options other than wget.
142-
RUN wget -c https://bootstrap.pypa.io/get-pip.py \
143-
&& yum -y install centos-release-scl \
144-
&& yum -y install python27 \
145-
&& chmod u+x ./get-pip.py \
146-
&& scl enable python27 "./get-pip.py" \
147-
&& scl enable python27 "pip -v install -r pyinstaller-requirements.txt"
152+
RUN eval "$(pyenv init -)" \
153+
&& pip -v install --upgrade pip \
154+
&& pip -v install -r pyinstaller-requirements.txt
148155

149156
#fpm package making requirements start
150-
RUN yum install -y rpmbuild rpm-build gcc make rh-ruby23 rh-ruby23-ruby-devel \
151-
&& scl enable rh-ruby23 "gem install --no-ri --no-rdoc fpm"
157+
RUN yum install -y centos-release-scl scl-utils
158+
RUN yum install -y rpmbuild rpm-build gcc make rh-ruby23 rh-ruby23-ruby-devel
159+
RUN scl enable rh-ruby23 "gem install --no-ri --no-rdoc fpm"
152160

153161
#pyinstaller start
154162
#commands specified for ENTRYPOINT and CMD are executed when the container is run, not when the image is built
155163
#use the following variables to choose the version of hubble
156-
ENV HUBBLE_CHECKOUT=v3.0.8
157-
ENV HUBBLE_VERSION=3.0.8
164+
ARG HUBBLE_CHECKOUT=v4.0.0
165+
ENV HUBBLE_VERSION=4.0.0
158166
ENV HUBBLE_ITERATION=1
159167
ENV HUBBLE_URL=https://github.com/hubblestack/hubble
160168
ENV HUBBLE_DESCRIPTION="Hubble is a modular, open-source, security & compliance auditing framework which is built in python, using SaltStack as a library."
@@ -167,7 +175,7 @@ ENV _INCLUDE_PATH=""
167175
ENV LD_LIBRARY_PATH=/opt/hubble/lib:/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
168176
RUN git clone "$HUBBLE_GIT_URL" "$HUBBLE_SRC_PATH" \
169177
&& cd "$HUBBLE_SRC_PATH" \
170-
&& git checkout "$HUBBLE_CHECKOUT" \
178+
&& git checkout -B hubble-build && git reset --hard "$HUBBLE_CHECKOUT" && git clean -dfx \
171179
&& cp -rf "$HUBBLE_SRC_PATH" /hubble_build \
172180
&& sed -i "s/BRANCH_NOT_SET/${HUBBLE_CHECKOUT}/g" /hubble_build/hubblestack/__init__.py \
173181
&& sed -i "s/COMMIT_NOT_SET/`git describe`/g" /hubble_build/hubblestack/__init__.py
@@ -176,7 +184,8 @@ VOLUME /data
176184
WORKDIR /hubble_build
177185
ENTRYPOINT [ "/bin/bash", "-o", "xtrace", "-c" ]
178186
CMD [ "if [ -f /data/hubble_buildinfo ] ; then echo \"\" >> /hubble_build/hubblestack/__init__.py ; cat /data/hubble_buildinfo >> /hubble_build/hubblestack/__init__.py; fi \
179-
&& scl enable python27 'pyinstaller --onedir --noconfirm --log-level ${_BINARY_LOG_LEVEL} --additional-hooks-dir=${_HOOK_DIR} --runtime-hook=pkg/pyinstaller-runtimehooks/pathopthubble.py hubble.py' \
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 \
180189
&& mkdir -p /var/log/hubble_osquery/backuplogs \
181190
# hubble default configuration file
182191
&& cp -rf /hubble_build/conf/hubble /etc/hubble/ \

pkg/centos7/Dockerfile

+19-8
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,22 @@ RUN mkdir -p "$LIBGIT2TEMP" \
134134
&& make \
135135
&& make install
136136

137-
#pyinstaller requirements start
138-
#must be preceded by libgit2 install
137+
# use pyenv
138+
ARG PYENV_VERSION=3.6.10
139+
ENV PYENV_INSTALLER_URL=https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer
140+
ENV PYENV_ROOT=/usr/local/pyenv
141+
ENV PATH=$PYENV_ROOT/bin:$PATH
142+
RUN umask 022 \
143+
&& curl -s -S -L "$PYENV_INSTALLER_URL" -o /usr/bin/pyenv-installer \
144+
&& chmod 0755 /usr/bin/pyenv-installer \
145+
&& /usr/bin/pyenv-installer \
146+
&& eval "$(pyenv init -)" \
147+
&& env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install $PYENV_VERSION \
148+
&& pyenv global $PYENV_VERSION
149+
139150
COPY pyinstaller-requirements.txt /
140-
#default python-pip from yum does not like upgrading itself from pip. looking for better options other than wget.
141-
RUN wget -c https://bootstrap.pypa.io/get-pip.py \
142-
&& python get-pip.py \
151+
RUN eval "$(pyenv init -)" \
152+
&& pip -v install --upgrade pip \
143153
&& pip -v install -r pyinstaller-requirements.txt
144154

145155
#fpm package making requirements start
@@ -149,8 +159,8 @@ RUN yum install -y ruby ruby-devel rpmbuild rpm-build rubygems gcc make \
149159
#pyinstaller start
150160
#commands specified for ENTRYPOINT and CMD are executed when the container is run, not when the image is built
151161
#use the following variables to choose the version of hubble
152-
ENV HUBBLE_CHECKOUT=v3.0.8
153-
ENV HUBBLE_VERSION=3.0.8
162+
ARG HUBBLE_CHECKOUT=v4.0.0
163+
ENV HUBBLE_VERSION=4.0.0
154164
ENV HUBBLE_ITERATION=1
155165
ENV HUBBLE_URL=https://github.com/hubblestack/hubble
156166
ENV HUBBLE_DESCRIPTION="Hubble is a modular, open-source, security & compliance auditing framework which is built in python, using SaltStack as a library."
@@ -163,7 +173,7 @@ ENV _INCLUDE_PATH=""
163173
ENV LD_LIBRARY_PATH=/opt/hubble/lib:/lib:/lib64:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64
164174
RUN git clone "$HUBBLE_GIT_URL" "$HUBBLE_SRC_PATH" \
165175
&& cd "$HUBBLE_SRC_PATH" \
166-
&& git checkout "$HUBBLE_CHECKOUT" \
176+
&& git checkout -B hubble-build && git reset --hard "$HUBBLE_CHECKOUT" && git clean -dfx \
167177
&& cp -rf "$HUBBLE_SRC_PATH" /hubble_build \
168178
&& sed -i "s/BRANCH_NOT_SET/${HUBBLE_CHECKOUT}/g" /hubble_build/hubblestack/__init__.py \
169179
&& sed -i "s/COMMIT_NOT_SET/`git describe`/g" /hubble_build/hubblestack/__init__.py
@@ -172,6 +182,7 @@ VOLUME /data
172182
WORKDIR /hubble_build
173183
ENTRYPOINT [ "/bin/bash", "-o", "xtrace", "-c" ]
174184
CMD [ "if [ -f /data/hubble_buildinfo ] ; then echo \"\" >> /hubble_build/hubblestack/__init__.py ; cat /data/hubble_buildinfo >> /hubble_build/hubblestack/__init__.py; fi \
185+
&& eval \"$(pyenv init -)\" \
175186
&& pyinstaller --onedir --noconfirm --log-level ${_BINARY_LOG_LEVEL} --additional-hooks-dir=${_HOOK_DIR} --runtime-hook=pkg/pyinstaller-runtimehooks/pathopthubble.py hubble.py \
176187
&& mkdir -p /var/log/hubble_osquery/backuplogs \
177188
# hubble default configuration file

0 commit comments

Comments
 (0)