-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,756 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/bin/sh | ||
|
||
# Allow for bind-mount setting.py overrides | ||
FILE=/settings/settings.py | ||
if test -f "$FILE"; then | ||
echo "============================================================" | ||
echo " Overriding DefectDojo's settings.py with $FILE." | ||
echo "============================================================" | ||
cp "$FILE" /app/dojo/settings/settings.py | ||
fi | ||
|
||
umask 0002 | ||
|
||
UWSGI_INIFILE=dojo/uwsgi.ini | ||
cat > $UWSGI_INIFILE<<EOF | ||
[uwsgi] | ||
$DD_UWSGI_MODE = $DD_UWSGI_ENDPOINT | ||
protocol = uwsgi | ||
module = dojo.wsgi:application | ||
enable-threads | ||
processes = ${DD_UWSGI_NUM_OF_PROCESSES:-2} | ||
threads = ${DD_UWSGI_NUM_OF_THREADS:-2} | ||
threaded-logger | ||
buffer-size = ${DD_UWSGI_BUFFER_SIZE:-4096} | ||
; HTTP endpoint is enabled for Kubernetes liveness checks. It should not be exposed as a serivce. | ||
http = 0.0.0.0:8081 | ||
http-to = ${DD_UWSGI_ENDPOINT} | ||
EOF | ||
|
||
if [ "${DD_LOGGING_HANDLER}" = "json_console" ]; then | ||
cat >> $UWSGI_INIFILE <<'EOF' | ||
; logging as json does not offer full tokenization for requests, everything will be in message. | ||
logger = stdio | ||
log-encoder = json {"timestamp":"${strftime:%%Y-%%m-%%d %%H:%%M:%%S%%z}", "source": "uwsgi", "message":"${msg}"} | ||
log-encoder = nl | ||
EOF | ||
fi | ||
|
||
exec uwsgi --ini $UWSGI_INIFILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# local_settings.py | ||
# this file will be included by settings.py *after* loading settings.dist.py | ||
|
||
from celery.schedules import crontab | ||
|
||
# add our own cb_tasks.py for tasks to get registered | ||
CELERY_IMPORTS += ('dojo.cb_tasks',) | ||
CELERY_BEAT_SCHEDULE['auto-delete-engagements'] = { | ||
'task': 'dojo.cb_tasks.auto_delete_engagements', | ||
'schedule': crontab(hour=9, minute=30) | ||
} | ||
|
||
# Temp fix - fix possible circular dups | ||
CELERY_BEAT_SCHEDULE['fix_loop_duplicates'] = { | ||
'task': 'dojo.tasks.fix_loop_duplicates_task', | ||
'schedule': crontab(hour=9, minute=00) | ||
} | ||
|
||
# ensure jira status reflect on defectdojo findings | ||
CELERY_BEAT_SCHEDULE['jira_status_reconciliation'] = { | ||
'task': 'dojo.tasks.jira_status_reconciliation_task', | ||
'schedule': timedelta(hours=24), | ||
'kwargs': {'mode': 'import_status_from_jira', 'dryrun': False, 'daysback': 2} | ||
} | ||
|
||
# Override deduplication for certain parsers | ||
HASHCODE_FIELDS_PER_SCANNER['Anchore Engine Scan'] = ['title', 'severity', 'component_name', 'component_version', 'file_path'] | ||
HASHCODE_ALLOWS_NULL_CWE['Anchore Engine Scan'] = True | ||
DEDUPLICATION_ALGORITHM_PER_PARSER['Anchore Engine Scan'] = DEDUPE_ALGO_HASH_CODE | ||
|
||
HASHCODE_FIELDS_PER_SCANNER['Twistlock Image Scan'] = ['title', 'severity', 'component_name', 'component_version'] | ||
HASHCODE_ALLOWS_NULL_CWE['Twistlock Image Scan'] = True | ||
DEDUPLICATION_ALGORITHM_PER_PARSER['Twistlock Image Scan'] = DEDUPE_ALGO_HASH_CODE | ||
|
||
# HASHCODE_FIELDS_PER_SCANNER['Dependency Check Scan'] = ['title', 'severity', 'component_name', 'component_version'] | ||
# HASHCODE_ALLOWS_NULL_CWE['Dependency Check Scan'] = True | ||
# DEDUPLICATION_ALGORITHM_PER_PARSER['Dependency Check Scan'] = DEDUPE_ALGO_HASH_CODE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
from dojo.cb_utils import auto_delete_engagements | ||
# from dojo.models import System_Settings | ||
from dojo.celery import app | ||
from celery.utils.log import get_task_logger | ||
|
||
logger = get_task_logger(__name__) | ||
|
||
|
||
@app.task(name='dojo.cb_tasks.auto_delete_engagements') | ||
def async_auto_delete_engagements(*args, **kwargs): | ||
try: | ||
# system_settings = System_Settings.objects.get() | ||
# if system_settings.engagement_auto_delete_enable: | ||
logger.info("Automatically deleting engagements and related as needed") | ||
auto_delete_engagements(*args, **kwargs) | ||
except Exception as e: | ||
logger.error("An unexpected error was thrown calling the engagements auto deletion code: {}".format(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from dojo.models import Finding, Engagement, System_Settings | ||
import logging | ||
from datetime import datetime, timedelta | ||
from django.utils import timezone | ||
from django.db.models import Q, Exists, OuterRef | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def auto_delete_engagements(): | ||
# TODO implement dry-run option | ||
""" | ||
For an engagement to be in-scope for automated deletion, the following rules apply: | ||
- must have been updated before x days (as defined in system settings) | ||
- (hardcoded) must be a CI/CD engagement | ||
- (hardcoded) must only contain duplicate findings | ||
- (hardocded) must not contain any notes on any of its findings | ||
The original use-case of this feature relates to the mass imports that one can have through CI pipelines, | ||
generating a vast amount of findings which ultimately will boggle down defectdojo's performance | ||
and make it harder to see what needs to be seen. | ||
""" | ||
|
||
""" | ||
def _notify(engagement_id, engagement_title): | ||
create_notification( | ||
event='auto_delete_engagement', | ||
title=engagement_title, | ||
id=engagement_id, | ||
) | ||
""" | ||
|
||
system_settings = System_Settings.objects.get() | ||
# if system_settings.engagement_auto_delete_enable: | ||
# how to not exclude the tag when not empty? If empty, then query results are unexpected. | ||
# setting arbitrary string for now, which is unlikely to be a used tag. | ||
# lock_tag = system_settings.engagement_auto_delete_lock_tag or 'qAEH2HL6Qd9ofZYLCGykN2WQ' | ||
lock_tag = 'donotdelete' | ||
logger.info("Proceeding with automatic engagements deletion, for engagements older than {} days".format( | ||
30 | ||
)) | ||
logger.info("Lock tag is {}".format(lock_tag)) | ||
|
||
# cutoff_date = timezone.make_aware(datetime.today()) - timedelta(days=system_settings.engagement_auto_delete_days) | ||
cutoff_date = timezone.make_aware(datetime.today()) - timedelta(days=30) | ||
cutoff_date.tzinfo | ||
logger.info("Cutoff date is {}".format(cutoff_date)) | ||
engagements_to_delete = Engagement.objects.annotate( | ||
all_duplicates=~Exists( | ||
Finding.objects.filter(~Q(duplicate=True), test__engagement_id=OuterRef('pk')) | ||
), | ||
has_no_note=~Exists( | ||
Finding.objects.filter(~Q(notes__isnull=True), test__engagement_id=OuterRef('pk')) | ||
), | ||
).filter( | ||
engagement_type='CI/CD', | ||
created__lt=cutoff_date, | ||
all_duplicates=True, | ||
has_no_note=True | ||
).exclude( | ||
tags__name__contains=lock_tag | ||
) | ||
|
||
for engagement in engagements_to_delete: | ||
logger.info("Deleting engagement id {} ({})".format(engagement.id, engagement.name)) | ||
# _notify(engagement, "Engagement {} ({})- auto-deleted".format(engagement.id, engagement.name)) | ||
engagement.delete() | ||
|
||
else: | ||
logger.debug("Automatic engagement deletion is not activated.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Generated by Django 2.2.17 on 2021-03-21 07:58 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django_extensions.db.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dojo', '0084_add_extras_in_tool'), | ||
] | ||
|
||
operations = [ | ||
migrations.RenameField( | ||
model_name='jira_instance', | ||
old_name='issue_template', | ||
new_name='issue_template_dir', | ||
), | ||
migrations.RenameField( | ||
model_name='jira_project', | ||
old_name='issue_template', | ||
new_name='issue_template_dir', | ||
), | ||
migrations.CreateModel( | ||
name='Finding_Group', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')), | ||
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')), | ||
('name', models.CharField(max_length=255)), | ||
('creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dojo.Dojo_User')), | ||
('findings', models.ManyToManyField(to='dojo.Finding')), | ||
('test', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dojo.Test')), | ||
], | ||
options={ | ||
'ordering': ['id'], | ||
}, | ||
), | ||
migrations.AddField( | ||
model_name='jira_issue', | ||
name='finding_group', | ||
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='dojo.Finding_Group'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.