Commit graph

17 commits

Author SHA1 Message Date
Thomas Haller
ea49b50651
all: add some README.md files describing the purpose of our sources 2021-08-19 17:51:11 +02:00
Thomas Haller
2665fe23c2
nm-sudo,dispatcher: rename and refactor code to make them more similar
nm-sudo and nm-dispatcher are very similar from a high level. Both are D-Bus activated
services that exit on idle and all they do, is to provide a simple D-Bus API with no
objects or properties.

Hence it's not surprising that they follow the same structure.

Rename the code to make them look more similar.
2021-08-06 14:33:39 +02:00
Thomas Haller
9f0984c63b
nm-sudo: don't register pending job for current operations
Currently we only implmement two operations (Ping() and GetFD()). Both
complete right away. There is no need to register a pending job, if
the job does not get processed asynchronously.

In the future, we may have methods that need asynchronous processing
and where we need to register them as pending job.
2021-08-06 14:32:55 +02:00
Thomas Haller
31c48ec616
nm-sudo: reject new request once we have no well-known-name
If we fail to acquire the well-known name or if we already released it,
we must not accept anymore new requests.

Otherwise, requests directly targeted to the unique name will keep the
process alive, and prevent it from restarting (and serving the
well-known name). Clients really should not talk to the unique name of a
service that exits on idle. If they do, and the service is about to shut
down, then the request will be rejected. After we released the name,
there is now turning back and we should quit fast (only processing the
requests we already have).

Also, if we receive a SIGTERM, then we are requested to quit and should
do so in a timely manner. That means, we will start with releasing the
name. As the service is D-Bus activated, new requests can be served by
the next instance (or if the service is about to be disabled altogether,
they will start failing).
2021-08-06 14:32:55 +02:00
Thomas Haller
0aaaab07d1
nm-sudo: fix clearing timeout source in _idle_timeout_cb()
Fixes: f137b32d31 ('sudo: introduce nm-sudo D-Bus service')
2021-08-06 14:32:51 +02:00
Thomas Haller
dbd459ec92
nm-sudo: expect unknown interface in _bus_method_call()
GDBus will invoke the method_call callback also for the Get/Set
functions. Thus, we need to check the interface_name and handle
them (actually, there is nothing to handle, no properties exist).

Also, "Ping" method only exists for testing. It is usually not called
in production, so check for "GetFD" first.
2021-08-04 09:41:09 +02:00
Thomas Haller
1e71a00817
nm-sudo: return result from _bus_register_service()
Instead of adding a flag to global state.
2021-08-04 09:41:09 +02:00
Thomas Haller
5105995514
nm-sudo: use nm_dbus_connection_call_blocking() in _bus_register_service() 2021-08-04 09:41:09 +02:00
Thomas Haller
eeb01bcba9
nm-sudo: use nm_g_main_context_iterate_ready() helper 2021-08-04 09:41:09 +02:00
Thomas Haller
2b8add959f
nm-sudo: cancel quit_cancellable during shutdown 2021-08-04 09:41:09 +02:00
Thomas Haller
62a9a48cc2
nm-sudo: use nm_g_bus_get_blocking() to create GDBusConnection 2021-08-04 09:41:09 +02:00
Thomas Haller
a210e9a6f4
nm-sudo: fix race during exit-on-idle
nm-sudo is D-Bus activated and exits-on-idle. To do that race-free we
need:

  - sd_notify("STOPPING=1")
  - ReleaseName
  - keep processing pending requests
2021-08-04 09:41:09 +02:00
Thomas Haller
292cf4c42f
nm-sudo: drop semicolon after _nm_log() macro 2021-08-04 08:23:59 +02:00
Thomas Haller
4ac66a4215
all: rename nm_utils_strdup_reset*() to nm_strdup_reset*() 2021-08-02 09:26:47 +02:00
Thomas Haller
ee5030c7bd
nm-sudo: fix printf format string in _handle_ping()
src/nm-sudo/nm-sudo.c: In function '_handle_ping':
src/nm-sudo/nm-sudo.c:92:79: error: format '%ld' expects argument of type 'long int', but argument 5 has type 'gint64' {aka 'long long int'} [-Werror=format=]
   92 |     msg = g_strdup_printf("pid=%lu, unique-name=%s, nm-name-owner=%s, since=%ld.%03d%s, pong=%s",
      |                                                                             ~~^
      |                                                                               |
      |                                                                               long int
      |                                                                             %lld
......
   96 |                           running_msec / 1000,
      |                           ~~~~~~~~~~~~~~~~~~~
      |                                        |
      |                                        gint64 {aka long long int}

Fixes: f137b32d31 ('sudo: introduce nm-sudo D-Bus service')
2021-07-26 18:13:26 +02:00
Thomas Haller
de5dddccbe
core: get file descriptor to ovsdb unix socket from nm-sudo
To talk to ovsdb, we use the unix socket at
/var/run/openvswitch/db.sock. But that socket is owned by another user
and NetworkManager would need dac_override capability to open it.

We want to drop dac_override, but we still need to talk to ovsdb. Add a
GetFD() method to nm-sudo.

We still first try to open the socket directly. Maybe it just works.

Note that SELinux may block passing file descriptors from nm-sudo. If it
doesn't work for you, test with SELinux permissive mode and wait for an
SELinux update.
2021-07-26 15:31:46 +02:00
Thomas Haller
f137b32d31
sudo: introduce nm-sudo D-Bus service
NetworkManager runs as root and has lots of capabilities.
We want to reduce the attach surface by dropping capabilities,
but there is a genuine need to do certain things.

For example, we currently require dac_override capability, to open
the unix socket of ovsdb. Most users wouldn't use OVS, so we should
find a way to not require that dac_override capability. The solution
is to have a separate, D-Bus activate service (nm-sudo), which
has the capability to open and provide the file descriptor.

For authentication, we only rely on D-Bus. We watch the name owner
of NetworkManager, and only accept requests from that service. We trust
D-Bus to get it right a request from that name owner is really coming
from NetworkManager. If we couldn't trust that, how could PolicyKit
or any authentication via D-Bus work? For testing, the user can set
NM_SUDO_NO_AUTH_FOR_TESTING=1.

https://bugzilla.redhat.com/show_bug.cgi?id=1921826
2021-07-26 15:31:46 +02:00