theupdateframework / python-tuf

Python reference implementation of The Update Framework (TUF)
https://theupdateframework.com/
Apache License 2.0
1.63k stars 273 forks source link

Implementation of Offline mode for TUF #2359

Open emboman13 opened 1 year ago

emboman13 commented 1 year ago

Sigstore's python client would like to use the TUF updater in a fully offline manner to allow for opt-in offline verification. To do so would require TUF to function using only locally-stored materials.

Within TUF's current implementation, regardless of the validity of already-stored materials, online access is always required. Thus far, we've been able to run the updater on a modified branch using only local materials and seek to expand this modification to allow for opt-in usage of expired metadata in offline mode. This would be useful for clients like sigstore that would to allow for verification with metadata that was previously valid. A primary use case for this would involve verifying on machines that do not necessarily maintain a connection online.

Changes on our experimental branch have been within updater.py and have consisted of adding a new boolean to UpdaterConfig and avoiding online refreshes if said boolean has been set. Further implementation would require changes to trusted_metadata_set.py to skip checks against the expiry of the metadata if the aforementioned boolean has been set.

Ideally the flow of TUF's updater with these changes would go as follows, given the boolean is set:

emboman13 commented 1 year ago

@jku @woodruffw correct me if I'm missing any details here

jku commented 1 year ago

Thanks for writing this down. I will have a look at the PR by tomorrow.

We had a TUF maintainer meeting in kubecon last week and discussed this area. The general consensus was:

jku commented 1 year ago

I'll also copy-paste my definition of the use-case -- I believe this is inline with what you wrote in the original description:

jku commented 1 year ago

Note that in the above description, if the application always uses "offline mode" after downloading for the first time, metadata never gets updated after that... So application is now left to implement some sort "max offline" time

woodruffw commented 1 year ago
  • In contrast to a normal TUF verification I would like the verification to succeed even if a metadata has expired -- the other security measures provided by TUF are still useful

I think this is the only point I have some trepidation around 🙂 -- if the metadata in question expires weekly (or less frequently), then IMO a hard error case for expired local metadata makes more sense than success (presumably with lots of warnings about expiry).

On the other hand, if these expires are <24 hours or similar, then this makes sense to me.

Otherwise, everything in https://github.com/theupdateframework/python-tuf/issues/2359#issuecomment-1521603904 sounds good, and is aligned with what we'd like on the sigstore-python client!

jku commented 1 year ago

Yeah I could easily be convinced to always respect expiry: it's definitely the part that makes me most vary of this...

It should be noted that the way sigstore clients are currently used in a lot of places would not get a lot of benefit from an offline implementation that does always respect expiry dates: in a lot of cases the client is run in a clean environment on CI so the metadata is always expired. The real fix for that issue might be to document caching and to make it as easy as possible -- so that TUF metadata gets cached and re-used.

woodruffw commented 1 year ago

in a lot of cases the client is run in a clean environment on CI so the metadata is always expired. The real fix for that issue might be to document caching and to make it as easy as possible -- so that TUF metadata gets cached and re-used.

Yeah, good point, and agreed -- that raises some interesting threat model/attack questions (what can an attacker do if they control the store that the TUF cache gets loaded from?), but IMO those questions largely boil down to "attacker controls the host" and that's already a "game over" scenario (since they could just rewrite the root of trust anyways).

(I also think, at least for CI workflows, that it makes sense to strongly encourage users to prefer online operations: they're online anyways due to the CI being online, and the privacy concerns aren't quite as salient since it isn't a personal machine. So, at least for sigstore-python, my first thought is to document offline mode as really only being useful to human signers/verifiers.)

jku commented 1 year ago

Ok, have spent a little more time with this. There's a thread on sigstore slack (https://sigstore.slack.com/archives/C024FPJKC6L/p1694691208834919) but documenting some technical details here:

jku commented 1 year ago

Documented my thinking here: https://docs.google.com/document/d/1IEVxgCsmLJNiAwdTFQ4aMvmGHJikmI_iOEHGpt8fIe8/edit?usp=sharing

Main takeaway: I don't think a user option "--offline" in sigstore or other TUF using app makes sense unless we also allow expired metadata -- otherwise it will be very difficult for users to figure out when the app will work and when it will fail

emboman13 commented 1 year ago

Hello, I've recently taken up a new job that is absorbing most of my time; thus I don't believe I will be able to offer work on this at a meaningful pace. I would be happy to offer assistance to anyone else who wanted to work on this at another time tho

jku commented 1 year ago

I have a untested branch of offline (non-expiry-respecting) mode in https://github.com/theupdateframework/python-tuf/compare/develop...jku:python-tuf:offline-mode -- It's based on the work in the existing PR and I think it looks complete now but next step is writing a bunch of tests and seeing if that's true...

emboman13 commented 1 year ago

I can take a look at it tonight

lukpueh commented 1 year ago

This has been implemented in #2472, but not been merged for the reasons summarised in https://github.com/theupdateframework/python-tuf/pull/2472#issuecomment-1818881302.

In short: there is little advantage of using TUF in offline mode, over not using TUF at all. To leverage that advantage, other work is required, which is not a priority at the moment.