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

builtin: Return evalerrors.ErrEvaluationSkipSilently in case the builtin evaluator doesn't match the entity #800

Merged
merged 1 commit into from
Sep 4, 2023

Conversation

jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Aug 30, 2023

Returning nil, nil is wrong as it would be treated the same as
"evaluation was performed an no issues were found"

evankanderson
evankanderson previously approved these changes Aug 30, 2023
internal/engine/ingester/builtin/builtin.go Outdated Show resolved Hide resolved
evankanderson
evankanderson previously approved these changes Aug 30, 2023
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

Feel free to say "it's good enough now, Evan" -- I know that you didn't create this tangle. 😁

Comment on lines +31 to +47
// GetMethod gets the method by name from the RuleMethods struct
func (r *RuleMethods) GetMethod(mName string) (reflect.Value, error) {
value := reflect.ValueOf(r)
method := value.MethodByName(mName)

// Check if the method exists
if !method.IsValid() {
return reflect.Value{}, fmt.Errorf("rule method not found")
}

return method, nil
}
Copy link
Member

Choose a reason for hiding this comment

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

Does this work, or do we just have no methods defined right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently there's no methods. We used to have the artifact verification method as a single builtin but the method and the builtin ingestor as a whole proved to be too limiting for what we needed to do so I ended up just adding a specialised artifact ingestor.

As I was trying to use the builtin ingestor for artifacts, I noticed this bug that we treat skipped entries as passing policy. That felt like a big enough bug to fix even if the ingestor is unused at the moment.

But at the same time, I think the builtin ingest still has value, so I didn't want to just nuke it completely. Actually, as I was writing this comment I realised that it would be better and make for easier testing if we have at least one method, so I added a "Passthrough" (that we already talked about before).

This also makes for better tests which are needed /especially/ because we don't use the builtin ingestor at the moment.

)

// RuleMethodGetter is the interface that is used to get the method by name
type RuleMethodGetter interface {
Copy link
Member

Choose a reason for hiding this comment

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

What do you think of calling this Methods since it's already in the rule_methods module (vs rule_methods.RuleMethodGetter, which has a high character : meaning ratio).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return reflect.Value{}, fmt.Errorf("rule method not found")
}

return method, 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 would be super-nifty if this returned a typed result that could be invoked without the jiggery-pokery on lines 76-87 of builtin.go (i.e. by moving them here, but other RuleMethodGetter implementations could use actual types).

Copy link
Member

Choose a reason for hiding this comment

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

I think that type would be:

func(context.Context, string, any) (any, error) or maybe func(context.Context, string, any) (json.RawMessage, error)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm probably a bad Go programmer but I couldn't make the conversion from the reflected Value to the function type work.

…tin evaluator doesn't match the entity

Returning `nil, nil` is wrong as it would be treated the same as
"evaluation was performed an no issues were found"
@lukehinds
Copy link
Contributor

@JAORMX I think your change is covered now, if you're ok to re-review.

@JAORMX JAORMX merged commit a0fca69 into mindersec:main Sep 4, 2023
13 checks passed
@JAORMX JAORMX deleted the builtin_skip_silent branch September 4, 2023 07:59
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