Commit Graph

3289 Commits

Author SHA1 Message Date
Nick Mathewson b137be222b Merge branch 'config-sources-api' into 'main'
Tidy up ConfigurationSource a bit

See merge request tpo/core/arti!495
2022-05-11 15:53:32 +00:00
Ian Jackson 775432bee8 Document semver changes to ConfigurationSources etc. 2022-05-11 15:53:17 +01:00
Ian Jackson 8fe62da871 Move default_config_file() into arti-client
This will let other embedders use it.
2022-05-11 15:53:03 +01:00
Ian Jackson c76c79d023 ConfigurationSources: Have the generics take Into<owned>
These generic arguments weren't consistent.  It doesn't make sense ot
insist on getting a borrowed type and then cloning it.  So tidy things
up in the direction of taking owned values, which is what
ConfigurationSources actually needs.

(My personal preference would be &dyn to avoid monomorphisation code
bloat but that was controversial last time I proposed it somewhere.)
2022-05-11 15:53:03 +01:00
Ian Jackson c9fee15cbf ConfigurationSource: Move "usual" logic for construction 2022-05-11 15:53:03 +01:00
Ian Jackson 93da612984 default_config_file(): Have it return Result, not Option
Discarding this error is not right.
2022-05-11 15:53:03 +01:00
Ian Jackson 26b3115586 tor-config: Export CfgPathError
It is not clear to me how this `pub enum` survived the "inaccessible
pub" lint.
2022-05-11 15:53:03 +01:00
Ian Jackson e363b79a01 ConfigurationSource: Rename new to new_empty
This emphasises its nature.  We're going to provide a more cooked
constructor in a moment.
2022-05-11 15:53:03 +01:00
Nick Mathewson cc3ec8089d Merge branch 'cargo-feature-elucidation' into 'main'
Improve documentation around Cargo features; make Runtime require Debug

Closes #445

See merge request tpo/core/arti!496
2022-05-11 14:17:33 +00:00
eta 864fd03917 Improve documentation around Cargo features; make Runtime require Debug
- arti#445 highlighted the lack of good documentation around Arti's
  multiple runtime support, as well as it being difficult to determine
  what runtime was actually in use.
- Improve the documentation to solve the first problem.
- To solve the second problem, make Runtime require Debug (which is
  arguably a good idea anyway, since it makes them easier to embed in
  things), and print out the current runtime's Debug information when
  arti is invoked with `--version`.
- (It also prints out other Cargo features, too!)

fixes arti#445
2022-05-11 13:26:35 +01:00
eta 0597c31a6f Merge branch 'dirmgr-purification-2' into 'main'
Refactor the tor-dirmgr bootstrapping code more gracefully

See merge request tpo/core/arti!488
2022-05-10 17:10:45 +00:00
eta 5a2d08e005 Merge branch 'fix-coverage-ci' into 'main'
Disable fs-mistrust in coverage CI.

See merge request tpo/core/arti!493
2022-05-10 13:09:45 +00:00
Nick Mathewson 50493c1300 Merge branch 'excise-husky' into 'main'
Remove cargo-husky, and replace with manual instructions

See merge request tpo/core/arti!494
2022-05-10 13:06:38 +00:00
eta 6fc7a864c7 Remove cargo-husky, and replace with manual instructions
A build script reaching into your .git/hooks/ and modifying them
nonconsensually was a bit of a horrifying concept, and also made it hard
to build arti with the feature disabled. Remove this crate, and replace
it with manual instructions on how to install the hooks in
CONTRIBUTING.md.
2022-05-10 13:36:49 +01:00
eta 33b2b428bd tor-dirmgr: move apply_netdir_changes() to be a DirMgr method 2022-05-10 13:29:39 +01:00
eta 27f4657ff1 tor-dirmgr: small fixups for the bootstrapping refactor
- Some FIXMEs got removed or amended.
- AddMicrodescs now yields a mutable reference, so we can use .drain()
  and reuse the allocation.
- Some panics were downgraded to debug_asserts.
2022-05-10 13:29:39 +01:00
eta 8347f8cb7e tor-dirmgr/bootstrap.rs: error on older netdirs, add log line
- We don't want to inadvertently replace our netdir with one that's
  actually older, so detect and error on this condition.
- Also, print a debug line when we get a new netdir without enough
  guards.
- (An unrelated TODO was also added.)
2022-05-10 13:29:39 +01:00
eta 2c28e217dd tor-dirmgr/state.rs: take an object to get a netdir, not a netdir
- Taking a previous netdir directly and keeping it around before we need
  it is a bit of a waste of memory, and also doesn't mesh well with how
  SharedMutArc works.
