Traefik V2 HostRegexp

Hello everyone,

We have some difficulties constructing a regex to match specific hosts according to the documentation :

We would like to be able to match all these hosts:

foo.dev.en.domain.com
foo.dev.domain.com
org-foo.dev.ru.domain.com
org-foo.dev.domain.com
foo.dev.en.domain.com.au
foo.dev.domain.com.au
org-foo.dev.ru.domain.com.au
org-foo.dev.domain.com.au

I have tried something like that but it doesn't correspond perfectly to what we expect:

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ingress-test
spec:
  entryPoints:
    - external
  routes:
    - kind: Rule
      match: HostRegexp("{(org-)?}foo.dev.{(en|ru)?(\.)?}domain.{[com|com\.au]}") && (PathPrefix("/"))
      services:
        - kind: Service
          name: my-service
          port: http

Tested several things and it seems this is the dot that is not considered (demo it match on regex tests but never through HostRegexp match rules via Traefik ingress route) :

For domain examples: org-foo.dev.en.domain.com or org-foo.dev.domain.com or org-foo.dev.domain.com.au
HostRegexp("{(org-)?}foo.dev.{(en|ru)?(\.)?}domain.{[com|com\.au]}")
HostRegexp("{(org-)?}foo.dev.{(en|ru)?(.\..)?}domain.{[com|com\.au]}")
HostRegexp("{(org-)?}foo.dev.{(en|ru)?}{(.\..)?}domain.{[com|com\.au]}")
HostRegexp("{(org-)?}foo.dev.{(en|ru)?}{(.\\..)?}domain.{[com|com\.au]}")

I guess, the first challenge is to manage correctly the dot image
which could be considered as a concatenator.

Help should be very appreciate
Thanks

I have found something like this which seems to works partially but really not maintainable. That's crazy to manage the regex like this instead of standard :

HostRegexp(`{subdomain:(org[-])?foo.dev.((en|ru)[.])?}domain.{[com\.au|com]}`)

The domain extension is still not working with a dot...

HostRegexp(`{subdomain:(org[-])?foo.dev.((en|ru)[.])?}domain.{[com\.au|com]}`) : KO
HostRegexp(`{subdomain:(org[-])?foo.dev.((en|ru)[.])?}domain.{[com.au|com]}`) : KO

Someone have an idea please ?

SOLUTION

HostRegexp(`{subdomain:(org[-])?foo.dev.((en|ru)[.])?}domain.{tld:(com\.au|com)}`) 

1 Like