From b151397d85d60afe6ac37fece1e9e2f894751912 Mon Sep 17 00:00:00 2001 From: Marco Ochse Date: Thu, 17 May 2018 17:38:09 +0000 Subject: [PATCH] fix some compile errors, tweaking --- docker/glastopf/Dockerfile | 30 ++++++------ docker/glastopf/dist/base_logger.py | 31 ------------- docker/glastopf/dist/glastopf.cfg | 13 +++--- docker/glastopf/dist/log_s3.py | 72 ----------------------------- docker/glastopf/docker-compose.yml | 6 +-- 5 files changed, 24 insertions(+), 128 deletions(-) delete mode 100644 docker/glastopf/dist/base_logger.py delete mode 100644 docker/glastopf/dist/log_s3.py diff --git a/docker/glastopf/Dockerfile b/docker/glastopf/Dockerfile index 21fa4995..55d69962 100644 --- a/docker/glastopf/Dockerfile +++ b/docker/glastopf/Dockerfile @@ -4,8 +4,8 @@ FROM alpine ADD dist/ /root/dist/ # Install packages -RUN apk -U --no-cache add autoconf \ - bash \ +RUN apk -U --no-cache add \ + autoconf \ bind-tools \ build-base \ cython \ @@ -61,9 +61,7 @@ RUN apk -U --no-cache add autoconf \ # Install glastopf from git git clone https://github.com/mushorg/glastopf.git /opt/glastopf && \ cd /opt/glastopf && \ - git checkout c4932d9cb513d284142e2c0d66284221201d7477 && \ - cp /root/dist/base_logger.py /opt/glastopf/glastopf/modules/reporting/auxiliary/ && \ - cp /root/dist/log_s3.py /opt/glastopf/glastopf/modules/reporting/auxiliary/ && \ + git checkout 67c2a3fce7419f0c6b418b2b91da3c45b399f2b8 && \ cp /root/dist/requirements.txt /opt/glastopf/ && \ pip install --no-cache-dir . && \ cd / && \ @@ -73,21 +71,23 @@ RUN apk -U --no-cache add autoconf \ # Setup user, groups and configs addgroup -g 2000 glastopf && \ adduser -S -H -u 2000 -D -g 2000 glastopf && \ - mkdir -p /opt/glastopf && \ - mv /root/dist/glastopf.cfg /opt/glastopf/ && \ + mkdir -p /etc/glastopf && \ + mv /root/dist/glastopf.cfg /etc/glastopf/ && \ # Clean up - apk del autoconf \ - build-base \ - git \ - libffi-dev \ - php7-dev \ - python-dev \ - py-pip && \ + apk del --purge autoconf \ + build-base \ + file \ + git \ + libffi-dev \ + php7-dev \ + python-dev \ + py-pip \ + re2c && \ rm -rf /root/* && \ rm -rf /var/cache/apk/* # Set workdir and start glastopf USER glastopf:glastopf WORKDIR /tmp/glastopf/ -CMD cp /opt/glastopf/glastopf.cfg /tmp/glastopf && exec glastopf-runner +CMD cp /etc/glastopf/glastopf.cfg /tmp/glastopf && exec glastopf-runner diff --git a/docker/glastopf/dist/base_logger.py b/docker/glastopf/dist/base_logger.py deleted file mode 100644 index 6f2544e4..00000000 --- a/docker/glastopf/dist/base_logger.py +++ /dev/null @@ -1,31 +0,0 @@ -# Copyright (C) 2015 Lukas Rist -# -# This program is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License -# as published by the Free Software Foundation; either version 2 -# of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -from ConfigParser import SafeConfigParser -import os - - -class BaseLogger(object): - def __init__(self, config='glastopf.cfg'): - if not isinstance(config, SafeConfigParser): - self.config = SafeConfigParser(os.environ) - self.config.read(config) - else: - self.config = config - - def insert(self, event): - pass diff --git a/docker/glastopf/dist/glastopf.cfg b/docker/glastopf/dist/glastopf.cfg index 19d68c0d..daaf4504 100644 --- a/docker/glastopf/dist/glastopf.cfg +++ b/docker/glastopf/dist/glastopf.cfg @@ -107,10 +107,9 @@ enabled = False [s3storage] enabled = False -endpoint = %(GLASTOPF_S3_ENDPOINT)s -aws_access_key_id = %(GLASTOPF_S3_ACCESS_KEY_ID)s -aws_secret_access_key = %(GLASTOPF_S3_SECRET_ACCESS_KEY)s -bucket = %(GLASTOPF_S3_BUCKET)s -region = %(GLASTOPF_S3_REGION)s -signature_version = %(GLASTOPF_S3_SIGNATURE_VERSION)s - +endpoint = http://localhost:8080/ +aws_access_key_id = YOUR_aws_access_key_id +aws_secret_access_key = YOUR_aws_access_key_id +bucket = glastopf +region = eu-west-1 +signature_version = s3 diff --git a/docker/glastopf/dist/log_s3.py b/docker/glastopf/dist/log_s3.py deleted file mode 100644 index 62ca1ed1..00000000 --- a/docker/glastopf/dist/log_s3.py +++ /dev/null @@ -1,72 +0,0 @@ -# Copyright (C) 2018 Andre Vorbach @vorband -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . - -import logging -import os -import gevent - -import botocore.session, botocore.client -from botocore.exceptions import ClientError - -from glastopf.modules.reporting.auxiliary.base_logger import BaseLogger - - -logger = logging.getLogger(__name__) - - -class S3Logger(BaseLogger): - - def __init__(self, data_dir, work_dir, config="glastopf.cfg", reconnect=True): - config = os.path.join(work_dir, config) - BaseLogger.__init__(self, config) - self.files_dir = os.path.join(data_dir, 'files/') - self.enabled = False - self._initial_connection_happend = False - self.options = {'enabled': self.enabled} - if self.config.getboolean("s3storage", "enabled"): - self.endpoint = self.config.get("s3storage", "endpoint") - self.accesskey = self.config.get("s3storage", "aws_access_key_id") - self.secretkey = self.config.get("s3storage", "aws_secret_access_key") - self.version = self.config.get("s3storage", "signature_version") - self.region = self.config.get("s3storage", "region") - self.bucket = self.config.get("s3storage", "bucket") - self.enabled = True - self.options = {'enabled': self.enabled} - self.s3client = None - self.s3session = None - gevent.spawn(self._start_connection, self.endpoint, self.accesskey, self.secretkey, self.version, self.region, self.bucket) - - def _start_connection(self, endpoint, accesskey, secretkey, version, region, bucket): - self.s3session = botocore.session.get_session() - self.s3session.set_credentials(accesskey, secretkey) - self.s3client = self.s3session.create_client( - 's3', - endpoint_url=self.endpoint, - region_name=self.region, - config=botocore.config.Config(signature_version=self.version) - ) - self._initial_connection_happend = True - - def insert(self, attack_event): - if self._initial_connection_happend: - if attack_event.file_name is not None: - with file(os.path.join(self.files_dir, attack_event.file_name), 'r') as file_handler: - try: - self.s3client.put_object(Bucket=self.bucket, Body=file_handler, Key=attack_event.sensorid+"/"+attack_event.file_name) - logger.debug('Sending file ({0}) using s3 bucket "{1}" on {2}'.format(attack_event.file_name, self.bucket, self.endpoint)) - except ClientError as e: - logger.warning("Received error: %s", e.response['Error']['Message']) - else: - logger.warning('Not storing attack file because initial s3 connect has not succeeded') diff --git a/docker/glastopf/docker-compose.yml b/docker/glastopf/docker-compose.yml index a444ee16..5d71f0ba 100644 --- a/docker/glastopf/docker-compose.yml +++ b/docker/glastopf/docker-compose.yml @@ -1,4 +1,4 @@ -version: '2.2' +version: '2.3' networks: glastopf_local: @@ -20,5 +20,5 @@ services: image: "dtagdevsec/glastopf:1804" read_only: true volumes: - - /data/glastopf/db:/opt/glastopf/db - - /data/glastopf/log:/opt/glastopf/log + - /data/glastopf/db:/tmp/glastopf/db + - /data/glastopf/log:/tmp/glastopf/log