23 Commits

Author SHA1 Message Date
Daan De Meyer
2691e7558b run0: Add note about processes having privileges over --empower sessions 2025-11-21 13:08:50 +01:00
Daan De Meyer
475729b805 run0: Make --same-root-dir available for run0
This enables running something like
"mkosi box -- run0 --empower --same-root-dir -E PATH" to get an
empowered session as the current user within the "mkosi box" environment.
2025-11-14 10:36:53 +01:00
Daan De Meyer
3150c34270 run0: Never ask --empower sessions for polkit auth
A --empower session is effectively root without being UID 0, so it
doesn't make sense to enforce polkit authentication in those. Let's
add the empower group, add --empower sessions to that group and ship
a polkit rule to skip authentication for all users in the empower
group.

(As a side-effect this will also allow users to add themselves to this
group outside of 'run0 --empower' to mimick NOPASSWD from sudo)
2025-11-12 19:55:35 +01:00
Daan De Meyer
5cabeed80b run0: Add --empower
--empower gives full privileges to a non-root user. Currently this
includes all capabilities but we leave the option open to add more
privileges via this option in the future.

Why is this useful? When running privileged development or debugging
commands from your home directory (think bpftrace, strace and such),
you want any files written by these tools to be owned by your current
user, and not by the root user. run0 --empower will allow you to run
all privileged operations (assuming the tools check for capabilities
and not UIDs), while any files written by the tools will still be owned
by the current user.
2025-10-30 15:28:36 +01:00
Mike Yuan
2950fb1b9b run0: drop -a short switch for --area=
Follow-up for f44e7a8c11

This breaks the rule stated at the beginning of help_sudo_mode():

> NB: Let's not go overboard with short options: we try to keep a modicum of compatibility with
> sudo's short switches, hence please do not introduce new short switches unless they have a roughly
> equivalent purpose on sudo. Use long options for everything private to run0.
2025-05-13 08:33:10 +09:00
Mike Yuan
e61d2011d1 run0: introduce --via-shell for invoking target user's shell, and -i shortcut
-i/--login has exact sudo semantics. But we only document
the short option and advertise expressly specifying
--via-shell --chdir='~' otherwise.
2025-05-07 18:32:20 +02:00
Lennart Poettering
b7ba8d55b8 run0: run agents during setup, until pty forwarder takes over
When services start up they might query for passwords, or issue polkit
requests. Hence it makese sense to run the password query agent and
polkit agent from systemd-run. We already ran the polkit agent, this
also ensures we run the password query agent.

There's one tweak to the story though: running the agents and the pty
forwarder concurrently is messy, since they both try to read from stdin
(one potentially, the other definitely). Hence, let's time the agents
properly: invoke them when we initialize, but stop them once the start
job for the unit we are supposed to run is complete, and only then run
the pty forwarder.

With this in place, the following series of commands starts to work
really nicely (which previously deadlocked):

    # homectl create foobar
    # run0 -u foobar

What happens in the background in run0 is this: a new session is invoked
for "foobar", which pulls in the user@.service instance for the user.
That user@.service instance will need to unlock the homedir first. Since
8af1b296cb this will happen via the askpw
logic. With this commit here this prompt will now be shown by run0. Once
the password is entered the directory is unlocked and the real session
begins. Nice!

