Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve The Security Model #270

Merged
merged 2 commits into from
Sep 28, 2024

Conversation

newtoallofthis123
Copy link
Contributor

GSoc Project 2: Improve Security Model for SWHKD

For full context and technical details: GSoC Logs

Changes

  1. Server no longer executes commands: The server is now only used for getting the environment from the user space that the daemon can use to execute the process. This means that server only responds with the env and can no longer act as a command execution medium

  2. Server and daemon communicate using an event based system: A hash based system is used to ensure that the env is refreshed only when needed. The server and daemon communicate using a socket based IPC.

  3. Remove Polkit dependency: Now the daemon can be run simply by setting the uid bit to 0 or using sudo or doas. Hence the polkit and pkexec dependency has now been retired

  4. User config file reading: The initial connection to the server is blocking, hence it is guaranteed that the daemon has access to the user's env. Hence, swhkd can now use the config file at XDG_CONFIG_DIR/swhkd by default.

  5. Thread deescalation: The commands that are parsed and detected by the daemon are executed by the daemon it self in an deescalated thread. The daemon communicates with this thread using tokio::mpc::channel.

  6. Update Documentation and MakeFile: The MakeFile and Documentation has been appropriately updated so to get this change, simply running the appropriate make command will work

Final Flow

The final flow of the daemon is as follows:
The daemon is launched in the root space and the server is launched in the user space.
This is reminiscent of the old IPC model as such:

./swhks && doas ./swhkd

The doas or sudo can be skipped by making the swhkd binary a setuid binary.
This can be done by running the following command:

sudo chown root:root swhkd
sudo chmod u+s swhkd

Right after this is done, the first connection to the server is made and the server sends the env to the daemon.
This is blocking.
A thread is spawned that is valid throughout the lifetime of the daemon.
The thread is also de-escalated to the user space and can communicate with the daemon through a channel.

Next, the daemon starts listening for the key events.
When a key event is detected, the daemon just sends it to the thread through the channel which executes it.
When the env is updated and the env hash changes, an event is sent that refreshes the env.

* The IPC functionality has been modulized

* Makefile and docs are updated

* SWEET parser has been integrated

* Daemon now looks for config file in the XDG_CONFIG_DIR correctly

* Server and Daemon have been integrated using socket based IPC

* Instance tracking for the server to prevent cpu load

* Daemon can be lauched using the setuid bit

* Event based environment refresh integrated for the server and daemon

* Daemon now reads the env from the server

* De-escalated thread used to execute commmands in daemon

* Old IPC model has been retired

* Polkit dependency has been removed

* Command execution has been ported from server to daemon
@Shinyzenith Shinyzenith merged commit 533295f into waycrate:main Sep 28, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants