InfoSecInnovations / concierge

Repo for Concierge AI dev work
Apache License 2.0
147 stars 28 forks source link

Configure webserver to listen globally, not just localhost #29

Open markjx opened 1 month ago

markjx commented 1 month ago

This may be a feature request.

We'd like to make Concierge available to a network rather than just running on localhost. I see the python webserver which is bound to 127.0.0.1:8000. Is there a way I could configure that to listen on *:8000?

I'd like to be able to have my colleagues hit the web server to use it. And, use it on an Ubuntu server which doesn't have a GUI.

(I know I'm opening myself up to all kinds of Security issues, and potential other concerns. )

rfolkker commented 1 month ago

A quick work-around I did for this was:

The following in the launcher.py

run_params=[get_venv_executable(), '-m', 'shiny', 'run', '--launch-browser', 'concierge_shiny/app.py']
if os.getenv("HOST") is not None:
    run_params.append("--host")
    run_params.append(os.getenv("HOST"))
if os.getenv("PORT") is not None:
    run_params.append("--port")
    run_params.append(os.getenv("PORT"))

subprocess.run(run_params)

You can then modify your .env file (sudo edit)

DOCKER_VOLUME_DIRECTORY=/opt/concierge
HOST=0.0.0.0
PORT=8800

And you should be good.

rfolkker commented 1 month ago

If you are using this on Windows and WSL, remember to also open the port on your firewall and to port forward your WSL.

(WSL Forwarding looks like the following, but replace your WSL_IP) netsh interface portproxy add v4tov4 listenport=8800 listenaddress=0.0.0.0 connectport=8800 connectaddress=WSL_IP

And open the firewall for the windows side, as the windows side port does not have to match the WSL side port.

markjx commented 1 month ago

@rfolkker : That's fantastic! That's good enough for what I need to do right now 😄

sebovzeoueb commented 3 weeks ago

Just an update on this: we've currently got the dockerized version in testing, if no major issues arise it should be here very soon. You'll be able to expose it to wherever you like using Docker's port mappings. I like the idea of adding HOST and PORT environment variables though for people running the Python script directly.

shipley-c commented 3 weeks ago

I made these changes in my launcher.py, .env file, and windows firewall. When I run launch.py now, I'm getting the following in the console. Where else might I need to change things to get past this error?

PS C:\utils\concierge> python launch.py Checking Docker container status...

C:\utils\concierge\Lib\site-packages\huggingface_hub\file_download.py:1132: FutureWarning: resume_download is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use force_download=True. warnings.warn( C:\utils\concierge\Lib\site-packages\huggingface_hub\file_download.py:1132: FutureWarning: resume_download is deprecated and will be removed in version 1.0.0. Downloads always resume when possible. If you want to force a new download, use force_download=True. warnings.warn( INFO: Started server process [7152] INFO: Waiting for application startup. INFO: Application startup complete. ERROR: [Errno 10048] error while attempting to bind on address ('0.0.0.0', 8800): only one usage of each socket address (protocol/network address/port) is normally permitted INFO: Waiting for application shutdown. INFO: Application shutdown complete. PS C:\utils\concierge>

rfolkker commented 3 weeks ago

It appears the port is already in use on your system, you likely will need to assign a different port (or if it is a stale connection, kill the task).

Since you are using windows, you can use either the powershell or commandline version (both documented below) on how to locate and end the process:

Commandline:

C:\Users\me>netstat -aon | find /i "8800"
  TCP    0.0.0.0:8800           0.0.0.0:0              LISTENING       6652

C:\Users\me>tasklist /fi "pid eq 6652"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
svchost.exe                   6652 Services                   0      9,824 K

Powershell

PS C:\Users\me> $(Get-Process -Id (Get-NetTCPConnection -LocalPort 8800).OwningProcess).ProcessName
svchost

I had problems with the port clearing on end a few times, especially if I started and stopped the service repeatedly.

I hope this helps.