Skip to content

Add the vulnerability report#6774

Merged
git-hyagi merged 1 commit intopulp:mainfrom
git-hyagi:vuln-report
Aug 12, 2025
Merged

Add the vulnerability report#6774
git-hyagi merged 1 commit intopulp:mainfrom
git-hyagi:vuln-report

Conversation

@git-hyagi
Copy link
Copy Markdown
Contributor

closes: #6773

@git-hyagi git-hyagi force-pushed the vuln-report branch 2 times, most recently from 7d21d69 to 20bad99 Compare July 11, 2025 18:21
@git-hyagi git-hyagi marked this pull request as draft July 14, 2025 12:24
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/models/vulnerability_report.py
@bmbouter
Copy link
Copy Markdown
Member

I think you should write a new section in the dev docs, e.g. here for a plugin writer showing example code of say the python vuln reporting as an example.

@git-hyagi git-hyagi force-pushed the vuln-report branch 5 times, most recently from 7434120 to a2b4b22 Compare July 14, 2025 20:08
@git-hyagi git-hyagi marked this pull request as ready for review July 15, 2025 11:27
Comment thread docs/dev/learn/other/vulnerability-report.md Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/tests/unit/test_vulnerability_report.py Outdated
Comment thread docs/dev/learn/other/vulnerability-report.md
@jobselko
Copy link
Copy Markdown
Member

@git-hyagi @bmbouter I would like to work on implementing this functionality in pulp python once this PR is done.

@git-hyagi git-hyagi force-pushed the vuln-report branch 4 times, most recently from 195dfce to 5fa343b Compare July 17, 2025 16:40
Comment thread pulpcore/constants.py Outdated
@git-hyagi git-hyagi marked this pull request as draft July 17, 2025 17:31
@git-hyagi git-hyagi marked this pull request as ready for review July 17, 2025 19:18
Copy link
Copy Markdown
Member

@jobselko jobselko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate it if someone could take a look at the queue and threading parts. The rest (aside from the things I already mentioned) looks good to me.

Comment thread docs/dev/learn/other/vulnerability-report.md Outdated
Comment thread docs/dev/learn/other/vulnerability-report.md Outdated
Comment thread docs/dev/learn/other/vulnerability-report.md Outdated
Comment thread docs/dev/learn/other/vulnerability-report.md Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/viewsets/vulnerability_report.py Outdated
@git-hyagi git-hyagi force-pushed the vuln-report branch 5 times, most recently from d2391f8 to 7710156 Compare July 22, 2025 12:51
Copy link
Copy Markdown
Contributor

@gerrod3 gerrod3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing how this is used in pulp-services, but it feels like this is currently missing the features needed to be useful for a user. e.g. How do I see what python/npm/rpm content is vulnerable? How do I see what vulnerabilities are in my repo-version?

Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment on lines +154 to +132
if created:
await CreatedResource.objects.acreate(content_object=vuln_report)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going to create a lot of CreatedResources, but I guess this is the only way to see what Vulnerabilites are in a repo-version?

Comment thread pulpcore/app/viewsets/vulnerability_report.py Outdated
Comment thread pulpcore/app/tasks/vulnerability_report.py Outdated
Comment thread pulpcore/app/serializers/vulnerability_report.py
@git-hyagi git-hyagi dismissed stale reviews from dkliban and jobselko via a3a7fce August 4, 2025 19:13
@git-hyagi git-hyagi force-pushed the vuln-report branch 4 times, most recently from de9a627 to 9bdca7e Compare August 4, 2025 19:29
Comment thread docs/dev/learn/other/vulnerability-report.md
Comment thread docs/dev/learn/other/vulnerability-report.md
Comment thread docs/dev/learn/other/vulnerability-report.md Outdated
Comment thread pulpcore/app/models/vulnerability_report.py Outdated
Comment thread pulpcore/app/settings.py
Comment thread docs/admin/reference/settings.md Outdated
Comment thread docs/dev/learn/other/vulnerability-report.md Outdated
jobselko
jobselko previously approved these changes Aug 5, 2025
dkliban
dkliban previously approved these changes Aug 6, 2025
@git-hyagi git-hyagi dismissed stale reviews from dkliban and jobselko via 6ffb783 August 7, 2025 01:18
Copy link
Copy Markdown
Contributor

@gerrod3 gerrod3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final nits. No more refactors after this, I promise 😅

from pulpcore.plugin import viewsets as core_viewsets
from pulpcore.plugin.tasking import check_content, dispatch

class MyPluginRepositoryVersionViewSet(core_viewsets.RepositoryVersionViewSet):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either we continue using pulp_python as an example or we change the get_content_from_repo_version to be more generic.

Comment on lines +137 to +139
async for content in func(*args):
tasks.append(asyncio.create_task(vuln_report_scanner.scan_packages(content)))
await asyncio.gather(*tasks)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do one last change to make this cleaner. Rename scan_packages to scan_package. Then create a new scan_packages method inside VulnerabilityReportScanner and move this async for logic + the progress report updating inside of the new method. i.e

class VulnerabilityReportScanner:
    def __init__(self, semaphore, generator, session=None):
        self.semaphore = semaphore
        self.generator = generator
        ...
    async def scan_packages(self):
         tasks = []
         async for content in self.generator:
              tasks.append(asyncio.create_task(self.scan_package(content))
         await asyncio.gather(*tasks)
         await self.session.close()  # This should remove that warning message we saw in the logs
         if self.created.done > 0:
             ...
             
# now in check_content
def check_content(func, args):
    ...
    semaphore = asyncio.Semaphore(settings.VULN_REPORT_TASK_LIMITER)
    vuln_report_scanner = VulnerabilityReportScanner(semaphore, func(*args))
    await vuln_report_scanner.scan_packages()

Comment thread pulpcore/constants.py Outdated
OSV_QUERY_URL = "https://api.osv.dev/v1/query"

# Timeout when waiting on tasks scan thread queue to avoid indefinite blocking.
VULNERABILITY_TASK_THREAD_TIMEOUT = 60
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't think we are using this anywhere.

Suggested change
VULNERABILITY_TASK_THREAD_TIMEOUT = 60

Copy link
Copy Markdown
Contributor

@gerrod3 gerrod3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. 🎉 Thanks for all the hard work on this!

Copy link
Copy Markdown
Member

@jobselko jobselko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉

@git-hyagi git-hyagi merged commit dd6ba20 into pulp:main Aug 12, 2025
13 checks passed
@git-hyagi git-hyagi deleted the vuln-report branch August 12, 2025 12:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add the vulnerability report to pulpcore

5 participants