-
Notifications
You must be signed in to change notification settings - Fork 3
Support path based matching for authenticators #41
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
base: rhobs-obs-api-konflux
Are you sure you want to change the base?
Conversation
moadz
left a comment
There was a problem hiding this 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) |
There was a problem hiding this comment.
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
| 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 | ||
| } | ||
| } |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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"` |
There was a problem hiding this comment.
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.
No description provided.