Skip to content

relaysrv: allow to listen for requests on an IP address different to the external address #7196

Closed

Description

@nadiamoe

When trying to run a relay using the syncthing/relaysrv docker image on a multihomed server (e.g. Kubernetes), I get the following:

2020/12/14 21:21:41 main.go:138: strelaysrv v1.3.4 "Fermium Flea" (go1.13.8 linux-amd64) [email protected] 2020-01-14 07:01:03 UTC
2020/12/14 21:21:41 main.go:144: Connection limit 838860
2020/12/14 21:21:41 main.go:157: Failed to load keypair. Generating one, this might take a while...
2020/12/14 21:21:41 main.go:183: ID: ZEHCSIS-ZBH4DQM-W6K75CQ-AACASFF-PTVRV3H-DDMZXJN-WQYBNZJ-6NAKVAH
2020/12/14 21:21:41 main.go:233: URI: relay://212.129.50.60:22067/?id=ZEHCSIS-ZBH4DQM-W6K75CQ-AACASFF-PTVRV3H-DDMZXJN-WQYBNZJ-6NAKVAH&pingInterval=1m0s&networkTimeout=2m0s&sessionLimitBps=0&globalLimitBps=2099200&statusAddr=:22070&providedBy=Roberto Santalla (@rsroobre)
2020/12/14 21:21:41 main.go:236: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2020/12/14 21:21:41 main.go:237: !!  Joining default relay pools, this relay will be available for public use. !!
2020/12/14 21:21:41 main.go:238: !!      Use the -pools="" command line option to make the relay private.      !!
2020/12/14 21:21:41 main.go:239: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
2020/12/14 21:21:41 pool.go:16: Joining https://relays.syncthing.net/endpoint
2020/12/14 21:21:41 pool.go:45: https://relays.syncthing.net/endpoint failed to join due to IP address not matching external address. Aborting

If I'm not mistaken, the last line is telling me the address in which I've set the relay server to listen is different from the IP my machine uses to make requests to the world. I think this is a fair use case for multihomed servers.

Is there any possibility of removing this check? My relay server has been up & running publicly for several years, having to remove it because I'm migrating my server to K8s would deeply sadden me :(

Thanks in advance for your time

