add connection-policy configuration #2788
Labels
No Label
0.2.0
0.3.0
0.4.0
0.5.0
0.5.1
0.6.0
0.6.1
0.7.0
0.8.0
0.9.0
1.0.0
1.1.0
1.10.0
1.10.1
1.10.2
1.10a2
1.11.0
1.12.0
1.12.1
1.13.0
1.14.0
1.15.0
1.15.1
1.2.0
1.3.0
1.4.1
1.5.0
1.6.0
1.6.1
1.7.0
1.7.1
1.7β
1.8.0
1.8.1
1.8.2
1.8.3
1.8β
1.9.0
1.9.0-s3branch
1.9.0a1
1.9.0a2
1.9.0b1
1.9.1
1.9.2
1.9.2a1
LeastAuthority.com automation
blocker
cannot reproduce
cloud-branch
code
code-dirnodes
code-encoding
code-frontend
code-frontend-cli
code-frontend-ftp-sftp
code-frontend-magic-folder
code-frontend-web
code-mutable
code-network
code-nodeadmin
code-peerselection
code-storage
contrib
critical
defect
dev-infrastructure
documentation
duplicate
enhancement
fixed
invalid
major
minor
n/a
normal
operational
packaging
somebody else's problem
supercritical
task
trivial
unknown
was already fixed
website
wontfix
worksforme
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Reference: tahoe-lafs/trac-2024-07-25#2788
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This ticket is for implementing the cache/reuse/override scheme described in #2759 (but that ticket is specifically about multiple Tubs, which is already done).
Here are the relevant ideas, copied from #2759:
workflow:
So our idea was that each YAML clause has two chunks of data: one local, one copied from the introducer announcement. The local data should include a string of some form that specifies the properties of the Tub that should be used for connections to this server. The StorageFarmBroker will spin up a new Tub for each connection, configure it according to those properties, then call getReference() (actually connectTo(), to get the reconnect-on-drop behavior).
The tahoe.cfg settings for foolscap connection-hint handlers get written into the cached introducer data. StorageFarmBroker creates Tubs that obey those rules because those rules are sitting next to the announcement that will contain the FURL.
Current status: reviewing https://github.com/tahoe-lafs/tahoe-lafs/pull/281 . Then we'll look at https://github.com/david415/tahoe-lafs/tree/2759.add_connections_yaml_config.0 .
In testing out PR281, I noticed that the
yaml.dump()
is emitting some pretty horrible-looking YAML, because of the preponderance of unicode strings in our announcements (which comes from the fact that we're shipping around JSON, in which everything is unicode). One test node I looked at had aNODEDIR/private/introducer_cache.yaml
with entries like:That's.. pretty ugly, and I'm not sure I'd want to ask someone to copy/edit/paste it into an override file.
I'm wondering if we should move to JSON instead (with
indent=1
on the output so we get newlines and indentation). It's not entirely human-friendly, but it wouldn't treat unicode as something magical.I noticed that if we used
yaml.safe_dump()
to write the file, intead ofyaml.dump()
, then both unicode and bytes get written out as normal strings (without the!!python/unicode
mess). When parsed withyaml.safe_load()
(or unsafeyaml.load()
), these come back as either bytes or unicode (probably depending upon whether it can be represented as ASCII or not). That's not ideal (I wish it would be consistently unicode), but it'd be easier to work with than the!!python/unicode
things.I'm changing the PR281 branch to use
safe_dump()
, to avoid this. Thanks to dstufft, I'm also modifying the loading side to always give us unicode strings, to match what we wrote out.In the longer run, I'm still thinking about JSON instead of YAML. On IRC, dstufft and simpson were in favor of JSON for machine-written files, but either YAML or TOML for files written by humans. (He said that Python is likely to be using TOML in the future, and !Rust/Cargo already does).
What about this: the cache could be in JSON, but the override file could be in YAML or TOML? I think we're only going to be putting three things in the override file (serverid as the key, FURL and connection-policy as the values), so it might not be necessary to copy-and-paste stuff from one to the other very much, and YAML/TOML is certainly easier to edit than JSON.
In 73b08d2/trunk:
The distutils-sig folks did a review of various structured-data file formats, in https://gist.github.com/njsmith/78f68204c5d969f8c8bc645ef77d4a8f , which makes for interesting reading.
here's the step 1 of the connections.yaml file:
https://github.com/tahoe-lafs/tahoe-lafs/pull/283
Daira has reviewed it. I committed a fix. What's next?
step 2 of the connections.yaml will include multiple introducers.
step 3 allow specification of transport plugins in various scopes; per server, per introducer and globally scoped.
Updating ticket title: this ticket is now the right place for connections.yaml stuff, and using the cache is just a minor part of that effort.
We spent most of today's devchat exploring syntax options for the "connection policy configuration file", aka connections.yaml.
We're still not entirely sure what to call it.
connections.yaml
?policy.yaml
?config.yaml
? We're also not sure about using YAML at all. We did decide that we like the nested-dictionary aspect of YAML, but we're leery of the gotchas that YAML offers (like strings vs identifiers vs booleans vs numbers, where some things are quoted and others are not). I'd still like to evaluate TOML for this, but I don't know if it does nested dictionaries nicely.But we did come up with syntax ideas that seem pretty good.
Introducers
First off: introducers. The
introducers:
section would map introducer nickname to FURL:The nickname is used to name the cache file. The introducer.furl from
tahoe.cfg
is also used (if any), and it gets some default-ish nickname likeintroducer
.If someone really convinces us, we could add connection-policy clauses (described below). But in the devchat we couldn't think of a use case where you'd want different policies for connecting to different introducers. And you can already influence the connection by just editing the FURL to change the hint types.
We also agreed that having different connection policies for the servers you learned from one introducer versus another was not likely to be a good idea (as in, "every server I learn from introducer A should get Tor-ified, but I'll make direct TCP connections to servers I meet through introducer B). Especially when dawuud pointed out that you might learn about the same storage server from two different introducers, in which case you'd have to figure out how to reconcile their two policies. But if you really wanted to do this, you could have another policy stanza under each introducer section, somehow named to make it clear that you're talking about servers learned through the introducer, rather than how you talk to the introducer itself.
"Introducerless mode" means
tahoe.cfg
has an emptyintroducer.furl=
, and there is nointroducers:
section in the YAML file. "Multi-introducer mode" means there are two or more introducers among tahoe.cfg andintroducers:
.Connection Policy
Now the global connection policy section. This tells Tahoe what to do when asked to make connections (to Foolscap connection hints now, later to HTTP things). For each type of connection hint, the policy file specifies a "handler" and some arguments. The default values are something like:
(We aren't sure this should be in a "global" section.. maybe the "connection_types" string should be at the top level. Also we aren't sure that it should be spelled "connection_types": maybe "connections" or "foolscap_connections" or something shorter)
The
tcp:
section controls what happens when a FURL wants you to connect via plain TCP (because the connection hint looks liketcp:example.org:1234
). Thehandler: tcp
goes to a lookup table that tells Tahoe to use a foolscap connection handler that uses plain TCP. In the future,handler: xyz
could ask the setuptools/twisted/zope.interface plugin system for a module that has registered itself with the name "xyz" (and to handle some specific Interface).The
tor:
section handles connection hints liketor:abcxyz.onion:80
. Thetor
handler would probably live in the Tahoe source tree (for now), and would try to import txtorcon (and log+ignore if it couldn't be imported). The keys undertor:
that aren't "handler" are passed as keyword arguments into the plugin. In this case, we're telling the tor-for-foolscap plugin that it's expected to launch it's own copy of the Tor daemon. Other options would be likecontrol_endpoint: tcp:localhost:9051
, to use a pre-running system Tor daemon.(question: we originally discussed:
with the extra
args:
because we originally thoughthandler:
would be a fully-qualified import+funcname string, like what setuptools entrypoint specifications do. In that case,args
would be passed as keyword arguments to the referenced callable. But withhandler:
being an index instead, we could probably be a bit more flexible about how arguments are passed. Also having the args at the same level ashandler:
is a bit cleaner. Maybe we should just pass the entire dictionary into the plugin and let it ignorehandler:
itself)For nodes that are configured to use Tor instead of plain TCP, there would be two nearly-identical sections, one for
tcp:
and one fortor:
, both specifying the "tor" handler:Note that any connection hint type not listed here would be ignored, to avoid the possibility of a new future connection type accidentally violating anonymity. Or maybe we only do that if
anonymous=1
is set.We can also imagine:
Server Overrides and New Servers
The
servers:
clause would serve two purposes. The first is to provide data on brand new (synthetic) servers, ones that might not be advertised through any introducer. This would mostly be used for the "introducerless" mode, but could also be used augment the regular introducer-based grid with a private server for just your own client.The second is to modify data about introducer-advertised servers, generally their connection policy and/or FURL. The following example would allow a private TCP-based server on a mostly-Tor grid (where the global policy says tcp should go to tor).
The dictionary key is the server identity key (an !Ed25519 public verifying key, currently used as the main index for introducer announcements). (we need to experiment to see if YAML can have hyphens or non-identifier characters in dictionary keys; we'd rather not put quotes around the string if we can avoid it).
Many of the other keys would replace or augment the data heard from the introducer. "nickname" is published by servers themselves, but could be overridden locally, in which case it would behave more like a pet name.
anonymous-storage-FURL
is the current way that clients connect to storage servers, although that will change when #666 Accounting happens (probably toaccounting-storage-FURL
or similar), andstorage-URL
will happen when we move to an HTTP-based storage protocol.permutation-seed-base32
is important for compatibility of share placement for older servers, but I think newer servers default to using the !Ed25519 pubkey for this, so it could maybe be omitted for synthetic servers.And then the
connection_types
section would control the connection policy. The idea is that each server (theallmydata.storage_client.NativeStorageServer
instance) will use the connection policy from theservers[$SERVERID]connection_types
dict if that's present, else it will fall back to theglobalconnection_types
config.We must be careful to prevent servers from publishing
connection_types:
themselves. We originally thought of putting the server-provided keys in one place, and the locally-specified keys in another, like:but it felt too verbose. Without the separate
announcement:
section, the code should probably first check forconnection_types
, then overlay the announcement with all remaining keys:The introducer announcement includes a lot of additional data that isn't very useful to override: version strings, sequence numbers, a "nonce" that I don't even remember the purpose of. While it might be useful to allow the YAML file to override any possible announcement key, it might be better to throw an error if we see any unknown key, or a key that doesn't make sense to override.
Finally, note that the Introducer was designed to let you publish more than just storage servers: each announcement includes a
service-name
field, and we originally planned to advertise Helpers, repairers, and even extra introducers through these announcements. The client only subscribes tostorage
, and we don't have any code to publish anything else. For brevity, we'll probably declare that the YAML file'sservers:
section is only referring to storage servers. If some future version of tahoe adds a new thing that we really want to call a "server" but which isn't a storage server, we'll have to come up with a new YAML section to describe it. Or, we could change the YAML section fromservers:
tostorage:
orstorage-servers:
or something.Accidentally Introducing A New Config-File Format
We know that we'd like to eventually move away from the INI-format
tahoe.cfg
file, for two reasons. The first is that it doesn't really support structured data (the original multi-introducer syntax would have needed lines likeintroducer.furl1=
andintroducer.furl2=
, since INI doesn't have lists). The second is that it'd be nice to safely machine-edit the config file.In Petmail, I've been experimenting with keeping all state in a SQLite database (config, runtime updates, user messages, everything). Config changes are done with CLI tools, or a web-based wizard-thing that gets to write changes as you click the boxes. While it's sad to not be able to point emacs at the file, you win transactional changes, schema enforcement, and no data-killing race conditions between user edits and program changes.
We talked a week or two ago about a
tahoe configure
command which could ask you some questions ("should we offer storage? you have X GB, how much should I use?") walk you through the setup process, examine your network situation ("it looks like you're behind NAT. Do you know what port-forwarding is? Let me test your setup. Great, we can be reached from the outside, enabling server."), sanity-check the config, then start the node. To re-run this tool inside a running node, we'd need the ability to safely modify the config file after startup.So I just want to avoid accidentally moving us to a YAML-based config file, if maybe we should be deliberately moving to an SQLite-based one. This YAML syntax is kind of nice, I can imagine moving other tahoe.cfg items over to it (eventually deprecating tahoe.cfg and automatically converting it to YAML at startup). But if we're going to do that, we should probably be intentional about it.
cache server information, use later (with overrides)to add connection-policy configurationI'm reading through the TOML spec. If we make "servers" into a list, with the pubkey as a dictionary item (instead of a key), then I our example would look like this:
Some notes:
servers
andintroducers
sectionsfoo.bar.baz
indicators, or with the inline{key = { subkey = "value"} }
syntax (which can be spread over multiple lines, like in python)"1.4"
(string) and1.4
(float).I think this pull-request is still relevant:
https://github.com/tahoe-lafs/tahoe-lafs/pull/283
It implements the connections.yaml 'servers' section, only.
Next I am going to work on the other two features that the connections.yaml should provide:
ok here's the multi-intro feature, the minimal code change without the web ui:
https://github.com/tahoe-lafs/tahoe-lafs/pull/284
ok next all add the transport plugin system...
btw i do think it will be a relatively easy code change if we want to switch away from yaml and use toml instead. if we wanna get fancy this of course could be abstracted into some api that sit's between the Client and the configuration. Maybe we should evaluate what that API would look like? It should help us switch to a database format as well.
note that the commit history for my multi-intro dev branch (pull request 284) preserves an epic battle against unit test failure. there was much bit rot. all fixed now:
https://github.com/david415/tahoe-lafs/commits/2788.multi_intro.0
I could make all this be a single commit or so if you want the fix-it commits removed.
Further... i had to add the web-ui changes (from truckee) in order to get all the tests to pass.
here's my work in progress implementing the transport plugin system:
https://github.com/david415/tahoe-lafs/tree/2788.transport_plugins.0
i'm still trying to fix it and get the tests to pass here. maybe you want a different plugin system than this one... but it should be easy to change it's design once i get it working.
ok then according to our discussion about transport plugins we've decided to utilize the existing twisted/zope IPlugin interface to manage the loading of plugins. Our connections.yaml file will merely refer to plugins by name which we will reference in our lookup table of plugins. Simple!
Foolscap transport plugins made to use the twisted/zope IPlugin interface and properly install the plugins into the twisted plugins directory via setup.py best practices, looky here! -->
https://foolscap.lothar.com/trac/ticket/256
i've also attempted to get my dev branch to use the twisted plugin system to load the foolscap transport plugins. so far it doesn't work... i'm doing something wrong but haven't tracked down my all mistakes yet. so what we have is a broken dev branch of an unfinished plugin system. ;-p
further, this dev branch ( https://github.com/david415/tahoe-lafs/tree/2788.transport_plugins.0 )
must be used with the corresponding foolscap dev branch with the IPlugin implementation of the transport plugins as specified in the previously mentioned foolscap trac ticket 256.
OK I've fixed an obvious bug and got most of the
test_introducer
unit tests to pass.Many of these unit tests are further complicated by our continuing to support the old intro V1 protocol... So I'm going to remove that code (there's a ticket open already --> #2784) because doing the code removal first saves lots of time.
Thoughts from our meeting today:
tub_options
that are passed throughStorageFarmBroker
intoNativeStorageServer
. It would change thattub_options
from a dictionary into a tuple of two dictionaries. The first dict would be used to callTub.setOption()
as now. The second would be used to callTub.addConnectionHintHandler()
(so the keys would be hint types and the values would be handler instances).DefaultTCP
in a stable place (foolscap#260), then change thetub_options
default to include{"tcp": DefaultTCP()}
, and changeNativeStorageServer.start_connecting()
to callTub.removeAllConnectionHintHandlers()
first. This will make it easy to modify the global connection policy in a later stepIn parallel to that, we can continue as planned (in comment:99512) to add patches that read from
connections.yaml
, one section at a time (maybe starting withintroducers
), leaving the connection policy stuff (and thus Tor) until the end.i quickly wrote an untested WIP dev branch to make tub_options be the 2-tuple as Brian describes above:
https://github.com/tahoe-lafs/tahoe-lafs/pull/311
i fixed some bugs in my code and made all the tests pass. that pull request is now ready for review
PR311 (tub_options/tub_handlers cleanup) landed in [61eb8398]
Make StorageFarmBroker use specified or default handler
another pull request
https://github.com/tahoe-lafs/tahoe-lafs/pull/317
please review
In reviewing the code to implement this, I'm starting to think that
connections.yaml
should only contain the per-server configuration (either overrides for introducer-announced servers, or complete information for non-Introducer locally-defined servers). And as a result, it should be calledservers.yaml
.Then
tahoe.cfg
would contain both the defaults (e.g. "use Tor to connect to TCP things"), and the details of how each connection type is implemented (e.g. "to use Tor, speak SOCKS to localhost:9050"). Neither one needs a lot of structure, so I don't think we need the nested dictionaries of YAML to control them.So I'm suggesting the following
tahoe.cfg
syntax:The
tor
section is defined as in #517 (defaulting to SOCKS on 9050/9150). Theconnections
section maps Foolscap connection-hint type (or "tcp" for HTTP) to a handler. To disable a type, map it to "disabled
" (which replaces thetor enable = false
setting from #517):(note that any unrecognized value for a
connections
key will cause a boot-time error, which should aid discovery of the correct syntax)Then
servers.yaml
won't have aglobal
section. It would still have a top-level section name (to preserve room for other sections, if we need to add them in the future), but I think it could be namedstorage
instead ofservers
, to make it clear that everything below is talking about storage servers and not about Helpers or something else. To add a brand-new (non-Introducer) server, you'd populate theannouncement
clause with a few important keys:(if you're pinning an introducer announcement, you could copy and indent the
ann
clause fromintroducer_cache.yaml
, although you don't strictly need to copy all the keys:What should happen if the same server-id show up in both
servers.yaml
and an introducer announcement? We could haveservers.yaml
overlay the announcement data (e.g.ann = introducer_ann.copy(); ann.update(yaml)
), which would let you override specific properties. But I can't think of any good use for that. I think it might be better to log an error when the announcement shows up. Since this log won't be very discoverable, it'd be a good idea to record the fact that an announcement appeared, and display a note on the relevant WUI page ("warning: announcement received (and ignored) for static server, see logs for details").Note that synthetic servers don't need a real server-id, and announcements are only accepted if they're signed, and the public verification key is the the server-id. So if you make up a server-id, there's no way for an announcement to ever overlap:
Each storage server has an implicit
connections
section, which is filled with the settings fromtahoe.cfg connections
. To handle Leif's use-case of a TCP-enabled server on a otherwise-Tor-restricted client, you'll need to overrideconnections
, to replace thetcp: tor
mapping withtcp: tcp
:tahoe.cfg
:servers.yaml
:In 66fcd6e/trunk:
dawuud reminded me that connections.yaml was also supposed to hold the multiple-introducer config. The proposed section was called
introducers
and contained a dictionary mapping introducer-petname to a dictionary with one defined key namedfurl
:(note that the original patch used "nickname" instead of "petname", which I think is inconsistent because this name is being chosen by the local client, whereas a "nickname", in our usage, is chosen by the object being named)
Since this is basically just a list of (petname, furl) tuples, I don't think we need the full power of YAML to represent it. So I'm thinking it can go into
tahoe.cfg
, right next to the oldintroducer.furl=
key. We just declare that every key which matchesintroducer-.*\.furl
is adding an introducer, and the part after the dash is the petname. This limits the petnames somewhat (no spaces, no dots, no punctuation), but I don't think that's a big deal.We can still use the petnames to build filenames for the local cache. The normal introducer has a petname of "" and uses
private/introducer_cache.yaml
. Atahoe.cfg
key ofintroducer-local.furl = pb://etc
would have a petname oflocal
and would useprivate/introducer_cache_local.yaml
.In 386edeb/trunk:
Note: https://github.com/tahoe-lafs/tahoe-lafs/pull/320 is really close to finishing this. Tor support works as it's supposed to. I2P is not yet implemented, but the framework is in place.
In 73d5376b/trunk:
In 0951201/trunk:
Two small updates:
tor enabled = false
instead ofconnections tor = disabled
, because that way I can avoid importing tor/txtorcon when we aren't going to use it. (the function that does the tor import is only paying attention to thetor
section, it was cleanest that way)tor enabled = false
, nottor enable = false
. I initially implemented it asenable
, but I'm fixing that now, since all other uses of enable/disable in tahoe.cfg use the past-tense (present-participle?) form, "enabled" / "disabled".In a03f68b/trunk: