Skip to content

Commit bb28e93

Browse files
committed
refactor: reorganize varlink sockets into public and private directories for improved access control
1 parent 49f0450 commit bb28e93

6 files changed

Lines changed: 19 additions & 14 deletions

File tree

AGENTS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ If you are an AI assistant working on this repository or a project that consumes
1818

1919
### 2. Available Interfaces
2020
The daemon exposes its state via **Varlink** on three separate Unix sockets:
21-
- `/run/contextd/contextd.socket` (Core system & game context)
22-
- `/run/contextd/contextd-rgb-observer.socket` (Public RGBA vibe - **0666**)
23-
- `/run/contextd/contextd-rgb-control.socket` (Public RGBA control - **0666**)
21+
- `/run/contextd/public/contextd.socket` (Core system & game context)
22+
- `/run/contextd/public/contextd-rgb-observer.socket` (Public RGBA vibe - **0666**)
23+
- `/run/contextd/private/contextd-rgb-control.socket` (Private RGBA control - **0666**)
2424

2525
| Socket | Interface | Access | Purpose |
2626
| :--- | :--- | :--- | :--- |
2727
| `contextd.socket` | `com.performativenonsense.contextd` | Public | System and Game Discovery |
2828
| `contextd-rgb-observer.socket` | `com.performativenonsense.contextd.rgb.Observer` | Public | Consume/Subscribe to lighting vibe |
29-
| `contextd-rgb-control.socket` | `com.performativenonsense.contextd.rgb.Control` | Public | Set/Update system lighting |
29+
| `contextd-rgb-control.socket` | `com.performativenonsense.contextd.rgb.Control` | Private | Set/Update system lighting |
3030

3131
Key methods to call:
3232
- `com.performativenonsense.contextd.Active()`: Returns the currently foregrounded game.

docs/design_goals.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Context Daemon is a lightweight Linux utility designed to bridge the gap between
2222
### 3. Security & IPC Model
2323
- **Principle of Least Privilege**: Although the daemon is initialized by systemd, it drops almost all root privileges via the Portable Service sandbox. It retains only `CAP_SYS_PTRACE` (for process scanning) and `CAP_DAC_READ_SEARCH` (for reading game manifests in `/home`).
2424
- **Strict Sandboxing**: Utilizes `ProtectSystem=strict`, `MemoryDenyWriteExecute=yes`, and other systemd hardenings to ensure the daemon cannot be easily compromised.
25-
- **Public Sockets**: Exposes `0666` permission sockets at `/run/contextd/contextd.socket` (Core), `/run/contextd/contextd-rgb-observer.socket` (RGB Observer), and `/run/contextd/contextd-rgb-control.socket` (RGB Control). Both daemons share the same dynamic user allowing them to coordinate in `/run/contextd`.
25+
- **Public Sockets**: Exposes `0666` permission sockets at `/run/contextd/public/contextd.socket` (Core), `/run/contextd/public/contextd-rgb-observer.socket` (RGB Observer), and `/run/contextd/private/contextd-rgb-control.socket` (RGB Control). Both daemons share the same dynamic user allowing them to coordinate in `/run/contextd`.
2626

2727
### 4. Linux-Centric Design
2828
- Leverage native Linux APIs (udev, procfs) to provide the most efficient implementation.

scripts/contextctl.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/bin/bash
22
# Simple CLI wrapper for contextd using varlinkctl
33

4-
ADDR="unix:/run/contextd/contextd.socket"
5-
RGB_OBS_ADDR="unix:/run/contextd/contextd-rgb-observer.socket"
6-
RGB_CTRL_ADDR="unix:/run/contextd/contextd-rgb-control.socket"
4+
ADDR="unix:/run/contextd/public/contextd.socket"
5+
RGB_OBS_ADDR="unix:/run/contextd/public/contextd-rgb-observer.socket"
6+
RGB_CTRL_ADDR="unix:/run/contextd/private/contextd-rgb-control.socket"
77

88
usage() {
99
echo "Usage: $0 [active|list-games|list-devices|list-rgb|diagnostics|rgb-get|rgb-set|rgb-set-matrix|rgb-subscribe]"

src/main.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ fn main() -> anyhow::Result<()> {
8181
log::info!("Starting Context Daemon in RGBA Mode (Dual-Socket)...");
8282
let rgb_service = rgb::service::RgbService::new();
8383

84-
let obs_addr = "unix:/run/contextd/contextd-rgb-observer.socket";
85-
let ctrl_addr = "unix:/run/contextd/contextd-rgb-control.socket";
84+
// Ensure socket directories exist
85+
let _ = std::fs::create_dir_all("/run/contextd/public");
86+
let _ = std::fs::create_dir_all("/run/contextd/private");
87+
88+
let obs_addr = "unix:/run/contextd/public/contextd-rgb-observer.socket";
89+
let ctrl_addr = "unix:/run/contextd/private/contextd-rgb-control.socket";
8690

8791
// Cleanup stale sockets
8892
let _ = std::fs::remove_file(obs_addr.trim_start_matches("unix:"));
@@ -118,7 +122,7 @@ fn main() -> anyhow::Result<()> {
118122
}
119123
});
120124

121-
// 2. Start Control Server (Public - 0666)
125+
// 2. Start Control Server (Private - 0666)
122126
let control_interface = vec![Box::new(rgb::control::new(Box::new(rgb_service)))
123127
as Box<dyn varlink::Interface + Send + Sync>];
124128
let control_service = VarlinkService::new(
@@ -146,7 +150,8 @@ fn main() -> anyhow::Result<()> {
146150
varlink::listen(control_service, ctrl_addr, &config)?;
147151
} else {
148152
log::info!("Starting Context Daemon in Core Mode...");
149-
let address = "unix:/run/contextd/contextd.socket";
153+
let _ = std::fs::create_dir_all("/run/contextd/public");
154+
let address = "unix:/run/contextd/public/contextd.socket";
150155
let _ = std::fs::remove_file(address.trim_start_matches("unix:"));
151156

152157
let service = ContextService {

tests/rgb_tester/animate_matrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def main():
3737

3838
try:
3939
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
40-
sock.connect("/run/contextd/contextd-rgb-control.socket")
40+
sock.connect("/run/contextd/private/contextd-rgb-control.socket")
4141
except Exception as e:
4242
print(f"Failed to connect to control socket: {e}")
4343
sys.exit(1)

tests/rgb_tester/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class VarlinkThread(QThread):
1111
def run(self):
1212
try:
1313
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
14-
sock.connect("/run/contextd/contextd-rgb-observer.socket")
14+
sock.connect("/run/contextd/public/contextd-rgb-observer.socket")
1515

1616
req = {
1717
"method": "com.performativenonsense.contextd.rgb.Observer.SubscribeLightingContext",

0 commit comments

Comments
 (0)