gravitl / netmaker

Netmaker makes networks with WireGuard. Netmaker automates fast, secure, and distributed virtual networks.
https://netmaker.io
Other
9.5k stars 552 forks source link

Failed to register to http://HOMEIP:31742/api/client/register request to server failed: 500 Internal Server Error #189

Closed linuxd3v closed 3 years ago

linuxd3v commented 3 years ago

Hi - very interesting project, trying to get it to work but failing.

Trying to launch the mongo/api/ui stack on my homenetwork and then connect to remote VPS. Client errors out with this message:

sudo ./netclient register -t MYTOKEN
2021/06/25 11:46:08 Failed to register to http://HOMEIP:31742/api/client/register
2021/06/25 11:46:08 request to server failed: 500 Internal Server Error

At the same time Im seeing this in the server docker logs:

netmaker-api   | UniqueAddress encountered  an error
netmaker-api   | {500 mongo: no documents in result}`

Iim launching docker compose like this:

version: "3.5" 

networks:
  default:
    external:
      name: infranet

services:
  mongodb:
    image: mongo:4.2
    ports:
      - ${MONGO_PORT}:${MONGO_PORT}
    container_name: ${PROJECT_NAME}-mongodb
    volumes:
      -  ${FS_DIR}/mongo/datadb:/data/db
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_ROOT_USER}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ROOT_PASSWORD}
    command: mongod --port ${MONGO_PORT}

  netmaker:
    container_name: ${PROJECT_NAME}-api
    ports:
      - ${PORT_HOST_API}:${PORT_CNT_API}
      - ${PORT_HOST_GRPC}:${PORT_CNT_GRPC}
    depends_on:
      - mongodb
    image: gravitl/netmaker:v0.5
    restart: always
    environment:
      SERVER_HOST: ${EXTERNAL_API_IP}
      DNS_MODE: "off"
      CLIENT_MODE: "off"
      GRPC_PORT: ${PORT_CNT_GRPC}
      API_PORT: ${PORT_CNT_API}
      MONGO_HOST: ${PROJECT_NAME}-mongodb
      MONGO_PORT: ${MONGO_PORT}
      MONGO_ADMIN: ${MONGO_ROOT_USER}
      MONGO_PASS: ${MONGO_ROOT_PASSWORD}
      SERVER_GRPC_WIREGUARD: "off"

  netmaker-ui:
    container_name: ${PROJECT_NAME}-ui
    depends_on:
      - netmaker
    image: gravitl/netmaker-ui:v0.5
    restart: always
    ports:
      - ${PORT_HOST_UI}:${PORT_CNT_UI}
    environment:
      BACKEND_URL: http://${LOCAL_API_IP}:${PORT_HOST_API}

With the following .env file:

#general settings
COMPOSE_PROJECT_NAME=netmaker
PROJECT_NAME=netmaker
FS_DIR=/mnt/480g_drive/dockervolumes/netmaker

#mysql settings
MONGO_ROOT_USER=mongoadmin
MONGO_ROOT_PASSWORD=SOME_PASS
MONGO_PORT=31743

#HOSTS
LOCAL_API_IP=192.168.10.103
EXTERNAL_API_IP=HOMEIP
EXTERNAL_API_HOST=HOMEDOMAIN

#PORTS
#UI
PORT_HOST_UI=31741
PORT_CNT_UI=80

#API
PORT_HOST_API=31742
PORT_CNT_API=31742

#GRPC
PORT_HOST_GRPC=31744
PORT_CNT_GRPC=31744

I also forward grpc and api ports through my router. (31744, 31742)

halp. lol. Any advice is appreciated.

afeiszli commented 3 years ago

@linuxd3v so you are running the main server on your home network and are attempting to attach a client from the VPS? Or is it the other way around? I am trying to understand if this is an issue with the provided public IP for your api server, which looks like will be providing your local address currently.

linuxd3v commented 3 years ago

@afeiszli correct. trying to launch main server on home network and connect client from the VPS.

I am trying to understand if this is an issue with the provided public IP for your api server, which looks like will be providing your local address currently.

well Ive omitted my external ip from above config but im populating it in EXTERNAL_API_IP=HOMEIP code. instead of HOMEIP there would be my external ip.

afeiszli commented 3 years ago

I see you are doing port forwarding but have you confirmed that the api is reachable from an external network before running the netclient? Typically I would deploy the netmaker server to a VPS.

afeiszli commented 3 years ago

Also, with "UniqueAddress encountered an error"...what is the network range you've defined for the network?

linuxd3v commented 3 years ago

@afeiszli

I see you are doing port forwarding but have you confirmed that the api is reachable from an external network before running the netclient?

Hi - it is reachable. well I've recchecked router port forwarding. And also the fact that I can see above error in the netmaker-api docker logs (which is within home network) i think is already enough to confirm reachability. I see this error exactly when I call netclient register -t from the vps.

Typically I would deploy the netmaker server to a VPS.

that would be my next test - however for my use-case I would prefer if I could host from home network.

Also, with "UniqueAddress encountered an error"...what is the network range you've defined for the network?

currently using: 10.200.117.0/24

afeiszli commented 3 years ago

Does "docker logs netmaker" give any additional logs related to the UniqueAddress error? Also, is "Secure GRPC" mode enabled (it is by default)?

linuxd3v commented 3 years ago

Does "docker logs netmaker" give any additional logs related to the UniqueAddress error?

unfortunately not really, thats the extent of it unless there is some way to increase verbosity.

all error relevant data seems to be this: "UniqueAddress encountered an error {500 mongo: no documents in result}"

2021/07/02 09:28:44 MongoDB Connected. 2021/07/02 09:28:44 Creating default network... 2021/07/02 09:28:44 Default network already exists. Skipping... 2021/07/02 09:28:44 main.go:146: Agent Server succesfully started on port 31744 (gRPC) 2021/07/02 09:28:44 main.go:162: Setup complete. You are ready to begin using netmaker. 2021/07/02 09:28:44 controller.go:47: REST Server succesfully started on port 31742 (REST) UniqueAddress encountered an error {500 mongo: no documents in result} UniqueAddress encountered an error {500 mongo: no documents in result}

Also, is "Secure GRPC" mode enabled (it is by default)?

if it is on by default then should be on - I haven notg disabled it intentionally to my best knowledge.

Punkado commented 3 years ago

I am having the same problem here, did you manage to find a solution?

linuxd3v commented 3 years ago

@Punkado I did not. Ive tried another wireguard mesh tool called innernet which happened to worked for me out of the box. but I would definately be interested to get netmaker working as getting UI would be great.

afeiszli commented 3 years ago

@linuxd3v @Punkado The issue with mongo was due to empty queries returning errors under certain circumstances. This has been fixed in the 0.7 release which is coming out tomorrow (8/11/21).

linuxd3v commented 3 years ago

@afeiszli Ah that's awesome. Ill close this ticket then and reopen if new version doesnt resolve it. Thank you!