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

ingestor: Return fallback body on certain HTTP status types #1172

Merged
merged 1 commit into from
Oct 11, 2023

Conversation

jhrozek
Copy link
Contributor

@jhrozek jhrozek commented Oct 11, 2023

At the moment, all HTTP errors from the ingestor are treated as errors
and returned to the caller. This also means that neither the evaluator
nor the remediate calls are called.

Some endpoints, like branch protection, do not exist if branch
protection is not enabled, which prevents us from going forward in the
engine and actually remediating the issue. This is visible with the
rule_type test command as:

$ go run cmd/dev/main.go rule --profile /Users/jakub/devel/playground/remediate.yaml --rule-type examples/github/rule-types/branch_protection.yaml --entity /Users/jakub/devel/playground/repository.yaml
Profile valid according to the JSON schema!
Error: error evaluating rule type: error ingesting data: cannot do request: cannot make request: GET https://api.github.com/repos/jakubtestorg/testrepo/branches/main/protection: 404 Branch not protected []
Error on execute: error evaluating rule type: error ingesting data:
cannot do request: cannot make request: GET https://api.github.com/repos/jakubtestorg/testrepo/branches/main/protection: 404 Branch not protected []
exit status 1

This patch defines a configurable per-rule fallback where for rules that
need this functionality, a dummy body is returned, which just falls
throught the evaluator and then eventually makes the remediate step
work.

I chose this programmable fallback approach over just falling back to an
empty body to prevent us from hiding issues where we might expand a
template wrong or just have a typo in the endpoint - this way we will
only proceed on error codes if the rule type explicitly says so.

At the moment, all HTTP errors from the ingestor are treated as errors
and returned to the caller. This also means that neither the evaluator
nor the remediate calls are called.

Some endpoints, like branch protection, do not exist if branch
protection is not enabled, which prevents us from going forward in the
engine and actually remediating the issue. This is visible with the
rule_type test command as:

```
$ go run cmd/dev/main.go rule --profile /Users/jakub/devel/playground/remediate.yaml --rule-type examples/github/rule-types/branch_protection.yaml --entity /Users/jakub/devel/playground/repository.yaml
Profile valid according to the JSON schema!
Error: error evaluating rule type: error ingesting data: cannot do request: cannot make request: GET https://api.github.com/repos/jakubtestorg/testrepo/branches/main/protection: 404 Branch not protected []
Error on execute: error evaluating rule type: error ingesting data:
cannot do request: cannot make request: GET https://api.github.com/repos/jakubtestorg/testrepo/branches/main/protection: 404 Branch not protected []
exit status 1
```

This patch defines a configurable per-rule fallback where for rules that
need this functionality, a dummy body is returned, which just falls
throught the evaluator and then eventually makes the remediate step
work.

I chose this programmable fallback approach over just falling back to an
empty body to prevent us from hiding issues where we might expand a
template wrong or just have a typo in the endpoint - this way we will
only proceed on error codes if the rule type explicitly says so.
Copy link
Contributor

@JAORMX JAORMX left a comment

Choose a reason for hiding this comment

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

Really dig this proposal, I'll review it ASAP

@JAORMX
Copy link
Contributor

JAORMX commented Oct 11, 2023

Makes sense to me!

@jhrozek jhrozek merged commit d9339a4 into mindersec:main Oct 11, 2023
13 checks passed
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.

2 participants