Skip to content

Commit 694fab0

Browse files
[feat] Improving the Security Model
* 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
1 parent 5631ef4 commit 694fab0

File tree

11 files changed

+459
-333
lines changed

11 files changed

+459
-333
lines changed

INSTALL.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ We have packaged `swhkd-git`. `swhkd-bin` has been packaged separately by a user
1010

1111
**Runtime:**
1212

13-
- Policy Kit Daemon ( polkit )
1413
- Uinput kernel module
1514
- Evdev kernel module
1615

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

3534
```
3635
swhks &
37-
pkexec swhkd
36+
swhkd
3837
```

Makefile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ DESTDIR ?= "/"
44
DAEMON_BINARY := swhkd
55
SERVER_BINARY := swhks
66
BUILDFLAGS := --release
7-
POLKIT_DIR := /usr/share/polkit-1/actions
8-
POLKIT_POLICY_FILE := com.github.swhkd.pkexec.policy
97
TARGET_DIR := /usr/bin
108
MAN1_DIR := /usr/share/man/man1
119
MAN5_DIR := /usr/share/man/man5
@@ -15,19 +13,17 @@ all: build
1513

1614
build:
1715
@cargo build $(BUILDFLAGS)
18-
@./scripts/build-polkit-policy.sh \
19-
--policy-path=$(POLKIT_POLICY_FILE) \
20-
--swhkd-path=$(TARGET_DIR)/$(DAEMON_BINARY)
2116

2217
install:
2318
@find ./docs -type f -iname "*.1.gz" \
2419
-exec install -Dm 644 {} -t $(DESTDIR)/$(MAN1_DIR) \;
2520
@find ./docs -type f -iname "*.5.gz" \
2621
-exec install -Dm 644 {} -t $(DESTDIR)/$(MAN5_DIR) \;
2722
@install -Dm 755 ./target/release/$(DAEMON_BINARY) -t $(DESTDIR)/$(TARGET_DIR)
23+
@sudo chown root:root $(DESTDIR)/$(TARGET_DIR)/$(DAEMON_BINARY)
24+
@sudo chmod u+s $(DESTDIR)/$(TARGET_DIR)/$(DAEMON_BINARY)
2825
@install -Dm 755 ./target/release/$(SERVER_BINARY) -t $(DESTDIR)/$(TARGET_DIR)
29-
@install -Dm 644 -o root ./$(POLKIT_POLICY_FILE) -t $(DESTDIR)/$(POLKIT_DIR)
30-
# Ideally, we would have a default config file instead of an empty one
26+
# Ideally, we would have a default config file instead of an empty one
3127
@if [ ! -f $(DESTDIR)/etc/$(DAEMON_BINARY)/$(DAEMON_BINARY)rc ]; then \
3228
touch ./$(DAEMON_BINARY)rc; \
3329
install -Dm 644 ./$(DAEMON_BINARY)rc -t $(DESTDIR)/etc/$(DAEMON_BINARY); \
@@ -38,7 +34,6 @@ uninstall:
3834
@$(RM) -f /usr/share/man/**/swhks.*
3935
@$(RM) $(TARGET_DIR)/$(SERVER_BINARY)
4036
@$(RM) $(TARGET_DIR)/$(DAEMON_BINARY)
41-
@$(RM) $(POLKIT_DIR)/$(POLKIT_POLICY_FILE)
4237

4338
check:
4439
@cargo fmt
@@ -57,7 +52,6 @@ clean:
5752
@cargo clean
5853
@$(RM) -f ./docs/*.gz
5954
@$(RM) -f $(DAEMON_BINARY)rc
60-
@$(RM) -f $(POLKIT_POLICY_FILE)
6155

6256
setup:
6357
@rustup install stable

README.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Xorg or Wayland desktops, and you can even use `swhkd` in a TTY.
3434

3535
```bash
3636
swhks &
37-
pkexec swhkd
37+
swhkd
3838
```
3939

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

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

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

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

8684
So yes, you're safe!
8785

docs/swhkd.1.scd

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,11 @@ swhkd - Hotkey daemon inspired by sxhkd written in Rust
66

77
# SYNOPSIS
88

9-
*pkexec swhkd* [_flags_]
9+
*swhkd* [_flags_]
1010

1111
# CONFIG FILE
1212

13-
The config file goes in */etc/swhkd/swhkdrc*. Since swhkd is written with a pkexec privilege escalation model in mind, we can't detect
14-
*$XDG_CONFIG_HOME*.
15-
16-
This can be avoided as such:
17-
- Using the *include* statement in your config file.
18-
- Using the *-c* flag to mention a custom config file at runtime.
19-
- Symlinking the config file from *~/.config/swhkd/swhkdrc* or any other directory of choice to */etc/swhkd/swhkdrc*.
20-
13+
The config file goes in *~/.config/swhkd/swhkdrc* with a fallback to */etc/swhkd/swhkdrc*.
2114
More about the config file syntax in `swhkd(5)`
2215

2316
# OPTIONS

docs/swhkd.5.scd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ swhkd - Hotkey daemon inspired by sxhkd written in Rust
66

77
# CONFIG FILE
88

9-
- 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*.
9+
- A global config can be defined in *~/.config/swhkd/swhkdrc*, with a
10+
fallback to */etc/swhkd/swhkdrc*. Swhkd attempts to look in your *$XDG_CONFIG_HOME*, failing which it defaults to *~/.config*.
1011
- A local config overrides the global one. Local configs should be placed in the root of the project.
1112

1213
# SYNTAX

docs/swhks.1.scd

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ swhks - Server for swhkd, used to run user level commands over IPC.
1616
*-V*, *--version*
1717
Print version information.
1818

19-
*-l*, *--log* <LOG_FILE_PATH>
20-
Set a log file path.
21-
If *XDG_DATA_HOME* exists then we use *swhks/swhks-current_time.log* relative to
22-
it, else we use *.local/share/swhks/swhks-current_time.log* relative to the
23-
user home directory.
24-
2519
*-d*, *--debug*
2620
Enable debug mode.
2721

0 commit comments

Comments
 (0)