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

Dependency ingester #5058

Merged
merged 4 commits into from
Nov 27, 2024
Merged

Dependency ingester #5058

merged 4 commits into from
Nov 27, 2024

Conversation

puerco
Copy link
Contributor

@puerco puerco commented Nov 27, 2024

Summary

This PR finishes Evan's ingester started in #5030. It enables the dependency ingester using ov-scalibr. This allows us to write rules on the ingested protobom structs.

Here's the example ruletype I have been using to test:

version: v1
release_phase: alpha
type: rule-type
name: avoid_malicious_dependency
display_name: Check a project's dependencies against a denylist
short_failure_message: Malicious dependencies in use
severity:
  value: high
context:
  provider: github
description: Alert if a repository uses a malicious dependency from a blocklist.
guidance: |
  Using the configured list of prohibited dependencies, Minder will check the 
  dependencies at use in a repository. If any package name is included in the
  disallowed list, the profile will fail.
def:
  in_entity: repository
  rule_schema:
    type: object
    properties:
      prohibited:
        type: array
        items:
          type: string
        description: |
          Names of packages not allowed in the repository
      branch:
        type: string
        description: "The name of the branch to check out. Defaults to 'main'"
    required:
      - prohibited
  # Defines the configuration for ingesting data relevant for the rule
  ingest:
    type: deps
  eval:
    type: rego
    rego:
      type: deny-by-default
      def: |
        package minder

        import rego.v1

        # Default deny rule
        default allow := false

        # Create a set of prohibited items from the profile definition
        prohibited := {pkg | pkg := input.profile.prohibited[_]}

        # Extract dependencies from the input
        deps := {node.name | node := input.ingested.node_list.nodes[_]}

        # Allow rule
        allow if {
            deps == deps - prohibited
        }

Supersedes #5030

Change Type

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

Here's a simple profile to test:

---
version: v1
type: profile
name: deps-ingest
display_name: Test dependency ingestion
context:
  provider: github
alert: "off"
remediate: "off"
repository:
   - type: avoid_malicious_dependency
     def:
      prohibited:
        - "invokehttp"

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@puerco puerco requested a review from a team as a code owner November 27, 2024 05:54
@coveralls
Copy link

coveralls commented Nov 27, 2024

Coverage Status

coverage: 54.608% (-0.05%) from 54.662%
when pulling 97cd9af on deps-ingest-post-evan
into 2b44edb on main.

@puerco puerco force-pushed the deps-ingest-post-evan branch from 695cb43 to fe2190d Compare November 27, 2024 06:20
evankanderson and others added 4 commits November 27, 2024 00:20
This commit connects the components defined in the previous commits
and fixes a panic when reading the configuration.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
@puerco puerco force-pushed the deps-ingest-post-evan branch from fe2190d to 97cd9af Compare November 27, 2024 06:21
return nil, fmt.Errorf("deps is only supported for repositories")
}
}
func (gi *Deps) ingestRepository(ctx context.Context, repo *pb.Repository, params map[string]any) (*interfaces.Result, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I wonder if we could call the git ingester directly from here and THEN process the result of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sgmt, I'll refactor it in follow up.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah, doesn't need to be in this PR


desiredCaps := scalibr_plugin.Capabilities{
OS: scalibr_plugin.OSLinux,
Network: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

what do we need the network option for? We might wanna add a small comment for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to select the plugins that require network access. I'll add a note.

@puerco puerco merged commit f6afcd4 into main Nov 27, 2024
26 checks passed
@puerco puerco deleted the deps-ingest-post-evan branch November 27, 2024 23:41
@puerco puerco mentioned this pull request Nov 27, 2024
10 tasks
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.

4 participants