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
  • Brite
  • 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

Offical apps | Community apps | Demo | Docs | Install
  1. Cloudron Forum
  2. Support
  3. VPN Protection (internal apps)

VPN Protection (internal apps)

Scheduled Pinned Locked Moved Solved Support
vpn
15 Posts 3 Posters 175 Views 3 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.
  • girishG
    girishG
    girish
    Staff
    wrote last edited by girish
    #4

    I have pushed a change for the next release.

    Workaround is to add 172.18.0.0/16 and fd00:c107:d509::/64 in the allowed IP addresses list.

    1 Reply Last reply
    0
    • girishG girish has marked this topic as solved
    • sponchS
      sponchS
      sponch
      wrote last edited by
      #5

      @girish already tried that before --> "Could not save VPN access policy: 172.18.0.0/16 includes internal docker network"

      1 Reply Last reply
      1
      • girishG
        girishG
        girish
        Staff
        wrote last edited by girish
        #6

        @sponch ah right 🤦 Will get a patch release out once we accumulate some more fixes. You can also manually apply https://git.cloudron.io/platform/box/-/commit/5a0bcbb1cd2b5f7f4eccfcd1a521be863c250b44 (only the .ejs file fix is needed)

        1 Reply Last reply
        2
        • necrevistonnezrN
          necrevistonnezrN
          necrevistonnezr
          Super Fan
          wrote last edited by necrevistonnezr
          #7

          After applying the patch, I still can't access a VPN-protected app from inside the server network.
          For me, the following script works via cron (enter your correct values in the API_URL and the API_TOKEN; make sure jq is installed):

          #!/usr/bin/env bash
          set -euo pipefail
          
          API_URL="https://REPLACE_WITH_YOUR_CLOUDRON_DOMAIN/api/v1/network/vpn_access_config"
          API_TOKEN="REPLACE_WITH_YOUR_CLOUDRON_API_TOKEN"
          MARKER_PREFIX="# AUTO-DYNAMIC-SERVER-IP"
          TIMESTAMP=$(date +%Y%m%d_%H%M)
          MARKER="${MARKER_PREFIX} ${TIMESTAMP}"
          
          # 1. Fetch current public IPv4 address using Cloudron's helper endpoint
          PUBLIC_IP=$(curl -fsS --max-time 10 https://ipv4.api.cloudron.io/api/v1/helper/public_ip | jq -r '.ip // empty')
          
          if [[ ! "$PUBLIC_IP" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
              echo "Failed to retrieve a valid public IPv4 address: '$PUBLIC_IP'" >&2
              exit 1
          fi
          
          TARGET_IP="${PUBLIC_IP}/32"
          
          # 2. Fetch the current VPN access configuration from Cloudron
          TMP_CFG=$(mktemp)
          TMP_RESP=$(mktemp)
          trap 'rm -f "$TMP_CFG" "$TMP_RESP"' EXIT
          
          curl -fsS --max-time 10 -H "Authorization: Bearer ${API_TOKEN}" "${API_URL}" > "$TMP_CFG"
          
          # 3. Build payload: remove any previous auto-managed block and append the current timestamp + IP
          PAYLOAD=$(jq --arg prefix "$MARKER_PREFIX" --arg marker "$MARKER" --arg ip "$TARGET_IP" '
              ((.allowlist // "") | split("\n")) as $lines
              | (
                  reduce range(0; $lines | length) as $i (
                    {out: [], skip_next: false};
                    if .skip_next then
                      .skip_next = false
                    elif ($lines[$i] | startswith($prefix)) then
                      .skip_next = true
                    else
                      .out += [$lines[$i]]
                    end
                  )
                  | .out
                  | join("\n")
                  | gsub("^\\n+|\\n+$"; "")
                ) as $cleaned
              | {
                  enabled: true,
                  vpnAppId: .vpnAppId,
                  tunnelRouting: .tunnelRouting,
                  allowlist: (
                    [
                      $cleaned,
                      ($marker + "\n" + $ip)
                    ]
                    | map(select(length > 0))
                    | join("\n")
                  )
                }
          ' < "$TMP_CFG")
          
          # 4. Push the updated configuration to the Cloudron API
          HTTP_CODE=$(printf '%s' "$PAYLOAD" | curl -sS --max-time 15 -o "$TMP_RESP" -w "%{http_code}" \
              -X POST "${API_URL}" \
              -H "Authorization: Bearer ${API_TOKEN}" \
              -H "Content-Type: application/json" \
              -d @-)
          
          if [[ "$HTTP_CODE" == "200" ]]; then
              logger -t cloudron-vpn-ip "Updated VPN allowlist to ${TARGET_IP} (${TIMESTAMP})"
              echo "Successfully updated: ${TARGET_IP} (${TIMESTAMP})"
          else
              logger -t cloudron-vpn-ip "Failed to update VPN allowlist (HTTP $HTTP_CODE): $(cat "$TMP_RESP")"
              echo "API error (HTTP $HTTP_CODE): $(cat "$TMP_RESP")" >&2
              exit 1
          fi
          

          The script fetches the current public IPv4 from ipv4.api.cloudron.io, reads the existing VPN configuration via the Cloudron API (/api/v1/network/vpn_access_config), replaces only its own marked block (# AUTO-DYNAMIC-SERVER-IP <YYYYMMDD_HHMM> + <IP>/32), and writes the updated configuration back via POST. Any manually maintained allowlist entries remain untouched, and the timestamp in the comment lets you see directly in the dashboard when the last update ran.

          1 Reply Last reply
          0
          • girishG
            girishG
            girish
            Staff
            wrote last edited by
            #8

            @necrevistonnezr you have to regenerate the nginx config. For this, you can simple toggle the VPN checkbox and it should regeneate it. Could that be it?

            1 Reply Last reply
            0
            • necrevistonnezrN
              necrevistonnezrN
              necrevistonnezr
              Super Fan
              wrote last edited by necrevistonnezr
              #9

              Sorry, what is the "VPN checkbox"? There's no checkbox under "Network" --> "VPN protection". Or do you mean I have to disable / enable VPN for each app (if so, that doesn't work)?

              BTW: I LOVE this feature in general!!

              1 Reply Last reply
              1
              • girishG
                girishG
                girish
                Staff
                wrote last edited by
                #10

                @necrevistonnezr I meant the https://docs.cloudron.io/apps#require-vpn "Require VPN" checkbox (App -> Access) .

                necrevistonnezrN 1 Reply Last reply
                0
                • girishG girish

                  @necrevistonnezr I meant the https://docs.cloudron.io/apps#require-vpn "Require VPN" checkbox (App -> Access) .

                  necrevistonnezrN
                  necrevistonnezrN
                  necrevistonnezr
                  Super Fan
                  wrote last edited by
                  #11

                  @girish said:

                  @necrevistonnezr I meant the https://docs.cloudron.io/apps#require-vpn "Require VPN" checkbox (App -> Access) .

                  This did not make a difference, as stated. I'll just wait for the next release and use my script until then. Again, this is a great feature!

                  1 Reply Last reply
                  0
                  • girishG
                    girishG
                    girish
                    Staff
                    wrote last edited by
                    #12

                    @necrevistonnezr mm, something is wrong then. Let me read your comment/script more closely. I am missing something.

                    1 Reply Last reply
                    1
                    • girishG
                      girishG
                      girish
                      Staff
                      wrote last edited by
                      #13

                      Got it now 😄 I completely skipped passed your messages. So, the fix was primarily for the Euro office issue which was accessing internally via Docker network. Your issue is separate and also valid. I have to make it work with the dynamic DNS also. Fixing.

                      1 Reply Last reply
                      2
                      • girishG
                        girishG
                        girish
                        Staff
                        wrote last edited by
                        #14

                        I fixed it to allow the public IP and also be in sync with the dynamic dns (when that feature is enabed). However, this didn't help my network situation. I use hairpin NAT and when the browser connects to the public IP, it comes back to the Cloudron as the internal network IP. So, I have to put 192.168.2.0/24 explicitly in the allow list and then it works.

                        So @necrevistonnezr I think if you have a situation like mine, you can update to 10.2.1 and then put your internal network in the VPN allow list.

                        necrevistonnezrN 1 Reply Last reply
                        1
                        • girishG girish

                          I fixed it to allow the public IP and also be in sync with the dynamic dns (when that feature is enabed). However, this didn't help my network situation. I use hairpin NAT and when the browser connects to the public IP, it comes back to the Cloudron as the internal network IP. So, I have to put 192.168.2.0/24 explicitly in the allow list and then it works.

                          So @necrevistonnezr I think if you have a situation like mine, you can update to 10.2.1 and then put your internal network in the VPN allow list.

                          necrevistonnezrN
                          necrevistonnezrN
                          necrevistonnezr
                          Super Fan
                          wrote last edited by
                          #15

                          @girish said:

                          I fixed it to allow the public IP and also be in sync with the dynamic dns (when that feature is enabed). However, this didn't help my network situation. I use hairpin NAT and when the browser connects to the public IP, it comes back to the Cloudron as the internal network IP. So, I have to put 192.168.2.0/24 explicitly in the allow list and then it works.

                          So @necrevistonnezr I think if you have a situation like mine, you can update to 10.2.1 and then put your internal network in the VPN allow list.

                          I’m on 10.2.1, followed your instructions - but when whitelisting 192.168.1.0/24 in my case, it’s still blocked. Whitelisting the external IP works.

                          1 Reply Last reply
                          0

                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                          With your input, this post could be even better 💗

                          Register Login
                          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