Dependency Free, Unified Payjoin Service #775
Replies: 1 comment
|
since it was mentioned on the call yesterday, assuming we go with eager persistence, some viable approaches in order of descending reasonableness:
any of these these would only implement a KV store with immutable expiring entries and no variation in TTL. all are arguably simpler simpler than redis or any other external database because they do not depend on any external processes/services, and do not use the database for signalling (the pubsub mechanism). not using the DB for signalling precludes running a directory with multiple web servers and a single DB server, but it is extremely unlikely that CPU will ever be the bottleneck for the directory and even if it is that a redis cluster would successfully scale this horizontally given the additional overheads. sqlite is perhaps overkill, but makes pruning very easy, no need to walk the file system or encode/decode data into filenames manually, so arguably just as reasonable as plain files. custom batch files would probably perform consistently whereas loose files may be more sensitive to choice of filesystem or OS but it seems very unlikely that this would be a problem in practice, and it seems like sqlite would be significantly simpler as an alternative to plain files on disk. sled is no longer actively maintained and arguably overkill for this use case so it seems like the least attractive. |
Uh oh!
There was an error while loading. Please reload this page.
This post proposes design for the combined directory + relay service in a single binary.
Motivation
Currently the relay and directory are two separate binary crates that live in two separate repositories. A reverse proxy is needed for TLS and in the directory's case redis is also required. We provide a docker compose configuration to set this up, but this has not been without challenges
It would be preferable if we had a single binary service that makes it possible to run both a directory and a relay in the same server (or only one of these services if so desired), and HTTPS was supported natively both as a server and in the relay's case as a client, only requiring a publicly reachable hostname as configuration, as opposed to a docker compose setup.
Design Considerations
ACMEv2
Given a hostname and contact email,
tokio-rustls-acmecan obtain a signed certificates, removing the need to deploy with certbot and a reverse proxy.PQ TLS
Enabling
prefer-post-quantumin rustls changes the preference order so X25519MLKEM768 is the preferred preferred KEM. AES 256 is preferred already, so this should provide post quantum secure transport layer encryption.This is desirable since directory or relay traffic saved today might be decrypted later, undoing privacy after the fact.
Note that this is not post quantum end to end encryption, see #680 for more details.
HTTP versions
QUIC should ideally be preferred between relay and directory. QUIC, HTTP 1.1 & 2 should all be supported. See #681.
This is not an immediate priority, but will become more valuable WRT traffic analysis adversary if multihop OHTTP is implemented, but before then would have a very limited impact on privacy.
Tor
See #774.
For
.onionaddresses in authorities, arti provides client services.For making services available over
.onionaddresses, arti has also supported hidden services for a few releases.Currently arti still has some privacy caveats for hidden service, so hosting an anonymous directory would not yet be supported, but for services accessible on clearnet anyway this does not present an issue.
HTTP handlers
Directory
The new behavior would be pretty much the same as the current behavior, with backwards compatible HTTP handling as well as an OHTTP gateway for v2 only services.
Relay
The relay would be served on the same host as the directory.
The relay must not forward OHTTP requests to itself. This is simple to enforce since the service will know it's own hostname, except for testing (where only
localhostcould be permitted?).Since the downstream OHTTP gateway's authority is also specified by path, but there is no ambiguity, shortids are 13 bech32 characters, and authorities are either hostnames (fully qualified, so containing a
.) or IP addresses (containing.or:). This allows v1 backwards compatible directory requests to be distinguished from v2 relay requests. v2 directory requests can be distinguished since they are handled by the OHTTP target resource.This seems preferrable to identifying the service by authority (e.g.
relay.mypayoinexample.tldvsdirectory.mypayjoinexample.tld) since that would require two DNS entries, and introduces two authority strings where OHTTP gateways might be found, needless complexity.This is also preferable to using the OHTTP key id to distinguish the services, since that field in the OHTTP header is visible to relays.
Relay (OHTTP Target Resource)
This is not necessary unless multi-hop OHTTP is implemented. See #582.
However, when implemented OHTTP submission would no longer distinguish relay vs. directory requests, so the OHTTP target resource handling is the same as telling apart v1 backwards compatibility from relay requests. Therefore it seems like it makes sense to implement just this routing behavior, as it is arguably simpler to implement that just once.
Storage
For simplicity, it makes sense to split v1 and v2 storage, as they have different properties:
Assuming a TTL of 24 hrs, 500,000 sessions in that time (=~ 3472.2 sessions per block, a very generous upper bound), and 2 messages per session, that's 7168 * 1e6 = 7GB of data for the payloads. The indexing overhead for 1 million entries would only require a few tens of MB in memory.
Rate limiting credentials can constrain this more strictly in the future should the need arise, but in general the implication is that 1-2 GiB should suffice for running a useful directory service even with significant adoption.
In Memory Storage:
A hashmap keyed by
ShortId, containing entries of the formwhere
Pis either[u8; 7168]for v2 orStringfor v1Then a dequeue of keys in insertion order can be used to delete entries in FIFO order, whether lazily or eagerly.
The read status (and timestamp?) of individual entries can also be tracked, to more preferentially expire entries that already have been read, at the cost of additional complexity (can't use a simple dequeue anymore for expiry).
Persistent Storage
Since the data is transient, for simplicity it's probably easiest to just serialize the in memory storage on graceful shutdown. Even in the worst case this should only take a few seconds to save.
Alternatively all this data can be written eagerly to a series of append only files, and deleted en masse (like a slab allocator) or to a sqlite or sled db entry by entry.
If v1 payloads are persisted (though see above for why that's probably not the best idea) they could additionally be encrypted by a key that is ratcheted forward on expiry, so that encrypted payloads don't end up on the server's persisted storage. That said it seems much better to just not store those persistently in the first place.
Graceful restarts & upgrades
In the absence of a reverse proxy, we can still have graceful upgrades with no downtime, e.g. using shellflip.
Logging
We use the tracing crate.
For testing runs, especially in CI, it would be nice if we created trace artifacts (e.g.
tracing_chromebased) with spans for individual test runs and test cases as well as all the services involved (including tracing across relay and directory when in the same process space, but without using any opentracing HTTP headers as that would be a privacy liability in production).For production, there is no substantial benefit for opentracing style spans. With docker compose we filled up the container logs, and lost them on restarts, neither of which is ideal. I think we can just leave this as is and not complicate with additional log collection, relying on docker for log rotation (or journald if deployed in a nixos module without the docker runtime).
For a testing deployment, maybe we want some sort of off the shelf log collection daemon and to also emit trace level events?
See also #509
Prometheus Metrics
See #735
Some proposed metrics:
Next Steps
The following order of operations makes sense to me, even though there are no dependencies between these:
everything else can be done more incrementally and concurrently, with the exception of multihop OHTTP which would be a significantly bigger project
All reactions