This new behaviour is conditioned behind --pty-late (distinct from the
existing --pty switches). For systemd-run we will never enable this mode
by default, for compat with command lines that use ExecStartPre=
(because we won't process the pty anymore during that command) For
run0 however this changes the default to --pty-late (unless
--no-ask-password is specified). This reflects the fact that run0 is
more of an interctive tool and unlikely to be used in more complex
service start-up situations with ExecStartPre= and suchlike.

This also merges JobDoneContext into RunContext, since it doesn't really
make sense to have two contexts around to communicate between outer
stack frame and event handlers. Let's just have one, and pass it around
to all handlers the same way. In particular as we should delay exit only
until both the unit's job is complete *and* in case of --wait the unit
is exited, one of the two should not suffice.
2025-03-05 13:17:50 +01:00
Lennart Poettering
9f036cfd57 docs: document the new area functionality 2025-02-06 09:23:49 +01:00
Lennart Poettering
ef5f72437e run0: allow explicit control of service manager activation for run0 sessions
This adds a new --lightweight=yes/no switch which allows controlling
whether the invoked service will have the service manager around or not.

Moreover, this changes that if the target user is root it will now
support to the lightweight mode, i.e. run0 towards root will no longer
pull in the service manager (a real tty login via getty still will
though!).

My thinking here is that quickly raising privileges via run0 probably
shouldn't be considered a proper login but just something short lived,
temporary for a single command or similar.
2025-01-15 17:03:21 +01:00
Jan Engelhardt
c592ebdf4f man: grammar fixes for introductory adverbs/phrases 2024-12-25 17:24:38 +01:00
Yu Watanabe
f29a07f3fc man: several more assorted fixes
Continuation of 4ebbb5bfe8.
Closes #35307.
2024-11-26 17:28:14 +01:00
Yu Watanabe
4ebbb5bfe8 man: asorted fixes
Closes #35307.
2024-11-24 01:11:42 +09:00
Yu Watanabe
ddeb701b55 man: fix typo
Follow-up for 115fac3c29.
2024-10-26 14:00:38 +09:00
Lennart Poettering
115fac3c29 run0: optionally show superhero emoji on each shell prompt
This makes use of the infra introduced in 229d4a9806 to indicate visually on each prompt that we are in superuser mode temporarily.
pick ad5de3222f userdbctl: add some basic client-side filtering
2024-10-25 17:31:06 +02:00
Lennart Poettering
edd10ab29c run0: add options to force allocation of PTY or of pipe use
Fixes: #33033
2024-10-25 14:14:26 +02:00
Mike Yuan
988ca0953e man: use standard-options for --no-ask-password everywhere 2024-08-21 15:17:02 +02:00
Mike Yuan
8d4fa6531b man/run0: remove @ syntax for --machine=
For run0 (as opposed to systemd-run in general), connecting to
the system bus (of localhost or container) as a different user
than root and then trying to elevate privilege from that
makes little sense:
https://github.com/systemd/systemd/issues/32997#issuecomment-2127992973

The @ syntax is mostly useful when connecting to the user bus,
which is not a use case for run0. Hence, let's remove the example.
The syntax will be properly refused in #32999.
2024-05-27 09:40:47 +09:00
Mike Yuan
006c02b371 man/run0: remove -M alias for --machine=
run0 doesn't know about the former.
2024-05-27 09:40:47 +09:00
Yu Watanabe
6fe998037a man: fix typo
Follow-up for 7df0297ac5.
2024-05-14 18:12:30 +09:00
Mike Yuan
18303adcd3 man/run0: remove the --user example for --machine=
run0's --user= option is different from other tools,
and the whole point of run0 is to connect to the system
manager. So the example is spurious.
2024-05-08 10:08:53 +02:00
Thayne McCombs
7df0297ac5 man/run0: Describe environment variables set (#32622)
* man/run0: Describe environment variables set
2024-05-04 12:06:16 +01:00
Mike Yuan
13e380b054 man/run0: fix typo (missing "by") 2024-05-01 14:43:32 +08:00
Zbigniew Jędrzejewski-Szmek
7aed434371 Rename uid0 to run0
Naming is always a matter of preference, and the old name would certainly work,
but I think the new one has the following advantages:
- A verb is better than a noun.
- The name more similar to "the competition", i.e. 'sudo', 'pkexec', 'runas',
  'doas', which generally include an action verb.
- The connection between 'systemd-run' and 'run0' is more obvious.

There has been no release yet with the old name, so we can rename without
caring for backwards compatibility.
2024-03-19 16:37:22 +01:00