- To remedy this, introduce a new trait `PreviousNetDir` and have the
  state machines take that instead. (I was a bit tempted to just pass in
  the SharedMutArc directly. Maybe I should've done that.)
2022-05-10 13:29:39 +01:00
Nick Mathewson 78e86e6b81 Disable fs-mistrust in coverage CI.
The CI runners like to run as root with umask 000, which our code
rightly freaks out about.
2022-05-10 08:14:13 -04:00
eta 27073a5d23 tor-dirmgr/state.rs: remove GetConsensusState::bodge_new
- (Also fixes up some dirfilter stuff, whoops.)
2022-05-10 11:50:07 +01:00
eta 7b5fad3130 tor-dirmgr/state.rs: remove WriteNetDir, use filters directly
- The only purpose of WriteNetDir was to provide a filter, which isn't
  necessary any more. Refactor to provide the filter directly.
2022-05-10 11:50:07 +01:00
eta 8b0166970e tor-dirmgr/state.rs: use the NetDirChange API instead of WriteNetDir
- GetMicrodescsState now uses the NetDirChange API to propagate netdir
  changes, instead of modifying the netdir directly.
- PendingNetDir was refactored in order to support this use case.
- As a result, the netdir-related methods in WriteNetDir can be removed,
  leaving only the DirFilter for now.
- add_from_cache() no longer takes a store, because nothing uses it.
- (bodge: apply_netdir_changes() was put in a few places missed
  previously)
2022-05-10 11:50:06 +01:00
eta 7a52e77e45 tor-dirmgr/state.rs: add new NetDirChange API, consume it
- The new DirState::get_netdir_change() API lets the state machine
  export a NetDirChange: a request to either replace the current netdir,
  or add microdescs to it.
- bootstrap.rs now consumes this new API, even though nothing implements
  it yet.
- This will let us implement GetMicrodescsState without having to
  directly mutate the netdir. The calling code also handles checking the
  netdir against the circmgr for sufficiency, and updating the consensus
  metadata in the store, meaning the revised GetMicrodescsState will not
  have to perform these tasks.
2022-05-10 11:48:57 +01:00
eta cad815e31d tor-dirmgr/state.rs: feed through additional parameters, use them
- The additional parameters passed to GetConsensusState are now passed
  through all the states, and used as well.
- WriteNetDir doesn't have a now() or config() method any more, since
  the states now get this from the runtime or the config parameters.
- This required modifying the tests to make a mocked runtime and custom
  config directly, instead of using DirRcv for this purpose.
- Additionally, because we don't have to upgrade a weak reference for
  DirState::dl_config(), that function no longer wraps its return value
  in Result.
- (A bunch of the FIXMEs from the previous commit that introduced the
  additional parameters have now been rectified as a result.)
2022-05-10 11:48:56 +01:00
eta f0739e46aa tor-rtcompat: make CompoundRuntime handle SleepProviders properly
Previously, CompoundRuntime would use the default implementations of
SleepProvider::now() and ::wallclock(), instead of using its wrapped
SleepProvider. This mildly embarrassing omission has been rectified.
2022-05-10 11:42:53 +01:00
eta a9bae9adfe tor-dirmgr/state.rs: refactor GetConsensusState::new
- GetConsensusState::new now takes a set of parameters matching what it
  actually needs, instead of just taking a writedir. (It still *does*
  take a writedir, and indeed still uses it for basically everything,
  but that will eventually go away.)
- Its call sites were updated.
  - Some tests now need to take a runtime, and got indented a lot as a
    result.
  - Resetting was made non-functional, because we need to thread through
    the parameters passed to GetConsensusState to all of the other
    states, too. This will happen in a later commit.
2022-05-10 11:42:50 +01:00
eta 62ece0ea21 tor-dirmgr: move DirState to state.rs
- Given that this is effectively an implementation detail, it doesn't
  really make sense to have it be in the crate root...
- (also, we're going to change it a bunch now)
2022-05-10 11:39:32 +01:00
eta 72ea9e3438 tor-dirmgr/bootstrap.rs: refactor fetch_single
- fetch_single now takes what it needs, instead of an Arc<DirMgr<R>>.
- This required refactoring the CANNED_RESPONSE mechanism, given the
  test would otherwise fail due to not having a CircMgr to pass to
  fetch_single.
2022-05-10 11:39:32 +01:00
eta 2fd03564b9 tor-dirmgr: make note_request_* functions standalone
- DirMgr::note_request_outcome and friends are now just standalone
  functions, taking a CircMgr.
2022-05-10 11:39:32 +01:00
eta 8b44569b5f tor-dirmgr/bootstrap.rs: refactor query_into_requests, make it used
- query_into_requests is now called make_requests_for_documents, and
  does the &[DocId] -> DocQuery conversion internally instead.
- DirMgr::make_consensus_request and DirMgr::query_into_requests are now
  gone. The tests use the new functions, as does fetch_multiple.
2022-05-10 11:39:32 +01:00
eta 4a98ed1301 tor-dirmgr: move query_into_requests into bootstrap.rs
- There's no good reason these functions needed to be part of the
  dirmgr, apart from needing a runtime and a store.
- However, we can just add those as arguments and copy them over. This
  commit does that.
2022-05-10 11:39:32 +01:00
eta 13446ac65a tor-dirmgr/bootstrap.rs: refactor load_all -> load_documents_from_store
- Function renamed & docs tidied up a bit
- Function signature now takes what it needs (immutable &dyn Store
  instead of mutex, slice instead of Vec) and nothing more
- DocQuery::load_documents_into was also renamed
  DocQuery::load_from_store_into and given similar treatment
2022-05-10 11:39:32 +01:00
eta 0dfac00842 tor-dirmgr/storage.rs: impl Store for Box<dyn Store>
Annoyingly, Rust doesn't automatically generate this sort of `impl` for
you, and I'd like to reduce the usage of Mutex<DynStore> everywhere else
in favour of either &dyn Store or &mut dyn Store.

(This is for two reasons: firstly, we might have a Store implementation
that doesn't use a mutex as above, or similar refactors; secondly,
passing the raw trait object reference lets us encode mutability into
the function signature, which I believe is quite valuable.)
2022-05-10 11:39:30 +01:00
eta d7f2718a8b tor-dirmgr/lib.rs: move DirMgr::load_documents_into to DocQuery
Move the function out of DirMgr, giving it a new &Mutex<DynStore>
argument instead.
2022-05-10 11:38:00 +01:00
eta b4f4b18a90 Merge branch 'tinystr_nicknames' into 'main'
netdoc: add a new type for Nicknames

See merge request tpo/core/arti!405
2022-05-10 10:16:42 +00:00
Nick Mathewson 3b0336e841 netdoc: add a new type for Nicknames
Relay nicknames are always between 1 and 19 characters long, and
they're always ASCII: That means that storing them in a [u8;19] will
always be possible, and always use less resources than storing them
in a String.

Fortunately, the tinystr crate already helps us with this kind of
thing.
2022-05-09 15:59:38 -04:00
Nick Mathewson 4262e9d0ec Merge branch 'use-fs-mistrust' 2022-05-09 15:27:25 -04:00
Nick Mathewson 5c33499f28 Loosen checking for readable files within target directories.
If the target directory itself is unreadable by untrusted users,
then its contents can't be read[*] by them regardless of their
permissions.  If the target directory _is_ readable, then _it_ will
be rejected if we are forbidding readable objects.  (And if we
aren't we don't care if the contents are readable.)

A similar argument would apply to writable objects within an
unreadable target directory.  We're not making that argument, since
such contents are likelier to be a mistake.

[*] Unless they're hard-linked; see comments in "Limitations"
section.
2022-05-09 14:40:29 -04:00
Nick Mathewson dcc5a3cfe8 Add a CLI option to disable FS permission checks. 2022-05-09 14:40:29 -04:00
Nick Mathewson 8a62f9ce52 Remove "Mistrust" from the public API of arti-client.
I'm doing this per discussion, so that we can have it be part of the
TorConfig later on, and not break stuff as we change the Mistrust
API to have a builder.

This change, unfortunately, results in a little more internal
complexity and duplicated code in arti and arti-client.  I've marked
those points with TODOs.
2022-05-09 14:40:29 -04:00
Nick Mathewson b0f39abe32 arti: use fs-mistrust to validate configuration file locations. 2022-05-09 14:40:29 -04:00
Nick Mathewson 2938268f34 arti-client: Configure and use fs-mistrust.
This is derived from the environment, not the configuration file: We
might not want to trust the configuration file until we've decided
whether we like its permissions.
2022-05-09 14:40:29 -04:00
Nick Mathewson 20a85061b6 Update tor-dirmgr to use fs-mistrust. 2022-05-09 14:40:29 -04:00
Nick Mathewson 984190b3a3 tor-persist: Use fs-mistrust to verify state file permissions. 2022-05-09 14:40:29 -04:00
Nick Mathewson 8509ffff7a Add new FsPermissions ErrorKind. 2022-05-09 14:40:29 -04:00
Nick Mathewson 14e8243bdc fs-mistrust: add various methods.
This includes:

  * a CachedDir::join method.
  * functions to read and write from provided filenames in a
    CachedDir.
  * a method to tell whether a fs-mistrust error is about bad file
    permissions, or failure to inspect file permissions or some other
    kind of IO problem.
2022-05-09 14:39:49 -04:00
Nick Mathewson 0eda471aaf Merge branch 'netparams' into 'main'
NetParams: Document its role as a validated config parameter

See merge request tpo/core/arti!492
2022-05-09 16:13:30 +00:00
Ian Jackson cc99efb72a NetParams: Document its role as a validated config parameter 2022-05-09 15:35:50 +01:00
Ian Jackson 3a0da9e86a Merge branch 'coverage-weekly' into 'main'
export coverage to pages

See merge request tpo/core/arti!489
2022-05-06 16:31:26 +00:00
Nick Mathewson 1dfb58a23c A few small changelog style edits. 2022-05-06 10:21:38 -04:00