Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no fmt for HTTPRequestRule #348

Open
LeoK80 opened this issue Nov 8, 2024 · 0 comments
Open

no fmt for HTTPRequestRule #348

LeoK80 opened this issue Nov 8, 2024 · 0 comments

Comments

@LeoK80
Copy link

LeoK80 commented Nov 8, 2024

TL;DR
I'm trying to add a simple path rewrite rule to drop a specific first part of a path when received from the front-end. I'm not sure if I'm overlooking something in the api docs or whether I'm dealing with some bugs here. I really would appreciate any feedback.

Method 1 - set-uri
Currently using haproxy v2 and dataplane api and running into and issue trying to rewrite the path.
Goal is to add a rule to a backend in haproxy:

http-request set-uri %[url,regsub(^/metrics/,/,)] if { path_beg /metrics }

I've been using the url as per documentation with the needed query params:

/v2/services/haproxy/configuration/http_request_rules?transaction_id={{transactionid}}&parent_name={{backend_name}}&parent_type=backend

With the JSON payload on POST request:

{
    "type": "set-uri",
    "index": 0,
    "expr": "%[url,regsub(^/metrics/,/,)]",
    "cond": "if",
    "cond_test": "{ path_beg /metrics }"
}

I've also tried with the "uri-match" and "uri-fmt" as well as "path_match" and "path_fmt", however the result is always the same. It ends up with an empty space for the expression used (mind, two spaces instead of one!):

http-request set-uri  if { path_beg /metrics }

The issue:
I can't seem to get the required expression into Haproxy using the dataplane api for HTTPRequestRule

Method 2 - path-replace
The other attempted approach is using the path-replace approach.

I've been using the url as per documentation with the needed query params:

/v2/services/haproxy/configuration/http_request_rules?transaction_id={{transactionid}}&parent_name={{backend_name}}&parent_type=backend

With the JSON payload on POST request:

{
    "type": "replace-path",
    "index": 0,
    "cond": "if",
    "cond_test": "{ url_beg /metric/ }",
    "path_fmt": "/\\1",
    "path_match": "/metrics/(.*)"
}

The resulting rule in haproxy.cfg:

http-request replace-path /metrics/(.*) /\\1 if { url_beg /metrics/ }

The issue: escape carries into the haproxy rules
It seems that the escape backslash used to satisfy JSON standards, carries on into the Haproxy config rule instead of being dropped. I'd expect this to break the look-back reference in haproxy.cfg

Expected output into haproxy.cfg:

http-request replace-path /metrics/(.*) /\1 if { url_beg /metrics/ }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant