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 #268

Closed
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
d17315c
Retire SWHKS
newtoallofthis123 Jul 6, 2024
0576581
Migrate to su
newtoallofthis123 Jul 6, 2024
cfe281a
Remove pkexec from daemon
newtoallofthis123 Jul 6, 2024
80717e4
Add launch from su
newtoallofthis123 Jul 6, 2024
4abbcfc
New Environ
newtoallofthis123 Jul 6, 2024
d397b00
Env to command
newtoallofthis123 Jul 6, 2024
1aa0ff3
Config read works
newtoallofthis123 Jul 10, 2024
d705b6d
It kinda works :)
newtoallofthis123 Jul 18, 2024
415375e
Port server
newtoallofthis123 Aug 7, 2024
119a822
Delete tests: ported to Sweet parser
newtoallofthis123 Aug 11, 2024
50c624f
Add env refresh
newtoallofthis123 Aug 24, 2024
88041af
Add logging
newtoallofthis123 Aug 24, 2024
4c434b4
Final setuid fix
newtoallofthis123 Aug 24, 2024
9556d4d
Run cargo fmt
newtoallofthis123 Aug 24, 2024
64930d8
Start work on threads
newtoallofthis123 Aug 24, 2024
0d360dc
Add server instance tracking
newtoallofthis123 Aug 24, 2024
c2655a4
Channels Approach
newtoallofthis123 Aug 24, 2024
cd21e58
Update Makefile and remove polkit
newtoallofthis123 Aug 25, 2024
ec446e2
Refresh Env works for Threads
newtoallofthis123 Aug 25, 2024
5b20699
Merge branch 'main' into security-model
newtoallofthis123 Aug 25, 2024
8a93e99
Small Rename
newtoallofthis123 Aug 25, 2024
456f6b7
Add server wait time
newtoallofthis123 Aug 25, 2024
6362748
Reduce wait time
newtoallofthis123 Aug 25, 2024
bef7ea2
Add event based refresh
newtoallofthis123 Aug 26, 2024
0b09477
Correct refresh time
newtoallofthis123 Aug 26, 2024
dcb6654
Remove need for uname
newtoallofthis123 Aug 27, 2024
0e96057
Add helpful comments
newtoallofthis123 Aug 29, 2024
9858cef
Update Documentation
newtoallofthis123 Aug 29, 2024
69053a7
Works to a good extent
newtoallofthis123 Sep 8, 2024
d695415
Added hash check
newtoallofthis123 Sep 8, 2024
0ba44e7
Modulize ipc functionality
newtoallofthis123 Sep 9, 2024
efe6c01
Add code comments and update man page
newtoallofthis123 Sep 9, 2024
53fa2cd
Add comments to ipc loop
newtoallofthis123 Sep 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ We have packaged `swhkd-git`. `swhkd-bin` has been packaged separately by a user

**Runtime:**

- Policy Kit Daemon ( polkit )
- Uinput kernel module
- Evdev kernel module

Expand All @@ -34,5 +33,5 @@ We have packaged `swhkd-git`. `swhkd-bin` has been packaged separately by a user

```
swhks &
pkexec swhkd
swhkd
```
12 changes: 3 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ DESTDIR ?= "/"
DAEMON_BINARY := swhkd
SERVER_BINARY := swhks
BUILDFLAGS := --release
POLKIT_DIR := /usr/share/polkit-1/actions
POLKIT_POLICY_FILE := com.github.swhkd.pkexec.policy
TARGET_DIR := /usr/bin
MAN1_DIR := /usr/share/man/man1
MAN5_DIR := /usr/share/man/man5
Expand All @@ -15,19 +13,17 @@ all: build

build:
@cargo build $(BUILDFLAGS)
@./scripts/build-polkit-policy.sh \
--policy-path=$(POLKIT_POLICY_FILE) \
--swhkd-path=$(TARGET_DIR)/$(DAEMON_BINARY)

install:
@find ./docs -type f -iname "*.1.gz" \
-exec install -Dm 644 {} -t $(DESTDIR)/$(MAN1_DIR) \;
@find ./docs -type f -iname "*.5.gz" \
-exec install -Dm 644 {} -t $(DESTDIR)/$(MAN5_DIR) \;
@install -Dm 755 ./target/release/$(DAEMON_BINARY) -t $(DESTDIR)/$(TARGET_DIR)
@sudo chown root:root $(DESTDIR)/$(TARGET_DIR)/$(DAEMON_BINARY)
@sudo chmod u+s $(DESTDIR)/$(TARGET_DIR)/$(DAEMON_BINARY)
@install -Dm 755 ./target/release/$(SERVER_BINARY) -t $(DESTDIR)/$(TARGET_DIR)
@install -Dm 644 -o root ./$(POLKIT_POLICY_FILE) -t $(DESTDIR)/$(POLKIT_DIR)
# Ideally, we would have a default config file instead of an empty one
# Ideally, we would have a default config file instead of an empty one
@if [ ! -f $(DESTDIR)/etc/$(DAEMON_BINARY)/$(DAEMON_BINARY)rc ]; then \
touch ./$(DAEMON_BINARY)rc; \
install -Dm 644 ./$(DAEMON_BINARY)rc -t $(DESTDIR)/etc/$(DAEMON_BINARY); \
Expand All @@ -38,7 +34,6 @@ uninstall:
@$(RM) -f /usr/share/man/**/swhks.*
@$(RM) $(TARGET_DIR)/$(SERVER_BINARY)
@$(RM) $(TARGET_DIR)/$(DAEMON_BINARY)
@$(RM) $(POLKIT_DIR)/$(POLKIT_POLICY_FILE)

