GyulyVGC / sniffnet

Comfortably monitor your Internet traffic 🕵️‍♂️
https://sniffnet.net
Apache License 2.0
14.73k stars 453 forks source link

Make a container available for easy deployment #69

Open Jogai opened 1 year ago

Jogai commented 1 year ago

A container makes it easy to test and run software. Containers are common practice among self hosters, and this software looks like it would be of interest to them, I think this is a valuable addition.

Maybe take some inspiration from https://github.com/RustScan/RustScan (its also about networks, and built with rust).

GyulyVGC commented 1 year ago

I'm already considering to make a container and I plan to publish it in the near future!

GyulyVGC commented 1 year ago

I started drafting a Dockerfile and I encountered some problems. The build of the container goes smoothly, but when I try to run it I get errors of missing dependencies. This are the dependencies needed from Sniffnet, but it seems that more dependencies are needed to run it from the built container. This is my current Dockerfile:

FROM rust as builder
WORKDIR /usr/src/sniffnet
COPY . .
RUN apt-get update && apt-get install -y libpcap-dev libasound2-dev libfontconfig libfontconfig1-dev && cargo install --path .

FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y libpcap-dev libasound2-dev libfontconfig libfontconfig1-dev
COPY --from=builder /usr/local/cargo/bin/sniffnet /usr/local/bin/sniffnet
CMD ["sniffnet"]

After the run error which specify the missing dependency, I added it and re-built. But when I run again, another missing dependency is pointed out.

How can I know a priori all the required dependency of this process? It took about 20 minutes to compile the container and I cannot wait this time every time just to find out the next missing dependency.

GyulyVGC commented 1 year ago

Update: after having included other apparently needed dependencies (libxcursor1, libxrandr2, libxi-dev, libx11-xcb-dev) I now get this error:

thread 'main' panicked at 'Failed to initialize any backend! Wayland status: XdgRuntimeDirNotSet X11 status: XOpenDisplayFailed', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.27.5/src/platform_impl/linux/mod.rs:719:9

I've already tried to set export DISPLAY=:0 as suggested from different sources online, but the error doesn't change. I will investigate a bit more.

AmadeusGraves commented 1 year ago

I find some related issues, @GyulyVGC this may be helpful for you.

https://github.com/bevyengine/bevy/discussions/4921

AmadeusGraves commented 1 year ago

I was thinking. If you already have your project compiled on .deb file, why you don't use it on the dockerfile and install all dependencies with the command.

https://askubuntu.com/questions/40011/how-to-let-dpkg-i-install-dependencies-for-me

Sorry, I don't have much experience with docker, if my solution doesn't make any sense I apologise in advance.

GyulyVGC commented 1 year ago

I was thinking.

If you already have your project compiled on .deb file, why you don't use it on the dockerfile and install all dependencies with the command.

This is an interesting point and I could try it out. However, if the problem is with the rendering I think it will persist even in this case. I'll let you know if I have any update.

abbbi commented 1 year ago

