Skip to content

Commit 843939a

Browse files
committed
main.go: fix help text for --unsafe-passthrough-paths
Also clarifies the implication of using --enable-label-apis in the help text and README. Signed-off-by: Simon Pasquier <[email protected]>
1 parent cf8b1c9 commit 843939a

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ go get github.com/prometheus-community/prom-label-proxy
4141
This application proxies the following endpoints and it ensures that a particular label is enforced in the particular request and response:
4242

4343
* `/federate` for GET method (Prometheus)
44-
* `/api/v1/query_exemplars` for GET and POST methods (Prometheus)
44+
* `/api/v1/query_exemplars` for GET and POST methods (Prometheus/Thanos)
4545
* `/api/v1/query` for GET and POST methods (Prometheus/Thanos)
4646
* `/api/v1/query_range` for GET and POST methods (Prometheus/Thanos)
4747
* `/api/v1/series` for GET method (Prometheus/Thanos)
@@ -103,8 +103,7 @@ This is enforced for any case, whether a label matcher is specified in the origi
103103

104104
Similar to query endpoint, for metadata endpoints `/api/v1/series`, `/api/v1/labels`, `/api/v1/label/<name>/values` the proxy injects the specified label all the provided `match[]` selectors.
105105

106-
NOTE: At the moment of creation `/api/v1/labels`, `/api/v1/label/<name>/values` does not support `match[]` so they are disabled by default. Use `-enable-label-apis` flag to enable
107-
those (see https://github.com/prometheus/prometheus/issues/6178 for tracking development).
106+
NOTE: When the `/api/v1/labels` and `/api/v1/label/<name>/values` endpoints were added to `prom-label-proxy`, the Prometheus and Thanos endpoints didn't support the `match[]` parameter hence the `prom-label-proxy` labels endpoints are disabled by default. Use the `-enable-label-apis` flag to enable after you've ensured that the upstream endpoints support label selectors (see https://github.com/prometheus/prometheus/issues/6178 and https://github.com/thanos-io/thanos/issues/3351).
108107

109108
### Rules endpoint
110109

injectproxy/routes.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ type routes struct {
4444
}
4545

4646
type options struct {
47-
enableLabelAPIs bool
48-
pasthroughPaths []string
49-
errorOnReplace bool
47+
enableLabelAPIs bool
48+
passthroughPaths []string
49+
errorOnReplace bool
5050
}
5151

5252
type Option interface {
@@ -71,7 +71,7 @@ func WithEnabledLabelsAPI() Option {
7171
// NOTE: Passthrough "all" paths like "/" or "" and regex are not allowed.
7272
func WithPassthroughPaths(paths []string) Option {
7373
return optionFunc(func(o *options) {
74-
o.pasthroughPaths = paths
74+
o.passthroughPaths = paths
7575
})
7676
}
7777

@@ -166,21 +166,21 @@ func NewRoutes(upstream *url.URL, label string, opts ...Option) (*routes, error)
166166
}
167167

168168
// Validate paths.
169-
for _, path := range opt.pasthroughPaths {
169+
for _, path := range opt.passthroughPaths {
170170
u, err := url.Parse(fmt.Sprintf("http://example.com%v", path))
171171
if err != nil {
172-
return nil, fmt.Errorf("path %v is not a valid URI path, got %v", path, opt.pasthroughPaths)
172+
return nil, fmt.Errorf("path %q is not a valid URI path, got %v", path, opt.passthroughPaths)
173173
}
174174
if u.Path != path {
175-
return nil, fmt.Errorf("path %v is not a valid URI path, got %v", path, opt.pasthroughPaths)
175+
return nil, fmt.Errorf("path %q is not a valid URI path, got %v", path, opt.passthroughPaths)
176176
}
177177
if u.Path == "" || u.Path == "/" {
178-
return nil, fmt.Errorf("path %v is not allowed, got %v", u.Path, opt.pasthroughPaths)
178+
return nil, fmt.Errorf("path %q is not allowed, got %v", u.Path, opt.passthroughPaths)
179179
}
180180
}
181181

182182
// Register optional passthrough paths.
183-
for _, path := range opt.pasthroughPaths {
183+
for _, path := range opt.passthroughPaths {
184184
if err := mux.Handle(path, http.HandlerFunc(r.passthrough)); err != nil {
185185
return nil, err
186186
}

main.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ func main() {
4343
flagset.StringVar(&label, "label", "", "The label to enforce in all proxied PromQL queries. "+
4444
"This label will be also required as the URL parameter to get the value to be injected. For example: -label=tenant will"+
4545
" make it required for this proxy to have URL in form of: <URL>?tenant=abc&other_params...")
46-
flagset.BoolVar(&enableLabelAPIs, "enable-label-apis", false, "When specified proxy allows to inject label to label APIs like /api/v1/labels and /api/v1/label/<name>/values."+
47-
"NOTE: Enable with care. Selection of matcher is still in development, see https://github.com/thanos-io/thanos/issues/3351 and https://github.com/prometheus/prometheus/issues/6178. If enabled and"+
48-
"any labels endpoint does not support selectors, injected matcher will be silently dropped.")
49-
flagset.StringVar(&unsafePassthroughPaths, "unsafe-passthrough-paths", "", "Comma delimited allow list of exact HTTP path segments should be allowed to hit upstream URL without any enforcement."+
50-
"This option is checked after Prometheus APIs, you can cannot override enforced API to be not enforced with this option. Use carefully as it can easily cause a data leak if the provided path is an important"+
51-
"API like targets or configuration. NOTE: \"all\" matching paths like \"/\" or \"\" and regex are not allowed.")
46+
flagset.BoolVar(&enableLabelAPIs, "enable-label-apis", false, "When specified proxy allows to inject label to label APIs like /api/v1/labels and /api/v1/label/<name>/values. "+
47+
"NOTE: Enable with care because filtering by matcher is not implemented in older versions of Prometheus/Thanos (see https://github.com/thanos-io/thanos/issues/3351 and https://github.com/prometheus/prometheus/issues/6178). If enabled and "+
48+
"any labels endpoint does not support selectors, the injected matcher will have no effect.")
49+
flagset.StringVar(&unsafePassthroughPaths, "unsafe-passthrough-paths", "", "Comma delimited allow list of exact HTTP path segments that should be allowed to hit upstream URL without any enforcement. "+
50+
"This option is checked after Prometheus APIs, you cannot override enforced API endpoints to be not enforced with this option. Use carefully as it can easily cause a data leak if the provided path is an important "+
51+
"API (like /api/v1/configuration) which isn't enforced by prom-label-proxy. NOTE: \"all\" matching paths like \"/\" or \"\" and regex are not allowed.")
5252
flagset.BoolVar(&errorOnReplace, "error-on-replace", false, "When specified, the proxy will return HTTP status code 400 if the query already contains a label matcher that differs from the one the proxy would inject.")
5353

5454
//nolint: errcheck // Parse() will exit on error.

0 commit comments

Comments
 (0)