Commit Graph

3256 Commits

Author SHA1 Message Date
Ian Jackson a334f17262 Merge branch 'socket-addr-list-builder' into 'main'
FallbackDir: orports: Introduce and use VecBuilder

See merge request tpo/core/arti!474
2022-05-04 18:13:45 +00:00
Ian Jackson df2813ed55 list_builder: Add some xrefs about macro_rules limitations
Apropos
  https://gitlab.torproject.org/tpo/core/arti/-/merge_requests/474#note_2800481
2022-05-04 18:35:33 +01:00
Nick Mathewson cb892116dc Fix typo 2022-05-04 17:34:47 +00:00
Nick Mathewson 019b3b9c59 Merge branch 'guard-restriction-list' into 'main'
GuardUsage: restrictions: Use list builder

See merge request tpo/core/arti!475
2022-05-04 16:24:56 +00:00
Ian Jackson 4ad4cae418 FallbackDir: Use VecBuilder for orports
And drop the ad-hoc orport() method.  This brings FallbackDir's
orports field in line with our list builder API.

The general semver note in "configuation" seems to cover most of this.
2022-05-04 17:18:55 +01:00
Ian Jackson cc394ca9b9 FallbackDir: Do orport validation after autogenerated build
This avoids it having to recapitulate defaulting logic.
2022-05-04 17:18:55 +01:00
Ian Jackson 6791758d0b FallbackDir: Do not consider defaulted-empty orport list to be valid 2022-05-04 17:18:55 +01:00
Ian Jackson 4262a440b5 list_builder: Update semver note 2022-05-04 17:18:55 +01:00
Ian Jackson 2487a46ef0 list_builder: Provide VecBuilder
This is for lists of plain types (non-builder types).
2022-05-04 17:18:55 +01:00
Ian Jackson 221fe63430 list_builder: Use Educe to derive Default
This allows us to use this with an item builder type which doesn't
impl Default.  (Obviously this only makes sense for items which aren't
actually builders.)
2022-05-04 17:18:05 +01:00
Ian Jackson 578684f290 list_builder: Make helper capable of handling generics
It is Quite Vexing that we have to use [ ] rather than the < > around
the generics, particularly given that we are also using [ ] to signal
"this is arrayish".

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-05-04 17:17:46 +01:00
Ian Jackson 0c001ed60e list_builder: Actually honour attributes
The docs were a lie.  $docs_and_attrs was missing from the expander.

And add a note about how any supplied docs are handled.
2022-05-04 17:16:36 +01:00
Nick Mathewson 1f64613e17 Merge branch 'locked' into 'main'
CI: Check that the lockfile is up to date.

See merge request tpo/core/arti!484
2022-05-04 15:58:19 +00:00
Ian Jackson c84d60910d GuardUsage: restrictions Add semver note 2022-05-04 16:19:09 +01:00
Ian Jackson 015db3d78d GuardUsage: restrictions: Use list builder
Although these do not appear in the config, it does have a builder.
It seems sensible to get rid of this ad-hoc list manipulation site,
and replace it with our standard list builder API.

define_list_builder_helper requires that the builder element type be
Deserialize.  Currently GuardUsageRestriction is a transparent, public
enum, so we aren't really exposing anything.

We could introduce GuardUsageRestrictionBuilder now, but
since it's not in the config and thereofore only in the public API of
the lower crates, we can definitely put that off.
2022-05-04 16:16:38 +01:00
Ian Jackson ab979b0ba6 Merge branch 'list-builder-rework' into 'main'
Replace list builder API and do not expose ThingListBuilder as part of config API

See merge request tpo/core/arti!481
2022-05-04 13:53:38 +00:00
Ian Jackson 875f3e4352 CI: Check that the lockfile is up to date.
For at least one job, run the first cargo run with --locked.  This
will fail if the lockfile needs updating.

I have verified that this correctly detects this situation:
  https://gitlab.torproject.org/Diziet/arti/-/pipelines/37692
failed.  Now I have rebased this branch onto main to get the fix to
Cargo.lock.
2022-05-04 14:31:20 +01:00
Nick Mathewson 28030c6c81 Merge branch 'fix-config-version' into 'main'
Fix config version

