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

rewritepolicy CRD: regex rewrite-criteria handling #575

Open
talbx opened this issue Mar 6, 2023 · 0 comments
Open

rewritepolicy CRD: regex rewrite-criteria handling #575

talbx opened this issue Mar 6, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@talbx
Copy link

talbx commented Mar 6, 2023

Hi,

I have some issues using the rewritepolicy CRD and I can't tell if it's just not working out or if I miss something.
I have a scenario where I want to rewrite any request containing /somethingblablabla to /someOtherPathblablabla; what is important, is that I want to preserve the appendix of /something, so that in the end it is also attached to the target path.

Therefore I planned to use regex in the rewrite-criteria property like this:

    - servicenames:
        - my-service
      rewrite-policy:
        operation: replace
        target: http.req.url
        modify-expression: '/someOtherPath\1'
        direction: REQUEST
        rewrite-criteria: HTTP.REQ.URL.PATH_REGEX_MATCH('regex(re~(/something.*)~)')

So this doesn't seem to work, the config push failed, when deployed to the k8s cluster. I also did not see any documentation on using regex in the rewrite-criteria field. I then tried out playing around with the multiple-occurence-modify property but that did not work either and that's why I'm here.

How do I specify a rewritepolicy which matches some path containing a regex pattern, and rewrites it to a target path while preserving all of its appendix (I read \n is the equivalent of $n in apache rewrites for preserving path elements) ?

Update:

I found out using multiple-occurence-modify it is possible to provide a regular expression like

    - rewrite-policy:
        comment: HTTP url replace string
        direction: REQUEST
        modify-expression: '"/someOtherPath\1"'
        multiple-occurence-modify: regex(re~(^/something.*)~)
        operation: replace_all
        rewrite-criteria: http.req.url.contains("/something")
        target: http.req.url
      servicenames:
        - my-service

but still, the preserving of the suffix right after /something is questionable. The syntax \n doesn't seem to work here.

Cheers

@subashd subashd added the enhancement New feature or request label Jul 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants