7 Commits

Author SHA1 Message Date
Sunil Mohan Adapa
0fdf59b9f0
privileged_daemon: Implement handling termination signal
- And gracefully terminate the process after finishing the current requests
underway.

Tests:

- Trigger a long operation such as an app installation. While the operation is
underway, run 'systemctl stop freedombox-privilved.service'. Journal will show
that the SIGTERM is handled and shutdown is more or less immediately complete.
However, the whole process will wait until the ongoing request is complete and
then exit.

- During the wait period, no new requests are accepted as experienced with
'freedombox-cmd plinth is_package_manager_busy --no-args' command.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2025-09-29 16:58:44 +03:00
Sunil Mohan Adapa
c2d5d1d3c8
privileged_daemon: Fix showing errors for freedombox-cmd command
Tests:

- When arguments are not provided to freedombox-cmd it shows errors on the
console.

- When a command is successfully executed, the output is printed on the console.

- The output of the privileged daemon goes to the journald.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Veiko Aasa <veiko17@disroot.org>
2025-09-29 16:58:41 +03:00
Sunil Mohan Adapa
944c427f44
actions: Framework for capturing stdout/stderr in privileged daemon
Tests:

- If there is a syntax error in communication with privileged server. 'stdout'
and 'stderr' keys are present in 'exception' dictionary of the reply.

- If there is a error in the privileged method in communication with privileged
server. 'stdout' and 'stderr' keys are present in 'exception' dictionary of the
reply. The values are filled with output of the command that have been run.

- If a privileged method uses action_utils.run, then raising an exception in the
method shows proper stdout and stderr in the UI HTML message.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2025-09-05 20:23:55 +05:30
Sunil Mohan Adapa
a580437de2
privileged_daemon: Introduce a command line client for the API
- Similar call signature as actions/actions.

Tests:

- Running make install places a binary file in /usr/bin/freedombox-cmd

- Running 'freedombox-cmd upgrades get_log --no-args' works.

- Running 'freedombox-cmd upgrades activate_backports --no-args' works.

- Running 'freedombox-cmd storage usage_info --no-args' works.

- Running 'freedombox-cmd sshfs is_mounted --no-args' works.

- echo '{"args": ["USERNAME", "AUTH_USER", "AUTH_PASSWORD"], "kwargs": {}}' |
sudo freedombox-cmd users remove_user.

- Distribution upgrade from Bookworm to Trixie works.

  - Snapshots are disabled and re-enabled during upgrade.

  - /etc/apt/sources.list changes are completed on completion.

- If a command fails, the return code is not 0.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2025-09-05 20:23:36 +05:30
Sunil Mohan Adapa
143e4a00bd
actions, backup: Implement raw output for privileged daemon
- Regression: downloading does not work with sudo based action anymore. However,
sudo based actions are to be removed in later patches.

Tests:

- Downloading tar backup archive works. Untar works. Downloading gives upto
10MiB/s speed.

- If API is not called with _raw_output=True, then special exception is raised.

- Downloading tar file from command line using nc also works.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2025-09-05 20:23:25 +05:30
Joseph Nuthalapati
2f53c4dd39
actions:privileged: Fix flake8 errors
Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
2025-08-16 23:04:16 +05:30
Sunil Mohan Adapa
c47a856e3e
privileged: Introduce a UNIX socket daemon for privileged calls
- This daemon will be faster than running actions using 'sudo' because the
actions sometimes load all the modules before certain safety checks can be
performed. The daemon will load just once for many privileged calls.

Tests:

- After daemon is started, systemd shows the status as 'activated'.

- When daemon is started using socket activation and requests are sent, the
  requests succeed.

- When daemon is started manually and requests are sent, the requests succeed.
  The socket file is created with root:root ownership and 0666 permissions.
  Parent directory is created if not exists. After the daemon exits, the socket
  file is removed. When daemon is started manually, automatic idle timeout exit
  does not happen.

- According to journalctl, server exists after 5 seconds. Proper log message is
  seen.

- Without development mode, server exists after 5 minutes of idle. Proper log
  message is seen.

- When a sleep is added in one of the actions and when the action is running,
  server does not exit. Server exits after the request is completed.

- When an error is raised in verify request, the server exits with proper error
  message. If the server exists with non-zero error code and is immediately
  restarted by systemd.

- Sending a sample request using nc from root user and plinth user works.

- Sending a sample request using nc from fbx user is rejected.

- If a non-unicode text is sent as request, the response is a valid error
  dictionary.

- If the request is larger than 1M, an 'request too large' error is thrown.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
2025-08-16 22:40:54 +05:30