netbirdio / netbird

Connect your devices into a secure WireGuard®-based overlay network with SSO, MFA and granular access controls.
https://netbird.io
BSD 3-Clause "New" or "Revised" License
11.03k stars 507 forks source link

netbird client inside docker: can not access to status or route list: context deadline exceeded #2345

Open bravosierrasierra opened 3 months ago

bravosierrasierra commented 3 months ago

Describe the problem

Can not access to netbird daemon from outside docker container. Daemon successfully started and registered in mesh with docker compose up -d

But i am can not access to daemon stats and routes:

$ docker compose exec netbird_client netbird --daemon-addr=unix:///var/run/netbird.sock status Error: failed to connect to daemon error: context deadline exceeded If the daemon is not running please run: netbird service install netbird service start

$ docker compose exec netbird_client ls -laF /var/run/ total 8 drwxr-xr-x 2 root root 4096 Jun 18 15:37 ./ drwxr-xr-x 1 root root 4096 Jul 29 14:48 ../ ubuntu@netbird-gw-dev-dc-01 .../docker-compose/netbird $

To Reproduce

use "docker compose up -d" and then "docker compose exec netbird_client netbird status" with this docker-compose.yaml:

services:
  netbird_client:
    image: "netbirdio/netbird:latest"
    restart: always
    logging:
      driver: local
    labels:
      logging: "promtail"
      logging_jobname: "containerlogs"
    container_name: netbird_client
    cap_add:
      - NET_ADMIN
      - SYS_ADMIN
      - SYS_RESOURCE
    environment:
      - NB_SETUP_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
      - NB_HOSTNAME=netbird-gw-dev-dc.domain.com
      - NB_SERVICE=netbird
      - NB_DAEMON_ADDR=unix:///var/run/netbird.sock
      - NB_MANAGEMENT_URL=https://mgmt.domain.com:33073
      - NB_LOG_LEVEL=debug
    volumes:
      - netbird-client:/etc/netbird
    network_mode: host
    privileged: true

volumes:
  netbird-client:
    driver: local

Expected behavior

netbird status should be fetched and printed

Are you using NetBird Cloud?

self-host NetBird's control plane

NetBird version

latest, 0.28.4, 0.27.7

itoffshore commented 3 months ago

I noticed the same issue under a privileged podman container / cloud hosted netbird

Maybe a good solution here would be to add a small function to detect if netbird is running in a container (query /proc/1/cgroup) - & if so skip the daemon check when querying status