check:
@cargo fmt
Expand All @@ -57,7 +52,6 @@ clean:
@cargo clean
@$(RM) -f ./docs/*.gz
@$(RM) -f $(DAEMON_BINARY)rc
@$(RM) -f $(POLKIT_POLICY_FILE)

setup:
@rustup install stable
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Xorg or Wayland desktops, and you can even use `swhkd` in a TTY.

```bash
swhks &
pkexec swhkd
swhkd
```

## Runtime signals
Expand All @@ -50,9 +50,7 @@ After opening `swhkd`, you can control the program through signals:
`swhkd` closely follows `sxhkd` syntax, so most existing `sxhkd` configs should
be functional with `swhkd`.

The default configuration file is in `/etc/swhkd/swhkdrc`. If you don't like
having to edit the file as root every single time, you can create a symlink from
`~/.config/swhkd/swhkdrc` to `/etc/swhkd/swhkdrc`.
The default configuration file is in `~/.config/swhkd/swhkdrc` with a fallback to `etc/swhkd/swhkdrc`.

If you use Vim, you can get `swhkd` config syntax highlighting with the
[swhkd-vim](https://github.com/waycrate/swhkd-vim) plugin. Install it in
Expand All @@ -75,13 +73,13 @@ All supported key and modifier names are listed in `man 5 swhkd-keys`.
## Security

We use a server-client model to keep you safe. The daemon (`swhkd` — privileged
process) communicates to the server (`swhks` — running as non-root user) after
checking for valid keybindings. Since the daemon is totally separate from the
server, no other process can read your keystrokes. As for shell commands, you
might be thinking that any program can send shell commands to the server and
that's true! But the server runs the commands as the currently logged-in user,
so no extra permissions are provided (This is essentially the same as any app on
your desktop calling shell commands).
process) is responsible for listening to key events and running shell commands.
The server (`swhks` — non-privileged process) is responsible for keeping a track of the
environment variables and sending them to the daemon. The daemon
uses these environment variables while running the shell commands.
The daemon only runs shell commands that have been parsed from the config file and there is no way to
run arbitrary shell commands. The server is responsible for only sending the environment variables to the daemon and nothing else.
This seperation of responsibilities ensures security.

So yes, you're safe!

Expand Down
11 changes: 2 additions & 9 deletions docs/swhkd.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,11 @@ swhkd - Hotkey daemon inspired by sxhkd written in Rust

# SYNOPSIS

*pkexec swhkd* [_flags_]
*swhkd* [_flags_]

# CONFIG FILE

The config file goes in */etc/swhkd/swhkdrc*. Since swhkd is written with a pkexec privilege escalation model in mind, we can't detect
*$XDG_CONFIG_HOME*.

This can be avoided as such:
- Using the *include* statement in your config file.
- Using the *-c* flag to mention a custom config file at runtime.
- Symlinking the config file from *~/.config/swhkd/swhkdrc* or any other directory of choice to */etc/swhkd/swhkdrc*.

The config file goes in *~/.config/swhkd/swhkdrc* with a fallback to */etc/swhkd/swhkdrc*.
More about the config file syntax in `swhkd(5)`

# OPTIONS
Expand Down
3 changes: 2 additions & 1 deletion docs/swhkd.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ swhkd - Hotkey daemon inspired by sxhkd written in Rust

# CONFIG FILE

- A global config can be defined in */etc/swhkd/swhkdrc*. Swhkd attempts to look in your *$XDG_CONFIG_HOME*, failing which it defaults to *~/.config*.
- A global config can be defined in *~/.config/swhkd/swhkdrc*, with a
fallback to */etc/swhkd/swhkdrc*. Swhkd attempts to look in your *$XDG_CONFIG_HOME*, failing which it defaults to *~/.config*.
- A local config overrides the global one. Local configs should be placed in the root of the project.

# SYNTAX
Expand Down
6 changes: 0 additions & 6 deletions docs/swhks.1.scd
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ swhks - Server for swhkd, used to run user level commands over IPC.
*-V*, *--version*
Print version information.

*-l*, *--log* <LOG_FILE_PATH>
Set a log file path.
If *XDG_DATA_HOME* exists then we use *swhks/swhks-current_time.log* relative to
it, else we use *.local/share/swhks/swhks-current_time.log* relative to the
user home directory.

*-d*, *--debug*
Enable debug mode.

Expand Down
89 changes: 0 additions & 89 deletions scripts/build-polkit-policy.sh

This file was deleted.

Loading
Loading