mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-11 15:34:56 +00:00
app/vmauth: allow dropping host header (#6525)
### Describe Your Changes Fixes #6453 ### Checklist The following checks are **mandatory**: - [ ] My change adheres [VictoriaMetrics contributing guidelines](https://docs.victoriametrics.com/contributing/).
This commit is contained in:
parent
48a5c4cb01
commit
f79df2aa8b
4 changed files with 23 additions and 1 deletions
|
@ -83,6 +83,7 @@ type UserInfo struct {
|
||||||
|
|
||||||
concurrencyLimitCh chan struct{}
|
concurrencyLimitCh chan struct{}
|
||||||
concurrencyLimitReached *metrics.Counter
|
concurrencyLimitReached *metrics.Counter
|
||||||
|
overrideHostHeader bool
|
||||||
|
|
||||||
rt http.RoundTripper
|
rt http.RoundTripper
|
||||||
|
|
||||||
|
@ -149,6 +150,15 @@ func (h *Header) MarshalYAML() (interface{}, error) {
|
||||||
return h.sOriginal, nil
|
return h.sOriginal, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func overrideHostHeader(headers []*Header) bool {
|
||||||
|
for _, h := range headers {
|
||||||
|
if h.Name == "Host" && h.Value == "" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// URLMap is a mapping from source paths to target urls.
|
// URLMap is a mapping from source paths to target urls.
|
||||||
type URLMap struct {
|
type URLMap struct {
|
||||||
// SrcPaths is an optional list of regular expressions, which must match the request path.
|
// SrcPaths is an optional list of regular expressions, which must match the request path.
|
||||||
|
@ -738,6 +748,7 @@ func parseAuthConfig(data []byte) (*AuthConfig, error) {
|
||||||
if err := ui.initURLs(); err != nil {
|
if err := ui.initURLs(); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ui.overrideHostHeader = overrideHostHeader(ui.HeadersConf.RequestHeaders)
|
||||||
|
|
||||||
metricLabels, err := ui.getMetricLabels()
|
metricLabels, err := ui.getMetricLabels()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -802,6 +813,7 @@ func parseAuthConfigUsers(ac *AuthConfig) (map[string]*UserInfo, error) {
|
||||||
_ = ac.ms.GetOrCreateGauge(`vmauth_user_concurrent_requests_current`+metricLabels, func() float64 {
|
_ = ac.ms.GetOrCreateGauge(`vmauth_user_concurrent_requests_current`+metricLabels, func() float64 {
|
||||||
return float64(len(ui.concurrencyLimitCh))
|
return float64(len(ui.concurrencyLimitCh))
|
||||||
})
|
})
|
||||||
|
ui.overrideHostHeader = overrideHostHeader(ui.HeadersConf.RequestHeaders)
|
||||||
|
|
||||||
rt, err := newRoundTripper(ui.TLSCAFile, ui.TLSCertFile, ui.TLSKeyFile, ui.TLSServerName, ui.TLSInsecureSkipVerify)
|
rt, err := newRoundTripper(ui.TLSCAFile, ui.TLSCertFile, ui.TLSKeyFile, ui.TLSServerName, ui.TLSInsecureSkipVerify)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -235,7 +235,7 @@ func tryProcessingRequest(w http.ResponseWriter, r *http.Request, targetURL *url
|
||||||
req := sanitizeRequestHeaders(r)
|
req := sanitizeRequestHeaders(r)
|
||||||
req.URL = targetURL
|
req.URL = targetURL
|
||||||
|
|
||||||
if req.URL.Scheme == "https" {
|
if req.URL.Scheme == "https" || ui.overrideHostHeader {
|
||||||
// Override req.Host only for https requests, since https server verifies hostnames during TLS handshake,
|
// Override req.Host only for https requests, since https server verifies hostnames during TLS handshake,
|
||||||
// so it expects the targetURL.Host in the request.
|
// so it expects the targetURL.Host in the request.
|
||||||
// There is no need in overriding the req.Host for http requests, since it is expected that backend server
|
// There is no need in overriding the req.Host for http requests, since it is expected that backend server
|
||||||
|
|
|
@ -29,6 +29,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/).
|
||||||
|
|
||||||
## tip
|
## tip
|
||||||
|
|
||||||
|
* FEATURE: [vmauth](https://docs.victoriametrics.com/vmauth/): allow overriding `Host` header with a target host before sending to a downstream. See this [issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6453)
|
||||||
* FEATURE: [dashboards](https://grafana.com/orgs/victoriametrics): add [Grafana dashboard](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/dashboards/vmauth.json) and [alerting rules](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts-vmauth.yml) for [vmauth](https://docs.victoriametrics.com/vmauth/) dashboard. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4313) for details.
|
* FEATURE: [dashboards](https://grafana.com/orgs/victoriametrics): add [Grafana dashboard](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/dashboards/vmauth.json) and [alerting rules](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/deployment/docker/alerts-vmauth.yml) for [vmauth](https://docs.victoriametrics.com/vmauth/) dashboard. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4313) for details.
|
||||||
|
|
||||||
* BUGFIX: [docker-compose](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#docker-compose-environment-for-victoriametrics): fix incorrect link to vmui from [VictoriaMetrics plugin in Grafana](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#grafana).
|
* BUGFIX: [docker-compose](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#docker-compose-environment-for-victoriametrics): fix incorrect link to vmui from [VictoriaMetrics plugin in Grafana](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#grafana).
|
||||||
|
|
|
@ -647,6 +647,15 @@ unauthorized_user:
|
||||||
- "X-Forwarded-For:"
|
- "X-Forwarded-For:"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
it's also possible to update `Host` header to a backend's host name
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
unauthorized_user:
|
||||||
|
url_prefix: "http://backend:1234/"
|
||||||
|
headers:
|
||||||
|
- "Host:" # Update host header to a backend's host
|
||||||
|
```
|
||||||
|
|
||||||
`vmauth` also supports the ability to set and remove HTTP response headers before returning the response from the backend to client.
|
`vmauth` also supports the ability to set and remove HTTP response headers before returning the response from the backend to client.
|
||||||
This is done via `response_headers` option. For example, the following [`-auth.config`](#auth-config) sets `Foo: bar` response header
|
This is done via `response_headers` option. For example, the following [`-auth.config`](#auth-config) sets `Foo: bar` response header
|
||||||
and removes `Server` response header before returning the response to client:
|
and removes `Server` response header before returning the response to client:
|
||||||
|
|
Loading…
Reference in a new issue