Skip to content

Commit

Permalink
Merge pull request #77 from mpast/bug-fix-dd-export-issue-73
Browse files Browse the repository at this point in the history
chore: improve error management in defect dojo export
  • Loading branch information
mpast committed Dec 26, 2022
2 parents 8d0ca9d + f2d1ba7 commit 963f914
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 80 deletions.
10 changes: 4 additions & 6 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
# Ignore the logs
app/logs/
rabbitmq/logs/
# Ignore rabbitmq and nginx
rabbitmq
nginx

# Ignore apk directory
app/media/apk

# Ignoring git folders
.git

# Ignore certificates
nginx/ssl/nginx.crt
nginx/ssl/nginx.key
.git
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
*.DS_Store
.env
.vscode
app/logs/*
rabbitmq/logs/*
nginx/logs/*
app/media/*
*.sqlite3
*.sqlite
Expand Down
138 changes: 69 additions & 69 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
FROM python:3.9.7-buster@sha256:79a631c93960c5919f27f3403e734ec19b130008370a5f902141bcff2e6d6f4c
# Update and package installation
RUN apt-get update && \
apt-get clean && \
apt-get install -y ca-certificates-java --no-install-recommends && \
apt-get clean

RUN apt-get update && \
apt-get install -y openjdk-11-jdk p11-kit wkhtmltopdf libqt5gui5 && \
apt-get install -y && \
apt-get clean && \
update-ca-certificates -f

# Get JADX Tool
ENV JADX_VERSION 1.4.5

RUN \
wget "https://github.com/skylot/jadx/releases/download/v$JADX_VERSION/jadx-$JADX_VERSION.zip" && \
unzip "jadx-$JADX_VERSION.zip"

# Create user
ARG uid=1000
ARG gid=1000
ARG user=app
ARG group=app

RUN groupadd -g ${gid} ${group} \
&& useradd -u ${uid} -g ${group} -s /bin/sh ${user}

# Copy entrypoints
COPY entrypoint/web_entrypoint.sh \
entrypoint/worker_entrypoint.sh /

RUN chown ${uid}:${gid} /web_entrypoint.sh /worker_entrypoint.sh && \
chmod u+x /web_entrypoint.sh /worker_entrypoint.sh

# Create a directory in the container in /app
RUN mkdir /app
# Copy all to /app directory
COPY . /app

# Use /app as the workdir
WORKDIR /app


# Upgrade pip and install python dependencies
RUN pip install --upgrade pip \
&& pip install -r requirements.txt

# Encoding configuration
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV PYTHONIOENCODING utf8

# Logs
RUN mkdir -p app/logs
RUN touch app/logs/debug.log

# RabbitMQ directory
RUN mkdir -p rabbitmq/logs

# Set the permissions to the user
RUN chown -R ${uid}:${gid} /app

# Run the container as non-root user
USER ${uid}

# Expose the 8000 port
EXPOSE 8000
FROM python:3.9.7-buster@sha256:79a631c93960c5919f27f3403e734ec19b130008370a5f902141bcff2e6d6f4c
# Update and package installation
RUN apt-get update && \
apt-get clean && \
apt-get install -y ca-certificates-java --no-install-recommends && \
apt-get clean

RUN apt-get update && \
apt-get install -y openjdk-11-jdk p11-kit wkhtmltopdf libqt5gui5 && \
apt-get install -y && \
apt-get clean && \
update-ca-certificates -f

# Get JADX Tool
ENV JADX_VERSION 1.4.5

RUN \
wget "https://github.com/skylot/jadx/releases/download/v$JADX_VERSION/jadx-$JADX_VERSION.zip" && \
unzip "jadx-$JADX_VERSION.zip"

# Create user
ARG uid=1000
ARG gid=1000
ARG user=app
ARG group=app

RUN groupadd -g ${gid} ${group} \
&& useradd -u ${uid} -g ${group} -s /bin/sh ${user}

# Copy entrypoints
COPY entrypoint/web_entrypoint.sh \
entrypoint/worker_entrypoint.sh /

RUN chown ${uid}:${gid} /web_entrypoint.sh /worker_entrypoint.sh && \
chmod u+x /web_entrypoint.sh /worker_entrypoint.sh

# Create a directory in the container in /app
RUN mkdir /app
# Copy all to /app directory
COPY . /app

# Use /app as the workdir
WORKDIR /app


# Upgrade pip and install python dependencies
RUN pip install --upgrade pip \
&& pip install -r requirements.txt

# Encoding configuration
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV PYTHONIOENCODING utf8

# Logs
RUN mkdir -p app/logs
RUN touch app/logs/debug.log

# RabbitMQ directory
RUN mkdir -p rabbitmq/logs

# Set the permissions to the user
RUN chown -R ${uid}:${gid} /app

# Run the container as non-root user
USER ${uid}

# Expose the 8000 port
EXPOSE 8000
1 change: 0 additions & 1 deletion app/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
license=openapi.License(name="GNU v3"),
),
public=True,
url="http://localhost:8888/api/v1/"
)

# API router
Expand Down
6 changes: 4 additions & 2 deletions app/integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def create_finding_on_dojo(finding):
'date': finding.created_on.strftime("%Y-%m-%d"),
#'product': product_id,
#'engagement': engagement_id,
'test': finding.scan.defectdojo_id,
'test': finding.scan.defectdojo_id if finding.scan.defectdojo_id else 1,
'impact': "N/A",
'active': True,
#'verified': verified,
Expand Down Expand Up @@ -223,8 +223,10 @@ def create_finding_on_dojo(finding):
response = requests.post(settings.DEFECTDOJO_API_URL + 'findings/', data = json_data, headers = headers, verify = False)
json_response = response.json()
logger.debug(json_response)
if (json_response['id']):
if ('id' in json_response and json_response['id']):
finding.defectdojo_id = json_response['id']
finding.save()
else:
logger.error(json_response)
except Exception as e:
logger.error(e)
4 changes: 2 additions & 2 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def home(request):
try:
scans_data[scan.id]['antivirus'] = VirusTotalScan.objects.filter(scan=scan.id).latest('created_on')
except Exception as e:
logger.error(e)
logger.debug(e)

return render(request, 'home.html', {
'apps': apps,
Expand Down Expand Up @@ -285,7 +285,7 @@ def findings(request, scan_id=''):
if (push_dojo and settings.DEFECTDOJO_ENABLED):
analysis.create_finding_on_dojo(f)
except Exception as e:
logger.error(e)
logger.debug(e)
if (edit and ok):
messages.success(request, 'Edited successfully')
else:
Expand Down
1 change: 1 addition & 0 deletions docker-compose.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ services:
- .:/app
- ./nginx/app_tls.conf:/etc/nginx/conf.d/app_tls.conf
- ./nginx/ssl:/etc/nginx/ssl
- ./nginx/logs:/var/log/nginx
depends_on:
- web
restart: on-failure
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ services:
volumes:
- .:/app
- ./nginx/app.conf:/etc/nginx/conf.d/app.conf
- ./nginx/logs:/var/log/nginx
depends_on:
- web
restart: on-failure
Expand Down
3 changes: 3 additions & 0 deletions nginx/app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ upstream web {

server {

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

client_max_body_size 300M;
uwsgi_connect_timeout 500;
uwsgi_read_timeout 500;
Expand Down
3 changes: 3 additions & 0 deletions nginx/app_tls.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ upstream app {
}

server {
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;

Expand Down

0 comments on commit 963f914

Please sign in to comment.