Skip to content

Commit 04552e6

Browse files
cmanziAleksey Sin
authored and
Aleksey Sin
committed
Fix web.external-prefix 404s and add web.prefix-header for bucket web UI. (thanos-io#1770)
* Add --web.prefix-header flag. Signed-off-by: Christopher Manzi <[email protected]> * Update changelog. Signed-off-by: Christopher Manzi <[email protected]> * Resolve conflicts with upstream. Signed-off-by: Christopher Manzi <[email protected]> * Lint docs. Signed-off-by: Christopher Manzi <[email protected]> * More docs linting. Signed-off-by: Christopher Manzi <[email protected]> * Remove extra flags. Signed-off-by: Christopher Manzi <[email protected]> * Update changelog. Signed-off-by: Christopher Manzi <[email protected]> * Lint docs. Signed-off-by: Christopher Manzi <[email protected]> * Final docs lint. Signed-off-by: Christopher Manzi <[email protected]> Signed-off-by: Aleksey Sin <[email protected]>
1 parent e557aca commit 04552e6

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ We use *breaking* word for marking changes that are not backward compatible (rel
2121
- [#1712](https://github.com/thanos-io/thanos/pull/1712) Rename flag on bucket web component from `--listen` to `--http-address` to match other components.
2222
- [#1733](https://github.com/thanos-io/thanos/pull/1733) New metric `thanos_compactor_iterations_total` on Thanos Compactor which shows the number of successful iterations.
2323
- [#1758](https://github.com/thanos-io/thanos/pull/1758) `thanos bucket web` now supports `--web.external-prefix` for proxying on a subpath.
24+
- [#1770](https://github.com/thanos-io/thanos/pull/1770) Add `--web.prefix-header` flags to allow for bucket UI to be accessible behind a reverse proxy.
2425

2526
### Fixed
2627

2728
- [#1656](https://github.com/thanos-io/thanos/pull/1656) Thanos Store now starts metric and status probe HTTP server earlier in its start-up sequence. `/-/healthy` endpoint now starts to respond with success earlier. `/metrics` endpoint starts serving metrics earlier as well. Make sure to point your readiness probes to the `/-/ready` endpoint rather than `/metrics`.
2829
- [#1669](https://github.com/thanos-io/thanos/pull/1669) Fixed store sharding. Now it does not load excluded meta.jsons and load/fetch index-cache.json files.
2930
- [#1670](https://github.com/thanos-io/thanos/pull/1670) Fixed un-ordered blocks upload. Sidecar now uploads the oldest blocks first.
3031
- [#1568](https://github.com/thanos-io/thanos/pull/1709) Thanos Store now retains the first raw value of a chunk during downsampling to avoid losing some counter resets that occur on an aggregation boundary.
32+
- [#1770](https://github.com/thanos-io/thanos/pull/1770) Fix `--web.external-prefix` 404s for static resources.
3133

3234
### Changed
3335

cmd/thanos/bucket.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,11 @@ func registerBucketInspect(m map[string]setupFunc, root *kingpin.CmdClause, name
311311
func registerBucketWeb(m map[string]setupFunc, root *kingpin.CmdClause, name string, objStoreConfig *extflag.PathOrContent) {
312312
cmd := root.Command("web", "Web interface for remote storage bucket")
313313
httpBindAddr, httpGracePeriod := regHTTPFlags(cmd)
314+
webExternalPrefix := cmd.Flag("web.external-prefix", "Static prefix for all HTML links and redirect URLs in the bucket web UI interface. Actual endpoints are still served on / or the web.route-prefix. This allows thanos bucket web UI to be served behind a reverse proxy that strips a URL sub-path.").Default("").String()
315+
webPrefixHeaderName := cmd.Flag("web.prefix-header", "Name of HTTP request header used for dynamic prefixing of UI links and redirects. This option is ignored if web.external-prefix argument is set. Security risk: enable this option only if a reverse proxy in front of thanos is resetting the header. The --web.prefix-header=X-Forwarded-Prefix option can be useful, for example, if Thanos UI is served via Traefik reverse proxy with PathPrefixStrip option enabled, which sends the stripped prefix value in X-Forwarded-Prefix header. This allows thanos UI to be served on a sub-path.").Default("").String()
314316
interval := cmd.Flag("refresh", "Refresh interval to download metadata from remote storage").Default("30m").Duration()
315317
timeout := cmd.Flag("timeout", "Timeout to download metadata from remote storage").Default("5m").Duration()
316318
label := cmd.Flag("label", "Prometheus label to use as timeline title").String()
317-
webExternalPrefix := cmd.Flag("web.external-prefix", "Static prefix for all HTML links and redirect URLs in the UI query web interface. Actual endpoints are still served on / or the web.route-prefix. This allows thanos UI to be served behind a reverse proxy that strips a URL sub-path.").Default("").String()
318319

319320
m[name+" web"] = func(g *run.Group, logger log.Logger, reg *prometheus.Registry, _ opentracing.Tracer, _ bool) error {
320321
ctx, cancel := context.WithCancel(context.Background())
@@ -328,11 +329,13 @@ func registerBucketWeb(m map[string]setupFunc, root *kingpin.CmdClause, name str
328329

329330
flagsMap := map[string]string{
330331
"web.external-prefix": *webExternalPrefix,
332+
"web.prefix-header": *webPrefixHeaderName,
331333
}
332334

333335
router := route.New()
336+
334337
bucketUI := ui.NewBucketUI(logger, *label, flagsMap)
335-
bucketUI.Register(router, extpromhttp.NewInstrumentationMiddleware(reg))
338+
bucketUI.Register(router.WithPrefix(*webExternalPrefix), extpromhttp.NewInstrumentationMiddleware(reg))
336339
srv.Handle("/", router)
337340

338341
if *interval < 5*time.Minute {

docs/components/bucket.md

+19-6
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,29 @@ Flags:
126126
Listen host:port for HTTP endpoints.
127127
--http-grace-period=2m Time to wait after an interrupt received for
128128
HTTP Server.
129+
--web.external-prefix="" Static prefix for all HTML links and redirect
130+
URLs in the bucket web UI interface. Actual
131+
endpoints are still served on / or the
132+
web.route-prefix. This allows thanos bucket web
133+
UI to be served behind a reverse proxy that
134+
strips a URL sub-path.
135+
--web.prefix-header="" Name of HTTP request header used for dynamic
136+
prefixing of UI links and redirects. This option
137+
is ignored if web.external-prefix argument is
138+
set. Security risk: enable this option only if a
139+
reverse proxy in front of thanos is resetting
140+
the header. The
141+
--web.prefix-header=X-Forwarded-Prefix option
142+
can be useful, for example, if Thanos UI is
143+
served via Traefik reverse proxy with
144+
PathPrefixStrip option enabled, which sends the
145+
stripped prefix value in X-Forwarded-Prefix
146+
header. This allows thanos UI to be served on a
147+
sub-path.
129148
--refresh=30m Refresh interval to download metadata from
130149
remote storage
131150
--timeout=5m Timeout to download metadata from remote storage
132151
--label=LABEL Prometheus label to use as timeline title
133-
--web.external-prefix="" Static prefix for all HTML links and redirect
134-
URLs in the UI query web interface. Actual
135-
endpoints are still served on / or the
136-
web.route-prefix. This allows thanos UI to be
137-
served behind a reverse proxy that strips a URL
138-
sub-path.
139152
140153
```
141154

pkg/ui/bucket.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ import (
1313
// Bucket is a web UI representing state of buckets as a timeline.
1414
type Bucket struct {
1515
*BaseUI
16+
flagsMap map[string]string
1617
// Unique Prometheus label that identifies each shard, used as the title. If
1718
// not present, all labels are displayed externally as a legend.
1819
Label string
1920
Blocks template.JS
2021
RefreshedAt time.Time
2122
Err error
22-
flagsMap map[string]string
2323
}
2424

2525
func NewBucketUI(logger log.Logger, label string, flagsMap map[string]string) *Bucket {

0 commit comments

Comments
 (0)