See merge request tpo/core/arti!482
2022-05-04 13:15:38 +00:00
Ian Jackson 9214eb5db2 tor-dirmgr: make DownloadScheduleBuilder public
This type was returned by the public DownloadSchedule::builder
function.  But the only thing that seems to have noticed that the type
name itself wasn't exported, was rustdoc.  Hmmm.
2022-05-04 13:50:12 +01:00
Nick Mathewson d0330d2c95 Fix typos 2022-05-04 13:50:12 +01:00
Ian Jackson 4bca912715 Change builder list API
The new API is (roughly) as discussed in
  https://gitlab.torproject.org/tpo/core/arti/-/issues/451

This is quite a large commit and it is not convenient to split it up.
It contains the following changes:

 * Redo the list builder and accessor macros implemnetation,
   including docs and tests.

 * Change uses of define_list_config_builder.  In each case:
   - Move the docs about the default value to the containing field.
   - Remove the other docs (which were just recapitulations, and
     are now not needed since the ListBuilder is no longer public).
   - Rewmove or replace `pub` in the define_list_builder_helper call,
     so that the builder is no longer public.
   - Change the main macro call site to use define_list_builder_helper.
   - Add a call to define_list_builder_accessors.

 * Make the module `list_builder` pub so that we have somewhere to
   put the overview documentation.

 * Consequential changes:
   - Change `outer.inner().replace(X)` to `outer.set_inner(X)`
   - Consequential changes to imports (`use` statements).
2022-05-04 13:50:10 +01:00
Ian Jackson 71911d2921 Introduce ThingListBuilder::default_list
This removes a caveat from the API and will be convenient for what is
coming.
2022-05-04 13:48:30 +01:00
Ian Jackson 8ad4735d58 Add dependency on paste crate
The list accessor macro is going to want this.
2022-05-04 13:48:30 +01:00
Ian Jackson ff624f6081 Rename NetworkConfig.fallback_caches
Previously this field was differently named to its serde and to its
accessors.  We are about to introduce a macro_rules macro which will
provide list accessors and we don't want that macro to have a field
renaming feature.

So stop renaming the field.
2022-05-04 13:41:39 +01:00
Ian Jackson f4088a755c Fix config version
This matches Cargo.lock.  I suspect a mismerge in arti!478.
2022-05-04 13:39:18 +01:00
Ian Jackson fbf5e8dcb5 Merge branch 'path' into 'main'
CfgPath overhaul

Closes #449

See merge request tpo/core/arti!478
2022-05-03 17:00:41 +00:00
Ian Jackson 2da84857a5 CfgPath: Test serialisation round-trip with a binary format
Use MessagePack.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2022-05-03 17:42:54 +01:00
Ian Jackson 1e6c6169a8 CfgPath: Make it Serialize
And provide round-trip tests.

As per https://gitlab.torproject.org/tpo/core/arti/-/issues/371
2022-05-03 17:42:54 +01:00
Ian Jackson ed970310e2 CfgPath: Overhaul API
Document that this can contain either a string for expansion, or a
literal PathBuf not for expansion.

Rename the `from_path` method to `new_literal`: a very important
difference is whether it gets expanded - less important than the Rust
type.  Also, now it takes `Into<PathBuf>`, which avoids a needless
clone.

(We don't change the API in `arti-client` because
`&tempfile::Tempdir()` doesn't implement `Into<PathBuf>`, so
`arti-client` has to have some new `as_ref` calls.)

Provide accessors `as_unexpanded_str` and `as_literal_path`.  The
deserialisation already makes this part of the stable API,l so not
pvoding accessors seems just obstructive.  They are useful for tests,
too.

Add tests for the new entrypoints, and for deserialisation of both
variants from TOML (via config, or directly) and JSON.
2022-05-03 17:42:14 +01:00
Ian Jackson ae776392fa CfgPath: Change deserialisaation of Literal variant
We introduce LiteralPath struct, so that a literal path deserialises
from
    some_path = { literal: "actual path string" }

This makes the deserialisation unambiguous.
2022-05-03 17:42:14 +01:00
Ian Jackson a150d53faa config: Enable "toml" feature
arti uses this.  Somehow this seems to be enabled by some other thing
in the crate graph, but I found that adding a similar dependency to
another crate resulted in a `config` which doesn't compile.
2022-05-03 17:42:14 +01:00
Nick Mathewson e46edc21fa Merge branch 'fs-mistrust-v2' into 'main'
Second cut at a fs-mistrust crate.

