providers/proxy: fix Issuer when AUTHENTIK_HOST_BROWSER is set (#11968)
correctly use host_browser's hostname as host header for token requests to ensure Issuer is identical
This commit is contained in:
@ -23,6 +23,7 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"goauthentik.io/api/v3"
|
"goauthentik.io/api/v3"
|
||||||
|
"goauthentik.io/internal/config"
|
||||||
"goauthentik.io/internal/outpost/ak"
|
"goauthentik.io/internal/outpost/ak"
|
||||||
"goauthentik.io/internal/outpost/proxyv2/constants"
|
"goauthentik.io/internal/outpost/proxyv2/constants"
|
||||||
"goauthentik.io/internal/outpost/proxyv2/hs256"
|
"goauthentik.io/internal/outpost/proxyv2/hs256"
|
||||||
@ -121,6 +122,14 @@ func NewApplication(p api.ProxyOutpostConfig, c *http.Client, server Server, old
|
|||||||
bs := string(h.Sum([]byte(*p.ClientId)))
|
bs := string(h.Sum([]byte(*p.ClientId)))
|
||||||
sessionName := fmt.Sprintf("authentik_proxy_%s", bs[:8])
|
sessionName := fmt.Sprintf("authentik_proxy_%s", bs[:8])
|
||||||
|
|
||||||
|
// When HOST_BROWSER is set, use that as Host header for token requests to make the issuer match
|
||||||
|
// otherwise we use the internally configured authentik_host
|
||||||
|
tokenEndpointHost := server.API().Outpost.Config["authentik_host"].(string)
|
||||||
|
if config.Get().AuthentikHostBrowser != "" {
|
||||||
|
tokenEndpointHost = config.Get().AuthentikHostBrowser
|
||||||
|
}
|
||||||
|
publicHTTPClient := web.NewHostInterceptor(c, tokenEndpointHost)
|
||||||
|
|
||||||
a := &Application{
|
a := &Application{
|
||||||
Host: externalHost.Host,
|
Host: externalHost.Host,
|
||||||
log: muxLogger,
|
log: muxLogger,
|
||||||
@ -131,7 +140,7 @@ func NewApplication(p api.ProxyOutpostConfig, c *http.Client, server Server, old
|
|||||||
tokenVerifier: verifier,
|
tokenVerifier: verifier,
|
||||||
proxyConfig: p,
|
proxyConfig: p,
|
||||||
httpClient: c,
|
httpClient: c,
|
||||||
publicHostHTTPClient: web.NewHostInterceptor(c, server.API().Outpost.Config["authentik_host"].(string)),
|
publicHostHTTPClient: publicHTTPClient,
|
||||||
mux: mux,
|
mux: mux,
|
||||||
errorTemplates: templates.GetTemplates(),
|
errorTemplates: templates.GetTemplates(),
|
||||||
ak: server.API(),
|
ak: server.API(),
|
||||||
|
@ -14,8 +14,10 @@ type hostInterceptor struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t hostInterceptor) RoundTrip(r *http.Request) (*http.Response, error) {
|
func (t hostInterceptor) RoundTrip(r *http.Request) (*http.Response, error) {
|
||||||
|
if r.Host != t.host {
|
||||||
r.Host = t.host
|
r.Host = t.host
|
||||||
r.Header.Set("X-Forwarded-Proto", t.scheme)
|
r.Header.Set("X-Forwarded-Proto", t.scheme)
|
||||||
|
}
|
||||||
return t.inner.RoundTrip(r)
|
return t.inner.RoundTrip(r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user