Repository navigation
Allow validation of relay join requests by certificate - #7217
Conversation
|
This is not trivially deployable in our actual infrastructure unfortunately because the relay pool server is behind a caddy reverse proxy that eats the HTTPS. We can forward the certificate in a header, like we do for discovery, but there it's behind nginx instead for historical reasons... I'll look into it. :/ |
* main: (27 commits) lib/fs: Correct wrapping order for meaningful log-caller (syncthing#7209) all: Handle errors opening db/creating file-set (ref syncthing#5907) (syncthing#7150) cmd/relaypoolsrv: Allow validation of relay join requests by certificate (fixes syncthing#7196) (syncthing#7217) lib: Close underlying conn in protocol (fixes syncthing#7165) (syncthing#7212) lib/db: Prevent IndexID creation race (syncthing#7211) gui: Reflect change in untrusted in sharing tab (syncthing#7201) lib/db: Remove index ids when dropping folder (syncthing#7200) lib/model: Fix flaky test and add some scanning debug (syncthing#7214) lib: Consistently set suture logging (syncthing#7202) lib/model: Unflake TestIgnoreDeleteUnignore (syncthing#7208) gui: Apply changes to untrusted (ref syncthing#6443) (syncthing#7206) lib/config: Remove deprecated pending entries from config (ref syncthing#6443) (syncthing#7204) all: Store pending devices and folders in database (fixes syncthing#7178) (syncthing#6443) gui, man, authors: Update docs, translations, and contributors gui: Sort folders and devices in advanced config modal (syncthing#7192) model: Actually print folder description in "Overriding" log message gui: version.tags is an array, which is truthy when empty build: Switch to gopsutil's v3 module (syncthing#7191) build: Update notify (fixes syncthing#7076) (syncthing#7189) lib/api: Returns tags in version as list (syncthing#7190) ...
Ouch, I've been there and it's a bit messy in that case. If you're going to forward the cert through a header tho, some things might need to be changed. Im not sure if this would work, for example: syncthing/cmd/strelaypoolsrv/main.go Line 345 in ac8c72f And this setting, which would need to be carried over to the reverse proxy: syncthing/cmd/strelaypoolsrv/main.go Line 213 in ac8c72f If it becomes a problem let me know so we can think about an alternative approach :) |
|
We already have this in the discosrv: syncthing/cmd/stdiscosrv/apisrv.go Lines 307 to 372 in 05f25e6 I think it's just a question of teaching Caddy to request & pass the client certificate and adding something similar to relaypoolsrv, so no big deal. |
|
Sooo I didn't submit my review :( |
| }, | ||
| }, | ||
| } | ||
| } |
There was a problem hiding this comment.
If I am not mistaken, we might fiddle with the default client somewhere in init/main setting our custom dialer?
There was a problem hiding this comment.
You are right, there was an httpClient initialized in main.go:
This is later modified with a few custom options. For some reason I misread that as the default client and changed it inadvertently. I have pushed a commit which reuses the pre-existing httpClient, however I'm not sure whether this is the correct approach, as the change made by poolHandler will propagate to other uses of the client.
| return | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Whats the rationale of this new check? I guess id might be empty at which point this would start failing?
There was a problem hiding this comment.
I think this is an attempt to do validation, but this is not what I have imagined. In the pool, there is code that tests the relay connectivity, the same code should check the certificate of the relay it got as it connected (to match the one it was given in post), checking for ids is fine I guess, but that doesn't prevent malicious advertisments.
There was a problem hiding this comment.
Yes, as @calmh pointed below, there was already another check in place for the presented cert to be equal to the id arg in the URI, so I leveraged that by checking it. Not the most clear approach in the world, but the id check was nested about 4 or 5 methods deep and I didn't want to break the signatures of all of them :(
|
I suspect this actually might not do what it says on the tin, and permits to work around the check :( i don't see any certs check in the "test" phase of this. |
|
I don't think this works around a check. We currently do two checks:
This adds an alternative to check number uno, namely that the announcer certificate matches the announced |
|
Ok, I guess I wasn't sure if the id in the uri is validated in any way, and browsing on mobile is painful. |
|
So apparently Caddy can't do this in any version today, unless I'm misreading things. (caddyserver/caddy#3767 to resolve shortly, I expect) |
Ouch, that sucks. Well, as a temporary workaround my relay is listening now on the external IP, so I guess I can leave it like that until caddy fixes that :) |
Purpose
As discussed in #7196, there might be some scenarios where a relay server might want to advertise itself from a different IP address from which it is actually listening on. This is currently not possible, as the relay pool server rejects join requests whose advertised remote address does not match the address used to make the join request.
This PR enables relay servers to send their TLS certificate in the join requests, provided the pool is contacted via https. The relay pool server will capture this certificate, generate the Device ID from it, and compare it to the advertised device ID. If they do not match, the request is rejected straight away.
This ensures that the agent sending the join request is indeed in possession of the key corresponding to the advertised device ID. This advertised device ID is later checked to be the same as the one behind the advertised IP address as a part of the original connection test by
performHandshakeAndValidationon:syncthing/lib/relay/client/static.go
Lines 240 to 242 in d904dfa
While this check is only triggered if
uri.Query().Get("id") != "", this is ensured by the mismatch check mentioned earlier.Testing
Very basic tested was performed locally by building a relay server and a pool server with the changes, and checking that they were able to exchange and validate the certificates. Please comment if you think more testing (automated or not) is desired for this.
Screenshots
N/A
Documentation
None done yet, please tell me if this is necessary.
Closes #7196