Skip to content

Conversation

@philipgough
Copy link

No description provided.

Copy link

@moadz moadz left a comment

Choose a reason for hiding this comment

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

LGTM :) Thanks for this. Excited to ttest.

for _, pattern := range config.PathPatterns {
matcher, err := regexp.Compile(pattern)
if err != nil {
return nil, fmt.Errorf("failed to compile mTLS path pattern %q: %v", pattern, err)
Copy link

Choose a reason for hiding this comment

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

nit: %w for error wrapping, should give detailed regex error to user when it fails to compile (i think) i'm rusty on regex stdlib

Comment on lines +110 to +123
pathMatches := false
for _, matcher := range a.config.pathMatchers {
if matcher.MatchString(r.URL.Path) {
pathMatches = true
break
}
}

// If path doesn't match, skip mTLS enforcement
if !pathMatches {
next.ServeHTTP(w, r)
return
}
}
Copy link

Choose a reason for hiding this comment

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

nit/readability: extract into helper (only used once so feel free to ignore 🤷🏽 )

pathMatches(path string)


// Path matches or no paths configured, enforce mTLS
if r.TLS == nil {
httperr.PrometheusAPIError(w, "mTLS required but no TLS connection", http.StatusBadRequest)
Copy link

Choose a reason for hiding this comment

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

Is this not used outside of prom? Why do we use PrometehusAPIError

Copy link
Author

Choose a reason for hiding this comment

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

just following the pattern for the rest of the project :)

}
}

// Path matches or no paths configured, enforce mTLS
Copy link

Choose a reason for hiding this comment

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

nit: comment could be clearer.

{
name: "overlapping_patterns",
yamlConfig: `
tenants:
Copy link

Choose a reason for hiding this comment

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

Do we need a test case for mTLS with no paths defined? Or is this tested elsewhere?

Copy link
Author

Choose a reason for hiding this comment

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

e2e tests already exist i think. i just wanted to isolate this clearly for now

CAs []*x509.Certificate
RawCA []byte `json:"ca"`
CAPath string `json:"caPath"`
PathPatterns []string `json:"pathPatterns"`
Copy link

Choose a reason for hiding this comment

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

for later, we should document that this is case sensitive.

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