Skip to content
This repository has been archived by the owner on Apr 22, 2024. It is now read-only.

Implement logic for TriggerRules config #3

Merged
merged 3 commits into from
Feb 12, 2024
Merged

Implement logic for TriggerRules config #3

merged 3 commits into from
Feb 12, 2024

Conversation

sergicastro
Copy link
Contributor

No description provided.

@sergicastro sergicastro requested a review from nacx February 12, 2024 11:48
Copy link

codecov bot commented Feb 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d9be6fe) 84.61% compared to head (30ad462) 85.48%.
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main       #3      +/-   ##
==========================================
+ Coverage   84.61%   85.48%   +0.86%     
==========================================
  Files           5        9       +4     
  Lines         247      427     +180     
==========================================
+ Hits          209      365     +156     
- Misses         34       58      +24     
  Partials        4        4              
Files Coverage Δ
internal/server/authz.go 82.83% <100.00%> (+0.74%) ⬆️

... and 5 files with indirect coverage changes

nacx
nacx previously approved these changes Feb 12, 2024
Copy link
Member

@nacx nacx left a comment

Choose a reason for hiding this comment

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

Just some small nits

// If there are no trigger rules, allow the request with no check executions.
// TriggerRules are used to determine which request should be checked by the filter and which don't.
if !mustTriggerCheck(e.cfg.TriggerRules, req) {
e.log.Debug(fmt.Sprintf("no matching trigger rule, so allowing request to proceed without any authservice functionality %s://%s%s",
Copy link
Member

Choose a reason for hiding this comment

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

Let's get the log.Context(ctx) to make sure we include any context logs here (such as the x-requesd-id or others that we could populate)

return strings.HasSuffix(path, m.Suffix)
case *configv1.StringMatch_Regex:
b, _ := regexp.MatchString(m.Regex, path)
// TODO: handle error
Copy link
Member

Choose a reason for hiding this comment

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

Let's just log the error and return false?

{"suffix-match", stringSuffix("test"), "123-test", true},
{"suffix-no-match", stringSuffix("test"), "no-match", false},
{"regex-match", stringRegex(".*st"), "test", true},
{"regex-no-match", stringRegex(".*st"), "no-match", false},
Copy link
Member

Choose a reason for hiding this comment

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

Add a test for the regexp error as well.

@@ -72,6 +73,17 @@ func (e *ExtAuthZFilter) Register(server *grpc.Server) {

// Check is the implementation of the Envoy AuthorizationServer interface.
func (e *ExtAuthZFilter) Check(ctx context.Context, req *envoy.CheckRequest) (response *envoy.CheckResponse, err error) {
// If there are no trigger rules, allow the request with no check executions.
// TriggerRules are used to determine which request should be checked by the filter and which don't.
trLog := e.log.Context(ctx)
Copy link
Member

Choose a reason for hiding this comment

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

In line 90 we're already getting the log from the context. let's just create the log variable here and reuse it later?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

totally, didn't notice that.

@sergicastro sergicastro enabled auto-merge (squash) February 12, 2024 15:39
@sergicastro sergicastro merged commit a7ac38b into main Feb 12, 2024
8 checks passed
@sergicastro sergicastro deleted the trigger-rules branch February 12, 2024 15:41
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants