Commit Graph
1027 Commits
Author SHA1 Message Date
Luca Boccassi 8324f9351c machine: add a comment to clarify that root_directory is informational only
To avoid any possible mistakes in the future, add a comment in the
object declaration
2025-09-16 15:58:28 +01:00
Luca Boccassi 44e3c4c8bc machine: validate root directory over varlink
Use strict validation to reject invalid directories as the D-Bus
API already does

Follow-up for 5b44c81ff8
2025-09-16 15:58:28 +01:00
Luca Boccassi 119d332d9c machine: do not allow unprivileged users to register other users' processes as machines
Registering a process as a machine means a caller can get machined
to send sigterm to it, and more. If an unpriv user is registering,
ensure the registered process is actually owned by the user.

Follow-up for adaff8eb35
2025-09-16 15:58:28 +01:00
Luca Boccassi 65badde82e machine: restrict register-machine action again
Follow-up for adaff8eb35
2025-09-05 19:29:09 +01:00
Yu Watanabe cace9cf6f6 machinectl: set TERM=dumb when running on a dumb terminal or with a pipe
Fixes #38527.
2025-08-13 23:43:51 +09:00
Yu Watanabe 7cd26f3560 ptyfwd: replace pty_forward_set_ignore_vhangup() with pty_forward_honor_vhangup()
Currently, pty_forward_set_ignore_vhangup() is only used for disabling
the flag. To make the function also disable PTY_FORWARD_IGNORE_INITIAL_VHANGUP
flag, this renames it to pty_forward_honor_vhangup().

Also, for consistency, pty_forward_get_ignore_vhangup() and
ignore_vhangup() are replaced with pty_forward_vhangup_honored().
2025-07-30 01:14:57 +09:00
Lennart Poettering d32ca63318 machined: use RET_GATHER() more 2025-07-15 13:09:08 +02:00
Lennart Poettering 4baede011d machined: align string table 2025-07-15 12:49:08 +02:00
Lennart Poettering ca1daebdd6 machinectl: output supervisor info in status output 2025-07-11 18:15:12 +02:00
Lennart Poettering 596c596d09 machined: add a bit more debug logging 2025-07-11 18:15:12 +02:00
Lennart Poettering 74546a7e29 machined: explicitly watch machine cgroup for getting empty 2025-07-11 18:15:12 +02:00
Lennart Poettering 97754cd14d machined: also track 'supervisor' process of a machine
So far, machined strictly tracked the "leader" process of a machine,
i.e. the topmost process that is actually the payload of the machine.
Its runtime also defines the runtime of the machine, and we can directly
interact with it if we need to, for example for containers to join the
namespaces, or kill it.

Let's optionally also track the "supervisor" process of a machine, i.e.
the host process that manages the payload if there is one. This is
generally useful info, but in particular is useful because we might need
to communicate with it to shutdown a machine without cooperation of the
payload. Traditionally we did this by simply stopping the unit of the
machine, but this is not doable now that the host machined can be used
to track per-user machines.

In the long run we probably want a more bespoke protocol between
machined and supervisors (so that we can execute other commands too,
such as request cooperative reboots/shutdowns), but that's for later.

Some environments call the concept "monitor" rather than "supervisor" or
use some other term. I stuck to "supervisor" because nspawn uses this,
and ultimately one name is as good as another.

And of course, in other implementations of VM managers of containers
there might not be a single process tracking each VM/container. Because
of this, the concept of a supervisor is optional.
2025-07-11 18:15:12 +02:00
Lennart Poettering adaff8eb35 machined: use different polkit actions for registering and creating a machine
The difference between these two operations are large: one is relatively
superficial: for "registration" all resources remain associated with the
invoking user, only the cgroup is reported to machined which then keeps
track of the machine, too. OTOH "creation" a scope is allocated in
system context, hence the invoked code will be owned by the system, and
its resource usage charged against the system.

Hence, use two distinct polkit actions for this, so that we can relax
access to registration, but keep access to creation tough.
2025-07-11 18:15:12 +02:00
Lennart Poettering 276d200186 machined: track UID owner of machines
Now that unpriv clients can register machines, let's register their UID
too. This allows us to do two things:

1. make sure the scope delegation is assigned to the right UID (so that
   the unpriv user can actually create cgroups below the delegated
   scope)

2. permit certain types of access (i.e. killing, or pty access) to the
   client without auth if it owns the machine.
2025-07-11 18:15:12 +02:00
Lennart Poettering d5feeb373c machined: optionally track machines in cgroup subgroups 2025-07-11 18:15:12 +02:00
Lennart Poettering a13fda9e67 machinectl: fix status output indentation
All other status output lines use tabs, use that for the ID shift line
too. otherwise output will appear unaligned if log viewers have fixed
tab stop positions.
2025-07-08 06:40:35 +02:00
Yu Watanabe 4f18ff2e29 tree-wide: include unistd.h where necessary
We use symbols provided by unistd.h without including it. E.g.
open(), close(), read(), write(), access(), symlink(), unlink(), rmdir(),
fsync(), syncfs(), lseek(), ftruncate(), fchown(), dup2(), pipe2(),
getuid(), getgid(), gettid(), getppid(), pipe2(), execv(), _exit(),
environ, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO, F_OK, and their
friends and variants, so on.

Currently, unistd.h is indirectly included mainly in the following two paths:
- through missing_syscall.h, which is planned to covert to .c file.
- through signal.h -> bits/sigstksz.h, which is new since glibc-2.34.
  Note, signal.h is included by sd-eevent.h. So, many source files
  indirectly include unistd.h if newer glibc is used.

Currently, our baseline on glibc is 2.31. We need to support glibc older
than 2.34, but unfortunately, we do not have any CI environments with
such old glibc. CIFuzz uses glibc-2.31, but it builds only fuzzers, and
many files are even not compiled.
2025-06-30 09:19:15 +02:00
Lennart Poettering 51cc3825d1 tree-wide: use sd_bus_message_send() instead of sd_bus_send() wherever possible
Also, add a coccinelle script that patches this automatically.
2025-06-24 23:23:40 +09:00
Yu Watanabe 9d5f05ae22 bus-util: coding style cleanups
- replace `type *func()` -> `type* func()`,
- rename arguments for storing results.
2025-06-18 01:55:46 +09:00
Yu Watanabe 984ae058dc discover-image: several cleanups around image_discover() (#37813) 2025-06-13 07:57:28 +09:00
Yu Watanabe 624d369868 discover-image: make image_discover() allocate hashmap when necessary 2025-06-11 22:45:08 +09:00
Yu Watanabe b52d575845 machinectl: use _RUNNER_MAX rather than ELEMENTSOF() 2025-06-11 22:41:54 +09:00
Yu Watanabe 093b025548 machinectl: align table 2025-06-11 22:41:54 +09:00
Lennart Poettering 790f516217 machined: open up machine registration for unpriv clients also via D-Bus
This is already opened up via Varlink. Let's also open it up via D-Bus
with the same polikit operation.
2025-06-07 00:27:11 +02:00
Lennart Poettering 02927af799 machined: properly open up all missing method calls via D-Bus to unpriv clients
These method calls all already have polkit hookup, hence actually allow
them to go through on all levels.

This is mostly playing catchup with a variety of calls added over the
years.
2025-06-06 22:15:25 +02:00
Yu Watanabe ac004f4cc9 tree-wide: introduce bus_error_is_connection() and use it where applicable 2025-06-06 21:42:25 +09:00
Lennart Poettering 020d6c1dce machined: open up OpenMachinePTY() for unpriv clients
The method call already does a PK check, it was just forgotten to
allowlist this in the dbus policy. And in the dbus vtable for
OpenMachinePTY() call. (It was allowlisted in the per-machine
vtable…)

Anyway, clean this up.
2025-06-05 12:44:08 +02:00
Zbigniew Jędrzejewski-Szmek 42ba99748d various: do not include file names directly in error messages
git grep -l 'Failed to open /'|xargs sed -r -i 's|"Failed to open (/[^ ]+): %m"|"Failed to open %s: %m", "\1"|g'
git grep -l $'Failed to open \'/'|xargs sed -r -i $'s|"Failed to open \'(/[^ ]+)\': %m"|"Failed to open %s: %m", "\\1"|g'
git grep -l "Failed to open /"|xargs sed -r -i $'s|"Failed to open (/[^ ]+), ignoring: %m"|"Failed to open %s, ignoring: %m", "\\1"|g'
+ some manual fixups.
2025-06-02 11:10:38 +02:00
Lennart Poettering 48764e2e58 machine: fix log message, doesn't have to be scope unit, can by any 2025-05-27 10:27:37 +02:00
Lennart Poettering ca02f658e0 machine: rework machine_gc()
Let's check the leader alive state, and let's log about dbus errors.
This mimics (but is not quite identical to) what we do these days in
logind for GC'ing user sessions.
2025-05-27 10:27:37 +02:00
Lennart Poettering 0c38bc6227 machine: shorten code 2025-05-27 10:23:36 +02:00
Lennart Poettering ee5622f9f0 machine: as safety precaution also check parsed machine name 2025-05-27 10:23:36 +02:00
Lennart Poettering 6981e465a7 machine: also save/restore vsock CID properly 2025-05-27 10:23:36 +02:00
Lennart Poettering 320b370ab3 machine: modernizations of serializing/deserializing netif data 2025-05-27 10:23:36 +02:00
Lennart Poettering 20babd6038 machine: save/restore machine leader pidfdid 2025-05-27 10:23:36 +02:00
Lennart Poettering 4b9c918431 machine: use the correct escaping calls for machine metadata 2025-05-27 10:23:36 +02:00
Lennart Poettering b8396f1102 machine: properly remove unit name symlink on removal 2025-05-27 10:23:36 +02:00
Lennart Poettering a4dc3b16d9 machine: port machined state files to fopen_tmpfile_linkable()
Similar to the erlier commit for logind, switch to a more modern way to
write the state files.
2025-05-27 10:23:36 +02:00
Lennart Poettering 0c18c0deee machine: insist in a valid root directory 2025-05-27 10:23:36 +02:00
Lennart Poettering 98fc46f2a6 logind,machined: expose bus properties for leader PID fd ids, too 2025-05-27 10:23:36 +02:00
Mike Yuan c3f900770d cgroup-util: drop handcrafted cg_is_empty(), always check cgroup.events populated field
This effectively renames cg_is_empty_recursive() to cg_is_empty().
Note that all existing code calls the former and not the latter,
hence with cgv1 support being dropped it's trivial to consult
cgroup.events directly for populated state everywhere.

Additionally, use more generic cg_get_keyed_attribute() helper
rather than cg_read_event().
2025-05-26 22:59:48 +02:00
Lennart Poettering 040637ebaa machinectl: fix indentation of status output field
One field is differently aligned then the others in the "status" output.
Fix that.
2025-05-26 18:08:28 +02:00
Lennart Poettering 3ae6e64641 loginctl,machinectl: use LESS_BY() where appropriate
And while we are at it, add a lower bound of the display output to 10
for all three cases, because it's pointless outputting someting with
less space.
2025-05-24 00:23:14 +09:00
Daan De Meyer 1e35e81b2c tree-wide: Clean up includes
Preparation for cleaning up includes in src/shared.
2025-05-22 21:10:15 +02:00
Daan De Meyer 6cc59a2de6 machine: Fix comment 2025-05-22 09:41:18 +02:00
Lennart Poettering 3c70cbae0f machined: call pidref_verify() in some cases this was missing
We need to protect us from recycled PIDs here like everywhere else: once
we read data from /proc/$PID/ we need to validate that $PID still points
to the original pidfd.
2025-05-22 02:38:38 +09:00
Daan De Meyer 64943cac5d machine: Clean up includes
Split out of #37344.
2025-05-21 18:08:50 +02:00
Daan De Meyer 9f74f56f36 test-tables: Pass enum type to test_table() as well
clang-include-cleaner has a hard time figuring out unused includes
with all the macro string concatentation we're doing in test_table().
Let's help it out a little by also passing the enum type into test_table().

While technically not needed, this makes the tests a bit more self-descriptive
and not really much more verbose so it feels like a good chance regardless,
even if the primary purpose is to help clang-include-cleaner figure out
used and unused includes.
2025-05-21 13:24:42 +02:00
Jelle van der Waa 00299a80f7 sd-event: rename 's' -> 'ret' 2025-05-21 10:50:25 +02:00
Daan De Meyer d86fead481 meson: Rework clang-tidy integration to be done via unit tests
Instead of using run-clang-tidy.py with its own scheduling, let's
just gather a list of source files ourselves and then use that to
add a unit test for each source file that runs clang-tidy on the
source file.

We also add a bit of logic to run clang-tidy on most header files
as well for extra coverage. This uncovered various header files that
were not standalone so this commit also includes fixes to make sure
the clang-tidy tests are all green.

We can also use this in a later commit to run clang-include-cleaner
on each source file in the same way.
2025-05-20 10:29:59 +02:00