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

feat: support openresty #25

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

feat: support openresty #25

wants to merge 3 commits into from

Conversation

oowl
Copy link

@oowl oowl commented Aug 18, 2022

support openresty luajit interactive

@guysv
Copy link
Owner

guysv commented Aug 18, 2022

Hey thanks for the PR! Could you please instruct me on how to use it?

@oowl
Copy link
Author

oowl commented Aug 18, 2022

Ok, https://github.com/openresty/lua-nginx-module running luajit on Nginx, And it impl some nginx api in luajit, so i want to use ilua online to execute this nginx related api. i use websocket to connect openresty server, use websocket message to trigger lua execute and complete, and return result to jupyter. Just install openresty, and then exec
ilua -i openresty

@guysv
Copy link
Owner

guysv commented Aug 18, 2022

Okay I managed to try it out!
First, there's a missing module exception for autobahn. consider adding it to the dependencies.

Second, very cool.
image

I see ssl is not implemented. Maybe we can self-sign ssl certs and configure openresty to use them so the console will have access to the ssl module. But maybe that's a feature for later 🤣


Now regarding actually merging this.
I'd like to ask you to consider publishing this as a stand-alone package. You can depend on ilua for the kernel classes and override what you need. If you need help API-wise for such integration i'd love to help! But I actually think you can manage to get this working just by subclassing my kernel.

ilua/kernel.py Outdated

import twisted

from ilua import websocket
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from . import websocket

http {
lua_package_path './lua/?.lua;{LUALIB};';
server {
listen {PORT};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see nginx is listening on 0.0.0.0, and that route goes into the unsandboxed lua interpreter
image
Not good for security.

Copy link
Owner

@guysv guysv Aug 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well to solve this the first step would be to switch to 127.0.0.1. But even then is vulnerable to dns rebind.

This is (semi? not really?) mitigated in the native lua implementation by sticking to FIFOs. I don't plan on adding HMAC to the lua implementation soon 🤣 , so I guess you can for now at least listen too on a unix socket instead of tcp.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, i switched to TCP that does not using a UNIX socket, because twisted WebSocket not support UNIX socket. I debug this long time.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure you can, let me get back to you with a POC.

@oowl
Copy link
Author

oowl commented Aug 22, 2022

I will consider creating iresty repo to achieve this( using ilua for the kernel classes ), but now I have no more time to do this. This implement looks dirty now.

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

Successfully merging this pull request may close these issues.

2 participants