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

Instantiate data sources from the policy engine #5060

Merged
merged 1 commit into from
Nov 27, 2024

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Nov 27, 2024

Summary

This hooks data source registration into Minder's policy engine. This is
done by populating individual data source registries into each rule type
engine, which pertains to a single rule type. This way, each rule type
would only have access to the data sources it instantiates.

This also caught a segfault we were unaware of. For some reason, the
builder of the ruletype engine cache was not populating all the needed
members of the struct which would segfault in case the cache did not
have a hit. This fixes that.

Closes: #5043

Change Type

Mark the type of change your PR introduces:

  • 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

Outline how the changes were tested, including steps to reproduce and any relevant configurations.
Attach screenshots if helpful.

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.

@JAORMX JAORMX requested a review from a team as a code owner November 27, 2024 08:35
@coveralls
Copy link

coveralls commented Nov 27, 2024

Coverage Status

coverage: 54.721% (+0.06%) from 54.662%
when pulling 58e6ee4 on JAORMX:datasources-engine
into 2b44edb on mindersec:main.

This hooks data source registration into Minder's policy engine. This is
done by populating individual data source registries into each rule type
engine, which pertains to a single rule type. This way, each rule type
would only have access to the data sources it instantiates.

This also caught a segfault we were unaware of. For some reason, the
builder of the ruletype engine cache was not populating all the needed
members of the struct which would segfault in case the cache did not
have a hit. This fixes that.

Signed-off-by: Juan Antonio Osorio <[email protected]>
//
// TODO: Do we need to pass in a transaction here?
// TODO: We _might_ want to pass in a slice of the hierarchy here.
dsreg, err := dssvc.BuildDataSourceRegistry(ctx, pbRuleType, nil)
Copy link
Member

Choose a reason for hiding this comment

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

It's not possible for this to conflict right? I.e. one ruletype having access to the data sources for another one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right. This is why I make the instantiation of the registry here and per rule type. The registry is not shared.

Copy link
Member

Choose a reason for hiding this comment

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

Perfect! 💯 😃

@JAORMX JAORMX merged commit c4f98a9 into mindersec:main Nov 27, 2024
25 checks passed
@JAORMX JAORMX deleted the datasources-engine branch November 27, 2024 09:58
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.

Allow Minder Policy Engine to inject Data Source functions into the Eval engine
3 participants