See merge request tpo/core/arti!468
2022-05-03 14:28:28 +00:00
Nick Mathewson f35b488129 fs-mistrust: write a lot about TOCTOU issues. 2022-05-03 10:03:32 -04:00
Nick Mathewson 2f467245ca fs-mistrust: Rename SecureDir to CheckedDir. 2022-05-03 10:03:32 -04:00
Nick Mathewson 2087dde3a0 fs-mistrust: Add a dangerously_trust_everyone method.
This helps make it possible to use `SecureDir` (name pending) even
when we want to disable permissions checks.  Otherwise, optional
permission checking would require users of this crate to maintain
separate code paths for the "check" and "don't check" cases.
2022-05-03 10:03:32 -04:00
Nick Mathewson 0c01fb97ac fs-mistrust: split check_one into two functions.
This will make a "trust_everyone" easier to implement.
2022-05-03 10:03:32 -04:00
Nick Mathewson ab190d2186 fs-mistrust: Make self-named groups trusted by default. 2022-05-03 10:03:32 -04:00
Nick Mathewson 703ad41265 Work around CI config weirdness.
Some of our builders put root into gid 0, but getgroups() doesn't
actually give any result.
2022-05-03 10:03:32 -04:00
Nick Mathewson 85d7084d95 fs-mistrust: Add code to make a self-named group "trusted".
This required a bit of poking through the `users` crate, to mess
with the user and group dbs.  The original goal was to "trust the
group with the same name as us", but it turned into a bit of a
production, since:

  * We want to take our own name from $USER, assuming that matches
    our uid.  (Otherwise we want to ask getpwuid_r().)
  * We only want to trust the group if we are actually a member of
    that group.
  * We want to cache this information.
  * We want to test this code.
2022-05-03 10:03:32 -04:00
Nick Mathewson c09a613590 fs-mistrust: refactor ResolvePath to avoid temporary changes.
Previously we would temporarily put self.resolved into an invalid
state by adding a path component that might be a symlink.  With this
change, we create a new temporary path object (using Cow to avoid
unnecessary allocations) and only conditionally replace
self.resolved.
2022-05-03 10:03:32 -04:00
Nick Mathewson 8e25954c49 fs-mistrust: clarify and test behavior for ".." past the fs root. 2022-05-03 10:03:32 -04:00
Nick Mathewson c9e17c5aaa Add a must_use (suggested by @diziet). 2022-05-03 10:03:32 -04:00
Nick Mathewson 7254fc60eb fs-mistrust: more examples, documentation. 2022-05-03 10:03:32 -04:00
Nick Mathewson 7f27744ef7 Add a SecureDir API for checked access to directories
The only way to get a SecureDir is by having checked a directory.
Once you have one, it encourages you to open and create files and
directories with the right permissions, and checks them for you.
2022-05-03 10:03:32 -04:00
Nick Mathewson 75633109c2 Add functionality to inspect directory content permissions
Also, explain _why_ this is pretty important.
2022-05-03 10:03:32 -04:00
Nick Mathewson d574afa230 By default, forbid special files. 2022-05-03 10:03:32 -04:00
Nick Mathewson 2042d0934b Support for "create missing directory". 2022-05-03 10:03:32 -04:00
Nick Mathewson 712b46174d Add support for trusted group IDs. 2022-05-03 10:03:32 -04:00
Nick Mathewson c4a6c6d82e Implement support for the Sticky Bit. 2022-05-03 10:03:32 -04:00
Nick Mathewson c4a5a49b55 Second cut at a fs-mistrust crate.
This crate is meant to solve #315 by giving a way to make sure that
a file or directory is only accessible by trusted users.  I've tried
to explain carefully (in comments and documentation) what this crate
is doing and why, under the assumption that it will someday be read
by another person like me who does _not_ live and breathe unix file
permissions.  The crate is still missing some key features, noted in
the TODO section.

It differs from the first version of the crate by taking a more
principled approach to directory checking: it emulates the path
lookup process (reading symlinks and all) one path change at a time,
thus ensuring that we check every directory which could enable
an untrusted user to get to our target file, _or_ which could
enable them to get to any symlink that would get them to the target
file.

The API is also slightly different: It separates the `Mistrust`
object (where you configure what you do or do not trust) from the
`Verifier` (where you set up a check that you want to perform on a
single object).  Verifiers are set up to be a bit ephemeral,
so that it is hard to accidentally declare that _every_ object
is meant to be readable when you only mean that _some_ objects
may be readable.
2022-05-03 10:03:32 -04:00