From 21db98fc8343eda548e38c4d2e6669a62485fb69 Mon Sep 17 00:00:00 2001 From: Lukas Puehringer Date: Sat, 30 Nov 2019 13:07:46 +0100 Subject: [PATCH] doc: Explicitly mark roles dirty in tutorial (WIP) TUF does not reliably mark roles as dirty whose metadata needs to be re-generated. Only roles that have changed are marked as dirty, but sometimes roles metadata needs to be updated, although the role wasn't changed directly (see #958). Furthermore, the tutorial assumes at one point that the reader leaves and re-enter the interpreter session, being forced to reload the signing keys, roles that later need to be re-written, are marked as dirty. If the reader does not leave the interpreter, the roles are not marked as dirty (see #XXX). To not confuse the reader with flawed state-keeping, and to never write an inconsistent repository to disk, the tutorial lets the reader explicitly mark all roles that need to be re-written as "dirty". This can be changed once above issues are fixed. TODO: Create issue #XXX and replace in tutorial snippet comments and in this commit message Signed-off-by: Lukas Puehringer --- docs/TUTORIAL.md | 42 +++++++++++++++--------------------------- 1 file changed, 15 insertions(+), 27 deletions(-) diff --git a/docs/TUTORIAL.md b/docs/TUTORIAL.md index 43c350e1e8..e00d9e6435 100644 --- a/docs/TUTORIAL.md +++ b/docs/TUTORIAL.md @@ -227,12 +227,6 @@ top-level roles, including itself. >>> repository.root.load_signing_key(private_root_key) >>> repository.root.load_signing_key(private_root_key2) -# Print the roles that are "dirty" (i.e., that have changed and have not yet -# been written to disk. Root should be dirty because verification keys were -# added, signing keys loaded, and a threshold added) ->>> repository.dirty_roles() -Dirty roles: ['root'] - # repository.status() shows missing verification and signing keys for the # top-level roles, and whether signatures can be created (also see #955). # This output shows that so far only the "root" role meets the key threshold and @@ -297,8 +291,8 @@ Enter a password for the encrypted RSA key (/path/to/timestamp_key): # week), timestamp(1 day). >>> repository.timestamp.expiration = datetime.datetime(2080, 10, 28, 12, 8) ->>> repository.dirty_roles() -Dirty roles: ['snapshot', 'targets', 'timestamp'] +# Mark roles for metadata update (see #XXX, #958) +>>> repository.mark_dirty(['root', 'snapshot', 'targets', 'timestamp']) # Write all metadata to "repository/metadata.staged/" >>> repository.writeall() @@ -414,8 +408,8 @@ Enter a password for the encrypted RSA key (/path/to/snapshot_key): Enter a password for the encrypted RSA key (/path/to/timestamp_key): >>> repository.timestamp.load_signing_key(private_timestamp_key) ->>> repository.dirty_roles() -Dirty roles: ['root', 'snapshot', 'targets', 'timestamp'] +# Mark roles for metadata update (see #XXX, #958) +>>> repository.mark_dirty(['snapshot', 'targets', 'timestamp']) # Generate new versions of the modified top-level metadata (targets, snapshot, # and timestamp). @@ -430,14 +424,9 @@ new metadata to disk. ```python # Continuing from the previous section . . . -# Remove a target file listed in the "targets" metadata. The target file is -# not actually deleted from the file system. ->>> repository.targets.remove_target('myproject/file4.txt') ->>> repository.dirty_roles() -Dirty roles: ['targets'] +# Mark roles for metadata update (see #XXX, #958) +>>> repository.mark_dirty(['snapshot', 'targets', 'timestamp']) -# Mark roles as dirty that have not changed but need to be updated (see #958) ->>> repository.mark_dirty(['snapshot', 'timestamp']) >>> repository.writeall() ``` @@ -519,18 +508,16 @@ Enter a password for the encrypted RSA key (/path/to/unclaimed_key): >>> repository.targets("unclaimed").load_signing_key(private_unclaimed_key) ->>> repository.dirty_roles() -Dirty roles: ['targets', 'unclaimed'] +# Mark roles for metadata update (see #XXX, #958) +>>> repository.mark_dirty(['snapshot', 'targets','timestamp', 'unclaimed']) -# Mark roles as dirty that have not changed but need to be updated (see #958) ->>> repository.mark_dirty(["snapshot", "timestamp"]) >>> repository.writeall() ```