Repository navigation
Add app-store endpoints so clash-cli can read and edit profile config - #13
zifengjiang wants to merge 1 commit into
Conversation
|
Thanks for this. We're handling it together with the client half, ProjectClash/Clash-Client#102. The two points to solve first (writes from two processes to the same store, and write access from LAN controller clients) are in our comment there: ProjectClash/Clash-Client#102 (comment) |
The App's profile store is a file the App also edits from its own process, so writes here take the same cross-process lock the App takes (<store>/profiles.lock, flock, 5s wait) and replace the file with a temp-then-rename write; a refusal is reported as 503 instead of a generic failure. Writes are local-only: they are accepted on the App Group socket and refused on every controller listener, including the loopback one, with a 403 and an X-Clash-Refusal header. Reads work on both. LAN writes are left off pending a security review (see ProjectClash/Clash-Client#102); the policy lives in one guard rather than a setting.
a11aa3e to
4694256
Compare
|
The kernel side follows the same protocol: writes take |
|
Thanks — noted alongside ProjectClash/Clash-Client#102. As we said there, this is on hold on our side for now; when we pick it up we'll review both halves together and follow up there: ProjectClash/Clash-Client#102 |
Why
clash-clican already read and drive the runtime (proxies, rules in force, DNS lookups, connections), but it cannot touch the app's configuration store: a profile's override rules and its per-domain DNS never leave the App Group, so the only way to edit them is the macOS/iOS UI. That blocks scripted setup and lets an AI assistant drive everything except the part that actually persists.What
Four endpoints on the existing private API surface, registered with the same
privateRoutePrefixeshelper as the rest of/clash/v1, and guarded by the same check as other app-state routes (overAppGroupSocketorRequestFromManagedListener), so a LAN controller client with the right secret and certificate fingerprint can use them too:GET /clash/v1/app/profilesGET|PUT /clash/v1/app/profiles/{id}/rulesoverride.prependRules,override.appendRules)GET|PUT /clash/v1/app/profiles/{id}/dns-policydns.nameserver-policyanddns.fake-ip-filterin the profile's runtime patchDesign notes:
published-rules.yaml, the resolved runtime config, revisions) stay owned by the app.PUTof DNS policy replaces only the keys it is given; other keys and unknown fields are preserved.app-store-v1from/clash/v1/capabilities, so clients can detect it.Tests
cd bind/clash && go build ./... && go test ./ -run AppStore -count=1Covers reading a real-shaped store, unknown-field preservation, replace-vs-preserve semantics for both rule lists and per-domain DNS, unknown profile ids, malformed payloads, and that a write leaves unrelated profiles byte-identical.