mirror of
https://github.com/traefik/traefik.git
synced 2026-06-18 19:38:23 +03:00
Merge branch v2.11 into v3.6
This commit is contained in:
@@ -614,32 +614,6 @@ func (p *Provider) loadConfigurationFromCRD(ctx context.Context, client Client)
|
||||
return conf
|
||||
}
|
||||
|
||||
func (p *Provider) resolveReference(ctx context.Context, parentNs, ns, name string) (string, error) {
|
||||
if strings.Contains(name, providerNamespaceSeparator) {
|
||||
if !p.AllowCrossNamespace && strings.HasSuffix(name, providerNamespaceSeparator+providerName) {
|
||||
return "", errors.New("when allowCrossNamespace is disabled, @kubernetescrd references are disallowed")
|
||||
}
|
||||
|
||||
if !isCrossProviderNamespaceAllowed(p.CrossProviderNamespaces, parentNs) {
|
||||
return "", fmt.Errorf("namespace %q is not in crossProviderNamespaces", parentNs)
|
||||
}
|
||||
|
||||
if ns != "" {
|
||||
log.Ctx(ctx).Warn().Msgf("Namespace %q is ignored in cross-provider context", ns)
|
||||
}
|
||||
|
||||
return name, nil
|
||||
}
|
||||
|
||||
ns = namespaceOrParentNamespace(ns, parentNs)
|
||||
|
||||
if !isNamespaceAllowed(p.AllowCrossNamespace, parentNs, ns) {
|
||||
return "", errors.New("allowCrossNamespace is disabled, cross-namespace are disallowed")
|
||||
}
|
||||
|
||||
return provider.Normalize(ns + "-" + name), nil
|
||||
}
|
||||
|
||||
func (p *Provider) createErrorPageMiddleware(ctx context.Context, client Client, namespace string, errorPage *traefikv1alpha1.ErrorPage) (string, *dynamic.ErrorPage, *dynamic.Service, error) {
|
||||
if errorPage == nil {
|
||||
return "", nil, nil, nil
|
||||
@@ -674,7 +648,7 @@ func (p *Provider) createChainMiddleware(ctx context.Context, parentNamespace st
|
||||
for _, mi := range chain.Middlewares {
|
||||
ctxMid := log.Ctx(ctx).With().Str("middlewareRef", mi.Namespace+"/"+mi.Name).Logger().WithContext(ctx)
|
||||
|
||||
middlewareRef, err := p.resolveReference(ctxMid, parentNamespace, mi.Namespace, mi.Name)
|
||||
middlewareRef, err := resolveReference(ctxMid, parentNamespace, mi.Namespace, mi.Name, p.CrossProviderNamespaces, p.AllowCrossNamespace)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid reference to middleware %s: %w", mi.Name, err)
|
||||
}
|
||||
@@ -1592,3 +1566,29 @@ func isCrossProviderNamespaceAllowed(allowList []string, namespace string) bool
|
||||
|
||||
return slices.Contains(allowList, namespace)
|
||||
}
|
||||
|
||||
func resolveReference(ctx context.Context, parentNs, ns, name string, crossProviderNamespaces []string, allowCrossNamespace bool) (string, error) {
|
||||
if strings.Contains(name, providerNamespaceSeparator) {
|
||||
if !allowCrossNamespace && strings.HasSuffix(name, providerNamespaceSeparator+providerName) {
|
||||
return "", errors.New("when allowCrossNamespace is disabled, @kubernetescrd references are disallowed")
|
||||
}
|
||||
|
||||
if !isCrossProviderNamespaceAllowed(crossProviderNamespaces, parentNs) {
|
||||
return "", fmt.Errorf("namespace %q is not in crossProviderNamespaces", parentNs)
|
||||
}
|
||||
|
||||
if ns != "" {
|
||||
log.Ctx(ctx).Warn().Msgf("Namespace %q is ignored in cross-provider context", ns)
|
||||
}
|
||||
|
||||
return name, nil
|
||||
}
|
||||
|
||||
ns = namespaceOrParentNamespace(ns, parentNs)
|
||||
|
||||
if !isNamespaceAllowed(allowCrossNamespace, parentNs, ns) {
|
||||
return "", errors.New("allowCrossNamespace is disabled, cross-namespace are disallowed")
|
||||
}
|
||||
|
||||
return provider.Normalize(ns + "-" + name), nil
|
||||
}
|
||||
|
||||
@@ -140,7 +140,7 @@ func (p *Provider) loadIngressRouteConfiguration(ctx context.Context, client Cli
|
||||
tlsOptions := ingressRoute.Spec.TLS.Options
|
||||
ctxTLSOption := log.Ctx(ctx).With().Str("TLSOption", tlsOptions.Name).Logger().WithContext(ctx)
|
||||
|
||||
r.TLS.Options, err = p.resolveReference(ctxTLSOption, ingressRoute.Namespace, tlsOptions.Namespace, tlsOptions.Name)
|
||||
r.TLS.Options, err = resolveReference(ctxTLSOption, ingressRoute.Namespace, tlsOptions.Namespace, tlsOptions.Name, p.CrossProviderNamespaces, p.AllowCrossNamespace)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msgf("Invalid reference to TLSOption %q", ingressRoute.Spec.TLS.Options.Name)
|
||||
continue
|
||||
@@ -163,7 +163,7 @@ func (p *Provider) makeMiddlewareKeys(ctx context.Context, ingRouteNamespace str
|
||||
for _, mi := range middlewares {
|
||||
ctxMid := log.Ctx(ctx).With().Str(logs.MiddlewareName, mi.Name).Logger().WithContext(ctx)
|
||||
|
||||
middlewareRef, err := p.resolveReference(ctxMid, ingRouteNamespace, mi.Namespace, mi.Name)
|
||||
middlewareRef, err := resolveReference(ctxMid, ingRouteNamespace, mi.Namespace, mi.Name, p.CrossProviderNamespaces, p.AllowCrossNamespace)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid reference to middleware %s: %w", mi.Name, err)
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ func (p *Provider) loadIngressRouteTCPConfiguration(ctx context.Context, client
|
||||
tlsOptions := ingressRouteTCP.Spec.TLS.Options
|
||||
ctxTLSOption := log.Ctx(ctx).With().Str("TLSOption", tlsOptions.Name).Logger().WithContext(ctx)
|
||||
|
||||
r.TLS.Options, err = p.resolveReference(ctxTLSOption, ingressRouteTCP.Namespace, tlsOptions.Namespace, tlsOptions.Name)
|
||||
r.TLS.Options, err = resolveReference(ctxTLSOption, ingressRouteTCP.Namespace, tlsOptions.Namespace, tlsOptions.Name, p.CrossProviderNamespaces, p.AllowCrossNamespace)
|
||||
if err != nil {
|
||||
logger.Error().Err(err).Msgf("Invalid reference to TLSOption %q", ingressRouteTCP.Spec.TLS.Options.Name)
|
||||
continue
|
||||
@@ -134,7 +134,7 @@ func (p *Provider) makeMiddlewareTCPKeys(ctx context.Context, ingRouteTCPNamespa
|
||||
for _, mi := range middlewares {
|
||||
ctxMid := log.Ctx(ctx).With().Str(logs.MiddlewareName, mi.Name).Logger().WithContext(ctx)
|
||||
|
||||
middlewareRef, err := p.resolveReference(ctxMid, ingRouteTCPNamespace, mi.Namespace, mi.Name)
|
||||
middlewareRef, err := resolveReference(ctxMid, ingRouteTCPNamespace, mi.Namespace, mi.Name, p.CrossProviderNamespaces, p.AllowCrossNamespace)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid reference to middleware %s: %w", mi.Name, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user