pigmonkey / nmtrust Goto Github PK
View Code? Open in Web Editor NEWA simple framework for determining network trust with NetworkManager
A simple framework for determining network trust with NetworkManager
We should check if the variables with the units are not empty. I don't have units configured in OFFLINE_SYSTEM_UNITS
and OFFLINE_USER_UNITS
this generates the following errors:
Nov 17 13:35:04 icarus nm-dispatcher[5665]: Too few arguments.
Nov 17 13:35:04 icarus nm-dispatcher[5603]: Starting trusted user offline units
Nov 17 13:35:04 icarus nm-dispatcher[5674]: Too few arguments.
Nov 17 13:35:04 icarus nm-dispatcher[5599]: req:1 'down' [wlp2s0], "/etc/NetworkManager/dispatcher.d/10trust": complete: failed with Script '/etc/NetworkManager/dispatcher.d/10trust' exited with error status 1.
Nov 17 13:35:04 icarus NetworkManager[1450]: <warn> [1605616504.9399] dispatcher: (21) /etc/NetworkManager/dispatcher.d/10trust failed (failed): Script '/etc/NetworkManager/dispatcher.d/10trust' exited with error status 1.
# sudo ttoggle
There are no active connections
Stopping trusted system units
Stopping trusted user units
Starting trusted system offline units
Too few arguments.
Starting trusted user offline units
usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
usage: sudo [-AbEHknPS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...
...
Starting trusted system offline units
+ systemctl start
Too few arguments.
...
+ sudo -u '' bash -c 'export XDG_RUNTIME_DIR=/run/user/1000; systemctl start --user '
usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
usage: sudo [-AbEHknPS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C num] [-D directory] [-g group] [-h host] [-p prompt] [-R directory] [-T timeout] [-u user] file ...
Hi man,
thanks for you cool repos and stuff :)
I have created the PKGBUILD for nmtrust, do you want to be a co-maintainer?
https://aur.archlinux.org/packages/nmtrust-git
Thanks you !
The dispatcher script gets executed for every connection. In my case it's loopback, WiFi, Docker bridged networks, etc. pp. This only happens at the system startup. It doesn't have a real negative impact except logging many messages in the log. The services are just "started multiple times".
Sep 04 17:13:13 icarus nm-dispatcher[1537]: req:9 'up' [wlp2s0], "/etc/NetworkManager/dispatcher.d/10trust": complete: failed with Script '/etc/NetworkManager/dispatcher.d/10trust' exited w>
...
Sep 04 17:13:14 icarus nm-dispatcher[2969]: All connections are trusted
Sep 04 17:13:14 icarus nm-dispatcher[2954]: Starting trusted system units
Sep 04 17:13:14 icarus nm-dispatcher[2954]: Starting trusted user units
...
Sep 04 17:13:14 icarus nm-dispatcher[1537]: req:12 'up' [br-4d9297e3e7cb], "/etc/NetworkManager/dispatcher.d/10trust": complete: failed with Script '/etc/NetworkManager/dispatcher.d/10trust>
...
Sep 04 17:13:15 icarus nm-dispatcher[3242]: All connections are trusted
Sep 04 17:13:15 icarus nm-dispatcher[3227]: Starting trusted system units
Sep 04 17:13:15 icarus nm-dispatcher[3227]: Starting trusted user units
...
Sep 04 17:13:15 icarus nm-dispatcher[1537]: req:15 'up' [br-8e15dbfdbac6], "/etc/NetworkManager/dispatcher.d/10trust": complete: failed with Script '/etc/NetworkManager/dispatcher.d/10trust>
...
Sep 04 17:13:16 icarus nm-dispatcher[3512]: All connections are trusted
Sep 04 17:13:16 icarus nm-dispatcher[3497]: Starting trusted system units
Sep 04 17:13:16 icarus nm-dispatcher[3497]: Starting trusted user units
...
Sep 04 17:13:16 icarus nm-dispatcher[1537]: req:16 'up' [br-89e023c415a6], "/etc/NetworkManager/dispatcher.d/10trust": complete: failed with Script '/etc/NetworkManager/dispatcher.d/10trust>
...
Sep 04 17:13:16 icarus nm-dispatcher[3782]: All connections are trusted
Sep 04 17:13:16 icarus nm-dispatcher[3767]: Starting trusted system units
Sep 04 17:13:16 icarus nm-dispatcher[3767]: Starting trusted user units
...
Those networks are all excluded:
/etc/nmtrust/excluded_networks
# Ansible managed
docker?
br-*
virbr*
vnet*
lo
Does it make sense to ignore all excluded networks from the dispatcher execution? For example:
/etc/NetworkManager/dispatcher.d/10trust
#!/bin/bash
# Toggle trusted units whenever a connection is activated or deactived.
EXCLUDEFILE="/etc/nmtrust/excluded_networks"
interface=$1 action=$2
check_connection() {
local name=$1
local connection_excluded=false
mapfile -t excludes < <(grep -v '^#' < $EXCLUDEFILE)
for exclude in "${excludes[@]}"; do
# NOTE: Cannot quote right-hand site of == because glob matching is needed [shellcheck(SC2053)]
if [[ "$name" == $exclude ]]; then
connection_excluded=true
break
fi
done
echo $connection_excluded
}
if [[ $(check_connection "$interface") = false ]]; then
echo "$interface"
case $action in
up)
ttoggle
;;
down)
ttoggle
;;
esac
fi
exit $?
So, does it make sense to only execute it for networks not excluded or just execute it every time?
hey, i would love to contribute to your project to support iwd directly, so i can ditch network-manager as dependency.
since my coding skills are almost none existent, i would need some help to point me in the right direction and audit my lines after pr of course. hope you like the idea and there is no major breakpoint that i miss for make it to work....?
as far as i could spot out, i think the interesting parts are line 94-118 at the nmtrust script?
best regards and thanks for sharing your tools ;)
Hey,
Thanks for spark and all the little gem you developed so far, really appreciate to use it.
I'm using syncthing to synchronise my stuff and my trusted_units looks like this:
syncthing.service,user:myuser
When using sudo ttoggle
I get an error:
Failed to connect to bus: No such file or directory
I have other trusted units which are not user, they are working correctly.
How I can debug this problem ?
If I use journalctl -fl
I see that a command is run:
fév 05 07:57:21 sudo[144802]: myuser : TTY=pts/2 ; PWD=/home/myuser ; USER=root ; COMMAND=/usr/bin/ttoggle
fév 05 07:57:21 sudo[144802]: pam_unix(sudo:session): session opened for user root(uid=0) by myuser(uid=1337)
fév 05 07:57:21 sudo[144863]: root : TTY=pts/4 ; PWD=/home/myuser ; USER=myuser ; COMMAND=/usr/bin/bash -c 'export XDG_RUNTIME_DIR=/run/user/1000; systemctl stop --user syncthing.service'
The command looks good, but syncthing is not stopped.
If I copy/past the same command in my shell, syncthing get stopped.
EDIT: I understand why, my uid is 1337 and not 1000, that's why it is failing in the ttoggle
script
dirty fix would be in file ttoggle
https://github.com/pigmonkey/nmtrust/blob/b1a43f43da29e38bf62d4d298127299a62258417/ttoggle#L59C9-L59C87
sudo -u "$unit_user" bash -c "export XDG_RUNTIME_DIR=/run/user/$(sudo -u "$unit_user" bash -c "id -u"); $command"
I'm also wondering if we should modify in spark:
To use also gid: "{{ user.uid }}"
in case the user want to change the default uid and that we match the gid as well.
Another issue I encountered, is that using nmtrust with NetworkManager raise an error in the journalctl log:
tput: No value for $TERM and no -T specified
Line 9 in b1a43f4
if tty -s; then
before the whole functions, which will run only if we are in a terminal
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.