Activity

  1. added
    enhancement
    needs-triage
    on Dec 14, 2020
  2. AudriusButkevicius commented on Dec 14, 2020

    @AudriusButkevicius
    Member

    Have you checked --help?

    --ext-address is there for this specific reason.

  3. nadiamoe commented on Dec 14, 2020

    @nadiamoe
    ContributorAuthor

    Hi @AudriusButkevicius ,

    Thanks for the quick response. I think I was too scarce on the post above, as I forgot to post the config I'm using (which includes --ext-address):

              args:
                - -global-rate
                - "2099200"
                - -provided-by
                - "Roberto Santalla (@rsroobre)"
                - -ext-address
                - st-relay.roobre.es:22067
                - -debug

    st-relay.roobre.es resolves to 212.129.50.60, which can be seen in the log I posted above. This is also the address where the input port is mapped and therefore where I expect clients to connect to. I double-checked that the port is correctly mapped and accessible from the outside by running nc -vv st-relay.roobre.es 22067 from my llocal machine.

    However, the machine hosting the relay server is performing requests to the internet from a different IP address, which I think might be confusing the relay pool. Could this be the case?

    Thanks!

  4. nadiamoe commented on Dec 14, 2020

    @nadiamoe
    ContributorAuthor

    I made a quick search and it would seem that the error I'm seeing is reported here:

    log.Printf("Failed to join %v: IP address not matching external address", pool)

    Which is, in turn, returned by the pool server here:

    http.Error(w, fmt.Sprintf("IP advertised %s does not match client IP %s", host, rhost), http.StatusUnauthorized)

    It would seem that this is indeed a check in the relay pool server, which rejects clients when the advertised address is different from the one making the request. I still want to make a point saying that this might not be an uncommon scenario for dedicated servers. Would you be open to reconsider this? Perhaps if I understood the motivation behind this check (security maybe?) we could discuss an alternative approach.

    Thanks again for your time.

  5. AudriusButkevicius commented on Dec 14, 2020

    @AudriusButkevicius
    Member

    Why is it dialing out a different gateway than it expects to get connections back?

  6. nadiamoe commented on Dec 14, 2020

    @nadiamoe
    ContributorAuthor

    Why is it dialing out a different gateway than it expects to get connections back?

    @AudriusButkevicius This is not uncommon in multihomed environments, or in this case, in Kubernetes. It is designed that way so the machine can have its own IP address, while at the same time the services hosted in it are accessed through other addresses, for example behind load balancers. In this case there is not the case (the address in which the relay server listens will not change), but it is different from the one the host uses because of this. This also allows to decouple the service from the machine is being run on, which is useful for clusters.

    It is not really my choice, it is "just how Kubernetes works", if you want to say it like that.

    I might, however, ask the opposite question: Why is the relay server assuming that a particular host can only have one address?

  7. AudriusButkevicius commented on Dec 14, 2020

    @AudriusButkevicius
    Member

    So I can't really see a good reason why the check is there.
    We perform a connection test anyway.

    Sorry for closing this early, but from your original report it looked to me like you are just looking for --ext-address.

  8. removed
    needs-triage
    on Dec 14, 2020
  9. calmh commented on Dec 15, 2020

    @calmh
    Member

    I think the check is reasonable as-is, in that I think we want the relay pool to only accept voluntary submissions. That the announcement comes from the actual relay is one way to check that. Without the check I could announce someone else's supposedly secret relay to the relay pool without their consent.

    Of course there are other solutions to this, but they would require changing the relay protocol (or at least handshake) I think.

  10. nadiamoe commented on Dec 15, 2020

    @nadiamoe
    ContributorAuthor

    Hi,

    Thanks for the explanation, I think I understand the problematic now. It is true that removing the check could open the door for a malicious agent to spam submissions on behalf of other hosts.

    A possible solution that comes to my mind is adding some sort of "negotiation phase" to the relay, in a way similar to the following:

    1. The relay advertises its address to the pool server
    2. The pool server returns a random token to the relay
    3. The relay stores that token in memory and serves it somewhere, e.g. in http://external-address:22070/token
    4. Two or three seconds later, the pool server tries to fetch http://external-address:22070/token and compares the token with the one it dispensed.

    In my mind (I haven't looked too much at the code) this could be implemented as a part of the discovery phase, rather than the relay protocol itself. In addition, this step could be triggered only if the advertised address and source address do not match (i.e. in this section of the code), making the change non-breaking.

    Of course this adds a bit of weight on the pool server, as it would need to keep track of these tokens at least for a short while.

    What do you think about this approach? If you think it is worth implementing, I could try and write a PoC and PR with it.

  11. calmh commented on Dec 15, 2020

    @calmh
    Member

    Yeah, that's something like what I was thinking of when I said another solution, though I was thinking the token would end up in the relay handshake. Your idea is better. Another option would be to do the registering with the relay certificate as client certificate. The relay pool server can then do the connect back to whatever address and accept it as long as the presented certificate is the same.

  12. nadiamoe commented on Dec 15, 2020

    @nadiamoe
    ContributorAuthor

    Another option would be to do the registering with the relay certificate as client certificate.

    By this, do you mean reusing the certificate for the HTTP registration? I think that might be more complex, as it would require setting up https and would break existing configurations.

  13. calmh commented on Dec 15, 2020

    @calmh
    Member

    The request to register with the pool server is a HTTPS POST to https://relays.syncthing.net/endpoint. The relay has a TLS certificate that is uses for relay connections. The relay server could present that certificate as a client certificate in the HTTPS POST. Then, when the relay pool does the connection check it can compare the certificate presented by the relay with that used in the registration request. If it's the same certificate we know it's the same relay server.

  14. AudriusButkevicius commented on Dec 15, 2020

    @AudriusButkevicius
    Member

    Anyways, all of these are non-trivial in terms of effort to implement and to support migration/rollout for existing relays.

    Do we really think we'll do this?

    I doubt it, hence my heart is going back towards close as won't fix.

  15. nadiamoe commented on Dec 15, 2020

    @nadiamoe
    ContributorAuthor

    The request to register with the pool server is a HTTPS POST to https://relays.syncthing.net/endpoint. The relay has a TLS certificate that is uses for relay connections. The relay server could present that certificate as a client certificate in the HTTPS POST. Then, when the relay pool does the connection check it can compare the certificate presented by the relay with that used in the registration request. If it's the same certificate we know it's the same relay server.

    Ok, I understand now. Sending the certificate on announcement is an easy change, and if said cert is already sent by the relaysrv to the pool in the connection check, asserting that it is the same shouldn't be much of a change either.

    Anyways, all of these are non-trivial in terms of effort to implement and to support migration/rollout for existing relays.

    I think that these mechanisms could be implemented only in the case the remote IP check fails. Rather than returning an error, the pool server could store a flag like "verification pending" and check the certificate in the connect phase only if this flag is set. That way the change would not be breaking, right?

    Do we really think we'll do this?

    In the end it's up to you to decide, but please keep in mind that you can count on me to lend a hand with a PR for the solution :)

  16. calmh commented on Dec 15, 2020

    @calmh
    Member

    Someone might, at some point.

  17. AudriusButkevicius commented on Dec 15, 2020

    @AudriusButkevicius
    Member

    Sure, if you want to file a PR fixing this, I won't stop you.

    Global discovery client/server already does this certificate validation to prevent this same spoofing, in case you are looking for inspiration.

    We don't need any sort of verification pending state, if the cert is there, we ignore host mismatch and do cert based validation in the "test that the relay actually works" part. If the cert is not there, we stick to host checking.

  18. nadiamoe commented on Dec 15, 2020

    @nadiamoe
    ContributorAuthor

    Looks like we have an approach then!

    Thanks for your feedback and ideas, I'll allocate some time to work on a PR implementing it :)

  19. added 2 commits that reference this issue on Dec 21, 2020
    b5de499
    7b89bc5
  20. added this to the v1.13.0 milestone on Dec 21, 2020
  21. added
    skip-changelog
    on Jan 11, 2021
  22. added a commit that references this issue on Jan 11, 2021
    a1146fa
  23. LINKIWI commented on Aug 10, 2021

    @LINKIWI

    @calmh @roobre I see that #7217 was merged quite some time ago but I'm still seeing IP address not matching external address when joining the public pool at https://relays.syncthing.net/endpoint and when the origin IP is different from the -ext-address declared IP. This behavior is reproducible on v1.15.0 as well as on db302b1 when built from source.

    I verified that the client (relay server) is properly sending along its cert and key in the initial request to the pool server. Is there some other client-side configuration I'm missing? Or is it simply the case that #7217 has not yet been delpoyed to relays.syncthing.net?

  24. added
    frozen-due-to-age
    on Feb 6, 2022
  25. locked and limited conversation to collaborators on Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfrozen-due-to-ageskip-changelog

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions