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

Scorecard Integration #1294

Open
wants to merge 60 commits into
base: main
Choose a base branch
from

Conversation

404-geek
Copy link
Collaborator

@404-geek 404-geek commented Jun 26, 2024

ScoreCode Integration

This pull request integrates the ScoreCode Repo into SCIO, enabling the fetching of the latest OSSF Scorecard Data for discovered packages using their vcs_url. The current implementation supports github.com and gitlab.com VCS URLs.

Key Features:

  • Integration with ScoreCode Repo
  • Fetching of OSSF Scorecard Data using vcs_url
  • Support for github.com and gitlab.com VCS URLs

Related Issues:

This feature enhances SCIO's functionality by ensuring that users can retrieve the most up-to-date security scores for packages discovered in their projects, improving overall security assessment and management.

404-geek added 30 commits June 26, 2024 13:20
developed functions to check for availability nexB#598

Signed-off-by: 404-geek <[email protected]>
Signed-off-by: 404-geek <[email protected]>
Signed-off-by: 404-geek <[email protected]>
…gration

# Conflicts:
#	scanpipe/models.py
#	scanpipe/tests/test_models.py
scanpipe/migrations/0068_merge_20240820_1656.py Outdated Show resolved Hide resolved
scanpipe/models.py Outdated Show resolved Hide resolved
)

@classmethod
@transaction.atomic()
Copy link
Contributor

Choose a reason for hiding this comment

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

@404-geek Could you provide an example that shows why atomic() is useful here?

scanpipe/models.py Outdated Show resolved Hide resolved
scanpipe/models.py Outdated Show resolved Hide resolved
scanpipe/pipelines/get_scorecard_info_packages.py Outdated Show resolved Hide resolved
if not scorecard.is_available():
raise Exception("scorecode service is not available.")

def lookup_save_packages_scorecode_info(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

fetch_packages_scorecode_info would be better.

scanpipe/pipelines/get_scorecard_info_packages.py Outdated Show resolved Hide resolved
setup.cfg Outdated Show resolved Hide resolved
setup.cfg Outdated Show resolved Hide resolved
@pombredanne
Copy link
Member

@404-geek can you check the failing tests?

@tdruez
Copy link
Contributor

tdruez commented Oct 29, 2024

Hey @404-geek , what's your latest status on this PR? Any chances we can complete and merge it before it diverges too much from the main branch?

@404-geek
Copy link
Collaborator Author

Hey @404-geek , what's your latest status on this PR? Any chances we can complete and merge it before it diverges too much from the main branch?

Hi @tdruez,

I’m planning to have this PR ready by next week. Most of the requested changes have been addressed; I just need to add a few test cases before pushing the final version.

Copy link
Contributor

@tdruez tdruez left a comment

Choose a reason for hiding this comment

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

@404-geek See my various comments ;)

Also, the new pipeline needs to be added to the built-in-pipelines.rst documentation.

Comment on lines +15 to +19
migrations.AlterField(
model_name='project',
name='purl',
field=models.CharField(blank=True, help_text="Package URL (PURL) for the project, required for pushing the project's scan result to FederatedCode. For example, if the input is an input URL like https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz, the corresponding PURL would be pkg:npm/[email protected].", max_length=2048),
),
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this field impacted by this PR?

Comment on lines +3971 to +3973
def __str__(self):
return self.score or str(self.uuid)

Copy link
Contributor

Choose a reason for hiding this comment

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

Follow the conventions used across the existing Models:

  1. Fields
  2. class Meta
  3. str

)

@classmethod
@transaction.atomic()
Copy link
Contributor

Choose a reason for hiding this comment

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

@404-geek You haven't address the question above yet ;)



class ScorecardCheck(UUIDPKModel, ScorecardChecksMixin):
def __str__(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Follow the conventions used across the existing Models:

  1. Fields
  2. class Meta
  3. str

Comment on lines +3980 to +3981
blank=True,
null=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can a DiscoveredPackageScore instance really exists without a DiscoveredPackage FK defined?

def check_scorecode_service_availability(self):
"""Check if the scorecode service is configured and available."""
if not ossf_scorecard.is_available():
raise Exception("scorecode service is not available.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Use ScoreCode case for consistency.

@@ -284,3 +286,10 @@ def make_dependency(project, **extra):
"license_key": "mpl-2.0",
},
}

scorecard_data = None
Copy link
Contributor

Choose a reason for hiding this comment

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

That line seems unnecessary.

Comment on lines +292 to +295
data = Path(__file__).parent / "data"

with open(f"{data}/scorecode/scorecard_response.json") as file:
scorecard_data = json.load(file)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be loaded in the module init but as needed in the test function context.

@@ -2477,6 +2481,29 @@ def test_scanpipe_codebase_resource_queryset_elfs(self):
self.assertTrue("e" in paths)
self.assertTrue("a" in paths)

def test_scorecard_models(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

The name of this function does not follow existing conventions.


run = project1.add_pipeline(pipeline_name)
pipeline = run.make_pipeline_instance()
# mock_is_configured.return_value = True
Copy link
Contributor

Choose a reason for hiding this comment

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

Unwanted comment.

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.

Store OSSF scorecard data in scancode.io models Enrich an SBOM using OSSF Security Score Card
4 participants