I made it work for me on debian bullseye with attached dockerfile (bcs of #138) My system is setup with amd renoir GPU, configured so its working with "radeontop". Forwarding the required devices files and xauthority stuff for X11 forwarding via docker command. Alternatively you might want to use docker --gpu all option, if that works out for you. sniffnet-works

Build:

sudo docker build . -t sniffnet

Run:

sudo -E docker run --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --group-add video --privileged -it sniffnet

alternative w/o --privileged

sudo -E docker run --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" --group-add video --device /dev/dri/ -it sniffnet

FROM rust as builder
WORKDIR /usr/src/sniffnet
COPY . .
RUN apt-get update && apt-get install -y libpcap-dev libasound2-dev libfontconfig libfontconfig1-dev && cargo install --path .

FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y libpcap-dev libasound2-dev libfontconfig libfontconfig1-dev libxcursor1 libxrandr2 libxi6 libx11-xcb1  xauth libegl1 libgl1-mesa-dri
COPY --from=builder /usr/local/cargo/bin/sniffnet /usr/local/bin/sniffnet
CMD ["sniffnet"]

If GPU is not working correctly, you might receive:

WARNING: lavapipe is not a conformant vulkan implementation, testing use only

and application malfunctions (quits after first attempt to use mouse)

PS (#138) I dont know how the released .deb package was built (using cargo helpers?) However, the resulting binary linking against the wrong openssl version suggests the debian package was built on a different system than debian bullseyes and additionally, its missing all the required dependencies in debian/control file, which are usually auto generated by the debian packaging scripts. You might want to change the way you build the debian package at all, becasue the build process seems quite broken.

GyulyVGC commented 1 year ago

PS (#138) I dont know how the released .deb package was built (using cargo helpers?) However, the resulting binary linking against the wrong openssl version suggests the debian package was built on a different system than debian bullseyes and additionally, its missing all the required dependencies in debian/control file, which are usually auto generated by the debian packaging scripts. You might want to change the way you build the debian package at all, becasue the build process seems quite broken.

I'm changing the way packages are created and I need some feedbacks.

Now dependencies are included in the control file and also the openssl version problem should be fixed.

sniffnet_1.2.0_amd64.deb.zip

@abbbi could you confirm that this DEB package works fine for you?

abbbi commented 1 year ago

tested in latest bulleye container:

root@cefix-bullseye-amd64-moa3:/srv# unzip sniff.zip Archive: sniff.zip inflating: sniffnet_1.2.0_amd64.deb
inflating: __MACOSX/._sniffnet_1.2.0_amd64.deb
root@cefix-bullseye-amd64-moa3:/srv# cat /etc/issue Debian GNU/Linux 11 \n \l

root@cefix-bullseye-amd64-moa3:/srv# apt install ./sniffnet_1.2.0_amd64.deb 
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'sniffnet' instead of './sniffnet_1.2.0_amd64.deb'
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 sniffnet : Depends: libssl3 (>= 3.0.0~~alpha1) but it is not installable
            Depends: libc6 (>= 2.35) but 2.31-13+deb11u6 is to be installed
E: Unable to correct problems, you have held broken packages.
GyulyVGC commented 1 year ago

Weird. The package has been created with cargo-deb this time (with auto generated dependencies).

Edit: I've also tried by manually specifying run deps but it still gives me an error related to libssl.so.8 not found

marc-gav commented 5 months ago

Hi guys. I have started attempting this issue again. You can find my draft PR here: https://github.com/GyulyVGC/sniffnet/pull/455/files

Let me know if I have understood this right. We want a Docker image that can allow users to run the app automatically right?

Could you help me out with this error?

[+] Building 3.2s (6/6) FINISHED                                                                                                                                                                      docker:desktop-linux
 => [build-image internal] load build definition from Dockerfile                                                                                                                                                      0.0s
 => => transferring dockerfile: 142B                                                                                                                                                                                  0.0s
 => [build-image internal] load metadata for docker.io/homebrew/ubuntu22.04:latest                                                                                                                                    3.0s
 => [build-image internal] load .dockerignore                                                                                                                                                                         0.0s
 => => transferring context: 2B                                                                                                                                                                                       0.0s
 => [build-image 1/3] FROM docker.io/homebrew/ubuntu22.04:latest@sha256:5575416635b5e552cd8faa54cdfe708f9169200246cd10118c450cbf545a6075                                                                              0.0s
 => CACHED [build-image 2/3] RUN brew install sniffnet                                                                                                                                                                0.0s
 => ERROR [build-image 3/3] RUN ["sniffnet"]                                                                                                                                                                          0.2s
------                                                                                                                                                                                                                     
 > [build-image 3/3] RUN ["sniffnet"]:
0.153 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: PcapError("tunl0: SIOCETHTOOL(ETHTOOL_GLINK) ioctl failed: Inappropriate ioctl for device")', src/configs/types/config_device.rs:19:43
0.154 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
------
failed to solve: process "sniffnet" did not complete successfully: exit code: 1
GyulyVGC commented 5 months ago

Hi guys. I have started attempting this issue again. You can find my draft PR here: https://github.com/GyulyVGC/sniffnet/pull/455/files

Thank you!

Let me know if I have understood this right. We want a Docker image that can allow users to run the app automatically right?

Yes, this would allow to easily run Sniffnet on any kind of system without worrying about dependencies and the running environment in general

Could you help me out with this error?

[...]                                                                                                                                                                                                                
 > [build-image 3/3] RUN ["sniffnet"]:
0.153 thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: PcapError("tunl0: SIOCETHTOOL(ETHTOOL_GLINK) ioctl failed: Inappropriate ioctl for device")', src/configs/types/config_device.rs:19:43
0.154 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[...]

This is due an error in the opening of the default network device. I'm not sure which network interface is considered default in that kind of environment, but it seems that something is not properly setup.

If you got this error I suppose you are using v1.2.2. Try using the main branch, where in case the default device returns an error I just pass a device with an empty name. Even in this case though, I suspect we can get anything useful from a fake device... but maybe it can be helpful to start debugging deeper.

marc-gav commented 5 months ago

I am studying how Docker deals with networks. I'll get back with some solutions and insights

marc-gav commented 5 months ago

I am considering running the app in a detached state and then doing SSH X11 forwarding to interact with it.

Some progress... I am building with

FROM rust:bullseye as builder
RUN apt-get upgrade -y && apt-get update
RUN apt-get install -y libpcap-dev libasound2-dev libfontconfig1-dev libgtk-3-dev
RUN apt-get install -y xorg openbox
RUN cargo install sniffnet
RUN apt-get install libx11-dev
RUN addgroup --system sniffnet
RUN adduser --system sniffnet --ingroup sniffnet
RUN ulimit -n 100000
USER sniffnet
CMD ["sniffnet"]

I get the following error:

➜  sniffnet git:(feat-docker-container-deployment) ✗ docker compose run sniffnet

  /---------------------------------------------------------\
 |     _____           _    __    __                  _      |
 |    / ____|         (_)  / _|  / _|                | |     |
 |   | (___    _ __    _  | |_  | |_   _ __     ___  | |_    |
 |    \___ \  | '_ \  | | |  _| |  _| | '_ \   / _ \ | __|   |
 |    ____) | | | | | | | | |   | |   | | | | |  __/ | |_    |
 |   |_____/  |_| |_| |_| |_|   |_|   |_| |_|  \___|  \__|   |
 |                                                           |
 |                   ___________                             |
 |                  /___________\                            |
 |                 | ___________ |                           |
 |                 | |         | |                           |
 |                 | | v1.2.2  | |                           |
 |                 | |_________| |________________________   |
 |                 \_____________/   by Giuliano Bellini  )  |
 |                 / ''''''''''' \                       /   |
 |                / ::::::::::::: \                  =D-'    |
 |               (_________________)                         |
  \_________________________________________________________/
thread 'main' panicked at /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.28.7/src/platform_impl/linux/mod.rs:757:9:
Failed to initialize any backend! Wayland status: XdgRuntimeDirNotSet X11 status: XOpenDisplayFailed
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    %         
GyulyVGC commented 5 months ago

This error is due to the winit dependency used by Iced, the GUI library used for Sniffnet. In some Wyland environments this seems to happen and a fix that always work was still not found I think. Maybe try setting an env var ICED_BACKEND=tiny-skia which tells the program to use the fallback graphical renderer.

marc-gav commented 5 months ago

Okay I see. I'll look for some references of projects that reliably run Iced inside Docker. As an alternative, a web interface like Pi-Hole could be useful