Cloudron makes it easy to run web apps like WordPress, Nextcloud, GitLab on your server. Find out more or install now.


Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Bookmarks
  • Search
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo

Cloudron Forum

Apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Feature Requests
  3. VPN tunnel for apps

VPN tunnel for apps

Scheduled Pinned Locked Moved Feature Requests
openvpnnetworking
137 Posts 9 Posters 39.7k Views 11 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • LonkleL Offline
    LonkleL Offline
    Lonkle
    wrote on last edited by
    #9

    So, @mehdi in another thread showed me the "semi-open source" code for Cloudron. I don't know how I'll be able to test it if it doesn't run if I clone the repo with no changes, but I can start to get some changes in there and see if I can add what I need and then do a merge request. Is that what would work best for you guys?

    1 Reply Last reply
    0
    • LonkleL Offline
      LonkleL Offline
      Lonkle
      wrote on last edited by
      #10

      I know I've written an exhausting amount, but thought I'd write a quick and simple question - so since this is easily doable within Docker? Would it not be as easy as Cloudron allowing for the --net=container:vpn-client to be passed to the application it's about to run?

      I envision this as a setting in the Cloudron App Settings pages. Saying "Have this app use another Cloudron app's network configuration (we recommend leaving this disabled and only using it if you need to): " and then a dropdown of other sites that have the net_admin Cloudron capability which my custom openvpn-client Docker converted to Cloudron app most certainly will have.

      1 Reply Last reply
      0
      • LonkleL Offline
        LonkleL Offline
        Lonkle
        wrote on last edited by Lonkle
        #11

        UPDATE: Combining Dockers didn't work. Too complex to combine Docker images.

        Next to experiment either:

        โ€ข With the Docker Cloudron "Add-on" which appears I can do what I need to though not ideally within all of Cloudron's app container's (looks like I can build the OpenVPN-Client and then another x Docker and run that under the network already running in the OpenVPN-Client).
        Ref: https://docs.cloudron.io/custom-apps/addons/#docker

        โ€ข Use the net_admin Cloudron "capability" to and see if I can get my OpenVPN-Client Docker installed successfully while using that capability.
        Ref: https://docs.cloudron.io/custom-apps/manifest/#capabilities

        Can't decide which to try first. ๐Ÿ˜‚

        1 Reply Last reply
        0
        • P Offline
          P Offline
          p44
          translator
          wrote on last edited by
          #12

          @Lonk @girish Yes, Is almost the same scenario, but for my knowledge seems bit complex to apply ๐Ÿ™‚

          LonkleL 1 Reply Last reply
          0
          • P p44

            @Lonk @girish Yes, Is almost the same scenario, but for my knowledge seems bit complex to apply ๐Ÿ™‚

            LonkleL Offline
            LonkleL Offline
            Lonkle
            wrote on last edited by Lonkle
            #13

            @p44 Thatโ€™s what this discussion is about. To make this possible for the average user, possibly even adding it to the store (just like the OpenVPN Server App was created). After we figure out if Cloudron wants to support this at the inter-app level (and if theyโ€™re going to mirror Docker arguments since that seems like the easiest solution for them to achieve this) remains in question.

            Youโ€™re right that as of now itโ€™s too complex for the average user. But my goal is to both make it possible and easy for all users. Just need to know how the Cloudron developers feel before figuring out how to proceed.

            If they want to work with me on making this a feature Cloudron can support, Iโ€™ll do as much of the legwork as possible and then Iโ€™ll ping ya on your thread lettinโ€™ you know what your best solution is depending on the outcome of this thread. โ˜บ๏ธ

            1 Reply Last reply
            0
            • girishG Offline
              girishG Offline
              girish
              Staff
              wrote on last edited by
              #14

              Still sifting through our 5.6 release bucket list, so I am trying to wrap my head around this a bit.

              @Lonk IIUC, the feature requested here is to pipe the network traffic of some apps via a VPN connection. I love the idea! ๐Ÿ™‚ I can see use cases like the ttrss one but also for any of the "pulling" apps like emby metadata download, torrent, searx, scapers etc.

              I think this involves two steps (which you already figured). Step 1 is to package the openvpn client app for Cloudron. I think you only need net_admin for this but we can easily add new caps depending on what is needed.

              Step 2 is to then have some configuration to let apps use this container as the networking layer. If you ignore the UI/UX, this is really just a one-line change: https://git.cloudron.io/cloudron/box/-/blob/master/src/docker.js#L311 will be changed to the VPN client app's container. If we had a way to identify vpn clients, we can just have a dropdown of vpn clients as the available 'networks' in the app's configuration UI. And that should be it.

              (I hope I understand your requirements correctly.)

              LonkleL 2 Replies Last reply
              1
              • girishG girish

                Still sifting through our 5.6 release bucket list, so I am trying to wrap my head around this a bit.

                @Lonk IIUC, the feature requested here is to pipe the network traffic of some apps via a VPN connection. I love the idea! ๐Ÿ™‚ I can see use cases like the ttrss one but also for any of the "pulling" apps like emby metadata download, torrent, searx, scapers etc.

                I think this involves two steps (which you already figured). Step 1 is to package the openvpn client app for Cloudron. I think you only need net_admin for this but we can easily add new caps depending on what is needed.

                Step 2 is to then have some configuration to let apps use this container as the networking layer. If you ignore the UI/UX, this is really just a one-line change: https://git.cloudron.io/cloudron/box/-/blob/master/src/docker.js#L311 will be changed to the VPN client app's container. If we had a way to identify vpn clients, we can just have a dropdown of vpn clients as the available 'networks' in the app's configuration UI. And that should be it.

                (I hope I understand your requirements correctly.)

                LonkleL Offline
                LonkleL Offline
                Lonkle
                wrote on last edited by Lonkle
                #15

                @girish You understand the use case perfectly, Iโ€™m genuinely grateful you took the time to read and understand my posts on this thread (I know they were long). โ˜บ๏ธ Iโ€™m actually almost done with Step 1. Using the net_admin capability was key so I should be finished with that tonight. Step 2 would be a slight change in Cloudronโ€™s manifest so as to identify an app as a โ€˜network clientโ€™ and then you could easily have a drop down at the app in Cloudron to list all other Cloudron apps flagged as a โ€œnetwork clientโ€ (of which the OpenVPN Client Iโ€™m making would be the first) to choose from. The Cloudron app switching itโ€™s network connection would need to be restarted for the change to take effect I believe (but am not ๐Ÿ’ฏ on that).

                Again, Iโ€™m kind of blown away by you guys being so engaging with us (your users) so if thereโ€™s anything else I can do aside from finishing building my fork of the VPN Client for Cloudron, let me know!

                1 Reply Last reply
                0
                • girishG Offline
                  girishG Offline
                  girish
                  Staff
                  wrote on last edited by
                  #16

                  @Lonk Thanks for the encouragement ๐Ÿ™‚ and let us know if you need help finishing up the client part.

                  Do you know how docker behaves when it comes to routing? There is a docker network attach that lets us attach the container to multiple networks. This is required on Cloudron because the addons like databases are in a network named cloudron. With your app, we will attach the app to the vpn client and cloudron network. I wonder how we can "route" all internet traffic via the vpn client. I can't find any obvious docs for this.

                  1 Reply Last reply
                  1
                  • mehdiM Offline
                    mehdiM Offline
                    mehdi
                    App Dev
                    wrote on last edited by
                    #17

                    I think automatically detecting and proposing "network providers" apps in a dropdown would not be very easy... Plus, I think a lot of other apps would benefit from "providing" services to other apps, like a minio instance could provide object storage for other apps.

                    But this is a big undertaking in my opinion.

                    In the meantime, simply providing an UI to add custom docker options manually would do the job I think. It would not be as easy to use, but with a little bit of doc it should be doable even for someone who doesn't know docker inside and out. Plus, it would obviously allow a lot of other customizations.

                    1 Reply Last reply
                    2
                    • girishG Offline
                      girishG Offline
                      girish
                      Staff
                      wrote on last edited by
                      #18

                      I think maybe adding fields to manifest etc to identify network client might be an overkill right now. What I was thinking is just to have an API to set an existing app id as the container's network. This is easy for the backend to do, we have to simply issue docker network attach. For the frontend dropdown, it can simply filter out network providers based on the manifest appstore id for now (hardcoded to openvpn client). Should be fine.

                      But I think the bigger thing to be figured out is how the routing works.

                      1 Reply Last reply
                      0
                      • LonkleL Offline
                        LonkleL Offline
                        Lonkle
                        wrote on last edited by Lonkle
                        #19

                        @girish Would docker connect work better in this regard? And also, I agree with the hardcoded dropdown to "openvpn-client" (manifest appstore id).

                        This is how I do it locally with just Docker:

                        docker run -it --cap-add=NET_ADMIN --device /dev/net/tun --dns 8.8.8.8 --name openvpn-client -e "CONNECTION_TIMEOUT=-1" -p 3000:3000 lonk/openvpn-client:latest

                        That starts the OpenVPN Client Docker and connects it to vpn.conf (a hardcoded VPN server). I set the DNS because the VPN can't seem to get the DNS otherwise for some reason, and I set the port because the other container needs that port to be open.

                        So then I connect my next Docker container to the VPN Client container at runtime:

                        docker run --name chrome -"CONNECTION_TIMEOUT=-1" --net=container:openvpn-client viridiancloud/chrome:latest

                        This works perfectly locally, the chrome container runs everything through the VPN if I pass the --net=container:openvpn-client on runtime. I'm trying to get the puppeteer container to use the network of the openvpn-client while it's still running now. Experimenting with docker network connect now on my localhost.

                        I may need to create a network somehow and assign the OpenVPN Client Docker to that. Looking into it now so we can further understand how to get this working in the cloudron network context (or in addition to it since containers can connect to multiple networks at once).

                        girishG 1 Reply Last reply
                        0
                        • LonkleL Lonkle

                          @girish Would docker connect work better in this regard? And also, I agree with the hardcoded dropdown to "openvpn-client" (manifest appstore id).

                          This is how I do it locally with just Docker:

                          docker run -it --cap-add=NET_ADMIN --device /dev/net/tun --dns 8.8.8.8 --name openvpn-client -e "CONNECTION_TIMEOUT=-1" -p 3000:3000 lonk/openvpn-client:latest

                          That starts the OpenVPN Client Docker and connects it to vpn.conf (a hardcoded VPN server). I set the DNS because the VPN can't seem to get the DNS otherwise for some reason, and I set the port because the other container needs that port to be open.

                          So then I connect my next Docker container to the VPN Client container at runtime:

                          docker run --name chrome -"CONNECTION_TIMEOUT=-1" --net=container:openvpn-client viridiancloud/chrome:latest

                          This works perfectly locally, the chrome container runs everything through the VPN if I pass the --net=container:openvpn-client on runtime. I'm trying to get the puppeteer container to use the network of the openvpn-client while it's still running now. Experimenting with docker network connect now on my localhost.

                          I may need to create a network somehow and assign the OpenVPN Client Docker to that. Looking into it now so we can further understand how to get this working in the cloudron network context (or in addition to it since containers can connect to multiple networks at once).

                          girishG Offline
                          girishG Offline
                          girish
                          Staff
                          wrote on last edited by girish
                          #20

                          @Lonk said in Better documentation for the API:

                          Would docker connect work better in this regard

                          Is this a new command? Atleast, I don't have this in my docker 19.03.12.

                          $ docker connect
                          docker: 'connect' is not a docker command.
                          See 'docker --help'
                          

                          edit: don't mind me, I guess they are just typos. docker network connect and docker network attach, I guess. I wasn't aware of this connect subcommand.

                          edit2: there is no, docker network attach ๐Ÿ™‚ I meant docker network connect all the time.

                          LonkleL 2 Replies Last reply
                          0
                          • girishG girish

                            @Lonk said in Better documentation for the API:

                            Would docker connect work better in this regard

                            Is this a new command? Atleast, I don't have this in my docker 19.03.12.

                            $ docker connect
                            docker: 'connect' is not a docker command.
                            See 'docker --help'
                            

                            edit: don't mind me, I guess they are just typos. docker network connect and docker network attach, I guess. I wasn't aware of this connect subcommand.

                            edit2: there is no, docker network attach ๐Ÿ™‚ I meant docker network connect all the time.

                            LonkleL Offline
                            LonkleL Offline
                            Lonkle
                            wrote on last edited by
                            #21

                            @girish said in VPN tunnel for apps:

                            there is no, docker network attach I meant docker network connect all the time.

                            Okay, that makes a lot of sense, when you mentioned the "network" attach command, I figured I had some reading up to do. ๐Ÿ˜‚

                            I edited my post to fix my typo and remove mentions of "docker attach".

                            LonkleL 1 Reply Last reply
                            0
                            • girishG girish

                              @Lonk said in Better documentation for the API:

                              Would docker connect work better in this regard

                              Is this a new command? Atleast, I don't have this in my docker 19.03.12.

                              $ docker connect
                              docker: 'connect' is not a docker command.
                              See 'docker --help'
                              

                              edit: don't mind me, I guess they are just typos. docker network connect and docker network attach, I guess. I wasn't aware of this connect subcommand.

                              edit2: there is no, docker network attach ๐Ÿ™‚ I meant docker network connect all the time.

                              LonkleL Offline
                              LonkleL Offline
                              Lonkle
                              wrote on last edited by Lonkle
                              #22

                              @girish I have finished converting the app into a Cloudron app and have pushed it to the Docker Hub, there appears to be one issue with these two lines in the start.sh file:

                              mkdir -p /dev/net
                              [[ -c /dev/net/tun ]] || mknod -m 0666 /dev/net/tun c 10 200

                              There seems to be an issue with this part of the starting script. Likely related to this docker run argument that I run locally --device /dev/net/tun. This is the exact error I get when attempting to run it on Cloudron (despite it successfully running locally with strictly Docker).

                              ERROR: Cannot ioctl TUNSETIFF tun: Operation not permitted (errno=1)

                              What do you think on the Cloudron side of things there?

                              1 Reply Last reply
                              0
                              • LonkleL Lonkle

                                @girish said in VPN tunnel for apps:

                                there is no, docker network attach I meant docker network connect all the time.

                                Okay, that makes a lot of sense, when you mentioned the "network" attach command, I figured I had some reading up to do. ๐Ÿ˜‚

                                I edited my post to fix my typo and remove mentions of "docker attach".

                                LonkleL Offline
                                LonkleL Offline
                                Lonkle
                                wrote on last edited by
                                #23

                                @Lonk Note: I submitted the DockerHub link for you here (https://www.cloudron.io/app-developer.html) to pull and test yourself locally via docker run -it --cap-add=NET_ADMIN --device /dev/net/tun --dns 8.8.8.8 image/name (which will succeed, just try curl icanhazip.com in the Docker container and it will see a different IP address). Then check the logs on cloudron when trying to install to it and you'll see the issues with /net/tun that don't exist locally.

                                1 Reply Last reply
                                0
                                • girishG Offline
                                  girishG Offline
                                  girish
                                  Staff
                                  wrote on last edited by
                                  #24

                                  @Lonk Have you pushed the package source code somewhere?

                                  1 Reply Last reply
                                  0
                                  • girishG Offline
                                    girishG Offline
                                    girish
                                    Staff
                                    wrote on last edited by
                                    #25

                                    For the tun device stuff, @mehdi solved it by creating the device in Dockerfile - https://git.cloudron.io/cloudron/openvpn-app/-/blob/master/Dockerfile#L30 (RUN mknod /app/code/net-tun c 10 200) and then using dev-node /app/code/net-tun option in openvpn.conf

                                    LonkleL 1 Reply Last reply
                                    0
                                    • mehdiM Offline
                                      mehdiM Offline
                                      mehdi
                                      App Dev
                                      wrote on last edited by
                                      #26

                                      It's quite a long time ago now that I wrote the openvpn-server app, but I remember that this ton device stuff was hell ๐Ÿ˜› (Plus, Cloudron did not have support for capabilities like NET_ADMIN back then, so I had to implement that in the server itself^^)

                                      @Lonk in your command line, you forward the host's /dev/net/tun device to the container, which cloudron does not do, so the problem probably comes from there.

                                      If @girish's suggestion of using the same trick as the openvpn-server app does not work, I'd be happy to take a look.

                                      1 Reply Last reply
                                      0
                                      • girishG girish

                                        For the tun device stuff, @mehdi solved it by creating the device in Dockerfile - https://git.cloudron.io/cloudron/openvpn-app/-/blob/master/Dockerfile#L30 (RUN mknod /app/code/net-tun c 10 200) and then using dev-node /app/code/net-tun option in openvpn.conf

                                        LonkleL Offline
                                        LonkleL Offline
                                        Lonkle
                                        wrote on last edited by Lonkle
                                        #27

                                        I worked on this for a few more hours tonight and after editing the starting script and DOCKERFILE (and a dumb mess up with CloudronManifest.json), I now have it 100% working within Cloudron.

                                        Thank you so much for your help @girish / @mehdi!

                                        There's a bunch of polish now that needs to be made. Proper healthcheck since this doesn't have a web admin exposed yet. I'll be making a custom web admin to change out VPN files (.ovpn) and credentials to make this a proper web app for Cloudron. For now, I'm just going to fake the healthcheck in testing just to see if we can connect containers using @girish Cloudron's code edit idea to make another container use my OpenVPN Client's Container's Network (akin to docker run's --net=container:vpn-client command).

                                        PS. @girish, I haven't published the code on Github yet because I've hardcoded my home's VPN credentials in there since this is just a proof of concept. I gave you guy's the DockerHub link through this form: https://www.cloudron.io/app-developer.html - so that only you guys would know the link to pull it to Cloudron. Once I make the VPN configurable, I'll be releasing the source. I'll fix the health check in the morning with v0.3. Until then, feel free to pull the image to Cloudron to install for your own testing purposes (the idea you had to make it connect to other Cloudron apps). If you don't have time to, or are unable, I can take a stab at editing the Cloudron code directly. Let me know! โ˜บ๏ธ

                                        1 Reply Last reply
                                        1
                                        • LonkleL Offline
                                          LonkleL Offline
                                          Lonkle
                                          wrote on last edited by Lonkle
                                          #28

                                          Alright, v0.3 release notes:

                                          โ€ข Uses cloudron:2.0 base image now.
                                          โ€ข Added apache to start the process of configuring a web interface (it'll need to do a few things like add dev-node /app/code/net-tun to the openvpn-server.ovpn files and convert them into vpn.conf files (which is stored in app/data so it's persistent and can change at anytime through an API endpoint I'm going to write...for now, you can change the file yourself and add it in the Cloudron File Manager and then restart the app).
                                          โ€ข Fixed the healthcheck so that Cloudron now runs it as a full fledged app

                                          This is at the point where I'm ready to upload it to Github tonight and I'll post the link. I just need to revoke my personal OVPN Server certificate first before I do that and I have some more testing when it comes to the web interface and modifying files.

                                          @girish Do you have any questions from me in order to make your side of things (Cloudron's base code) connect to this container's network to other apps on Cloudron? Were you able to find and pull my testing image from the DockerHub through the form I submitted - which I did get a response, as I'm now in the contributor program ๐ŸŽ‰ and I'm happy to be because developing with Cloudron is just getting more and more fun. I have some ideas for Wordpress which is where my real expertise is. I'll finish this project and then move onto that after you guys release 6.0 (since I know it's coming with Wordpress changes).

                                          1 Reply Last reply
                                          3
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Bookmarks
                                          • Search