Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sca fixed in improvements #192

Merged
merged 9 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.9'

- name: Set-up environment
run: pip install -r surface/requirements_test.txt

Expand Down
1 change: 1 addition & 0 deletions dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ RUN apt-get update \
libldap2-dev \
libsasl2-dev \
git \
pkg-config \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /wheels
Expand Down
1 change: 1 addition & 0 deletions dev/Dockerfile-IN-A-BOX
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ RUN apt-get update \
libldap2-dev \
libsasl2-dev \
git \
pkg-config \
&& rm -rf /var/lib/apt/lists/*

RUN --mount=type=bind,target=/tmpapp \
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ select = [
src = ['surface', 'e2e']

[tool.ruff.isort]
known-first-party = ["theme", "dkron", "django_restful_admin", "slackbot", "dbcleanup", "olympus", "notifications", "ppbenviron", "logbasecommand", "impersonate", "apitokens"]
known-first-party = ["theme", "dkron", "django_restful_admin", "slackbot", "dbcleanup", "olympus", "notifications", "ppbenviron", "logbasecommand", "impersonate", "apitokens", "sbomrepo"]
3 changes: 1 addition & 2 deletions surface/requirements.txt
fpintoppb marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Core Libraries

Django==3.2.25
django-admin-rangefilter==0.11.0
django-after-response==0.2.2
Expand Down Expand Up @@ -27,7 +26,7 @@ django-impersonator==0.0.2
django-apitokens==0.0.2
django-sbomrepo==0.0.6

mysqlclient==2.0.3
mysqlclient==2.2.4
tqdm==4.65.0 # for core_utils that is not really a app/package ..?
django-database-locks==0.5 # distributed locks (on mysql)
django-bulk-update-or-create==0.3.0 # for faster batch operations with update_or_create
Expand Down
6 changes: 3 additions & 3 deletions surface/sca/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
from core_utils.admin_filters import DefaultFilterMixin
from core_utils.utils import admin_reverse
from dkron.utils import run_async
from inventory.models import GitSource
from sca import models
from sca.utils import only_highest_version_dependencies
from theme.filters import RelatedFieldAjaxListFilter
from inventory.models import GitSource

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -190,9 +190,9 @@ class Meta:

def filter_fixed_in(self, queryset, name, value):
if value == "true":
return queryset.exclude(Q(fixed_in="") | Q(fixed_in__isnull=True))
return queryset.exclude(fixed_in="")
elif value == "false":
return queryset.filter(Q(fixed_in="") | Q(fixed_in__isnull=True))
return queryset.filter(fixed_in="")
return queryset


Expand Down
18 changes: 18 additions & 0 deletions surface/sca/migrations/0002_alter_scafinding_fixed_in.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.23 on 2024-09-16 10:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('sca', '0001_initial'),
]

operations = [
migrations.AlterField(
model_name='scafinding',
name='fixed_in',
field=models.TextField(default=''),
),
]
5 changes: 2 additions & 3 deletions surface/sca/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from enum import Enum
from typing import Union

from bulk_update_or_create import BulkUpdateOrCreateQuerySet
from django.db import models
from django.db.models import Case, Count, Q, When

Expand Down Expand Up @@ -164,7 +163,7 @@ def get_dependencies(root_dependency: "SCADependency") -> list:
def update_vulnerability_counters(self) -> "SCAFindingCounter":
severity_counters = (
SCAFinding.objects.filter(
(Q(fixed_in__isnull=False) | Q(finding_type=SCAFinding.FindingType.EOL)),
(Q(fixed_in__gt="") | Q(finding_type=SCAFinding.FindingType.EOL)),
dependency__purl__in=self.dependencies,
state__in=(SCAFinding.State.NEW, SCAFinding.State.OPEN),
)
Expand Down Expand Up @@ -247,7 +246,7 @@ class FindingType(models.IntegerChoices):
vuln_id = models.CharField(max_length=128)
published = models.DateTimeField()
aliases = models.TextField(default="")
fixed_in = models.TextField(default=None, null=True)
fixed_in = models.TextField(default="")
cvss_vector = models.CharField(max_length=128, default="")
ecosystem = models.CharField(max_length=20)
finding_type = models.IntegerField(choices=FindingType.choices, default=FindingType.VULN)
Expand Down
2 changes: 1 addition & 1 deletion surface/sca/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_admin_changelist(self):

# Assert Vulnerabilities Counters
assert "1 Critical" in content
assert "4 High" in content
assert "3 High" in content
assert "3 Medium" in content
assert "0 Low" in content
assert "0 End of Life" in content
Expand Down
2 changes: 1 addition & 1 deletion surface/sca/tests/test_resync_sbom_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_resync_sbom_repo(self, now):
assert SCAFindingCounter.objects.filter(dependency=main_dependency).exists()
counter = SCAFindingCounter.objects.filter(dependency=main_dependency).first()
assert counter.critical == 1
assert counter.high == 4
assert counter.high == 3
assert counter.medium == 3

# Asserts main dependency has only one git source "https://github.com/test/repo"
Expand Down