IngressRoute to match anything not working

I have been attempting to make an IngressRoute match anything.

This is not working:

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: direct-rpc
spec:
  entryPoints:
    - {{ .Values.rpcEntryPoint }}
  routes:
    - match: "HostRegexp(`{.*}`)"
      kind: Rule
      services:
        - name: myservice
          port: rpc

The above only seems to work if no host header is set. When I set one it doesn't match and I get 404.

Tests:

# works: 
curl localhost:28138

# doesn't work:
curl --header 'Host: example.com' localhost:28138

I have resorted to this:

apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
  name: direct-rpc
spec:
  entryPoints:
    - {{ .Values.rpcEntryPoint }}
  routes:
    - match: "!HostRegexp(`ahost.thatdoesnot.exist.never`)"
      kind: Rule
      services:
        - name: myservice
          port: rpc

What did you see instead?

404 page not found

What version of Traefik are you using?

v2.10.4

What is your environment & configuration?

ports:
  rpc:
    port: 28100
    expose: true
    exposedPort: 28100
    protocol: TCP
logs:
  general:
    level: DEBUG
  access:
    enabled: true

Just standard helm install on K8s cluster with the above values file

If applicable, please paste the log output in DEBUG level

Debug logs just show 404s

192.168.65.4 - - [20/Sep/2023:14:40:37 +0000] "POST / HTTP/1.1" 404 76 "-" "-" 7780 "direct-rp 73234b1b1e8726bbbb2c@kubernetescrd" "http://10.1.3.181:183" 0ms

Is this a bug? I would have expected the regex to match anything. Many thanks.

hello,

the syntax of the rule must be HostRegexp(`{host:.*}`)

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.

1 Like

Thanks @ldez, I had already tried naming the regex match but that doesn't work at all. Now both the curl tests return 404.

The rule works, maybe you have another problem not related to the rule.
Maybe it's your endpoint, your network, etc.

I'm only changing the match rule and it goes from working to not working. Doesn't that rule out it being a problem elsewhere?

I'll try and make a minimum reproducible set up.

Time for the embarrassed apology!

I had a ! not left over from previous experiments.

Many thanks @ldez for staying patient with me and for fixing my problem. It did indeed just need the regex match naming.

The old programming lesson I never seem to learn, when you think it's a bug in the tool, it's probably not.

1 Like

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