Traefik not prioritising rules properly

Hi, I am running Traefik as an ingress controller in my k8s cluster. I want to use an ingressroute for my Matrix server so I need the following routes working properly:

Under the host matrix.artichoke.cc, the following paths must be routed to the mas-main service:
/_matrix/client/*/login
/_matrix/client/*/logout
/_matrix/client/*/refresh

Every other route under matrix.artichoke.cc must be routed to synapse-matrix-synapse.

Every route under mas.artichoke.cc must be routed to the mas-main service.

So, do do this, I have created the following ingressroute:

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt-production
  name: synapse
  namespace: synapse
spec:
  entryPoints:
    - websecure
  routes:
    - kind: Rule
      match: Host(`matrix.artichoke.cc`) && PathRegexp(`^/_matrix/client/(.*)/(login|logout|refresh)`)
      priority: 100
      services:
        - name: mas-main
          port: 8081
    - kind: Rule
      match: Host(`matrix.artichoke.cc`) && PathPrefix(`/`)
      priority: 10
      services:
        - name: synapse-matrix-synapse
          port: 8008
    - kind: Rule
      match: Host(`artichoke.cc`) && PathPrefix(`/.well-known/matrix/`)
      services:
        - name: synapse-wellknown-lighttpd
          port: 80
    - kind: Rule
      match: Host(`mas.artichoke.cc`) && PathPrefix(`/`)
      services:
        - name: mas-main
          port: 8081
  tls:
    secretName: tls-secret

However, when I try routes such as /_matrix/client/v2/login, they get routed to the synapse backend rather than the mas backend. I made sure they were listed in the right order, so that they don't get caught in the root rule, but this did not work. So, as you can see, I set explicit priorities. This did not work either.

I am using Traefik v2.

It seems like Traefik is either ignoring my priorities or calculating them incorrectly. How can I solve this problem?

It seems there is no PathRegexp() in Traefik v2 (doc). Only in Traefik v3 (doc).

Also note that Regex in Traefik v2 are somehow "special":

Regexp Syntax
HostRegexp, PathPrefix, and Path accept an expression with zero or more groups enclosed by curly braces, which are called named regexps. Named regexps, of the form {name:regexp}, are the only expressions considered for regexp matching. The regexp name (name in the above example) is an arbitrary value, that exists only for historical reasons.
Any regexp supported by Go's regexp package may be used. For example, here is a case-insensitive path matcher syntax: Path(/{path:(?i:Products)}).

1 Like

Thanks for pointing that out! Made the jump to v3 and everything is working now.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.