Repository navigation
cmd/strelaysrv: Add optional auth token (fixes #3987) - #8561
Conversation
Make replaysrv check for a token before allowing clients to join. The token can be set via the replay-uri.
dd7c302 to
f9f9ae1
Compare
calmh
left a comment
There was a problem hiding this comment.
Minor organizational comments...
|
Also, I think we should disable joining the pool if its provided, given that's the default behaviour? |
calmh
left a comment
There was a problem hiding this comment.
So unfortunately it's not that simple. The relay protocol uses the simple, old and outdated XDR encoding and it's not the case there that we can simply add a field. As written the relay server now always expects the token field to be there when deserializing, though it may of course be zero bytes, so it will reject "old" Syncthing clients with an error. The quick hack solution here is probably to check the incoming join request length before deserializing it -- if it's zero bytes it's the old variant and we don't need to deserialize, if it's more than zero bytes it's the new version. A longer term solution would be to evolve the protocol to protobuf but that requires a few more changes.
In prior versions of the protocol JoinRelayRequest did not have a token field. Trying to unmarshal such a request will result in an error. Return an empty JoinRelayRequest, that is a request without token, instead.
|
I tried the quick-fix for now, giving the protobuf-change a shot requires some prior learning on my part, but i may tackle that in the future. |
| messageTimeout: time.Minute * 2, | ||
| connectTimeout: timeout, | ||
|
|
||
| token: uri.Query().Get("token"), |
There was a problem hiding this comment.
Just being cautious, are we sure this doesn't panic if you don't have a query string/query param?
There was a problem hiding this comment.
I just tested it but also the documentation of net/url reads
Query parses RawQuery and returns the corresponding values. It silently discards malformed value pairs.
and
Get gets the first value associated with the given key. If there are no values associated with the key, Get returns the empty string.
AudriusButkevicius
left a comment
There was a problem hiding this comment.
Lgtm other than the last question
* main: docker: Fix handling of PCAP variable (fixes syncthing#8567) cmd/stcrashreceiver: Update to more modern panicparse (syncthing#8566) cmd/strelaysrv: Add optional auth token (fixes syncthing#3987) (syncthing#8561) lib/fs: Skip xattrs test on EOPNOTSUPP (fixes syncthing#8564) (syncthing#8565) gui: Add connection status icons to Remote Devices (fixes syncthing#8244) (syncthing#8553)
|
I don't know if this does what it's supposed to do. As this is currently implemented, it just leaks the relayserver token to discovery, where it can be retrieved by anyone, without authentication. Anyone can then use the token to join the relay, so there isn't really any security right now. The only requirement is that you need the device ID of a device connected to a "protected" relay. Discovery then tells you the token as part of the announced addresses. Given that syncthing does not consider device ID's to be a secret, it means that the token implemented here is not a secret either. |
|
:D that should probably be improved |
That is unfortunate, i was not aware of this. It is my understanding that, as long as you also run your own discovery-server with a private certificate (requiring its ID on the client), the token should not get leaked to devices you do not control. Is that correct? |
I think that depends on how visible/reachable the private discovery server is. AFAIK, discovery servers do not require client certificates on GET requests (only when clients announce/POST themselves), so if your server is reachable for a potential attacker they can still query this information. All clients that have access to the discovery server can see the token. The server-side certificate on the discovery server doesn't matter, as the attacker can simply skip certificate validation. It's there to ensure authenticity, not for access control. |
Don't you still need to know the ID of the discovery-server, even if it is reachable for a potential attacker? But i understand, that the behavior as implemented at the moment, is not optimal. Maybe actually using client-certificates for authentication would be a possible way? |
No. The ID of the discovery server is a human-friendly encoding of the discovery server's certificate hash (just like normal st clients). The syncthing client uses it for identity verification (authentication) of the discovery server. This prevents MITM of the connection, but it is not a mechanism that can be used for authorization. Any attacker can immediatly deduce the ID from the certificate simply by connecting to the discovery server (under the assumption that the attacker is not itself subject to MITM during this connection).
Client certificates are currently used for authentication. Whenever a syncthing client wants to announce itself on the discovery server, it needs to present its certificate (incl. proof of key possession) to authenticate itself. For device probing (requesting info about others) authentication of the client is currently irrelevant, so there's no client authentication here. I presume your goal is authorization: Authorization is access-control (ensuring that someone is allowed to access something), while authentication is simply the assertion of an identity ("yes, I am really syncthing client 12345"). The discovery server can only perform authentication, as it cannot possibly know which devices are authorized to access it. The design of the discovery server is such that any device is allowed to access it. Identity is asserted (authentication) where necessary, to prevent clients from stealing others identity (which could be misused to advertise malicious addresses in the name of others). You can of course look into adding some sort of authorization into the discovery server: A list of preshared device IDs that are allowed for example, or a password like with this PR. With respect to this PR, I would definetly suggest preventing the leak of the token to discovery altogether. Adding authorization to discovery is certainly something that could be interesting for some use cases, but I would consider it a bandaid for the relay server token issue: We should not assume that the relayserver token feature is only used in conjunction with a private discovery server. The reason the token is currently leaked to discovery appears to be because custom relayservers are currently treated as an URL/URI in the syncthing client. The token is configured as a parameter within this URL, and the entire URL (incl. token) is announced to discovery. This used to be necessary, because the URL also contains the ID of the relay server, which is needed for authentication of the relay server by others. Hence the syncthing client posts the entire URL. However, now that we have added a token to that URL, it is also announced. A possible solution I imagine (not having actually looked at the codebase too much) is to change the handling of relay server URLs. Perhaps the token could be treated as a special parameter that is filtered from the URL before announcing it to discovery. This would mean that clients attempting to dial a relay server (joining an existing session in relay protocol speak?) cannot know the correct token, but as its implemented in this PR, the token isn't actually required for that purpose, right? So it would just work, even if dialing clients don't know the token. |
|
Thanks @GermanCoding for the detailed answer. Please bear with me here:
If one would generate the client certificates (~/.config/syncthing/*.pem) by hand with an own CA, would it not be hypothetically possible for the discovery- and realy-server to check if the certificate was signed by that CA and therefore authorize the client? Than one "just" needs to distribute certificates to the private clients and there would be no need for tokens.
I'm not sure if i understand: after your proposed change, a client not having the token configured in its configuration would not be able to deduce the token via discovery and therefore not be able to use the relay announced by discovery, what is what we want correct? What do you mean with "it would just work"? |
For the relay server: In theory yes, but that's a significant philosophy change for syncthing. Syncthing is not based around the PKI-world, but rather uses certificates as a type of preshared public key. CA-signed certificates don't really play well with this. For example, in order to use your own certificates in syncthing you need to enable advanced options to allow different CN names. Syncthing is also currently hardcoded to expect exactly 1 certificate, so its difficult to use things like intermediate certificates - a necessity for a secure PKI. Validating certificate chains is also a rabbit hole in itself. In general this adds a lot of new complexity and moving parts in the syncthing core where previously was none. Securely running your own PKI is also not a trivial task, asking a lot from even experienced users. Syncthing also has no method of revoking certificates currently, another thing that would need to be considered. For the discovery server, even more code + design changes are needed, since the certificates are currently optional for GET operations and would need to become mandatory in order to enable this.
I probably worded this confusingly. What I meant: My understanding of the syncthing codebase is, that relays work as follows:
WIth the current PR, the current state appears to be that the token is required only for opening a new session with a relay server (the If the previous paragraph is the current state, a fix is (more or less) trivial: Just don't leak the token to discovery, and everything will still work as it is now. If the previous paragraph is false, more changes might be needed. (My thought process was that currently both syncthing clients A and B have the token due to the discovery leak. If the discovery leak is removed only A knows the token. This may be a problem, but with the current logic, it's not) |
Documentation for PR syncthing/syncthing#8561 Also took the opportunity to document missing flags `-pprof` and `-version`
Attempt to implement a sort of authentication for relaysrv by checking for a simple token before allowing clients to join.
tested with
I'm not quite sure if this is a good way to implement this, or if there are security-implications so i am happy for comments.
Relevant issue: #3987