-
Notifications
You must be signed in to change notification settings - Fork 422
Allow restrictions based on custom Authorization Header matching logic #445
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
base: main
Are you sure you want to change the base?
Conversation
In commit e1205b7 ("Allow restrictions based on Authorization header"), we added restriction match type that tests the Auth Header of the websocket upgrade request matches a regex. We'd like to augment that approach for cases where the wstunnel server needs to perform some computation on the presented Auth Header value, or perform some custom matching logic. Examples would be computing a hash, performing jwt validation, comparing to a dynamic set of values, etc. There could be numerous different custom match implementations. So instead of suggesting additional tailored MatchConfig types, lets allow the admin to pass a lua script that implements his custom match logic. The script is processed and a global function named 'auth_validate' is invoked, given the Auth Header value as a parameter. The function must return true/false; true iff access is granted. example lua script: -- local match = string.match function auth_validate(auth) if match(auth, "^Basic aGk6dGhlcmU=$") then return true end return false end -- Any failure loading the script or invoking the lua function is considered an authentication failure.
Hello, Thank you for the PR and the feature is nice, but sadly I doubt it is going to be merged into the project. Also from a technical standpoint there are 2 limitations with the current PR:
|
Thanks @erebe ! There are several design benefits performing the authentication in wstunnel server itself and not in a reverse proxy. Re your 2nd point, can you please suggest the proper code location where the scripts needs to be read and cached? |
Would you mind describing the benefits ? I don't want to give you false hope, so I am going to tell that even with the changes, the PR is not going to be merged. But the code is pretty isolated, so I don't think you will have trouble to maintain a fork with your patch. Regarding the code location for the cache, you should compile the lua code while parsing the config file and add a hook for the file to be watched for change in |
Sure.
NP, thanks for the heads-up. BTW, instead of a generic scripting facility for wstunnel server authentication, how about the more-scoped solution presented here? Do you think this is a better merge candidate? Thanks! |
Thanks for the explanation 👍
What kind of logic do you have in mind ? |
like this one:
implemented in this commit WDYT? |
I prefer the lua version to be honest 🙈 Having a |
Definitely. This is exactly why initially submitted a generic solution: "instead of suggesting additional tailored MatchConfig types, lets allow the admin to pass a lua script that implements his custom match logic". Anyway, we're left with the following options:
Let me know. |
Yeah, the lua version is more powerful/flexible in your case. Without traction beside on your part, I am not going to merge the PR. But if some other people manifest, I may re-open the question. If I were you, if your needs stop at having a hash of the JWT. I would go with the custom matcher and maintaining a fork. This part of the code does not move/evolve much, so I doubt it will be a big toil to maintain the patch. If you plan to have more complex matcher, I would go into refining the patch with the lua interpreter to avoid the blocking in the critical part. As explained, as long as you can reload/modify the config file when you update the lua file, you can compile the lua code outside of the critical path when the config file is being parsed. |
Thanks @erebe, will go with a fork then. |
5ce3fb8
to
c5e2981
Compare
In commit e1205b7 ("Allow restrictions based on Authorization header"), we added restriction match type that tests the Auth Header of the websocket upgrade request matches a regex.
We'd like to augment that approach for cases where the wstunnel server needs to perform some computation on the presented Auth Header value, or perform some custom matching logic.
Examples would be computing a hash, performing jwt validation, comparing to a dynamic set of values, etc.
There could be numerous different custom match implementations. So instead of suggesting additional tailored MatchConfig types, lets allow the admin to pass a lua script that implements his custom match logic.
The script is processed and a global function named 'auth_validate' is invoked, given the Auth Header value as a parameter. The function must return true/false; true iff access is granted.
example lua script:
Any failure loading the script or invoking the lua function is considered an authentication failure.