mirror of
https://github.com/pomerium/pomerium.git
synced 2025-08-02 16:30:17 +02:00
envoyconfig: clean up filter chain construction (#3844)
* cleanup filter chain construction * rename domains to server names * rename to hosts * fix tests * update function name * improved domaain matching
This commit is contained in:
parent
a49f86d023
commit
67e12101fa
10 changed files with 405 additions and 246 deletions
|
@ -47,12 +47,12 @@ func (b *Builder) buildGRPCRoutes() ([]*envoy_config_route_v3.Route, error) {
|
|||
}}, nil
|
||||
}
|
||||
|
||||
func (b *Builder) buildPomeriumHTTPRoutes(options *config.Options, domain string) ([]*envoy_config_route_v3.Route, error) {
|
||||
func (b *Builder) buildPomeriumHTTPRoutes(options *config.Options, host string) ([]*envoy_config_route_v3.Route, error) {
|
||||
var routes []*envoy_config_route_v3.Route
|
||||
|
||||
// if this is the pomerium proxy in front of the the authenticate service, don't add
|
||||
// these routes since they will be handled by authenticate
|
||||
isFrontingAuthenticate, err := isProxyFrontingAuthenticate(options, domain)
|
||||
isFrontingAuthenticate, err := isProxyFrontingAuthenticate(options, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ func (b *Builder) buildPomeriumHTTPRoutes(options *config.Options, domain string
|
|||
b.buildControlPlanePrefixRoute("/.well-known/pomerium/", false),
|
||||
)
|
||||
// per #837, only add robots.txt if there are no unauthenticated routes
|
||||
if !hasPublicPolicyMatchingURL(options, url.URL{Scheme: "https", Host: domain, Path: "/robots.txt"}) {
|
||||
if !hasPublicPolicyMatchingURL(options, url.URL{Scheme: "https", Host: host, Path: "/robots.txt"}) {
|
||||
routes = append(routes, b.buildControlPlanePathRoute("/robots.txt", false))
|
||||
}
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ func (b *Builder) buildPomeriumHTTPRoutes(options *config.Options, domain string
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if config.IsAuthenticate(options.Services) && hostMatchesDomain(authenticateURL, domain) {
|
||||
if config.IsAuthenticate(options.Services) && urlMatchesHost(authenticateURL, host) {
|
||||
routes = append(routes,
|
||||
b.buildControlPlanePathRoute(options.AuthenticateCallbackPath, false),
|
||||
b.buildControlPlanePathRoute("/", false),
|
||||
|
@ -151,12 +151,12 @@ func getClusterStatsName(policy *config.Policy) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
func (b *Builder) buildPolicyRoutes(options *config.Options, domain string) ([]*envoy_config_route_v3.Route, error) {
|
||||
func (b *Builder) buildPolicyRoutes(options *config.Options, host string) ([]*envoy_config_route_v3.Route, error) {
|
||||
var routes []*envoy_config_route_v3.Route
|
||||
|
||||
for i, p := range options.GetAllPolicies() {
|
||||
policy := p
|
||||
if !hostMatchesDomain(policy.Source.URL, domain) {
|
||||
if !urlMatchesHost(policy.Source.URL, host) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -188,7 +188,7 @@ func (b *Builder) buildPolicyRoutes(options *config.Options, domain string) ([]*
|
|||
}
|
||||
|
||||
// disable authentication entirely when the proxy is fronting authenticate
|
||||
isFrontingAuthenticate, err := isProxyFrontingAuthenticate(options, domain)
|
||||
isFrontingAuthenticate, err := isProxyFrontingAuthenticate(options, host)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -497,13 +497,13 @@ func hasPublicPolicyMatchingURL(options *config.Options, requestURL url.URL) boo
|
|||
return false
|
||||
}
|
||||
|
||||
func isProxyFrontingAuthenticate(options *config.Options, domain string) (bool, error) {
|
||||
func isProxyFrontingAuthenticate(options *config.Options, host string) (bool, error) {
|
||||
authenticateURL, err := options.GetAuthenticateURL()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if !config.IsAuthenticate(options.Services) && hostMatchesDomain(authenticateURL, domain) {
|
||||
if !config.IsAuthenticate(options.Services) && urlMatchesHost(authenticateURL, host) {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue